Page 1 of 1

Impact engine, 2d Idle shooter. Need help with timer.

Posted: Fri Apr 26, 2013 9:55 pm
by Sanity
am attempting to make an idle game that can still be entertaining to interact with. To do this im using 2d type play style where you can move around but the direction in which you shoot and mob spawn is static.

The timer i need help with is getting the Fireball that you just casted, to only cast once every so many seconds. Right now i have only been able to get it to animate as a flamethrower where the Fireball is casted continuously, and where its casted for a few seconds and then stops all together.

Here is the main code for spawning the Fireball:

Code: Select all

if(this.countdown = false){

                  this.cast.set(0.5);
                  this.countdown = true;
  }

                  if(this.cast.delta() == 0){
                    if(this.countdown = true){
                      ig.game.spawnEntity( EntityBullet, this.pos.x + 60, this.pos.y + 40, {flip:this.flip} );
                        this.cast.reset();
                      }
                  }
                      else{
                    this.countdown = false;//conditions met reset the trigger to allow this action be triggered again

                    }


Re: Impact engine, 2d Idle shooter. Need help with timer.

Posted: Sat Apr 27, 2013 1:16 pm
by Ark
Not so sure what you're asking but you mean a timer that fires when the player cast a fireball right?

player.js

Code: Select all

if( ig.input.pressed('x') && this.cast.delta() > 0 ) {
 this.cast.reset()
 // spawn the fireball
}

Re: Impact engine, 2d Idle shooter. Need help with timer.

Posted: Tue Apr 30, 2013 6:04 pm
by Sanity
no, sorry about not being to clear. It actually to me a while to figure it out but, i needed a way to set it up so it would cast one at a time by itself on a timer continuously:

Code: Select all

//declare:
//        castTimer: new ig.Timer(),
//        castRate: 3, // Casts per second.

update: function(){
                // casting rate
        	if( this.castTimer.delta() >= 1 / this.castRate ){
                  this.cast();
                  this.castTimer.reset();

         }
},

// Casting fireball
	cast: function(){
          var x = this.pos.x + 35;
          var y = this.pos.y + 50;
          ig.game.spawnEntity( EntityFireball, x, y, {flip:this.flip});

 },