diff --git a/intro-to-crafty/index.html b/intro-to-crafty/index.html index 56bf795..67eb0cb 100644 --- a/intro-to-crafty/index.html +++ b/intro-to-crafty/index.html @@ -3,6 +3,7 @@ + diff --git a/intro-to-crafty/src/components.js b/intro-to-crafty/src/components.js index 5dd844d..8e232cc 100644 --- a/intro-to-crafty/src/components.js +++ b/intro-to-crafty/src/components.js @@ -22,16 +22,22 @@ Crafty.c('Grid', { } }); +Crafty.c('Actor', { + init: function() { + this.requires('2D, Canvas, Grid'); + } +}); + Crafty.c('Tree', { init: function() { - this.requires('2D, Canvas, Grid, Color'); - this.color('rgb(20, 125, 40)'); + this.requires('Actor, Color') + .color('rgb(20, 125, 40)'); } }); Crafty.c('Bush', { init: function() { - this.requires('2D, Canvas, Grid, Color'); - this.color('rgb(20, 185, 40)'); + this.requires('Actor, Color') + .color('rgb(20, 185, 40)'); } }); diff --git a/intro-to-crafty/src/game.js b/intro-to-crafty/src/game.js index bdf3ff9..e5cded6 100644 --- a/intro-to-crafty/src/game.js +++ b/intro-to-crafty/src/game.js @@ -25,23 +25,9 @@ Game = { var at_edge = x == 0 || x == Game.map_grid.width - 1 || y == 0 || y == Game.map_grid.height - 1; if (at_edge) { - Crafty.e('2D, Canvas, Color') - .attr({ - x: x * Game.map_grid.tile.width, - y: y * Game.map_grid.tile.height, - w: Game.map_grid.tile.width, - h: Game.map_grid.tile.height - }) - .color('rgb(20, 125, 40)'); + Crafty.e('Tree').at(x, y); } else if (Math.random() < 0.06) { - Crafty.e('2D, Canvas, Color') - .attr({ - x: x * Game.map_grid.tile.width, - y: y * Game.map_grid.tile.height, - w: Game.map_grid.tile.width, - h: Game.map_grid.tile.height - }) - .color('rgb(20, 185, 40)'); + Crafty.e('Bush').at(x, y); } } }