This is the beginning of the player inputs in the game. This method of storing and using the controls is awesome. Inside of key_left, when the left arrow key is pressed on the keyboard, a 1 is stored. What this means is that for the variable move, when key_right - Key_left = - 1 which would be on the left side of x and y grid, but if key_right is pressed it would equal 1, which is right on the grid.
key_left = keyboard_check(vk_left); //vk = virtual keyboard
key_right = keyboard_check(vk_right);
key_jump = keyboard_check_pressed(vk_space);
var move = key_right - key_left; //this is so smart i am impressed as hell, excited to explain to lio
var onWall = place_meeting(x-5,y,ointeractController) - place_meeting(x+5,y,ointeractController);
var onGround = place_meeting(x,y+1,ointeractController);
var dash = keyboard_check_pressed(vk_shift);
player character code.
I also created a range of variables which contain the information for events within the game, such as the player movement, a collision with a wall, and checking if a button is pressed. This makes it easier so later in development, I can just call these variables rather than rechecking all the different functions.
//vetial collision section
if (place_meeting(x,y+vsp,ointeractController))
{
while (!place_meeting(x,y+sign(vsp),ointeractController))
{
y = y + sign(vsp);
}
vsp = 0;
jumps = 0;
}
y = y + vsp;
//horizontal collision section
if (place_meeting(x+hsp,y,ointeractController))
{
while (!place_meeting(x+sign(hsp),y,ointeractController))
{
x = x + sign(hsp);
}
hsp = 0;
jumps = 0;
}
x = x + hsp;
This part of the code is extremely important as this is where the game checks for the collisions with the wall. This is then used a lot throughout the game for the platforming so that the player can navigate the game. place_meeting is the collision check in-game maker and here it's checking for the InteractController which is my controller for the wall. Once the player hits the wall the vsp or hsp is set to 0 which means the player wont move. However this could mean that the player stops a little before hitting the wall, so we use the sign function to get as close to the wall as possible before stopping the player.