///Step Event
//Inputs
key_right = keyboard_check(vk_right);
key_left = keyboard_check(vk_left);
key_down = keyboard_check(vk_down);
key_jump = keyboard_check_pressed(vk_space);
//Grounded Checks
grounded = false;
if place_meeting(x,y+1,obj_block) grounded = true; //If the player is on top of a block, set grounded to true
with (obj_platform)
{
//If the player is on top of the platform and not inside it, set grounded to true
if place_meeting(x,y-1,other) and !place_meeting(x,y,other) other.grounded = true;
}
//Player Movement
move = key_right - key_left;
if !(move = 0)
{
hsp = walksp * move;
}
else hsp = 0;
//Gravity
if !(grounded) vsp +=grv; //If the player isn't on the ground, add gravity to their vertical speed
//Jump
if (key_jump) and (grounded) //If we're on the ground and the jump key was pressed
{
vsp -= jumpsp; //Move us up by our jumpspeed
}
//Jump Through Platform Collision
with (obj_platform) //Run the following code from inside all the jump through platforms:
{
if (other.vsp > 0) //If the player is falling down
{
//If the player would collide with this specific platform at their current speed and is not already colliding with this platform
if place_meeting(x, y-ceil(other.vsp),other) and !place_meeting(x,y,other)
{
while !place_meeting(x,y-1,other) //While the player isn't on top of this platform
{
other.y +=1; //Move them down
}
other.vsp = 0; //Then set their vertical speed to 0
}
}
}
//Horizontal Collision
if (place_meeting(x+hsp,y,obj_block))
{
while (!place_meeting(x+sign(hsp),y,obj_block))
{
x = x + sign(hsp);
}
hsp = 0;
}
x = x + hsp;
//Vertical Collision
if (place_meeting(x,y+vsp,obj_block))
{
while (!place_meeting(x,y+sign(vsp),obj_block))
{
y = y + sign(vsp);
}
vsp = 0;
}
y = y + vsp;