Draw the tiles

This commit is contained in:
Aaron Mueller 2014-12-06 12:37:57 +01:00
parent 374ccd95ce
commit 5bda68d44a
4 changed files with 21 additions and 12 deletions

View file

@ -1,3 +1,3 @@
class Base_entity class BaseEntity
constructor: (options) -> constructor: (options) ->
{} = options {} = options

View file

@ -1,4 +1,4 @@
class Tile extends Base_entity class Tile extends BaseEntity
constructor: (options) -> constructor: (options) ->
super options super options
@ -10,8 +10,11 @@ class Tile extends Base_entity
new Tilelayer type: 'gold' new Tilelayer type: 'gold'
] ]
@currentLayer = 0
tick: (delta) -> tick: (delta) ->
# TODO: digging deeper? # TODO: digging deeper?
render: -> render: (x, y)->
app.layer.fillStyle("#fff").fillRect(0, 0, 8, 8); tile = @layers[@currentLayer]
tile.render(app.layer, x, y)

View file

@ -1,3 +1,10 @@
class Tilelayer extends Base_entity class Tilelayer extends BaseEntity
constructor: (options) -> constructor: (options) ->
{@type, @depth, @amount} = options {@type, @depth, @amount} = options
render: (layer, x, y)->
# TODO: Draw sprite
color = "green"
layer.fillStyle color
.fillRect x*8, y*8, 8, 8

View file

@ -1,4 +1,4 @@
app.game = { app.game =
start: -> start: ->
for i in [0..20*15] for i in [0..20*15]
@map[i] = new Tile @map[i] = new Tile
@ -9,8 +9,8 @@ app.game = {
.fillRect 0, 0, 200, 50 .fillRect 0, 0, 200, 50
render: -> render: ->
for i in @map for tile, i in @map
i.render() tile.render(i-(Math.floor(i/20)*20), Math.floor(i/20))
step: -> step: ->
@hud @hud
@ -20,4 +20,3 @@ app.game = {
resources: resources:
ore:50 ore:50
stone: 100 stone: 100
}