Start to add components
This commit is contained in:
parent
a8eca340ca
commit
29eef55a28
37
intro-to-crafty/src/components.js
Normal file
37
intro-to-crafty/src/components.js
Normal file
@ -0,0 +1,37 @@
|
||||
Crafty.c('Grid', {
|
||||
init: function() {
|
||||
this.attr({
|
||||
w: Game.map_grid.tile.width,
|
||||
h: Game.map_grid.tile.height
|
||||
})
|
||||
},
|
||||
|
||||
at: function(x, y) {
|
||||
if (x === undefined && y === undefined) {
|
||||
return {
|
||||
x: this.x / Game.map_grid.tile.width,
|
||||
y: this.y / Game.map_grid.tile.height
|
||||
}
|
||||
} else {
|
||||
this.attr({
|
||||
x: x * Game.map_grid.tile.width,
|
||||
y: y * Game.map_grid.tile.height
|
||||
});
|
||||
return this;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
Crafty.c('Tree', {
|
||||
init: function() {
|
||||
this.requires('2D, Canvas, Grid, Color');
|
||||
this.color('rgb(20, 125, 40)');
|
||||
}
|
||||
});
|
||||
|
||||
Crafty.c('Bush', {
|
||||
init: function() {
|
||||
this.requires('2D, Canvas, Grid, Color');
|
||||
this.color('rgb(20, 185, 40)');
|
||||
}
|
||||
});
|
Loading…
Reference in New Issue
Block a user