Star Student Builder logoStar Student BuilderA Learnerโ€™s Guide
โ† 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