AdriandotEXE
Member
Hello everyone,
I have imported a sprite sheet featuring my character running with a weapon. I was hoping to use this animation after the player picks up the weapon object. However, I'm unsure about how to insert the animation into the code. I know it has to take the form of an if statement, but I'm unsure as to how to implement it, without causing any trouble down the line as I insert power ups and other weapons. I wanted to use finite state machines to switch between an unarmed state and an armed state, but I don't know if that's too complicated for what I want to accomplish and I'm unsure as to how to implement that as well. I inserted most of the code in the player step event into PlayerNormal script minus the animations. Here is the code:
Player_Normal();
#region //Animation
if(!place_meeting(x,y+1,Owall))
{
sprite_index = SplayerA;
image_speed = 1;
if sign(vsp) < 0 and image_index > image_index= 68 //if going up and animation passes halfway
{
image_index = image_index= 68;
}
}
else
{
canjump= 10;
if(sprite_index == SplayerA)
{
audio_sound_pitch(snLanding,choose(0.8,1.0,1.1));
audio_play_sound(snLanding,4,false);
repeat(5)
with(instance_create_layer(x,bbox_bottom,"Bullets",Odust))
{
vsp = 0;
}
}
image_speed = 1;
if (hsp==0)
{
sprite_index = Splayer
}
else
{
sprite_index = SplayerR;
}
}
Also, currently the gun is a separate object and sprite.
if(hsp != 0) image_xscale = sign(hsp)
#endregion
I have imported a sprite sheet featuring my character running with a weapon. I was hoping to use this animation after the player picks up the weapon object. However, I'm unsure about how to insert the animation into the code. I know it has to take the form of an if statement, but I'm unsure as to how to implement it, without causing any trouble down the line as I insert power ups and other weapons. I wanted to use finite state machines to switch between an unarmed state and an armed state, but I don't know if that's too complicated for what I want to accomplish and I'm unsure as to how to implement that as well. I inserted most of the code in the player step event into PlayerNormal script minus the animations. Here is the code:
Player_Normal();
#region //Animation
if(!place_meeting(x,y+1,Owall))
{
sprite_index = SplayerA;
image_speed = 1;
if sign(vsp) < 0 and image_index > image_index= 68 //if going up and animation passes halfway
{
image_index = image_index= 68;
}
}
else
{
canjump= 10;
if(sprite_index == SplayerA)
{
audio_sound_pitch(snLanding,choose(0.8,1.0,1.1));
audio_play_sound(snLanding,4,false);
repeat(5)
with(instance_create_layer(x,bbox_bottom,"Bullets",Odust))
{
vsp = 0;
}
}
image_speed = 1;
if (hsp==0)
{
sprite_index = Splayer
}
else
{
sprite_index = SplayerR;
}
}
Also, currently the gun is a separate object and sprite.
if(hsp != 0) image_xscale = sign(hsp)
#endregion
Last edited: