Star Student Builder logoStar Student Builder
← Real Games Std 6–8Project 4 of 4

A Platform Game with Gravity

🎯 A character runs, jumps, falls and lands on platforms.

πŸ’‘ The idea behind it

Gravity in a game is one variable that is constantly added to the y position and reset on landing. Understanding this is the step from making toys to making games.

🧱 Blocks you will need

variables (yv)foreverif … thentouching colour?change y bykey pressed?

πŸ”¨ Build it

  1. Make a variable yv β€” the vertical speed.
  2. forever: change yv by βˆ’1 (that is gravity) β†’ change y by yv.
  3. If touching the platform colour: repeat until not touching β†’ change y by 1, then set yv to 0. That pushes you out of the floor and stops the falling.
  4. Jump: if (key up pressed) and (touching platform colour) β†’ set yv to 12. The second condition is what stops jumping in mid-air.
  5. Left and right: change x by 5 or βˆ’5, with a similar push-out if you walk into a wall.

πŸš€ Make it harder

  • Add moving platforms and make the player ride them.
  • Add a scrolling level by moving everything else instead of the player.

🐞 Bugs you will hit

  • The player sinks through the floor: the fall speed per frame is larger than the platform is thick. Either thicken the platform or cap yv.
  • You can jump forever in mid-air: the ground check is missing from the jump condition.
  • The player judders on the ground: yv is not being reset to 0 on landing.

⬇ Need Scratch itself?

Free from MIT, in a browser or as an offline app that needs no connection at all.

Get it β†’
Ask GuruAcharya Samayeshwar