Working on tile stuff.

This commit is contained in:
Ruben Müller 2014-12-06 12:57:25 +01:00
parent 5bda68d44a
commit c52e532d69
3 changed files with 14 additions and 3 deletions

View file

@ -1,7 +1,9 @@
class Tile extends BaseEntity class Tile extends BaseEntity
constructor: (options) -> constructor: (options) ->
super options super options
@seed = getRandomInt 0, 4
@layers = [ @layers = [
new Tilelayer type: 'grass' new Tilelayer type: 'grass'
new Tilelayer type: 'mud' new Tilelayer type: 'mud'
@ -10,7 +12,7 @@ class Tile extends BaseEntity
new Tilelayer type: 'gold' new Tilelayer type: 'gold'
] ]
@currentLayer = 0 @currentLayer = getRandomInt 0, 4
tick: (delta) -> tick: (delta) ->
# TODO: digging deeper? # TODO: digging deeper?

View file

@ -4,7 +4,14 @@ class Tilelayer extends BaseEntity
render: (layer, x, y)-> render: (layer, x, y)->
# TODO: Draw sprite # TODO: Draw sprite
color = "green"
switch @type
when "grass" then color = "green"
when "mud" then color = "brown"
when "gravel" then color = "lightgrey"
when "stone" then color = "darkgrey"
when "gold" then color = "yellow"
layer.fillStyle color layer.fillStyle color
.fillRect x*8, y*8, 8, 8 .fillRect x*8, y*8, 8, 8

2
src/tools.coffee Normal file
View file

@ -0,0 +1,2 @@
getRandomInt = (min, max) ->
Math.floor(Math.random() * (max - min + 1)) + min;