Revision as of 01:19, 5 September 2013 by ErnieParke (talk | contribs) (Advanced: Added several then's.)

Warning.png This article or section is currently undergoing major changes by Turkey3 (talk | contribs). Please avoid largely modifying this page's contents until this template has been removed. (Date?)

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, it helps 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:

when gf clicked
set [Gravity v] to [insert strength of gravity here]
forever
  if <key [left arrow v] pressed?>
    set [XVel v] to [-4]
  end
  if <key [right arrow v] pressed?>
    set [XVel v] to [4]
  end
  if <<not <key [left arrow v] pressed?>> and <not <key [right arrow v] pressed?>>>
    set [XVel v] to [0]
  end
  if <not <touching [ground sprite v]>>
    change y by (Gravity)
  end
  change x by (XVel)

Making Levels

Simple

Colors would be involved at this part. Lets say that black is the main color the sprite stands on, red makes the sprite go back to the beginning of the level when it touches it, and touching yellow will bring the sprite to the next level.

File:Level.gif

However, yellow doesn't have to always be square, and red doesn't always have to be a basic line. They can be any kind of strange shape like yellow (Level goal) can be some line and red (Obstacle) could be something like a circle or square.

File:Alt Level.gif

Levels can look like this! That's what makes platformers popular on Scratch.


When you're done making all your levels, add the following script to the Player sprite:

when gf clicked
forever
  if <touching color [#FF0000]?>
    go to x:(-180) y:(-47)
  end
  if <touching color [#FFFF00]?>
    broadcast [New level v]
    go to x:(-180) y:(-47)
  end

And add the following scripts to the Levels sprite/background:

when gf clicked
switch to costume [Level 1 v]
when I receive [New level v]
next costume

Finally, add this script to the Player sprite:

when gf clicked
forever
  if <([costume # v] of [Levels v]) = [insert number of levels here]>
    hide
  end

Advanced

When doing platformers, variables are usually present. These varaibles can range from Lives Left to Deaths or Seconds Survived to Coins Collected. The basic name used in simple platformers for variables is Score. To incorporate variables into your platformer, you can use the following script:

when gf clicked
forever
  if <touching color [#FF0000]?> then
    go to x:(-180) y:(-47)
    change [Deaths v] by (1)
  end
  if <touching color [#FFFF00]?> then
    broadcast [New level v]
    go to x:(-180) y:(-47)
  end

And for the broadcast received:

when gf clicked
switch to costume [Level 1 v]
set [Level v] to [1]

when I receive [New level v]
next costume
change [Level v] by (1)

or if you want to incorporate Lives

when gf clicked
forever
  if <touching color [#FF0000]?> then
    go to x:(-180) y:(-47)
    change [Lives v] by (-1)
  end
  if <touching color [#FFFF00]?> then
    broadcast [New level v]
    go to x:(-180) y:(-47)
  end

for the sprite's script.

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.

External Links

Tutorial