Impact

This forum is read only and just serves as an archive. If you have any questions, please post them on github.com/phoboslab/impact

1 decade ago by sanity

I 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:
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

                    }

1 decade ago by Joncom

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

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

cast: function() {
    var x = this.pos.x + 60;
    var y = this.pos.y + 40;
    ig.game.spawnEntity( EntityBullet, x, y, {flip:this.flip} );
}

1 decade ago by sanity

Quote from Joncom
##
castTimer: new ig.Timer(),
castRate: 3, // Casts per second.

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

cast: function() {
var x = this.pos.x + 60;
var y = this.pos.y + 40;
ig.game.spawnEntity( EntityBullet, x, y, {flip:this.flip} );
}
##


Thanks for the code, you even cleaned up my slopy coding. I appreciate it.
Page 1 of 1
« first « previous next › last »