M
MegaGamer99
Guest
Greetings, Game Makers!
I've been working on my engine, and when I was about to add a sliding action, he doesn't move!
It was probably because of one of the pieces of code on his ducking action, since I couldn't get him to stop moving when he's ducking. I cleared out the sliding action, so I can start over.
So to recap, I need help on giving Kirby the ability to slide, and here's how it works:
Here is the code for reference:
I've been working on my engine, and when I was about to add a sliding action, he doesn't move!
It was probably because of one of the pieces of code on his ducking action, since I couldn't get him to stop moving when he's ducking. I cleared out the sliding action, so I can start over.
So to recap, I need help on giving Kirby the ability to slide, and here's how it works:
- While Ducking, pressing the Jump button while on the ground should cause Kirby to slide.
- While Sliding, his initial hspeed should be like 8, and his hspeed should go down by 1.
- He should exit Sliding mode when he either falls off of the ground, his hspeed hits 0, or when he hits the wall.
Here is the code for reference:
Code:
Create Event:
execute code:
//-----Intitialize Variables-----//
movespeed = 2; //Moving speed (2 pixels per frame)
flyspeed = -4;
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
flying = false;
falling = false;
step = 0;
ducking = false;
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_Attack = keyboard_check(ord('X'));
Key_Down = keyboard_check(vk_down);
//Horizontal Motion
if (Key_Left) and (!ducking)
{
hsp = -movespeed; //Walk left
image_xscale = -1; //Face left
}
if (Key_Right) and (!ducking)
{
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 !ducking)
{
vsp = jumpspeed;
}
//Variable Jumping
if (!flying)
{
if (Key_Fall and !ground and vsp < -3) vsp = -2;
}
//Fall with gravity
if (!ground) vsp += grav;
//Limit Vspeed
if (!flying)
{
if (vsp > 6) vsp = 6;
}
if (flying)
{
if (vsp > 1) vsp = 1;
}
//Flying
if (!ground) and (Key_Jump)
flying = true;
if (Key_Jump) and (flying)
vsp = flyspeed;
if (Key_Attack and flying)
{
flying = false;
}
if (flying) faling = false;
//Falling
if (!ground and vsp > 0 and !falling and !flying)
{
step += 1;
}else{
step = 0;
}
if (step = 17 and !falling and !flying)
{
if (step < 17) step = 17;
falling = true;
}
if (ground and falling)
{
vsp = -4;
}
if (falling) and (!vsp)
falling = false;
//Ducking
if (Key_Down and ground and !ducking and !flying and !falling and vsp = 0)
ducking = true;
if (ducking) and (sprite_index = spr_player)
sprite_index = spr_player_duck;
if (!ducking) and (sprite_index = spr_player_duck)
sprite_index = spr_player;
if (!Key_Down) and (ducking)
ducking = false;
if (ducking) and (Key_Left) and (hsp < 0) hsp = 0;
if (ducking) and (Key_Right) and (hsp > 0) hsp = 0;
//Sliding
//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;
Last edited by a moderator: