ld31-space-diggers/src/speechbubble.coffee

42 lines
1012 B
CoffeeScript
Raw Permalink Normal View History

2014-12-07 15:52:54 +01:00
app.game.speechbubble =
start: ->
@sprite = [0, 0, 27, 13]
2014-12-07 18:41:33 +01:00
@positioning = 'mouse'
2014-12-07 15:52:54 +01:00
2014-12-07 18:41:33 +01:00
setFix: (x, y) ->
@x = x
@y = y
@positioning = 'fixed'
setMouse: ->
@positioning = 'mouse'
say: (text, timeout = 1000) ->
2014-12-07 15:52:54 +01:00
clearTimeout(@timeout) if @timeout
switch text
when 'help' then @sprite = [0, 0, 27, 13]
when 'toofar' then @sprite = [0, 13, 90, 13]
2014-12-07 17:31:30 +01:00
when 'nores' then @sprite = [0, 26, 90, 13]
2014-12-07 17:41:21 +01:00
when 'nosel' then @sprite = [0, 39, 90, 13]
2014-12-07 18:41:33 +01:00
when 'damn' then @sprite = [0, 52, 90, 13]
when 'need' then @sprite = [0, 65, 90, 13]
when 'collect' then @sprite = [0, 78, 90, 13]
2014-12-07 15:52:54 +01:00
@visible = true
2014-12-07 18:41:33 +01:00
@timeout = window.setTimeout @hide, timeout
2014-12-07 15:52:54 +01:00
hide: =>
app.game.speechbubble.visible = false
render: ->
2014-12-07 18:41:33 +01:00
switch @positioning
when 'mouse'
x = app.game.mouseX+5
y = app.game.mouseY-15
when 'fixed'
x = @x
y = @y
app.layer.drawRegion app.images.speechbubbles, @sprite, x, y if @visible