X
xPaz
Guest
So, in my game, at the left side of the screen there is a character that the user controls. At the right side of the screen there is a monster that walking toward the character. When the monster hits the character his hp turns to 0 and he dies. The player can attack the monster with 'X' and if the distance between them is <=5 he kills it.
now for the problem
1. Whenever i press X the attack animation ( sprite7 ) is played. problem is that if i release X halfway through the animation it stops. I want sprite7 to run a single loop every time I press X without considering if I'm holding the key or not ( holding will just cause another loop ).
2. I did not load the attacking sprite to the left but after I attack I immediately return to sprite 1 ( standing faced right ). How can I know if the attacking was made when the character looked to the left or right ?
Player Code :
I hope you guys can help me, I really want to advance forward but I have no idea how to fix this since the lack of experience.
now for the problem
1. Whenever i press X the attack animation ( sprite7 ) is played. problem is that if i release X halfway through the animation it stops. I want sprite7 to run a single loop every time I press X without considering if I'm holding the key or not ( holding will just cause another loop ).
2. I did not load the attacking sprite to the left but after I attack I immediately return to sprite 1 ( standing faced right ). How can I know if the attacking was made when the character looked to the left or right ?
Player Code :
Code:
// this part is about moving
if(keyboard_check(vk_right)) {x+=2;sprite_index = sprite2;image_speed =0.3;}
if(keyboard_check_released(vk_right)) sprite_index = sprite1;
if(keyboard_check(vk_left)) {x-=2;sprite_index = sprite4;image_speed =0.3;}
if(keyboard_check_released(vk_left)) sprite_index = sprite5;
if(hp=0) instance_destroy(); // Death
if(keyboard_check_pressed(ord('X'))) // Attack
{
sprite_index = sprite7;image_speed = 0.3;
if(distance_to_object(monster) <=5)
monster.hp =0;
}
if(keyboard_check_released(ord('X'))) sprite_index = sprite1;