Programming the Game

Game Rules

  • Blinka the purple snake has 4 seconds to get to the star. Clock resets and the score increases by 1 each time this is accomplished. 
  • Blinka must avoid Sparky the blue smoke monster who is bouncing around the screen. Each time Sparky hits Blinka, one out of 3 lives is lost.
  • Sparky's speed increases every 5 seconds.

Feel free to follow along by creating a new project in MakeCode Arcade or by viewing the completed project.

Background

  • In an on start loop, grab a set background image block and create the desired background image for the game to start on.
  • You can edit this image by clicking the part of the block with the thumbnail.
  • Next add a pause block to let the intro image stay on the screen for one second.
  • Then set the background image and background color to black.

Creating Blinka's Sprite

  • Now drag a set mySprite block under the last block we set.
  • Click the drop down menu next to mySprite. Create a new variable and name it Blinka or what ever character name you want.
  • Next, click the thumbnail for the sprite and create your desired sprite.*
  • Click the drop down menu at the end of the block and select the Player sprite type.
  • Now add a set position block to place Blinka in a specific spot each time the game starts. By clicking on the number values, the program allows us to set x and y values visually. Just move the mouse over the game console to choose a place to put the sprite.
  • Lastly add a move block and click the plus sign to set arrow keys as the way we move Blinka around.

*MakeCode Arcade usually allows importing images to use for background and sprites by dragging and dropping png files into the editor space. However at the time of this writing, this functionality is not available due to being in Beta Mode.

Sparky's Sprite

  • Drag in set mySprite block, create new variable called Sparky, make the sprite graphic and change the kind to Enemy.
  • Set to a position in the game.
  • Create two new variables called SparkySpeedx and SparkySpeedy.
  • Also in the variables block section, drag in two set mySprites to blocks. Set one toSparkySpeedx with a value of 40 and the other to SparkySpeedy with a value of 60.
  • Now, with a set mySprite velocity block, choose Sparky as the sprite, and drag in the SparkySpeedx and SparkySpeedy as the velocity values. This will allow us to increase the speed of Sparky over time later!
  • Lastly, drag in a set mySprite to stay in screen block, change the drop down to bounce on wall and switch to on.

Life, Food and Countdown!

  • Drag in a set life block and set the desired value.
  • Next, drag in set mySprite block, create new variable called Star, make the sprite graphic and change the kind to Food.
  • Set its location.
  • Drag in a start countdown block and set the desired value.

Reaching Stars

  • In the sprite blocks category, drag in an on sprite of kind block, set kind to Player and overlaps kind to Food.
  • Play a sound when Blinka hits each star.
  • Add a change score by 1 block.
  • Next we want the star to move to a new random location. To do this drag in a set position block. In the math blocks category, find and drag in a pick random 0 to 0 block inside both x and y values. Set ranges accordingly.
  • Start the countdown over.

Losing Lives

  • Drag in an on sprite of kind block, set kind to Player and overlaps kind to Enemy.
  • Play desired sound when Sparky hits Blinka.
  • Lose a life.
  • Move Sparky to a random new location.
  • Shake camera to show player a life has just been lost.

Increasing Sparky's Speed

  • Drag in an on game update every x ms block and change value to desired amount of time intervals in which to increase Sparky's speed. 5000ms is 5 seconds.
  • From the variables block category, drag in two change mySprite by blocks and enter value of desired speed increase.
  • Then to update Sparky's speed, drag in a set velocity block, changing the sprite to Sparky and the vx and vy to SparkySpeedx and SparkySpeedy.

All done with code!

This guide was first published on Jan 25, 2019. It was last updated on Jan 25, 2019. This page (Programming the Game) was last updated on May 23, 2019.