1 decade ago by bitmapshades
I'm following the tutorial to create a zombie monster class from the HTML5 game book by Jesse Freeman.. but I can't get the entity to move with the update function code explained in the chapter. My sprite size is 40 x 40 pixels with a 10 pixel offset so how do I modify it to work with this code example?
ig.module(
'game.entities.thug'
)
.requires(
'impact.entity'
)
.defines(function(){
EntityThug = ig.Entity.extend({
animSheet: new ig.AnimationSheet( 'media/thug.png', 40, 40 ),
size: {x: 40, y: 40},
offset: {x: 10, y: 0},
maxVel: {x: 100, y: 100},
flip: false,
friction: {x: 100, y: 0},
health: 10,
type: ig.Entity.TYPE.B, // Evil enemy group
checkAgainst: ig.Entity.TYPE.A, // Check against friendly
collides: ig.Entity.COLLIDES.PASSIVE,
init: function( x, y, settings ) {
this.parent( x, y, settings );
//this.addAnim( 'idle', 1, [0] );
this.addAnim( 'walk', 0.7, [1,2,3,4,5] );
},
update: function() {
// near an edge? return!
if( !ig.game.collisionMap.getTile(
this.pos.x + (this.flip ? +4 : this.size.x -4),
this.pos.y + this.size.y+1
)
) {
this.flip = !this.flip;
}
var xdir = this.flip ? -1 : 1;
this.vel.x = this.speed * xdir;
this.parent();
},
handleMovementTrace: function( res ) {
this.parent( res );
// collision with a wall? return!
if( res.collision.x ) {
this.flip = !this.flip;
}
},
check: function( other ) {
other.receiveDamage( 10, this );
}
});
});
