Speechbubble work
This commit is contained in:
parent
e26acf2c2e
commit
6f482e8d2c
5 changed files with 35 additions and 4 deletions
|
@ -21,7 +21,7 @@ gulp.task('server', function() {
|
|||
});
|
||||
|
||||
gulp.task('compile', function() {
|
||||
return gulp.src(['src/entities/*.coffee', 'src/items/*.coffee', , 'src/tiles/*.coffee', 'src/tools.coffee', 'src/app.coffee', 'src/game.coffee', 'src/hud.coffee'])
|
||||
return gulp.src(['src/entities/*.coffee', 'src/items/*.coffee', , 'src/tiles/*.coffee', 'src/tools.coffee', 'src/app.coffee', 'src/game.coffee', 'src/hud.coffee', 'src/speechbubble.coffee'])
|
||||
.pipe(sourcemaps.init())
|
||||
.pipe(coffee({bare: true}))
|
||||
.pipe(concat('app.js'))
|
||||
|
|
BIN
public/images/speechbubbles.png
Normal file
BIN
public/images/speechbubbles.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.4 KiB |
|
@ -5,7 +5,7 @@ app = playground(
|
|||
smoothing: false,
|
||||
|
||||
create: ->
|
||||
@loadImages "layers", "active", "progress", "selected", "entities", "hud", "actions"
|
||||
@loadImages "layers", "active", "progress", "selected", "entities", "hud", "actions", "speechbubbles"
|
||||
@currentHoveredTile = new Tile
|
||||
|
||||
ready: ->
|
||||
|
|
|
@ -4,11 +4,15 @@ app.game =
|
|||
@map[i] = new Tile(i)
|
||||
@map[20*5+10].entity = new Base
|
||||
|
||||
@mouseX = 0
|
||||
@mouseY = 0
|
||||
|
||||
@currentHoveredTile = new Tile(-1)
|
||||
@currentSelectedTile = null
|
||||
|
||||
window.setInterval @tick, 1000
|
||||
@hud.start()
|
||||
@speechbubble.start()
|
||||
|
||||
render: ->
|
||||
for tile, i in @map
|
||||
|
@ -16,6 +20,7 @@ app.game =
|
|||
x = i-(y*20)
|
||||
tile.render(x, y)
|
||||
@hud.render()
|
||||
@speechbubble.render()
|
||||
|
||||
mousedown: (event)->
|
||||
if @isMouseInView event.x/8, event.y/8
|
||||
|
@ -32,6 +37,9 @@ app.game =
|
|||
@currentSelectedTile = null
|
||||
|
||||
mousemove: (event)->
|
||||
@mouseX = event.x
|
||||
@mouseY = event.y
|
||||
|
||||
if @isMouseInView event.x, event.y
|
||||
tile = posToTile(Math.floor(event.x/8), Math.floor(event.y/8))
|
||||
|
||||
|
@ -67,8 +75,12 @@ app.game =
|
|||
@currentSelectedTile.entity = new Miner
|
||||
|
||||
createSilo: ->
|
||||
if @currentSelectedTile and @checkPosition(@currentSelectedTile) and @checkResource('stardust', 20, true)
|
||||
@currentSelectedTile.entity = new Silo
|
||||
if @currentSelectedTile
|
||||
if @checkPosition(@currentSelectedTile)
|
||||
if @checkResource('stardust', 20, true)
|
||||
@currentSelectedTile.entity = new Silo
|
||||
else
|
||||
@speechbubble.say 'toofar'
|
||||
|
||||
checkResource: (type, amount, drain = false) ->
|
||||
if @resources[type] >= amount
|
||||
|
|
19
src/speechbubble.coffee
Normal file
19
src/speechbubble.coffee
Normal file
|
@ -0,0 +1,19 @@
|
|||
app.game.speechbubble =
|
||||
start: ->
|
||||
@sprite = [0, 0, 27, 13]
|
||||
|
||||
say: (text) ->
|
||||
clearTimeout(@timeout) if @timeout
|
||||
|
||||
switch text
|
||||
when 'help' then @sprite = [0, 0, 27, 13]
|
||||
when 'toofar' then @sprite = [0, 13, 90, 13]
|
||||
|
||||
@visible = true
|
||||
@timeout = window.setTimeout @hide, 1000
|
||||
|
||||
hide: =>
|
||||
app.game.speechbubble.visible = false
|
||||
|
||||
render: ->
|
||||
app.layer.drawRegion app.images.speechbubbles, @sprite, app.game.mouseX+5, app.game.mouseY-15 if @visible
|
Loading…
Reference in a new issue