Use externalized components

This commit is contained in:
Dan Buch 2015-05-15 22:12:32 -04:00
parent 29eef55a28
commit 00bdf3b5df
3 changed files with 13 additions and 20 deletions

View File

@ -3,6 +3,7 @@
<head> <head>
<script src="lib/crafty.js"></script> <script src="lib/crafty.js"></script>
<script src="src/game.js"></script> <script src="src/game.js"></script>
<script src="src/components.js"></script>
<script> <script>
window.addEventListener('load', Game.start); window.addEventListener('load', Game.start);
</script> </script>

View File

@ -22,16 +22,22 @@ Crafty.c('Grid', {
} }
}); });
Crafty.c('Actor', {
init: function() {
this.requires('2D, Canvas, Grid');
}
});
Crafty.c('Tree', { Crafty.c('Tree', {
init: function() { init: function() {
this.requires('2D, Canvas, Grid, Color'); this.requires('Actor, Color')
this.color('rgb(20, 125, 40)'); .color('rgb(20, 125, 40)');
} }
}); });
Crafty.c('Bush', { Crafty.c('Bush', {
init: function() { init: function() {
this.requires('2D, Canvas, Grid, Color'); this.requires('Actor, Color')
this.color('rgb(20, 185, 40)'); .color('rgb(20, 185, 40)');
} }
}); });

View File

@ -25,23 +25,9 @@ Game = {
var at_edge = x == 0 || x == Game.map_grid.width - 1 || y == 0 || y == Game.map_grid.height - 1; var at_edge = x == 0 || x == Game.map_grid.width - 1 || y == 0 || y == Game.map_grid.height - 1;
if (at_edge) { if (at_edge) {
Crafty.e('2D, Canvas, Color') Crafty.e('Tree').at(x, y);
.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)');
} else if (Math.random() < 0.06) { } else if (Math.random() < 0.06) {
Crafty.e('2D, Canvas, Color') Crafty.e('Bush').at(x, y);
.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)');
} }
} }
} }