1 decade ago by dotnetprodev
I am going through the "Introducing HTML5 Game Development" book.
EntityBullet = ig.Entity.extend({
size: {x:5, y:3},
animSheet: new ig.AnimationSheet( 'media/bullet.png', 5, 3 ),
maxVel: {x:200, y:0},
type: ig.Entity.TYPE.NONE,
checkAgainst: ig.Entity.TYPE.B,
collides: ig.Entity.COLLIDES.PASSIVE,
init: function( x, y, settings ) {
this.parent( x + ( settings.flip ? -4 : 8), y+8, settings );
this.vel.x = this.accel.x = ( settings.flip ? -this.maxVel.x : this.maxVel.x );
this.addAnim( 'idle', 0.2, [0] );
},
handleTraceMovement: function( res ) {
this.parent( res );
if( res.collision.x || res.collision.y ){
this.kill();
}
},
check: function( other ) {
other.receiveDamage( 3, this );
this.kill();
}
});
It is hitting the zombies, giving damage and disappearing. But when it hits a wall it is stopping but not disappearing. Is the code in the book wrong or am I missing something?
EntityBullet = ig.Entity.extend({
size: {x:5, y:3},
animSheet: new ig.AnimationSheet( 'media/bullet.png', 5, 3 ),
maxVel: {x:200, y:0},
type: ig.Entity.TYPE.NONE,
checkAgainst: ig.Entity.TYPE.B,
collides: ig.Entity.COLLIDES.PASSIVE,
init: function( x, y, settings ) {
this.parent( x + ( settings.flip ? -4 : 8), y+8, settings );
this.vel.x = this.accel.x = ( settings.flip ? -this.maxVel.x : this.maxVel.x );
this.addAnim( 'idle', 0.2, [0] );
},
handleTraceMovement: function( res ) {
this.parent( res );
if( res.collision.x || res.collision.y ){
this.kill();
}
},
check: function( other ) {
other.receiveDamage( 3, this );
this.kill();
}
});
It is hitting the zombies, giving damage and disappearing. But when it hits a wall it is stopping but not disappearing. Is the code in the book wrong or am I missing something?