🎮

Building a Complete Platform Game Series Kickoff

Jun 9, 2024

Lecture Notes: Building a Complete Platform Game Series Kickoff

Introduction

  • Objective: Building a complete platform game from scratch
  • End Goals: Functioning frontend, backend, menu screens, flourishes, etc.
  • Tool Used: GameMaker Studio 2
  • Target Audience: Beginner developers

Setting Up the Project

Creating Sprites

  • Player Sprite: s_player

    • Default size: 32x32 (can be adjusted in preferences)
    • Created a green rectangle for simplicity
    • Important to set the origin to middle center (16x16) for accurate positioning
  • Wall Sprite: Duplicate s_player, rename to s_wall

    • Changed color to gray
    • Ensure the origin is also set to middle center

Creating Objects

  • Player Object: o_player

    • Set sprite to s_player
    • To hold all player-related game logic
  • Wall Object: o_wall

    • Set sprite to s_wall
    • To represent the walls in the game

Setting Up the Room

  • Default Room: room0
    • Open Room Editor and ensure instances layer is selected
  • Placing Objects: Add o_player and multiple o_wall objects to shape the game area

Adding Game Logic

Introduction to Events

  • Events and Actions: Game logic is based on triggering actions through events (e.g., button press, object creation)

Create Event

  • Declaring Variables:
    • hsp: Horizontal speed
    • vsp: Vertical speed
    • grv: Gravity (e.g., 0.1)
    • walksp: Walk speed (e.g., 4)

Step Event

  • Check for Key Presses:

    • key_left: Check if left arrow key is pressed
    • key_right: Check if right arrow key is pressed
    • key_jump: Check if space bar is pressed
  • Calculate Movement:

    • Use key_left and key_right to determine direction
    • Update hsp by multiplying directional input by walksp
    • Update player coordinate X by adding hsp

Handling Collisions

  • Horizontal Collision:

    • Predict collision instead of detecting post-movement
    • Use place_meeting to check for a wall collision at the predicted position
    • Adjust position to stop just before the collision
  • Vertical Collision:

    • Similar logic applied for vertical movement using vsp and grv
    • Ensure player falls down due to gravity and handles vertical collisions

Gravity and Jumping

  • Applying Gravity:

    • Continuously update vsp by adding gravity
  • Jumping:

    • Check if player is on the floor and the jump key is pressed
    • Set vsp to a negative value to initiate the jump

Final Adjustments

  • Run the Game: Set game FPS to 60 for smooth gameplay
  • Debugging: If collisions or movements aren't right, re-check the conditions and logic

Conclusion

  • Encouragement to Practice: Try typing in the code and use the manual to understand functions
  • Acknowledgment: Kudos to supporters and viewers for their continued support and engagement in the learning process

Additional Resources

  • GameMaker Manual: Middle-click on functions to access relevant documentation for deeper understanding
  • Support: Consider subscribing or pledging on Patreon for more tutorials and support.