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

Place for questions and answers for all newcomers and new coders. This is a free for all forum, no question is too stupid and to noob.
Post Reply
Sanity
Posts: 10
Joined: Sat Jan 19, 2013 12:58 am

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

Post 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

                    }

User avatar
Ark
Posts: 427
Joined: Wed Jun 01, 2011 10:25 pm

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

Post 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
}
Orgullo Catracho
Sanity
Posts: 10
Joined: Sat Jan 19, 2013 12:58 am

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

Post 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});

 },




Post Reply

Return to “Beginner Help and Support”