Adding villages and village collection
This commit is contained in:
parent
40ddea42d6
commit
a6ec1d560e
@ -47,7 +47,8 @@ Crafty.c('PlayerCharacter', {
|
||||
this.requires('Actor, Fourway, Color, Collision')
|
||||
.fourway(4)
|
||||
.color('rgb(20, 75, 40)')
|
||||
.stopOnSolids();
|
||||
.stopOnSolids()
|
||||
.onHit('Village', this.visitVillage);
|
||||
},
|
||||
|
||||
stopOnSolids: function() {
|
||||
@ -61,5 +62,20 @@ Crafty.c('PlayerCharacter', {
|
||||
this.x -= this._movement.x;
|
||||
this.y -= this._movement.y;
|
||||
}
|
||||
},
|
||||
|
||||
visitVillage: function(data) {
|
||||
data[0].obj.collect();
|
||||
}
|
||||
});
|
||||
|
||||
Crafty.c('Village', {
|
||||
init: function() {
|
||||
this.requires('Actor, Color')
|
||||
.color('rgb(170, 125, 40)');
|
||||
},
|
||||
|
||||
collect: function() {
|
||||
this.destroy();
|
||||
}
|
||||
});
|
||||
|
@ -22,15 +22,24 @@ Game = {
|
||||
|
||||
Crafty.e('PlayerCharacter').at(5, 5);
|
||||
|
||||
var max_villages = 5;
|
||||
|
||||
for (var x = 0; x < Game.map_grid.width; x++) {
|
||||
for (var y = 0; y < Game.map_grid.height; y++) {
|
||||
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) {
|
||||
Crafty.e('Tree').at(x, y);
|
||||
} else if (Math.random() < 0.06) {
|
||||
Crafty.e('Bush').at(x, y);
|
||||
}
|
||||
|
||||
if (Math.random() < 0.02 && Crafty('Village').length < max_villages) {
|
||||
Crafty.e('Village').at(x, y);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user