SaraTonen
Member
I have my player so that they can either press the attack button and fire a shot or hold it and fire a shot based on a cooldown. The problem I'm having is that sometimes when trying to do the press then release action, additional shots might be fired. I assume it has to do with the variable 'button_held' and there being an in between frame or two where it's value is true for both actions (held or pressed). Any thoughts would be appreciated.
Code:
//Player End Step
//Shoot Projectile
if (player_state == 0)
{
if (key_attack)
{
if (button_held > projectile_cooldown && energy >= 1) //Player Holding Button
{
var _inst = instance_create_layer(x+lengthdir_x(16, dir), y+lengthdir_y(16, dir), "Instances", obj_p_projectile);
with (_inst) direction = other.dir;
energy -= projectile_cost;
button_held = 0;
}
else
{
button_held++;
}
}
else
if (button_held > 0) //Player Pressed then Released Button
{
if (button_held < projectile_cooldown && energy >= 1)
{
var _inst = instance_create_layer(x+lengthdir_x(6, dir), y+lengthdir_y(6, dir), "Instances", obj_p_projectile);
with (_inst) direction = other.dir;
energy -= projectile_cost;
button_held = 0;
}
}
}