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 Jerczu

This is a pretty basic way I developed a simple combo counter in my game.


In your player entity add these attributes

        comboModeTimer:new ig.Timer(),
	comboModeCooldown: new ig.Timer(),
	comboHit:0,
	isInComboMode:false,
	isInComboCooldown:false,

In your player entity init function add

                this.comboModeTimer.set(1);
		this.comboModeCooldown.set(2);

This will set the timers to 1 sec for combo and 2 sec for cooldown - so you will need to attack opponent within one second more than one time.

Ok now go to your enemy code

In your check or receiveDamage (depending on when you count your combos - in my game combo is counted on catch so I do it on check) function add these lines (of course check if other is a player entity first)

		    if(!other.isInComboMode && !other.isInComboCooldown){
			other.isInComboMode = true;
			other.comboModeTimer.reset();
			other.comboHit++
		    }else if(other.isInComboMode && !other.isInComboCooldown){
			other.comboModeTimer.reset();
			other.comboHit++
		    }

what it does simply it checks if player is not in cooldown mode and if it is or isnt in combo mode - if combo mode is not started set the combo mode in player - reset the timer for combo mode and add a hit to combo. Every time while in combo mode add a hit and reset combo timer.

Now go back to your player entity and in update function add these

if(this.comboModeTimer.delta()>0 && this.isInComboMode){
			this.isInComboCooldown = true;
			this.comboModeCooldown.reset();
			this.isInComboMode = false;
			this.comboHit = 0;
		}

And these

		if(this.comboModeCooldown.delta()>0){
			this.isInComboCooldown = false;
		}

So that is pretty much it - So if comboMode timer exceeded limit amount (1s) set the cooldownMode reset cooldown timer turn off combo mode and reset the hit counter. And once the cooldown mode is finished set cooldown mode to false.


Finally you may want to check the combo running in your main.js draw function add this

var player = this.getEntitiesByType( EntityPlayer )[0];
		if(player.comboHit>1){
			this.font.draw( player.comboHit+'Hit Combo', 300, 10, ig.Font.ALIGN.CENTER );
		}

That is it...

1 decade ago by Jerczu

Enjoy

It does work (I just copied it from my game) - so if it doesn't work in your game you may be doing something wrong.

PS: You check if other is player entity this way
In your enemy (check or receiveDamage)
if(other instanceof EntityPlayer){
//your combo / kill code
}

1 decade ago by alexandre

Thanks for this. Will come in handy.
Page 1 of 1
« first « previous next › last »