SGC17 day 21 - Molly can jump (code)

This morning I was working on the jump function for my game. It can be tricky but I found a way I like. The main jump code looks like this (by the way I am programming this game in Game Maker):

If the player press space in the game when the character y-position is at the point "playerY", which is a variable I created of the players start position, which is just another way of saying that the player is standing on the ground, then a bunch of things will be set. The y-position is by the way the vertical position on the game screen.

What will be set it that the speed direction is set to 90 degrees, in other word straight up. After some testing I decided to set the actual speed to 12, this will send Molly flying upwards 12 pixels each frame of the game. I also set the gravity direction to 270 degrees, in other words straight down. After some testing I decided to use a gravity of 0.4;

But to be able to stop Molly I have to stop all speed and gravity. This was a bit tricky but I solved it by creating an alarm that sets the boolean variable "isJumping" to true, after five frames time. I did this because if I ran the stop code immediately Molly would have never jumped in the first place.

So when Molly is drawn downwards by the gravity and reach the y-position "playerY", which is the ground-level, and the the variable "isJumping" is true, then speed and gravity will be set to 0 and Molly will stop - "on the ground".