Camp Imagination Videogame Design Arena Shooter: Movement
An arena shooter is a game where you keep shooting enemies until one of the hits your character. You can use the built-in tutorial in GameMaker Studio 2 for this called "My First Game - DnD." The final game will look something like the screenshot below. "DnD" stands for "Drag and Drop." GameMaker projects can either be "drag and drop" or "GameMaker language." We will focus on drag and drop projects for this camp.
The empty area in the middle of the screen is the workspace. The workspace is where you will do the majority of the work editing your game. On the right side of the workspace is the resource tree, which lists different elements that can be put in your game such as sprites (images), objects, or rooms. You can move the resource tree wherever you'd like on the screen if you don't like it on the right side.
- In the main GameMaker window click on the Tutorials button.
- Select the "My First Game - DnD" tutorial.
- Save the tutorial to your desktop.
Sprites are images you plan to use in your game. You can go to the GameMaker Marketplace to download free resources or pay for resources. However, you need to have a paid version of GameMaker to use the Marketplace so we will not be able to use it for this camp.
Follow the steps below to create a new sprite for the player in Arena Shooter. You need to find your own image for the player if you do not want to use the tutorial's image. Follow the steps on the left if you are looking for your own image in Google.
- Right-click on Sprites in the resource tree.
- Choose "Create" to open the Sprite Editor.
- Name your sprite "sprPlayer."
- Click on "Import" to select the image you want to use. If you are using the default image it is in the "TutorialResources" folder.
Now that your sprite has an image, you need to set the origin of the image. The origin is a point on the sprite that is used to position the sprite within the game.
- Click on the drop-down menu above the image prview in the Sprite Editor.
- Select "Middle Center" to put the origin in the exact center of the image.
- You can now close the Sprite Editor.
An object in GameMaker is something that is used in the game world. You can think of an object as a blueprint for a house. The blueprint gives you information on what the house will look like and you can build as many houses from the blueprint as you want. SImilarly, you can put as many of the same object into your game as you want. Every time you put an object into your game it is called an instance of the object. We will only have one isntance of the player object but we will have multiple instances of the enemy object.
- Right-click on Objects in the resource tree.
- Choose "Create" to open the Object Editor.
- Name your object "objPlayer."
- Click on "No Sprite" and select the "sprPlayer" sprite.
Associating a sprite with an object means the object will look like the sprite when you add an instance of the object to your game, which we will do next.
The Visible checkbox is checked by default so you can see the object in the game. Occasionally, there are times where you don't want an object to be visible since the player doesn't interact with it. The Solid checkbox lets us add collision detection to the object, which we will need so the ball can bounce off the walls.
Rooms are the levels of your game in GameMaker. A room called "room0" is already created for you when you start a new game.
- Click on the arrow next to Rooms in the resource tree.
- Right-click on "room0" and rename it "roomMain."
- Double-click on "roomMain" to open the Room Editor.
While rooms are typically used as the levels of your game, they can be used in other ways such as splash screens or a main menu. The room is made up of a grid of black squares that represent a canvas for you to create your game.
- Drag the "objPlayer" object from the resource tree to the Room Editor.
To get the player moving we will need to add events that run when certain things happen such as a keyboard key being pressed. Follow the steps below to add events to the player object.
- Double-click on the "objPlayer" object to open the Object Editor.
- Click on the "Add Event" button and select "Step."
- Within the "Step" options choose the Step Event.
The Step Event runs every frame of animation, which by default means it runs 30 times every second. Once you have created an event the editor is split into three parts: the action list on the left that gives an overview of all actions for the event, the action workspace in the middle where actions can be dropped and edited, and the action toolbox on the right where you can drag and drop action blocks. We are now going to use a variable to control the left and right movement of the player.
- Drag the Assign Variable action from the "Common" section of the action toolbox to the action workspace.
- Change the name of the variable to "x."
- Set the value of the variable to "4."
- Check the "Relative" checkbox.
A variable is a place to store information in a computer program. Instance of objects in GameMaker have some built-in variables, including the variable "x" that represents the x coordinate of the instance's origin in the room. By setting the variable to "relative" it means the variable is increasing by 4 and not being set to the number 4. You can run your program by pressing "F5" and you should see the player move off the screen to the right.
We want the player to move when we press the arrow keys. We are going to use key down action to do this. A key down action runs when a keyboard key is first pressed down.
- Drag the If Key Down action from the "Mouse & Keyboard" section above the Assign Variable action in the action workspace.
- Change the "Key" to the Right key.
- Drag the Assign Variable action into the If Key Down action.
By dragging the Assign Variable action under the If Key Down action we made it so the variable is only changed if the right arrow key is being pressed. You can now implement action to get the player to move in the other three directions.
- Left: x - 4
- Up: y - 4
- Down: y + 4
Before we implement shooting, we want the player instance to follow the cursor so it will always face the direction it is firing. We will need to change the rotation of the player to do this using a temporary variable that only exists in the action.
- Drag the Declare Temp action to the action workspace from the "Common" section.
- Call the temporary variable "dir."
- Set the value to "point_direction(x, y, mouse_x, mouse_y)".
- Finally, drag the Set Instance Rotation action from the "Instances" section.
- Set the "Angle" of the new action to "dir."
If you run your game by pressing "F5," you should see that your player moves using the arrow keys and rotates to follow the mouse cursor.