game.Player = me.Entity.extend({
init : function (x, y, data) {
var image = me.loader.getImage("hello");
this.data = data;
this.onBodyEntered = false;
this._super(me.Entity, "init", [x, y, {
image: "player_idle",
width: 250,
height: 250,
anchorPoint : new me.Vector2d(0.5, 0.5)
}]);
this.body.gravity = 0;
this.body.gravityForce = 0;
this.body.removeShapeAt(0);
this.body.addShape(new me.Ellipse(this.width/2, this.width/2, 45, 45))
this.canimation = "idle";
this.playerstate = "idle";
this.newanimation = "";
this.body.collisionType = me.collision.types.PLAYER_OBJECT;
this.chooseShipImage();
},
chooseShipImage: function () {
var frame = ~~(Math.random() * 3);
this.renderable.addAnimation("idle", generateFrames(57), 57/1.4);
this.renderable.addAnimation("walk", generateFrames(42), 42/1.4);
console.log(this.canimation)
this.renderable.setCurrentAnimation("idle");
},
update : function (dt) {
this.body.update(dt);
if(!me.collision.check(this)){ // They are not colliding
this.onBodyEntered = false
}
if(this.body.vel.x != 0 || this.body.vel.y !=0){
//console.log("Player is moving");
this.canimation = "walk";
//console.log(this.renderable.getCurrentAnimationFrame())
}else{
this.canimation = "idle";
}
if(this.canimation != this.newanimation){
this.renderable.setCurrentAnimation(this.canimation)
this.renderable.image = me.loader.getImage("player_"+this.canimation)
this.newanimation = this.canimation;
}