Creating a fixed shooter game
Yea! Shooter games are fun!
Today we're going to make a basic shooter game! More specifically, ours will be a fixed shooter. Some popular fixed shooters include Space Invaders, Galaxian, and Galaga.
The object of our game is for the player to destroy all enemy ships.
Rules/Structure:
- The player can move his ship left or right, but it stays at the bottom of the screen.
- Enemies move from the top of the screen to the bottom.
- If the player's ship hits an enemy ship, the player will lose a life.
- If an enemy's ship passes the bottom of the screen, the player will lose a life.
- The player can fire missiles by pressing spacebar. If a missile hits an enemy, the enemy (and the missile) is destroyed.
- The game is over when the player runs out of lives or all enemy ships are destroyed.
This tutorial is divided into steps, and each step has a list of instructions. When you complete an instruction, you can click on it to mark it as complete. This will help you keep your place.
You can use the arrows at the left and right to navigate through this tutorial. The first step starts on the next page!
Step 0 - Getting started
- Close every application you have open except this one.
- Find the UBGD_FileSync_v2.2.exe file on the desktop and double click it. If it's not there, you can download it here.
- We want to download the project, so type "1" and then [ENTER].
- Select "Student Files" by typing "1" and then [ENTER].
- Find your name in the list. Type the number which corresponds to your name and then [ENTER].
- Find the project called "MyBasicShooterGame.gmx.zip". Type the corresponding number and then [ENTER].
- The Sync Tool will download your project, extract it, and launch it for you.
- When it's done, GameMaker Studio will be open.
Step 1 - Creating sprites
A "sprite" is the visual representation of a game object. Before we can create objects, we need sprites for them!
-
Click on, drag, and drop the images below onto GameMaker Studio.
Name each sprite as indicated.
(Sprites were created for Galaga, by Namco and Midway)Name Description ship_sprite This is the ship the player will control miniShip_sprite This image represents the number of lives the player has. playerMissile_sprite This is the weapon the player can fire. enemy1_sprite This is the one type of enemy. enemy2_sprite This is the one type of enemy. - Each sprite should be centered.
- Also, create an object for each of these sprites. Name them appropriately and mark them as solid.
Step 2 - Creating a level
Levels can be implemented in GameMaker Studio by creating a "Room". We'll make one now!
- Right-click on the "Rooms" folder, and select "Create Room".
- Add a single player ship near the bottom of the screen.
- Add several enemy ships in the top-half of the room.
- Be sure to save your work so far by clicking the button!
Step 3 - Making stuff happen
Alright, we've created our first level... but it doesn't do anything yet! Let's give our player control. We'll do this by adding keyboard events to the player's ship object.
- Double click the Player's Ship object under the Objects folder.
- Click the "Add Event" button at the bottom of this window and select the Keyboard <LEFT> key.
- Have the player's ship move -4 in the x-direction, relative to his current position.
- Now add an event for the Keyboard <RIGHT> key. Here, you'll use a positive 4 in th x-direction.
- Be sure to save your work so far by clicking the button!
- Once you're done, let's try out your game by pressing the button at the top left of GameMaker Studio.
Step 4 - Pew, pew, pew!
To clear each world, the player must destroy all enemy ships. He can do this by firing a missile at them.
- Double click the Player's Ship object under the Objects folder.
- Select the Keyboard <SPACE> event.
- Find and add the "Create Instance" action from the "Main1" tab. It looks like a single light bulb.
- In the Create Instance dialog, select the player's missile object.
- X and Y should be 0, with relative checked (we want to create the missile in the same spot the player's ship is in).
- Now we've created the missile, but it won't go anywhere just yet. First, we need to open the missile object.
- Now add the "Create" event for the missile object.
- Find and add the "Set Vertical Speed" action, with a speed of -8.
Step 5 - Shooting is fun... but even better when stuff blows up!
As of right now, we have 2 different enemy objects. We could add collision events for each one, but this will become cumbersome if we decied to add more enemy ships in the future. Instead, we'll create a "parent object" for the enemy ships and attach events to that.
- Right-click ont he "Objects" folder and select "Create Object".
- Name this object "enemyShip_parent" and mark it as solid.
- Click "OK" to close the "enemyShip_parent" for now, we'll come back to it in a moment.
- Open the "enemyShip1" object.
- On the left hand side of the Object window, you'll find a field labeled "Parent". Change the value of this field to the "enemyShip_parent" we just created.
- Repeat the previous step for the "enemyShip2" object. If you create your own ships later, you'll want to make those children of the enemyShip_parent as well.
- Now open the EnemyShip_parent object again.
- Add an event for "Collision" with a "playerMissile".
-
When the missile collides with an enemy ship, things should happen:
- Remove the enemy ship (Self)
- Remove the missile (Other)
- Be sure to save your work so far by clicking the button!
- Once you're done, let's try out your game by pressing the button at the top left of GameMaker Studio. You should be able to steer the ship and fire missiles which move up the screen.
Step 8 - Beating the level
Right now, ships are being destroyed, but nothing happens when you destroy all of them!
- Open the "enemyShip_parent" object.
- Add a new event for "Destroy". (Recall that ships are destroyed when a missile collides with them, so we don't have to!).
- Add a "Test Instance Count" action.
- Set the object to the "enemeyShip_parent" object.
- Set the number to "1" and press OK.
- Next, add the "Restart Room" action.
- Save your game and play it! If you want to create a second level now, you can. Remember though, that it's often easier to duplicate an existing room and adjust it, rather than starting from scratch.
Step 9 - Losing the game
It's not fun if you can't actually lose, right? We'll give the player lives, and then remove one life everytime he runs into an enemy, or if an enemy goess off screen.
- First, let's give the player 5 lives. Open the playerShip object.
- Add a new event for "Game Start" (it's under the button labeled "other".
- Find and add the "Set Lives" action, in the "Score" tab.
- Enter a value of 3 (or whatever you want) and press ok.
Now that the player has lives, we can start taking them away!
- Open the "enemyShip_parent" object.
- Add a "Collsion" event for colliding with the playerShip.
- Add an action to destroy the enemyShip object (self).
- Add an action to destroy the playerShip object (other).
- Now open the playerShip object.
- Add the "Destroy" event to the playerShip object. By putting actions in here, we can have them processed regardless of how the ship was actually destroyed!
- For now, we just want to remove 1 life from the player when the ship is destroyed. Add the "Set Lives" action from the "Score" tab.
- Set the value to -1 relative.
- Can you figure out how to subtract one life when an enemy ship goes off screen?
Step 10 - Giving the player feedback
It's important to let the player know when they're doing well, and when they're doing poorly. We'll accomplish this by showing the player's score and number of available lives.
- Open the "playerShip" object
- Add a new event for "Draw GUI"
- Add the "Draw Score" action from the "Score" tab. I suggest drawing the score at the top-left corner (0, 0), but this is up to you.
- Add the "Draw the lives as image" action. Use the miniship_sprite. I suggest drawing the lives at the bottom-left corner (0, 480), but this is up to you.
- You'll need to determine when to award the player points and how many points to give them!
Step 11 - Making the enemies move
To make the game more exciting, we'll make the enemies move towards the player. We'll accomplish this using an alarm clock.
- Open the "enemyShip_parent" object.
- Add an event for "Create".
- From the "Main2" tab, add the "Set Alarm" action (it looks like a clock).
- Set "Alarm 0" to go off in 120 steps (FYI, by default, our games have 60 steps per second, so this is about 2 seconds).
- Now add an event for the Alarm activating.
-
When this alarm is activated, we want 2 things to happen:
- Make the object jump 8 pixels in the (relative) Y direction ("Jump to Position" action)
- Reset Alarm 0 to 60 steps
- Be sure to save your work so far by clicking the button!
- When you play your game now, you should see the enemy ships begin to move after a short delay.
What's missing?
- * Create a title/game over screen
- * Take the player to the title/game over screen when out of lives
- * Create levels with multiple waves of enemies
- Reset the remaining enemy ships when the player's ship is destroyed. This will give the player a chance to recover.
- Create enemies which can fire back.
- * Create enemies which move in a unique way (left and right instead of straight down; diagonally; smoothly; etc).
- Sound and visual effects (such as explosions)
- Create a scrolling background.
* indicates mandatory items