• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

GameMaker Help with Attacking States

E

elikapika

Guest
So I've mostly been using Shaun Spalding's tutorials on GMS/GMS2, and I'm currently adding attacks into my platformer game. I have a standard attack so far, but I am trying to add others, such as when you attack in the air, attack with the down button, and so on. However, I'm not sure how to get these other attack states to work.
Code:
vsp = 0;
hsp = 0;

if (sprite_index !=attack)
{
    sprite_index = attack;
    image_index = 0;
    ds_list_clear(hitByAttack);
}

mask_index = hb;
var hitByAttackNow = ds_list_create();
var hits = instance_place_list(x,y,enemy,hitByAttackNow, false);
if (hits > 0)
{
    for (var i =0; i<hits; i++)
    {
        var hitID = hitByAttackNow[| i];
        if (ds_list_find_index(hitByAttack,hitID)== -1)
        {
            ds_list_add(hitByAttack,hitID);
            with(hitID)
            {
               //what will happen to the enemy, currently does nothing ;
            }   
        }
    }
}
ds_list_destroy(hitByAttackNow);
mask_index = s_idle;
if (animation_end())
{
    sprite_index = s_idle;
    state = PLAYERSTATE.FREE;
}
The code above is the normal attack, which does work. I thought using this same code for everything else and changing the different animations would still work.
The code in which would change the states would be this:
Code:
if (key_attack) state = PLAYERSTATE.ATTACK;
if (key_attack and !onGround) state = PLAYERSTATE.AIR_ATTACK;
if (key_attack and !onGround and keyboard_check_direct(vk_down)) state = PLAYERSTATE.DOWN_ATTACK_AIR;
if (key_attack and !onGround and keyboard_check_direct(vk_up)) state = PLAYERSTATE.UP_ATTACK_AIR;
if (key_attack and keyboard_check_direct(vk_down)) state = PLAYERSTATE.DOWN_ATTACK;
if (key_attack and keyboard_check_direct(vk_up)) state = PLAYERSTATE.UP_ATTACK;
onGround is a variable that uses a script with the code
Code:
return place_meeting(x,y+1,c);
The result of doing anything but the normal attack results in the player character floating higher than a regular jump allows, and falls back down to the ground, but is still in the fall animation. Movement is locked once the player hits the ground.

Sorry if I messed anything up with my first time posting here, and I hope I don't make some people irritated with my use of tutorials and/or if this is a simple question.
 

Alexx

Member
Welcome to the forum.

There seems to be a few errors in your logic, for example:
Code:
if (key_attack and !onGround and keyboard_check_direct(vk_down)) state = PLAYERSTATE.DOWN_ATTACK_AIR;
Then this:
Code:
if (key_attack and keyboard_check_direct(vk_down)) state = PLAYERSTATE.DOWN_ATTACK;
Will set to PLAYERSTATE.DOWN_ATTACK regardless of the first check when key_attack and key down.
 
E

elikapika

Guest
Welcome to the forum.

There seems to be a few errors in your logic, for example:
Code:
if (key_attack and !onGround and keyboard_check_direct(vk_down)) state = PLAYERSTATE.DOWN_ATTACK_AIR;
Then this:
Code:
if (key_attack and keyboard_check_direct(vk_down)) state = PLAYERSTATE.DOWN_ATTACK;
Will set to PLAYERSTATE.DOWN_ATTACK regardless of the first check when key_attack and key down.
I did notice that when I try to do the down air, it doesn't really work at all. Although my first issue was me forgetting to add the cases, I'm now not sure how to correct this.
Code:
if (key_attack and down and !onGround and state != PLAYERSTATE.DOWN_ATTACK) state = PLAYERSTATE.DOWN_ATTACK_AIR;
if (key_attack and up and !onGround and state != PLAYERSTATE.UP_ATTACK) state = PLAYERSTATE.UP_ATTACK_AIR;
I tried doing this, but this doesn't seem to work either.
 
Top