Robert - Game Mechanics


Robert - Game Mechanics

Today, I took the time to create the main mechanics of the game, including:

  • Movable objects (springs, boxes, and planks)
  • Platforms that the planks can be placed on
  • Elevators and movable platforms
  • Buttons and switches
  • Doors
  • Hearts and keys

Movable Objects

The movable objects have the same basic code for picking up/putting down. To pick up the objects, the player must click the left mouse button, which triggers a boolean variable to true. This will be used to indicate whether the player wants to pick up an object or not. When the player overlaps an object, a timer is started which loops every 0.1 seconds, and checks the following conditions:

  • The player is still overlapping the object 
  • The left mouse button is pressed 
  • The player currently has nothing picked up 

If the conditions above are met, the actor will be destroyed and the type of object the player has just picked up will be set to true (if s spring is picked up, the "spring" boolean variable will be set to true). To put an object down, the player must press the right mouse button, which runs the following code:

This code gets the transform for the object to be placed (this depends on the type of object). After this, if any of the boolean variables are true, the corresponding item will be spawned at the transform, and all variables are turned false. This means that after this, the player will have nothing in hand.

Platforms that the planks can be placed on

Once the pickups were sorted, I focused on the platforms on which the planks can be placed. To do this, I made an actor that contains a sprite for the platform and a sprite for the plank, which will light up when the player is within range and show them where the plank can be placed. I also added a box collision to detect when the player is within range. 

Much like the movable objects, I used a timer to detect when the player is in range and whether the following conditions are met:

  • The player is in range of the object
  • The player is holding a plank
  • The player is pressing the E key


If these conditions are met, the player will place the plank down. When this happens, collision is turned on for the plank, meaning that the player can now walk up the plank onto the next platform. To pick the plank back up, a second timer checks for the following conditions:

  • The player is in range of the object
  • The player currently has nothing picked up 
  • The platform currently has a plank placed 
  • The left mouse button is pressed


If these conditions are met, the "plank" variable will be set to true, and the collision is turned off for the placed plank, so the player can no longer walk on it.

Elevators and movable platforms

For the elevators, I created two custom events called "Lower" and "Raise", which are both connected to a timeline. The timeline lerps the relative Z location of the elevator from -88 to 115. "Raise" is connected to "Play" and "Lower" is connected to "Reverse from end".


For the moving platforms, I used very similar code. However, the sprite's location follows a spline.


Both the elevators and moving platforms will be controlled by buttons, and the custom events will be called in those button actors.

Buttons and switches

Buttons and switches will be used to control elevators, doors, and moving platforms. To control these, the actors have references for the actors in which they control, which are set in the different instances of these actors.

For the button actor, I used a timeline to lerp the relative Z position of the button surface itself, so that the button goes down when stepped on. Once again, I created two custom events called "Play" and "Reverse", which will change the location of the button.


These custom events are then called when the player overlaps the actor (shown below). This specific button actor is for the elevator. 


Doors

Much like the elevator and moving platform, the doors have two custom events; "Open" and "Close". These custom events had to perfectly time the length of the flipbooks with delays and change the collision depending on whether the door is open or closed.


These custom events will be called in the button or switch actors.

Hearts and keys

The heart actor is very simple. When the player overlaps the actor, the player's heart size will increase by 1 and the actor will be deleted.


Every heart actor also has a box trigger around it. When this box trigger is also overlapped, the game's post-processing settings are updated to make the game brighter. This is done by lerping the float values from the old value to the new value using a timeline. This makes the transition smooth and not sudden.

The key actor works in a very similar way, when the actor is overlapped, the key variable is set to true and the actor is destroyed.

Now that the main mechanics are finished, I can focus on finer details. Thank you for reading!

Files

Robert.zip 425 MB
Jun 12, 2022

Get Robert

Leave a comment

Log in with itch.io to leave a comment.