9 years ago by KevMcKenzie
Hi Guys,
I need to stop the Player while he attacks and the running animation must not be interrupted.
Here is my Code:
(At this moment only the Attack_up animation is set.)
Oh and other tips for the code would be nice.
I'm new at the Impact Framework and Javascript.
Hope you can Help me out.
And sorry for my bad English.
I need to stop the Player while he attacks and the running animation must not be interrupted.
Here is my Code:
(At this moment only the Attack_up animation is set.)
Oh and other tips for the code would be nice.
I'm new at the Impact Framework and Javascript.
ig.module(
'game.entities.player'
)
.requires(
'impact.entity'
)
.defines(function() {
EntityPlayer = ig.Entity.extend({
size: {x: 38, y: 38},
friction: {x: 1, y: 1},
walk: 110,
run: 200,
animSheet: new ig.AnimationSheet('media/hero.png', 38, 38),
init: function (x, y, settings) {
this.parent(x, y, settings);
ig.game.player = this;
// Idle Animation
this.addAnim('idle_up', 1, [48]);
this.addAnim('idle_right', 1, [49]);
this.addAnim('idle_down', 1, [51]);
this.addAnim('idle_left', 1, [50]);
// Walk Animation
this.addAnim('walk_up', 0.1, [12,13,14,15,16,17] , false );
this.addAnim('walk_right', 0.1, [0,1,2,3,4,5] , false );
this.addAnim('walk_down', 0.1, [6,7,8,9,10,11] , false );
this.addAnim('walk_left', 0.1, [18,19,20,21,22,23] , false );
// Run Animation
this.addAnim('run_up', 0.1, [24,25,26,27,28,29] , false );
this.addAnim('run_right', 0.1, [30,30,31,32,33,33,34,31] , false );
this.addAnim('run_down', 0.1, [42,42,43,44,45,45,46,47] , false );
this.addAnim('run_left', 0.1, [40,40,39,38,37,37,36,39] , false );
// Attack Animation
this.addAnim('attack_up', 0.1, [54,55,56,57,48] , true );
this.addAnim('attack_right', 0.1, [] , true );
this.addAnim('attack_down', 0.1, [] , true );
this.addAnim('attack_left', 0.1, [] , true );
},
update: function(){
this.parent();
// Walk and Run
// Example Documentation at Walk/Run Up
// Walk/ Run left
if(ig.input.state("left")) {
if(ig.input.state("run")) {
this.vel.x = -this.run;
this.currentAnim = this.anims.run_left;
} else {
this.vel.x = -this.walk;
this.currentAnim = this.anims.walk_left;
}
}
// Walk/Run right
if(ig.input.state("right")) {
if(ig.input.state("run")) {
this.vel.x = this.run;
this.currentAnim = this.anims.run_right;
} else {
this.vel.x = this.walk;
this.currentAnim = this.anims.walk_right;
}
}
// Walk/Run up
// If Key Up is pressed
if(ig.input.state("up")) {
// If also Key Run is pressed
if(ig.input.state("run")) {
// Run Up
this.vel.y = -this.run;
// If Key right is also Pressed
if(ig.input.state("right")) {
// Animation Run right
this.currentAnim = this.anims.run_right;
// If Key left is also Pressed
} else if(ig.input.state("left")) {
// Animation run left
this.currentAnim = this.anims.run_left;
} else {
// Animation Run up
this.currentAnim = this.anims.run_up;
}
} else {
// Walk Up
this.vel.y = -this.walk;
// If Key right is also Pressed
if(ig.input.state("right")) {
// Animation Walk right
this.currentAnim = this.anims.walk_right;
// If Key left is also Pressed
} else if(ig.input.state("left")) {
// Animation Walk left
this.currentAnim = this.anims.walk_left;
} else {
// Animation Walk up
this.currentAnim = this.anims.walk_up;
}
}
}
// Walk/Run down
if(ig.input.state("down")) {
if(ig.input.state("run")) {
this.vel.y = this.run;
if(ig.input.state("right")) {
this.currentAnim = this.anims.run_right;
} else if(ig.input.state("left")) {
this.currentAnim = this.anims.run_left;
} else {
this.currentAnim = this.anims.run_down;
}
} else {
this.vel.y = this.walk;
if(ig.input.state("right")) {
this.currentAnim = this.anims.walk_right;
} else if(ig.input.state("left")) {
this.currentAnim = this.anims.walk_left;
} else {
this.currentAnim = this.anims.walk_down;
}
}
}
// After Release all Keys
if(ig.input.released("left") || ig.input.released("right") || ig.input.released("up") || ig.input.released("down")) {
if(ig.input.released("left")) {
this.currentAnim = this.anims.idle_left;
} else if(ig.input.released("right")) {
this.currentAnim = this.anims.idle_right;
} else if(ig.input.released("down")) {
this.currentAnim = this.anims.idle_down;
} else if(ig.input.released("up")) {
this.currentAnim = this.anims.idle_up;
}
this.accel.x = 0;
this.accel.y = 0;
this.vel.x = 0;
this.vel.y = 0;
}
// Walk and Run
// END
// Attack
if(ig.input.state("attack")) {
if(this.currentAnim == this.anims.idle_up || this.currentAnim == this.anims.walk_up || this.currentAnim == this.anims.run_up) {
// Attack up
this.currentAnim = this.anims.attack_up.rewind();
}
if(this.currentAnim == this.anims.idle_right || this.currentAnim == this.anims.walk_right || this.currentAnim == this.anims.run_right) {
// Attack right
}
if(this.currentAnim == this.anims.idle_left || this.currentAnim == this.anims.walk_left || this.currentAnim == this.anims.run_left) {
// Attack left
}
if(this.currentAnim == this.anims.idle_down || this.currentAnim == this.anims.walk_down || this.currentAnim == this.anims.run_down) {
// Attack down
}
}
// Attack
// END
}
});
})
Hope you can Help me out.
And sorry for my bad English.
