Shooting games are based on an environment in which a main character gets points for hitting another character or a set of characters. This genre is often quite difficult and can test the player’s speed and reaction time. Often the player-character, if they survive obstacles, do not lose a life and claim a certain score, they can then advance to another level or another mission.
We are going to program a shooting game with the Scratch software in which we are a ship in space which must destroy meteorites. The longer you hold on, the more points you earn.
1) Go to Upload Backdrop to add space image.
2) Choose space image for game background:
3) We obtain the background containing the image of space.
The library gathers all the sprites created by Scratch.
1) Click on the Choose sprite icon .
2) Clicking the “Import Sprite” button should take you to the Sprite menu, a library of different sprites you can use in the program.
3) Click on the Rocketship sprite and the Scratch will create it as a new sprite in your game.
4) Insert these program blocks in the code area of the cannon sprite which allows the racket to be directed to the left or to the right using the two arrows (right and left) on the keyboard.
5) Add these two blocks that hide the Rocketship sprite if it receives a message from an enemy sprite (i.e. if the Rocketship sprite is hit by the enemy sprite).
Here is the final program for the Rocketship sprite:
The missile sprite is launched by the Rocketship sprite to destroy the meteorite (enemy sprite).
1) Go to the new sprites section and select the paint icon.
2) Draw the missile sprite using the drawing editor.
Added code to missile sprite
All on board we must create clones of the missile sprite thanks to this block
Here is the first part of the missile sprite program which allows you to create copies of the missile sprite when you press hard on the space key on the keyboard.
To fire the Rocketship sprite missile upwards:
– Position the missile clones on the Rocketship
– We display the clones of the missile sprite on the stage
– Aim the missile sprite clones upwards to destroy enemies.
– We hide the clones of the missile sprite when they touch the edges of the scene or the enemy sprite
Here is the second program part of the missile sprite which allows you to fire the Rocketship missile towards the enemies.
The enemy sprite is going to feature two costumes:
– the enemy sprite
– the explosion sprite
1) Go to Upload Sprite to add the image of the enemy.
2) Choose the enemy image:
2) Go to the enemy sprite’s costume to add the second explosion costume
3) Choose the explosion image :
We get an enemy sprite with two costumes, one of which represents an explosion.
Added code to enemy sprite
The enemy sprite moves in a line up and down. If hit by a missile, it will be destroyed. Then the enemy sprite starts moving up and down again.
If the enemy sprite touches the ‘Rocketship’ spaceship or the edge of the stage, the game is over.
– On board, we must create the variable score.
The set score to 0 block is executed when the green flag is clicked.
– Then we switch the enemy sprite to the enemy costume.
– Then, we randomly position the enemy sprite.
– The rest of the program is inserted into the repeat forever block:
– We move the enemy sprite from top to bottom:
– If the enemy sprite is hit by the missile:
We switch the enemy sprite to the explosion costume.
we increment the score variable by 1
the enemy sprite is repositioned randomly.
we switch the enemy sprite to the first costume to restart the game.
– If the enemy sprite hits the Rocketship or the edge of the stage:
we send a message to the Rocketship sprite:
we switch the enemy sprite to the explosion costume.
the message ‘Game Over’ is displayed on the stage
We stop all the scripts to finish the game
Here is the final program for the enemy sprite: