Now:
ig.module(
'game.entities.character001'
)
.requires(
'impact.entity'
)
.defines(function(){
EntityCharacter001 = ig.Entity.extend({
// Collision Area vom Character mit offset
size: {x: 8, y:14},
offset: {x: 4, y: 2},
maxVel: {x: 100, y: 200},
friction: {x: 600, y: 0},
type: ig.Entity.TYPE.A, // "Spieler" Gruppe (.B Gruppe = CPU)
checkAgainst: ig.Entity.TYPE.NONE,
collides: ig.Entity.COLLIDES.PASSIVE,
animSheet: new ig.AnimationSheet( 'media/character001.png', 16, 16 ),
// Eigenschaften
flip: false,
accelGround: 400,
accelAir: 200,
jump: 200,
health: 10,
flip: false,
init: function( x, y, settings ) {
this.parent( x, y, settings );
// Animationen
this.addAnim( 'idle', 1, [0] );
this.addAnim( 'run', 0.07, [0,1,2,3,4,5] );
this.addAnim( 'jump', 1, [9] );
this.addAnim( 'fall', 0.4, [6,7] );
},
update: function() {
// links, rechts bewegen
var accel = this.standing ? this.accelGround : this.accelAir;
if( ig.input.state('left') ) {
this.accel.x = -accel;
this.flip = true;
}
else if( ig.input.state('right') ) {
this.accel.x = accel;
this.flip = false;
}
else {
this.accel.x = 0;
}
// jump
if( this.standing && ig.input.pressed('jump') ) {
this.vel.y = -this.jump;
}
// Animation nach Spielers Geschwindigkeit aufbauen
if( this.vel.y < 0 ) {
this.currentAnim = this.anims.jump;
}
else if( this.vel.y > 0 ) {
this.currentAnim = this.anims.fall;
}
else if( this.vel.x != 0 ) {
this.currentAnim = this.anims.run;
}
else {
this.currentAnim = this.anims.idle;
}
this.currentAnim.flip.x = this.flip;
// move!
this.parent();
}
});
});
But if i split it something like this:
Character:
// Collision Area vom Character mit offset
size: {x: 8, y:14},
offset: {x: 4, y: 2},
maxVel: {x: 100, y: 200},
friction: {x: 600, y: 0},
type: ig.Entity.TYPE.A, // "Spieler" Gruppe (.B Gruppe = CPU)
checkAgainst: ig.Entity.TYPE.NONE,
collides: ig.Entity.COLLIDES.PASSIVE,
animSheet: new ig.AnimationSheet( 'media/character001.png', 16, 16 ),
// Eigenschaften
flip: false,
accelGround: 400,
accelAir: 200,
jump: 200,
health: 10,
flip: false,
init: function( x, y, settings ) {
this.parent( x, y, settings );
// Animationen
this.addAnim( 'idle', 1, [0] );
this.addAnim( 'run', 0.07, [0,1,2,3,4,5] );
this.addAnim( 'jump', 1, [9] );
this.addAnim( 'fall', 0.4, [6,7] );
}
Human Player:
update: function() {
// links, rechts bewegen
var accel = this.standing ? this.accelGround : this.accelAir;
if( ig.input.state('left') ) {
this.accel.x = -accel;
this.flip = true;
}
else if( ig.input.state('right') ) {
this.accel.x = accel;
this.flip = false;
}
else {
this.accel.x = 0;
}
// jump
if( this.standing && ig.input.pressed('jump') ) {
this.vel.y = -this.jump;
}
// Animation nach Spielers Geschwindigkeit aufbauen
if( this.vel.y < 0 ) {
this.currentAnim = this.anims.jump;
}
else if( this.vel.y > 0 ) {
this.currentAnim = this.anims.fall;
}
else if( this.vel.x != 0 ) {
this.currentAnim = this.anims.run;
}
else {
this.currentAnim = this.anims.idle;
}
this.currentAnim.flip.x = this.flip;
// move!
this.parent();
}
It wont work..