M
MegaGamer99
Guest
Greetings, Game Makers!
While I'm implementing animations for my game, I happen to run towards a few issues:
While I'm implementing animations for my game, I happen to run towards a few issues:
- I don't know a way to add a horizontal squish sprite whenever I run into a wall and turn back to normal (I tried doing it but the squished sprite stayed that way whenever I still touched the wall).
- The squished sprite for my vertical collision (AKA the crouch sprite) works, but landing on the floor had the sprite changing back to normal quicker than the sprite change on collision with the ceiling.
- And finally, whenever Kirby has Fall mode on and landing on the floor, his fall2 sprite changes after colliding the floor the first time, I want the fall2 sprite to change after the Fall bounce (performed when colliding with the floor in Fall mode).
Code:
Create Event:
execute code:
//-----Intitialize Variables-----//
movespeed = 2; //Moving speed (2 pixels per frame)
runspeed = 4;//Running Speed (4 pixels per frame)
jumpspeed = -7; //Jumping speed (negative because it goes up)
grav = 0.6; //Gravity strength (usually a small value)
//These variables are actually used to move the player
hsp = 0; //Horizontal speed
vsp = 0; //Vertical speed
ground = 1; //Whether the player is on the ground
Duck = false;
Fall = false;
step = 0;
Step Event:
execute code:
//-----Keyboard Input-----//
Key_Left = keyboard_check(vk_left);
Key_Right = keyboard_check(vk_right);
Key_Jump = keyboard_check_pressed(ord('Z'));
//This one's for variable jump height:
Key_Fall = keyboard_check_released(ord('Z'));
Key_Down = keyboard_check(vk_down);
Key_Attack = keyboard_check(ord('X'));
//Horizontal Motion
if (Key_Left) and (Duck = false)
{
hsp = -movespeed; //Walk left
image_xscale = -1; //Face left
}
if (Key_Right) and (Duck = false)
{
hsp = movespeed; //Walk right
image_xscale = 1; //Face right
}
//Movement Key Release
if (!Key_Left) and (!Key_Right) hsp = 0;
//Vertical Motion
//Is the player in the air?
if (place_meeting(x,y+1,obj_blockpar)) ground = 1;
else ground = 0;
if (Key_Jump and ground and !Key_Down)
{
vsp = jumpspeed;
}
//Variable Jumping
if (Key_Fall and !ground and vsp < -3 and !Key_Down) vsp = -2;
//Fall with gravity
if (!ground) vsp += grav;
//Limit Vspeed
if (vsp > 6) vsp = 6;
//Horizontal Collision
if (place_meeting(x+hsp,y,obj_blockpar))
{
while(!place_meeting(x+sign(hsp),y,obj_blockpar))
{
x += sign(hsp);
}
hsp = 0;
}
x += hsp;
//Vertical Collision
if (place_meeting(x,y+vsp,obj_blockpar))
{
while(!place_meeting(x,y+sign(vsp),obj_blockpar))
{
y += sign(vsp);
}
vsp = 0;
}
y += vsp;
//Ducking
if (Key_Down) and (Duck = false) and (ground = 1)
Duck = true;
if (Duck = true) and (ground = 1) and (hsp != 0)
{
if (hsp > 0) hsp -= movespeed;
if (hsp < 0) hsp += movespeed;
}
if (!Key_Down) and (Duck = true)
Duck = false;
//Falling
if (ground = 0 and vsp > 0 and Fall = false)
{
step += 1;
}else{
step = 0;
}
if (step = 17 and Fall = false)
{
if (step < 17) step = 17;
Fall = true;
}
if (ground = 1)
{
if (Fall = true)
vsp = -4;
Fall = false;
}
//Sprite Change
if (ground = 1) and (hsp = 0)
sprite_index = spr_kirby_idle;
if (ground = 0)
sprite_index = spr_kirby_jump;
if (ground = 0) and (vsp > 0)
sprite_index = spr_kirby_fall;
if (ground = 1) and (hsp != 0)
sprite_index = spr_kirby_walk; image_speed = 0.30;
if (Duck = true) and (Key_Down)
sprite_index = spr_kirby_duck;
if (Fall = true)
sprite_index = spr_kirby_fall2;
if (place_meeting(x,y+1,obj_blockpar)) and (ground = 0)
sprite_index = spr_kirby_duck;
if (place_meeting(x,y-1,obj_blockpar)) and (ground = 0)
sprite_index = spr_kirby_squishv;
//Mask Change
if (Duck = true) or (sprite_index = spr_kirby_duck)
{
mask_index = spr_kirby_mask2;
}else{
mask_index = spr_kirby_mask1;
}
if (sprite_index = spr_kirby_squish)
{
mask_index = spr_kirby_mask3;
}else{
mask_index = spr_kirby_mask1;
}