Wouldn't you already have all the entities set up? Like each tetroid would be its own entity with its animations and sprites defined.
Then in the main game loop you would just randomly generate a new entity and add it into the game?
Is there some reason you can't / don't want to do this?
I'll go that way i think. But right now i'm confronted to a new problem, i can't call my new entity, here's the code :
ig.module(
'game.entities.cubeplayer'
)
.requires(
'impact.entity'
)
.defines(function(){
EntityCubeplayer = ig.Entity.extend({
size: {x:35, y:54},
collides: ig.Entity.COLLIDES.ACTIVE,
timer: new ig.Timer(), //le timer se déclenche
animSheet: new ig.AnimationSheet( 'media/cube.png', 35, 54 ), //sprite meuf
init: function( x, y, settings ) {
this.addAnim( 'idle', 1, [0] );
this.parent( x, y, settings );
this.pos.x = 64;
this.pos.y = 0;
},
update: function() {
var counter = this.timer.delta(); //on distribue la valeur du timer à la variable
if( ig.input.state('left') ) {
this.vel.x = -100;
}
else if( ig.input.state('right') ) {
this.vel.x = 100;
}
else if(ig.input.pressed('down') ) {
counter++;
if(counter >= 1) {
this.pos.y = this.pos.y + 1;
counter--;
}
}
else {
this.vel.x = 0;
}
if(counter > 1){
this.timer.reset();
this.pos.y = this.pos.y + 27;
}
if(this.pos.y >= 266) {
this.pos.y = 266;
this.vel.x = 0;
this.time.pause();
}
this.parent();
}
});
SecondEntityCubeplayer = ig.Entity.extend({
size: {x:64, y:64},
collides: ig.Entity.COLLIDES.ACTIVE,
timer: new ig.Timer(),
animSheet: new ig.AnimationSheet( 'media/cube2.png', 64, 64 ), //sprite meuf
init: function( x, y, settings ) {
this.addAnim( 'idle', 1, [0] );
this.parent( x, y, settings );
},
update: function() {
var counter = this.timer.delta(); //on distribue la valeur du timer à la variable
if( ig.input.state('left') ) {
this.vel.x = -100;
}
else if( ig.input.state('right') ) {
this.vel.x = 100;
}
else if(ig.input.state('down') ) {
counter++;
if(counter >= 1) {
this.pos.y = this.pos.y + 1;
counter--;
}
}
else {
this.vel.x = 0;
}
if(counter > 1){
this.timer.reset();
this.pos.y = this.pos.y + 27;
}
if(this.pos.y >= 266) {
this.pos.y = 266;
this.vel.x = 0;
}
this.parent();
}
});
});
I dont find any way to put the following line
ig.game.spawnEntity(SecondCubePlayer, 64, 0)
i tried all kind of condition, i think i must create a function but what condition could trigger that second entity ?