Hi !
Where should i be referencing it ? I have some in the main, but none in the player, should i put one there ?
here's my main code :
and here's my player code :
ig.module (
'game.entities.player'
)
.requires (
'impact.entity',
'impact.font',
'impact.sound'
)
.defines (function(){
EntityPlayer = ig.Entity.extend({
//AnimSheet
//animSheet: new ig.AnimationSheet ( 'media/player.png', 16, 16 ),
animSheet: new ig.AnimationSheet ( 'media/welfring.png', 30, 30 ),
//Sounds
jumpSFX: new ig.Sound( 'media/sounds/jump.*'),
shootSFX: new ig.Sound ( 'media/sounds/shoot.*'),
deathSFX: new ig.Sound( 'media/sounds/death.*' ),
//Weapons
weapon: 0,
totalWeapons: 2,
activeWeapon: "EntityBullet",
//RespawnShit
invincible: true,
invincibleDelay: 2,
invincibleTimer: null,
//Settings of image
size: {x: 30, y:30},
offset: {x: 4, y: 0},
flip: false,
//Movement
maxVel:{x:110,y:500},
friction: {x: 300, y: 10},
accelGround: 400,
accelAir:150,
jump:0,
jumpTime: 7,
isJumping: false,
//Collision
type: ig.Entity.TYPE.A,
checkAgainst: ig.Entity.TYPE.NONE,
collides: ig.Entity.COLLIDES.PASSIVE,
startPosition: null,
Action: false,
health: 20,
init: function( x, y, settings ) {
this.invincibleTimer = new ig.Timer();
this.makeInvincible();
this.startPosition = { x:x, y:y };
this.parent( x, y, settings );
this.setupAnimation( this.weapon );
},
setupAnimation: function ( offset ){
offset = offset * 10;
this.addAnim( 'idle', 1, [ 0 + offset]);
//this.addAnim( 'run',.07, [ 0 + offset, 1 + offset, 2 + offset, 3 + offset, 4 + offset, 5 + offset]);
this.addAnim( 'run',.2, [ 1 + offset, 2 + offset, 3 + offset, 2 + offset]);
this.addAnim( 'running',.1, [ 1 + offset, 2 + offset, 3 + offset, 2 + offset]);
//this.addAnim( 'running',.05, [ 0 + offset, 1 + offset, 2 + offset, 3 + offset, 4 + offset, 5 + offset]);
//this.addAnim( 'jump', 1, [ 9 + offset ]);
this.addAnim( 'jump', 1, [ 1 + offset ]);
//this.addAnim( 'fall', 0.4, [ 6 + offset, 7 + offset]);
this.addAnim( 'fall', 0.4, [ 1 + offset ]);
},
update: function(){
//move left or right
var accel = this.standing ? this.accelGround : this.accelAir;
if( this.invincibleTimer.delta() > this.invincibleDelay ) {
this.invincible = false;
this.currentAnim.alpha = 1;
}
if( ig.input.state('action')) {
ig.game.Action = true;
} else {
ig.game.Action = false;
}
if( ig.input.state('left') && this.vel.x > -70 ) {
this.accel.x = -accel;
this.flip = true;
}else if( ig.input.state('right') && this.vel.x < 70 ) {
this.accel.x = accel;
this.flip = false;
} else if ( ig.input.state('right') && ig.input.state('run')) {
this.accel.x = accel;
this.flip = false;
} else if ( ig.input.state('left') && ig.input.state('run')) {
this.accel.x = -accel;
this.flip = true;
}else{
this.accel.x = 0;
}
//jump
if( this.standing && ig.input.pressed('jump') && !this.isJumping ) {
this.jumpTime = 8;
this.jump = 10;
this.vel.y = -this.jump;
this.isJumping = true;
/*ig.game.MyNoteManager.spawnNote(new ig.Font('media/04b03.font.png'),
'my entity message ',this.pos.x, this.pos.y,
{vel: { x: 0, y: 0 }, alpha: 0.5, lifetime: 2.2, fadetime: 0.3,});*/
// this.jumpSFX.volume = 0.1;
// this.jumpSFX.play();
} else if ( ig.input.state('jump') && this.jumpTime > 0 && !this.standing && this.isJumping ) {
this.jumpTime--;
this.jump += 22;
this.vel.y = -this.jump;
} else if ( this.standing ) {
this.jumpTime = 7;
this.jump = 50;
this.isJumping = false;
} else {
this.jumpTime = 0;
}
if ( ig.input.pressed( 'shoot' ) ) {
ig.game.spawnEntity ( this.activeWeapon, this.pos.x, this.pos.y, { flip:this.flip } );
this.shootSFX.volume = 0.1;
this.shootSFX.play();
}
if( ig.input.pressed( 'switch' ) ) {
this.weapon++;
if( this.weapon >= this.totalWeapons )
this.weapon = 0;
switch( this.weapon ){
case(0): this.activeWeapon = "EntityBullet";
break;
case(1): this.activeWeapon = "EntityGrenade";
break;
}
this.setupAnimation( this.weapon );
}
if( this.vel.y < 0) {
this.currentAnim = this.anims.jump;
}else if( this.vel.y > 50 ) {
this.currentAnim = this.anims.fall;
}else if( this.vel.x != 0 && !ig.input.state('run') ) {
this.currentAnim = this.anims.run;
}else if( ig.input.state('run') && this.vel.x != 0 ) {
this.currentAnim = this.anims.running;
}else{
this.currentAnim = this.anims.idle;
}
this.currentAnim.flip.x = this.flip;
//move !
this.parent();
},
kill: function(){
this.deathSFX.volume = 0.5;
this.deathSFX.play();
this.parent();
ig.game.respawnPosition = this.startPosition;
ig.game.spawnEntity(EntityDeathExplosion, this.pos.x, this.pos.y, {callBack:this.onDeath} );
},
onDeath: function(){
ig.game.stats.deaths ++;
ig.game.lives --;
if(ig.game.lives < 0){
ig.game.gameOver();
}else{
ig.game.spawnEntity( EntityPlayer, ig.game.respawnPosition.x, ig.game.respawnPosition.y);
}
},
makeInvincible: function(){
this.invincible = true;
this.invincibleTimer.reset();
},
receiveDamage: function(amount, from) {
if ( this.invincible)
return;
this.parent( amount, from);
},
draw: function() {
if(this.invincible)
this.currentAnim.alpha = this.invincibleTimer.delta()/this.invincibleDelay * 1;
this.parent();
}
});
EntityBullet = ig.Entity.extend({
size: {x: 5, y: 3},
animSheet: new ig.AnimationSheet( 'media/bullet.png', 5, 3),
maxVel: {x: 200, y: 0},
type: ig.Entity.TYPE.NONE,
checkAgainst: ig.Entity.TYPE.B,
collides: ig.Entity.COLLIDES.PASSIVE,
init: function ( x, y, settings ) {
this.parent( x + (settings.flip ? -4 : 8), y + 8, settings);
this.vel.x = this.accel.x = ( settings.flip ? -this.maxVel.x : this.maxVel.x );
this.addAnim( 'idle', 0.2, [0] );
},
handleMovementTrace: function( res ) {
this.parent( res );
if( res.collision.x || res.collision.y ) {
this.kill();
}
},
check: function( other ) {
other.receiveDamage( 3, this );
this.kill();
}
});
EntityGrenade = ig.Entity.extend({
size: {x: 4, y: 4},
offset: {x: 2, y: 2},
animSheet: new ig.AnimationSheet( 'media/grenade.png', 8, 8 ),
type: ig.Entity.TYPE.NONE,
checkAgainst: ig.Entity.TYPE.BOTH,
collides: ig.Entity.COLLIDES.PASSIVE,
maxVel: {x: 200, y: 200},
bounciness: 0.6,
bounceCounter: 0,
init: function( x, y, settings ){
this.parent( x + ( settings.flip ? -4 : 7), y, settings);
this.vel.x = ( settings.flip ? -this.maxVel.x : this.maxVel.x );
this.vel.y = -(50 +(Math.random()*100));
this.addAnim( 'idle', 0.2, [0,1] );
},
handleMovementTrace: function( res ){
this.parent( res );
if ( res.collision.x || res.collision.y ) {
//only bounce three times
this.bounceCounter++;
if( this.bounceCounter > 3 ) {
this.kill();
}
}
},
check: function( other ){
other.receiveDamage( 10, this );
this.kill();
},
kill: function() {
for( var i = 0; i < 20; i++ )
ig.game.spawnEntity(EntityGrenadeParticle, this.pos.x, this.pos.y);
this.parent();
}
});
EntityDeathExplosion = ig.Entity.extend({
lifetime: 1,
callBack: null,
particles: 50,
init: function( x, y, settings ) {
this.parent( x, y, settings );
for ( var i = 0; i < this.particles; i++)
ig.game.spawnEntity( EntityDeathExplosionParticle, x, y, { colorOffset: settings.colorOffset ? settings.colorOffset : 0 });
this.idleTimer = new ig.Timer();
},
update: function() {
if ( this.idleTimer.delta() > this.lifetime ) {
this.kill();
if( this.callBack )
this.callBack();
return;
}
}
});
EntityDeathExplosionParticle = ig.Entity.extend({
size: {x: 2, y:2},
maxVel: {x: 260, y: 250},
lifetime: 2,
fadetime: 1,
bounciness: 0.3,
gravityFactor: 0.2,
vel: { x: 200, y:100},
friction: { x:10, y:10},
collides: ig.Entity.COLLIDES.LITE,
colorOffset: 0,
totalColors: 7,
animSheet: new ig.AnimationSheet( 'media/blood.png', 2, 2 ),
init: function( x, y, settings ) {
this.parent( x, y, settings );
var frameID = Math.round( Math.random()*this.totalColors ) + ( this.colorOffset * ( this.totalColors + 1 ));
this.addAnim( 'idle', 0.2, [frameID] );
this.vel.x = (Math.random() * 2 - 1) * this.vel.x;
this.vel.y = (Math.random() * 2 - 1) * this.vel.y;
this.idleTimer = new ig.Timer();
},
update: function() {
if( this.idleTimer.delta() > this.lifetime ) {
this.kill();
return;
}
this.currentAnim.alpha = this.idleTimer.delta().map( this.lifetime - this.fadetime, this.lifetime, 1, 0 );
this.parent();
}
});
EntityGrenadeParticle = ig.Entity.extend({
size: {x: 1, y:1},
maxVel: {x: 160, y: 200},
lifetime: 1,
fadetime: 1,
bounciness: 0.3,
vel: { x: 40, y:50},
friction: { x:20, y:20},
checkAgainst: ig.Entity.TYPE.B,
collides: ig.Entity.COLLIDES.LITE,
animSheet: new ig.AnimationSheet('media/explosion.png', 1, 1 ),
init: function ( x, y, settings) {
this.parent( x, y, settings );
this.vel.x = (Math.random() * 4 - 1) * this.vel.x;
this.vel.y = (Math.random() * 10-1) * this.vel.y;
this.idleTimer = new ig.Timer();
var frameID = Math.round(Math.random() * 7);
this.addAnim('idle', 0.2, [frameID] );
},
update: function() {
if( this.idleTimer.delta() > this.lifetime ) {
this.kill();
return;
}
this.currentAnim.alpha = this.idleTimer.delta().map( this.lifetime - this.fadetime, this.lifetime, 1, 0);
this.parent();
}
});
});
What's wrong ?
Thank you very much !