HELP Shooting- Change Sprite on earth vs air

R

RPC PRO

Guest
*Not native English speaker


Hi, im having troubles changing the sprite of my player while he shoots (sp_nr_shoot1).



1° problem:
The sprite doesnt finish and it change immediately to the "stand sprite (sp_nr_stand)", i need that the animation of the shoot sprite keeps playing till the end.

2° problem:
I need it to change while its in the air,to a second sprite ( sp_nr_shootair). I havent make it code yet, because i dont know how.

3° problem:
If need a third sprite change, while the player is running and shooting. Something like:
if (move!=0) while button 1 sprite_index = sp_nr_runshoot;


I think that i have the trouble in the //input part of the code, in the
button1 = keyboard_check_pressed(vk_space);

And in the //animation part:
if button1 sprite_index = sp_nr_shoot1;

Everything else works fine.
If someone can help me please.
Thanks a lot.


--------------------------------------------------------------------------------------------------------------------------------------------


Here is the code: its in the step event

//input ( IMPORTANT)
key_right = keyboard_check(vk_right) or keyboard_check(ord("D"));

key_left = -keyboard_check(vk_left) -keyboard_check(ord("A"));

key_jump = keyboard_check_pressed(vk_up) or keyboard_check(ord("W"));

button1 = keyboard_check_pressed(vk_space); // this is the shoot button

key_down = keyboard_check(ord("S"));

//React to inputs
move = key_left + key_right;
hsp = move * movespeed;
if (vsp < 30) vsp += grav;

if (place_meeting(x,y+1,obj_muros_1))
{
if (key_jump) vsp = -jumpspeed
}

//Horizontal Collision
if (place_meeting(x+hsp,y,obj_muros_1))
{
yplus=0;
while (place_meeting(x+hsp,y-yplus,obj_muros_1) && yplus <= abs(1*hsp)) yplus +=1;
if place_meeting(x+hsp,y-yplus,obj_muros_1)
{
while(!place_meeting(x+sign(hsp),y,obj_muros_1))x += sign(hsp);
hsp = 0;
}
else
{
y -=yplus;
}
}
x += hsp;

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


//animation ( IMPORTANT)
if (move!=0) image_xscale = move;

if (place_meeting(x,y+1,obj_muros_1))
{
if (move!=0) sprite_index = sp_nr_run; else sprite_index = sp_nr_stand;
}
else

{
if (vsp < 0) sprite_index = sp_nr_jumpup; else sprite_index = sp_nr_jumpdown;
};

if button1 sprite_index = sp_nr_shoot1;
 
I think what you need is something called a "Finite State Machine". It's a programming organizational concept that will help you have full control over what your character is doing at any time. Look it up, read about it, and then re-organize your code to fit into one. You'll have a lot more control over what your character is doing at any one time, including what sprite it's using, and whether it can finish it's animation or not.
 
I

ItchyPancake

Guest
you could just reorganize your code so that certain animations have priority. What ever is on the bottom of your step event replaces what is above it.

Idle animation
Shoot Animation
Running Animation
Running Shooting Animation
Jump Animation
Jump Shoot Animation

That order should keep the correct sprite above.
As for finishing the shooting animation, make a variable and an alarm

if shoot = 0{
No keypress{
idle animation}}

No A or D (left or right) and shooting{
shoot animation
image_index =0
shooting = 1}

if shoot =0{
A or D{
Running animation}}

A or D + shooting{
Running Shooting animation
image_index =0
shoot = 1}

if shoot = 0{
Jumping{
Jump}}

Jump + shoot{
Jump Shoot
image_index =0
shoot = 1}


THEN on the animation end event, just say
if shoot = 1{
shoot = 0}
 
Top