However, we want the player to obey the laws of gravity, so we will then gradually decrease the Sprite's y position until the Hero touches the ground. When the up arrow is initially pressed, we will change the y position by a positive number so that the character rises. If so, we will change the Hero's y position. So we will add another block to check if the up arrow key is pressed. Now that our character can move left and right, we want our character to be able to jump using the up arrow. Add the change below and run your program. This will make the xchange value go down from 1 to 0 gradually. To do this, multiply the xchange variable we create by a number less than 1 as shown below. To make our character's movement more realistic, we will simulate some friction and gradually slow the Sprite's speed down to zero. You will notice that your Hero will rapidly move in the direction of the arrow pressed. Modify your script to look like the one below and test this out:
The arrow presses will modify this value and we will update the Sprite's position each time the loop runs. Let's create a variable called xchange that will store the amount to change the character's x position by. If the right arrow key is pressed, we will point the Hero right (90) and change the Hero's x position by a positive number. If the left arrow key is pressed, we will point the Hero left (-90) and change the Hero's x position by a negative value. In our game loop (the forever block), we will check if the left or right arrow key is pressed. To do this, we will use the "key pressed" block under "Sensing". Now we want to move our Hero left and right when the player presses the left and right arrow keys on their keyboard. When you click the flag to start the game, your Hero should be walking in place just above the ground. When you are done adding your background to the stage, your screen should now look like the one below. When the player completes the objective for each level, you can broadcast a "level completed" message and change the costume of the stage to the next level's background. You will create a background for each level or stage in the game. Drag the stage image to the costumes tab to change the background. Once the image is saved, switch to the Stage Sprite in Snap and click on the Costumes tab. Let's start by saving the image below to the desktop: Since our platform game will have multiple levels or stages, we will want to design multiple costumes for the stage that represent each level. Our Hero is now animated, but the stage still has the default white background costume. When you run your program, your hero should look like it is walking in place.
When you are done, your Costumes tab should look like the one below:Īfter you have added your costumes, click on the Scripts tab to add the code to change costumes every tenth of a second as shown below. This will make it clear that this Sprite represents the main character in your platform game. Right click on each of the images below and save them to your desktop.ĭrag these images to the costumes tab for your sprite in Snap. To try this out, let's use some simple stick figure costumes. For instance, we could use the "next costume" block in a forever loop, waiting 0.1 seconds between each costume change. We can animate a character by repeatedly changing its costume. The first task is to create costumes to control how our Hero Sprite will look. The Hero is controlled by the person playing the game using the arrow keys. We will start off our platform game by creating a Hero sprite. In this project, you will design your own unique platform game, including the Hero, multiple powerups, levels, and hazards. Examples of powerups in Metroid include the Ice Beam (freezes enemies), High Jump Boots (make Samus jump higher), and Missile Packs (more powerful attacks). Other examples of platform games include Sonic the Hedgehog, Metroid, and many others. Examples of powerups in Mario Brothers include Mushrooms (make Mario stronger), Stars (make Mario invincible), and Flower Power (gives Mario the ability to shoot fire). Mario collects various powerups to get special abilities.
Enemies in Mario Brothers include Goombas, Koopa Troopas, and Thwomps, who each attack Mario in various ways. Mario completes a level by touching the flag or defeating Bowser. In Mario Brothers, the Heroes are Mario and Luigi.
One of the most famous platform games is Super Mario Brothers. Platform games typically have a number of powerups that make the Hero more powerful. It is called a platform game because the player jumps on platforms to dodge various enemies and hazards. Each level has an objective or goal that must be achieved in order to complete the level.
A platform game consists of a player-controlled Hero who completes a series of levels or missions by defeating enemies, avoiding hazards, and collecting powerups.