You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
ld31-space-diggers/src/speechbubble.coffee

42 lines
1012 B

app.game.speechbubble =
start: ->
@sprite = [0, 0, 27, 13]
@positioning = 'mouse'
setFix: (x, y) ->
@x = x
@y = y
@positioning = 'fixed'
setMouse: ->
@positioning = 'mouse'
say: (text, timeout = 1000) ->
clearTimeout(@timeout) if @timeout
switch text
when 'help' then @sprite = [0, 0, 27, 13]
when 'toofar' then @sprite = [0, 13, 90, 13]
when 'nores' then @sprite = [0, 26, 90, 13]
when 'nosel' then @sprite = [0, 39, 90, 13]
when 'damn' then @sprite = [0, 52, 90, 13]
when 'need' then @sprite = [0, 65, 90, 13]
when 'collect' then @sprite = [0, 78, 90, 13]
@visible = true
@timeout = window.setTimeout @hide, timeout
hide: =>
app.game.speechbubble.visible = false
render: ->
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