Add collision bits to player

This commit is contained in:
Dan Buch 2015-05-15 22:20:39 -04:00
parent dc4af9b023
commit 40ddea42d6

View File

@ -30,22 +30,36 @@ Crafty.c('Actor', {
Crafty.c('Tree', { Crafty.c('Tree', {
init: function() { init: function() {
this.requires('Actor, Color') this.requires('Actor, Color, Solid')
.color('rgb(20, 125, 40)'); .color('rgb(20, 125, 40)');
} }
}); });
Crafty.c('Bush', { Crafty.c('Bush', {
init: function() { init: function() {
this.requires('Actor, Color') this.requires('Actor, Color, Solid')
.color('rgb(20, 185, 40)'); .color('rgb(20, 185, 40)');
} }
}); });
Crafty.c('PlayerCharacter', { Crafty.c('PlayerCharacter', {
init: function() { init: function() {
this.requires('Actor, Fourway, Color') this.requires('Actor, Fourway, Color, Collision')
.fourway(4) .fourway(4)
.color('rgb(20, 75, 40)'); .color('rgb(20, 75, 40)')
.stopOnSolids();
},
stopOnSolids: function() {
this.onHit('Solid', this.stopMovement);
return this;
},
stopMovement: function() {
this._speed = 0;
if (this._movement) {
this.x -= this._movement.x;
this.y -= this._movement.y;
}
} }
}); });