Code: Select all
/lib
/game
/entities
player.js
/levels
level1.js
Here is my entity:
Code: Select all
ig.module(
'game.entities.player'
)
.requires(
'impact.entity'
)
.defines(function(){
EntityPlayer = ig.Entity.extend({
//main properties
collides: ig.Entity.collides.ACTIVE,
type: ig.Entity.TYPE.A,
checkAgainst: ig.Entity.TYPE.B,
size: {x: 14, y: 14},
health: 1,
offset: {x: 1, y: 1},
//custom properties
//doubleJumps: 0,
//set animation sheet
animSheet: new ig.AnimationSheet('media/player.png', 16, 16),
init: function(x, y, settings) {
//add test animations
this.addAnim('idle', 1, [0]);
this.addAnim('jumping', 1, [1]);
this.addAnim('dying', 1, [2]);
this.addAnim('shootRight', 1, [3]);
this.addAnim('shootLeft', 1, [4]);
this.addAnim('wallSlideRight', 1, [5]);
this.addAnim('wallSlideLeft', 1, [6]);
//call parent constructor
this.parent(x, y, settings);
},
update: function() {
//this method called for each frame of the entity
//react to input
if (ig.input.pressed('right')) {
//walk to the right
this.vel.x = 100;
//animate walking right if on ground, or flying through air left if in air
} else if (ig.input.pressed('left')) {
//walk to the left
this.vel.x = -100;
//animate walking left if on ground, or flying through air right if in air
}
this.parent();
},
draw: function() {
this.parent();
}
});
});