#Week 7: Speed boosts, teleporters, and double-jumping

Today we’ll add a few more interesting game mechanics into our game. We’ll create a speed boost collectable object, a teleporter, and we’ll restrict jumping to a double-jump.

Programming concepts we’ll learn:

  • If-else selection logic
  • Variables

1: Setting up the speed boost

In this step we’ll set up the speed boost object and the speed variable on the player. Watch the video below for a refresher on using number variables.

  • Place a speed boost object in the playable level

  • Right-click add script
  • When created
  • Add tag
  • Tag “speed boost”

  • Close script and save
  • Edit player script
  • Go to “when level starts”
  • Create new number variable “speed”
  • Set speed to default x velocity (200)

  • Find blocks where x velocity is set
  • Replace hard coded numbers with “number speed” from variables
  • For negative velocity, use “+” from operators, and change it to “x” with -1 in front

  • In the next step we’ll reset the speed back to its original value

 

2: A time delay to reset the speed

In this step we’ll make the player detect when it collides with the speed boost object, and use the time delay block to set the speed back to normal. Watch the video below to see how to use the time delay block.

  • Edit player script
  • Go to “when touched” section
  • Duplicate one of the “if toucher had tag” sections
  • Change tag to “speed boost”
  • “Destroy myself” from control flow
  • Replace myself with “Instance toucher” from variables
  • “Set number speed to” from variables
  • Duplicate a number block, set speed to “500”
  • “100 milliseconds have passed” from control flow
  • Change to 5000
  • Duplicate “set number speed” and pit inside “5000 milliseconds have passed”
  • Set speed back to 200

  • In the next step we’ll create a teleporter

 

3: Creating a teleporter

In this step we’ll program another object that teleports the player to another location. Watch the video below for a refresher on positioning objects and determining coordinates in a level.

  • Place new teleporter object

  • Add script
  • When created
  • Add tag “teleporter1”
  • Set immovable true from physics

  • Close script and save
  • Edit player script
  • Go to “when touched”
  • Duplicate one of the “if toucher has tag” blocks
  • Change tag to “teleporter1”
  • “Set x position of myself to 0” from transform
  • Duplicate for “set y position of myself”

  • Where should this teleport us to? Close script and save
  • In level editor find coordinate using layers panel, write it down

  • Reopen player script and use these coordinates for x and y position

  • Save and close
  • Play game
  • In the next step we’ll get double-jumping working

 

4: Restricting jumping to a double-jump

In this step we’ll make the player only able to jump once and then once again in the air. Watch the video below for a refresher on using if-statements with variables.

  • Edit player script
  • Go to “when up arrow pressed”
  • Add “if do” from control flow
  • Click settings icon, drag “else if” into “if”
  • Click icon again to close it
  • =” from operators
  • “Velocity y” from physics
  • “0” from operators
  • Create a new variable “set number jumps” from variable
  • Set jumps to 1
  • Drag “set velocity y -500” into this “if” block
  • Duplicate = block, drag into “else if”
  • Replace “velocity y” with “number jumps” from variables
  • “Set number jumps” from variables
  • +” from operators
  • “Number jumps” into left side of +
  • “1” into right side of +
  • Duplicate “set velocity y -500” into “else if”

  • Next week we’ll be wrapping up and publishing our game

 

results matching ""

    No results matching ""