Advanced Platformer Tutorial
Описание | Как создать продвинутый платформер |
---|---|
Область знаний | Информатика |
Область использования (ISTE) | Computational Thinker |
Возрастная категория | 14
|
Поясняющее видео | |
Близкие рецепту понятия | |
Среды и средства для приготовления рецепта: | Scratch, Snap! |
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:
(x velocity) (y velocity) (gravity)
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":
define platform / Jump Height: (J) Acceleration: (A) Friction: (F) Wall Jump X: (W.J.X) Wall Jump Y: (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:
define platform / Jump Height: (J) Acceleration: (A) Friction: (F) Wall Jump X: (W.J.X) Wall Jump Y: (W.J.Y) change [y velocity v] by (gravity) // this changes the value the player moves down by. change y by (y velocity) // this changes the player position, based on the y velocity variable. when gf clicked set [y velocity v] to [0] go to x: [0] y: [150] forever platform / Jump Height: () Acceleration: () Friction: () Wall Jump X: () Wall Jump Y: ()
However, the player isn't colliding with the "level" sprite. Collision scripting is shown below:
define platform / Jump Height: (J) Acceleration: (A) Friction: (F) Wall Jump X: (W.J.X) Wall Jump Y: (W.J.Y) change [y velocity v] by (gravity) // this changes the value the player moves down by. change y by (y velocity) // this changes the player position, based on the y velocity variable. if <touching [level v]> then repeat until <not <touching [level v]> change y by ((([abs v] of (y velocity))/(y velocity))*[-1]) //this slowly pushes the player out of the collision on the y-axis. end set [y velocity v] to [0] // this resets the y-speed. when gf clicked set [y velocity v] to [0] go to x: [0] y: [150]