Advanced Platformer Tutorial

Материал из Поле цифровой дидактики
Описание Как создать продвинутый платформер
Область знаний Информатика
Область использования (ISTE) Computational Thinker
Возрастная категория 14


Поясняющее видео
Близкие рецепту понятия
Среды и средства для приготовления рецепта: Scratch

A advanced platformer is a game where the player has to jump on platforms and get to the finish to win. This tutorial shows how to make a static platformer, where the player has to get to a green square to move on to the next level. This features wall jumping, wall detection, ceiling detection, danger detection, implementations of extra gimmicks to the platforming script, and realistic gravity. Note: This article has not been entirely finished. The article will be finished in due course.

Preparation

Variables

Make these variables:

xvelocityyvelocitygravity

Sprites

These sprites are needed:

  • A player sprite (a small but visible shape)
  • A level sprite

Blocks

Make this block, set to "run without screen refresh":

defineplatform/JumpHeight:JAcceleration:AFriction:FWallJumpX:W.J.XWallJumpY:W.J.Y

in the player sprite.

Making the Game

Y-Movement

In order to achieve realistic gravity, the player must fall down faster the longer the player is in the air. This can be achieved as shown below:

defineplatform/JumpHeight:JAcceleration:AFriction:FWallJumpX:W.J.XWallJumpY:W.J.Ychangeyvelocitybygravitythischangesthevaluetheplayermovesdownby.changeybyyvelocitythischangestheplayerposition,basedontheyvelocityvariable.whenclickedsetyvelocityto0gotox:0y:150foreverplatform/JumpHeight:Acceleration:Friction:WallJumpX:WallJumpY:

However, the player isn't colliding with the "level" sprite. Collision scripting is shown below:

defineplatform/JumpHeight:JAcceleration:AFriction:FWallJumpX:W.J.XWallJumpY:W.J.Ychangeyvelocitybygravitythischangesthevaluetheplayermovesdownby.changeybyyvelocitythischangestheplayerposition,basedontheyvelocityvariable.iftouchinglevelthenrepeatuntilnottouchinglevelchangeybyabsofyvelocity/yvelocity*-1endsetyvelocityto0thisresetsthey-speed.whenclickedsetyvelocityto0gotox:0y:150