Skip to content
Open
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions Cakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{exec} = require 'child_process'
COFFEE = 'coffee --compile'
COFFE_MAP = '#{COFFEE} --map'

task 'build', 'Build client and server code', ->
invoke 'build:client'
invoke 'build:server'

task 'build:client', 'Build client code only', ->
exec "#{COFFEE} client/js/", (err, stdout, stderr) ->
throw err if err

task 'build:server', 'Build server code only', ->
exec "#{COFFEE} server/js/", (err, stdout, stderr) ->
throw err if err
44 changes: 44 additions & 0 deletions client/js/animation.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
define ->
class Animation
constructor: (@name, @length, @row, @width, @height) ->
@reset()

tick: ->
i = @currentFrame.index

if i < @length - 1 then i += 1 else i = 0

if @count > 0 and i is 0
@count -= 1
if @count is 0
@currentFrame.index = 0
@endcount_callback()
return

@currentFrame.x = @width * i
@currentFrame.y = @height * @row
@currentFrame.index = i

setSpeed: (@speed) ->

setCount: (@count, @endcount_callback) ->

isTimeToAnimate: (time) ->
(time - @lastTime) > @speed

update: (time) ->
if @lastTime is 0 and @name[..3] is "atk"
@lastTime = time

if @isTimeToAnimate time
@lastTime = time
@tick()
true
else
false

reset: ->
@lastTime = 0
@currentFrame = { index: 0, x: 0, y: @row * @height }

Animation
14 changes: 14 additions & 0 deletions client/js/area.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
define ->
class Area
constructor: (@x, @y, @width, @height) ->

contains: (entity) ->
if entity?
entity.gridX >= @x and
entity.gridY >= @x and
entity.gridX < @x + @width and
entity.gridY < @y + @height
else
false

Area
55 changes: 55 additions & 0 deletions client/js/bubble.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
define ['jquery', 'timer'] ($, timer) ->

class Bubble
constructor: (@id, @element, time) ->
@timer = new Timer(5000, time)

isOver: (time) ->
if @timer.isOver time
true
false

destroy: ->
$(@element).remove()

reset: (time) ->
@timer.lastTime = time

class BubbleManager
constructor: (@container) ->
@bubbles = {}

getBubbleById: (id) ->
if id in @bubbles
@bubbles[id]
null

create: (id, message, time) ->
if @bubbles[id]
@bubbles[id].reset(time)
$("#"+id+" p").html(message)
else
el = $("<div id=\""+id+"\" class=\"bubble\"><p>"+message+"</p><div class=\"thingy\"></div></div>") #attr('id', id)
$(el).appendTo @container
@bubbles[id] = new Bubble(id, el, time)

update: (time) ->
for bubble in @bubbles[0..@bubbles.length] # Don't mutate the list being iterated over
if bubble.isOver(time)
bubble.destroy()
delete @bubbles[bubble.id]

clean: ->
bubble.destroy(); delete @bubbles[bubble.id] for bubble in @bubbles
@bubbles = {}

destroyBubble: (id) ->
bubble = @getBubbleById(id)
if bubble
bubble.destroy()
delete @bubbles[id]

forEachBubble: (callback) ->
calback(bubble) for bubble in @bubbles

BubbleManager
23 changes: 23 additions & 0 deletions client/js/item.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
define ['entity'], -> (Entity)
class Item extends Entity
constructor: (id, kind, @type) ->
super id, kind

@itemKind = Types.getKindAsString kind
@wasDropped = false
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking through this now (relearning CoffeeScript 😄), why no "type" variable?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In CoffeeScript, you can prefix a parameter with @ (in this case type), to have it set as an instance variable. This way, you can avoid an extra line of code (this.type = type).

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. 😄 I think my brain is in "slow absorbing mode".

This might take a while. 😦


hasShadow: -> true

onLoot: (player) ->
if @type == "weapon"
player.switchWeapon @itemKind
else if @type == "armor"
player.armorloot_callback @itemKind

getSpriteName: ->
"item-" + @itemKind

getLootMessage: ->
@lootMessage

Item
23 changes: 23 additions & 0 deletions client/js/tile.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
define ->
class Tile

class AnimatedTile extends Tile
constructor: (@id, @length, @speed, @index) ->
@startId = id
@lastTime = 0

tick: ->
if (@id - @startId) < @length - 1
@id += 1
else
@id = @startId

animate: (time) ->
if (time - @lastTime) > @speed
@tick()
@lastTime = time
true
else
false

AnimatedTile