Use externalized components

cat-town
Dan Buch 10 years ago
parent 29eef55a28
commit 00bdf3b5df

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

@ -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)');
}
});

@ -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);
}
}
}

Loading…
Cancel
Save