GML Stationary attack and attack animation problems

B

Bengs

Guest
Hello everyone my name is Ben,

I just started using gamemaker and i am usingit for a school project.
This is my code so far except i have 2 problems

1) My attack animations doesnt seem to play al the wat
2) I dont know the code to make my character attack when he is stationary

Note: changing mouse_check_button(mb_left) to mouse_check_button_pressed(mb_left) only makes things worse.

Code:
//Variables
key_left = keyboard_check(ord("A"));
key_right = keyboard_check(ord("D"));
key_space = keyboard_check_pressed(vk_space);
key_w = keyboard_check_
pressed(ord("W"));
key_lmb = mouse_check_button(mb_left);
jump = 0;

//Attack Status
if key_lmb {
attack= 1;
} else {
attack = 0;
}

//Hp
if Chp <= 0
{
    instance_destroy();
    game_restart();
}

//calculating movement
var move = key_right - key_left;
hsp = move * walksp;
vsp = vsp + grv;

//horizontal collission
if (place_meeting(x+hsp,y,Obj_Wall))
{
    while (!place_meeting(x+sign(hsp),y,Obj_Wall))
    {
        x=x+sign(hsp);
    }
    hsp = 0;
}

if (place_meeting(x+hsp,y,Obj_GrassBlock))
{
    while (!place_meeting(x+sign(hsp),y,Obj_GrassBlock))
    {
        x=x+sign(hsp);
    }
    hsp = 0;
}

//Vertical collission
if (place_meeting(x,y+vsp,Obj_GrassBlock))
{
    while (!place_meeting(x,y+sign(vsp),Obj_GrassBlock))
    {
        y=y+sign(vsp);
    }
    vsp = 0;
}

//moving controls
if (keyboard_check(vk_nokey))
{
    image_speed = 0;
    image_index = 0;
    attack = 0;
}

if (key_right) and (vsp=0){
    if attack = 0
    {
        x = x + hsp;
        Cdmg= 0;
        image_speed = hsp/1.5;
        sprite_index = Spr_CharacterWalkRight;
    } else
        {
            attack = 1;
            image_speed = 2;
            sprite_index = Spr_CharacterAttack01Right;
            if (place_meeting(x+1,y,par_enemy))
            {
                    Cdmg=100;
            }
        }
}


if (key_left) and (vsp=0) {
    if attack = 0
    {
        x = x + hsp;
        Cdmg= 0;
        image_speed = hsp/1.5;
        sprite_index = Spr_CharacterWalkLeft;
    } else
        {
            attack = 1;
            image_speed = 2;
            sprite_index = Spr_CharacterAttack01Left;
            if (place_meeting(x+1,y,par_enemy))
            {
                    Cdmg=100;
            }
        }
}

y = y + vsp;

if (place_meeting(x,y+1,Obj_GrassBlock)) and (key_space or key_w)
{
    jump = 1;
    vsp = -3.5;
}

if (key_left) and (vsp != 0) {
    if attack = 0{
        x = x + hsp;
        Cdmg= 0;
        image_speed = 0;
        image_index = 0;
        sprite_index = Spr_CharacterWalkLeft;
        }     
        else {
            image_speed = 2;
            sprite_index = Spr_CharacterAttack01Left;
            if (place_meeting(x-1,y,par_enemy))
            {
                Cdmg=100;
            }
}
}
if (key_right) and (vsp !=0) {
    if attack = 0{
        x = x + hsp;
        Cdmg= 0;
        image_speed = 0;
        image_index = 0;
        sprite_index = Spr_CharacterWalkRight;
    } else {
            image_speed = 2;
            sprite_index = Spr_CharacterAttack01Right;
            if (place_meeting(x+1,y,par_enemy))
            {
                Cdmg=100;
            }
}
}

//Stationary Attacks
 
G

guyinboots

Guest
Your Attack animation is only gonna last when your holding down the attack key. Thats bad. What you need to do is set key_lmb to mouse_check_pressed, and get rid of the part that sets attack to 0 if your not pressing that key. Right where you have the code that sets cdmg to 100, put attack = 0; underneath so that you stop attacking after you give the enemy damage. Hope this helps
 
B

Bengs

Guest
Your Attack animation is only gonna last when your holding down the attack key. Thats bad. What you need to do is set key_lmb to mouse_check_pressed, and get rid of the part that sets attack to 0 if your not pressing that key. Right where you have the code that sets cdmg to 100, put attack = 0; underneath so that you stop attacking after you give the enemy damage. Hope this helps
Ty. Didn't work completely for me, but did really help me get tot the point where i wanted to go
 
G

guyinboots

Guest
NP, if you need any more help, just post here and I can try to help you :D
 
B

Bengs

Guest
NP, if you need any more help, just post here and I can try to help you :D
Ty. Is there a way to see what way your character is facing because if so I can make the code for my stationary attack
 
B

Bengs

Guest
Nm someone else helped thnx again al my problems are fixed :D
 
Top