Line 63: | Line 63: | ||
show | show | ||
wait until <([backdrop # v] of [Stage v]) = (amount of backdrops)> //wait until the last level is reached | wait until <([backdrop # v] of [Stage v]) = (amount of backdrops)> //wait until the last level is reached | ||
− | + | stop [all v] | |
</scratchblocks> | </scratchblocks> | ||
Revision as of 03:27, 24 November 2016
A platformer is a simulation of actual physics that take place in real life. Objects fall, move, slide, jump, and bounce, and a platformer associates those properties into a game in which one controls a character to typically move toward some form of a goal.
Creating the platformer sprite
To start off, one first needs to create the platformer sprite: the sprite that one controls and plays as in the game. The appearance of the sprite can affect the gameplay slightly, depending on the angles and size of it. Implementing an animating sprite which switches among costumes of different dimensions can prove difficulties within the project. After designing the artwork for the sprite, create two new variables called "x velocity" and "gravity"; select the option "for this sprite only" in the creation menu. That setting makes the variable only changeable by the sprite it is created within, and is used often in a physics situation because they represent personal properties of an individual sprite. Once the variables are created, add the following script to the sprite. Note that the Gravity variable can be anything you want.:
when gf clicked set [Gravity v] to [5] forever if <key [left arrow v] pressed?> then set [XVel v] to [-4] end if <key [right arrow v] pressed?> then set [XVel v] to [4] end if <<not <key [left arrow v] pressed?>> and <not <key [right arrow v] pressed?>>> then set [XVel v] to [0] end if <not <touching [ground sprite v]>> then change y by (Gravity) end change x by (XVel)
Making Levels
Colors can be used in a platform for detection of the end of a level or an object which sends one back to the beginning of the level. For this tutorial, assume the following:
- the character sprite performing the physics is named "Player"
- black is the color of the platform, or ground and walls, in which the character cannot pass through
- red is the color that sends one back to the beginning of the level he or she is on
- yellow is the color which must be reached to move on to the next level
- backgrounds are used as levels instead of sprites
- scrolling is not incorporated
The shapes do not need to be geometric, but can be organic, meaning an unordinary, inconsistent structure. There can be curvature to the various colors and platforms, which can be used to create diverse, numerous levels. The following image displays an example of some organic shapes being used:
When you finish designing the levels as backdrops in the Stage, add the following script to the "Player" sprite:
when gf clicked forever if <touching color [#FF0000]?> then //if in contact with the color red go to x:(-180) y:(-47) //relocate to the start end if <touching color [#FFFF00]?> then //if at the end of a level go to x:(-180) y:(-47) //relocate to the start switch backdrop to [next backdrop v] //next level end
The scripts within the "forever" loop can be merged with the larger physics script shown farther above. Merging the scripts reduces the amount of conditions being checked at once and can possibly make the project more uniform and orderly, meaning the "Player" makes each movement and then checks for the conditions instead of the conditions possibly being checked during the sprite's movement.
![]() | A condition is a statement that is checked for a true/false response. In the example above, when the sprite checks if it's touching a color, it's checking a condition. |
Then add the following script to any sprite:
when gf clicked switch backdrop to [Level 1 v] //begin with the first level
Lastly, add the following script to the "Player" sprite:
when gf clicked show wait until <([backdrop # v] of [Stage v]) = (amount of backdrops)> //wait until the last level is reached stop [all v]
Making the Win Background
Last of all, comes the win background. After finishing all the levels in the platformer, something would come up that says something like "You Win!". Put it as the last costume in the sprite/background. It can be some text in a basic white background saying "You win" or the art can be complex.
See also
- Advanced Platformer Physics — For achievement of a more realistic platformer