Chapter 6
In This Chapter
Creating a Time Line
Using Objects with Time Lines
Placing a Time Line Object in a Room
Introducing a boss battle
In this chapter, I show you how to create a Room using a Time Line, which you can then use as a level in your game. I conclude the chapter by providing an example of how to create a boss battle.
I’m particularly proud of the boss battle tutorial, because I came up with it on my own after finishing the in-software Scrolling Shooter tutorial (you can find tutorials within GameMaker from the New Project window). As I was teaching myself how to create the boss battle, my research showed me how to perform certain Actions through code instead of using the drag-and-drop Action icons. Later, I learned that I could perform those Actions I coded by hand by using the drag-and-drop Actions. It just goes to show that there are multiple ways to perform the same Actions — by using code or by using the drag-and-drop Action icons. GameMaker is such a flexible tool that you can mix and match handwritten code (through an Execute Code Action; see Chapter 4) and the Action icons within the same Events.
When using Time Lines, you need to become familiar with how X and Y coordinates work, which is how you place Instances of Objects in the Room. At first, using Time Lines may seem like an arduous task of determining X and Y coordinates as opposed to placing the Instances in the Room by hand (as you do when using Views; see Chapter 5). However, after you’ve set up an enemy fleet of planes, the Time Line provides an extremely flexible way to quickly change when the enemy planes appear by simply updating the Step number. When you manually place the planes using Views, you have to go back and select each plane and then move them up and down the Room to change when they appear. There are trade-offs to each method — you’ll learn through experience when it’s the best time to use the different techniques.
Using Time Lines to create and control enemy behavior gives you significant control over how your game plays. The in-software Scrolling Shooter tutorial begins by showing how to create a game using a random generator for the enemy planes. This creates a challenging game in that it continuously gets harder over time, but there are problems with that approach, such as planes overlapping each other. Time Lines can help solve that problem.
When you use Time Lines, you present the player with the same pattern of enemy planes each time they play the game. It provides players with an opportunity to learn the game, so they can play it better over time. This gives players a sense of satisfaction — which is important, because they’ll want to continue playing your game!
When working with Time Lines, you use Time Line resources; within each Time Line resource, you specify a number of Moments in time (measured in steps of the game); and for each Moment, you create an Action. In this tutorial, you create Time Line resources that control when enemy planes appear. The planes should be destroyed when they leave the Room and not reappear.
When you create a Time Line, you work with the Time Line Properties window, which looks similar to the Object Properties window. You can name the Time Line, you can add Moments (as compared to Events when working with Objects), and to those Moments you drag and drop Actions from the tabs (see Figure 6-1).
To create a Time Line, follow these steps:
The Time Line Properties window appears.
The name appears in the Name field.
The Adding a Moment dialog box appears (see Figure 6-2).
A Moment is measured in steps, so if you enter 1 in the Adding a Moment dialog box, the Actions you assign to this Moment will trigger at the first step of the game.
Step 0 appears in the Moments column of the Time Lines Properties window.
The Create Instance Action properties window appears (see Figure 6-3).
The name of the Object appears in the Object field.
You can get the X and Y coordinates from the Room, which you create next.
The Action is listed in the Actions section of the Time Line Properties window (see Figure 6-4).
You can have more than one Action per Moment if you want more than one thing to happen at a time during your game. In the next procedure, I show you how to create a second Moment in the Time Line that has more than a single Action.
To add more Moments in the Time Line, to trigger additional enemy planes to appear during the game, follow these steps:
The Adding a Moment dialog box appears.
It takes approximately 100 steps in the game for an enemy plane to travel down the Room (based on the Scrolling Shooter tutorial).
The new Moment appears in the Moments section of the Time Lines Properties window.
The Create Instance Action properties window appears.
Try placing different types of enemies in the game, such as enemies that don’t shoot, those that do shoot, and others that can shoot bullets that track the player. You can find examples of this in Chapter 5.
The name of the Object appears in the Object field.
You can get the X and Y coordinates from the Room, which you create next.
The Create Instance Action appears in the Actions section of the Time Lines Properties window.
The Create Instance Action properties window appears.
The name of the Object appears in the Object field.
You can get the X and Y coordinates from the Room, which you create next.
The Create Instance Action appears in the Actions section of the Time Lines Properties window.
Now you should have two Moments defined in your Time Line: one Moment at Step 0, which creates an Instance of a single enemy plane, and a second Moment at Step 50, which creates two enemy planes flying on either side of the Room (see Figure 6-4). Before you can test the Time Line, you need to create a new Room and an Object for the Time Line.
In this chapter, I show you how to build a Time Line that you then place in a Room. You can think of the levels in your game as a different Room that contains a different Time Line. In that sense, you can create multiple Time Lines within multiple Rooms that the player can transition to as they complete each level. I show you how to do the transitioning later, but for now, I show you how to create a new Room and an Object for a Time Line.
To create an Object for the Time Line, which you’ll place in the Room, follow these steps:
The Object Properties window appears.
A Create Event appears in the Events section.
The Set Time Line Action properties window appears (see Figure 6-6).
The Set Time Line Action properties window is saved.
You’ve created an Object for the Time Line you created earlier. You can place an Instance of this Object in a Room, so that your Time Line is triggered during the game. In the next section, I show you how to create a new Room in which you can place your Time Line Object.
To get your Time Line to trigger during a game, you need to place an Instance of a Time Line Object (see the preceding section) into a Room. To create a Room for a Time Line Object, follow these steps:
The Room Properties window appears.
The Room is represented by a square grid on a gray background (unless you replaced it with a background image), and you’ll see a transparency pattern behind that (refer to Figure 6-8).
The name of the Object appears in the field.
A blue circle with a question mark appears in the Room where you clicked (refer to Figure 6-8). The blue circle is shown because you didn’t load a Sprite to the Object. This blue circle doesn’t actually appear in the game.
The Room Properties window saves and closes.
Now is an excellent time to test your game. You should see the enemy planes appear as you configured the Time Line.
At this point, you can go back to your Time Line and add more Moments with additional Objects (enemy planes and islands). Now that you have a Room set up, you can reference the X and Y coordinates to help you plan formations and so forth for the enemy planes.
If you decide you want to change when a Moment happens — say, you want more enemy planes to show up sooner — you can easily do that by changing the Step number. To change the Step number of a Moment, follow these steps:
The name of the Moment appears with a blue background.
The Changing a Moment dialog box appears.
Now the Actions defined for this Moment will trigger twice as quickly as when it was set to 50.
The updated Step number appears in the Moments section of the Time Line Properties window.
To make new Actions for Moments quickly, follow these steps:
The Time Line Properties window appears.
The Actions for that Moment appear in the Actions section.
That Create Instance Action is now copied to your Clipboard.
The Action, such as the Create Instance Action, you copied earlier appears.
The Create Instance Action properties window, for example, appears.
The name of the Object you chose appears in the field.
In this way, you can quickly place Instances of Objects (such as the islands from the Scrolling Shooter tutorial) into the game. Plus, by only slightly changing the values of the coordinates, you make sure that the islands won’t appear directly beneath the planes. Unless, of course, you want to place the islands directly beneath the planes.
If you think that Views are a much easier way to place the enemy planes in the Room than using Time Lines, you aren’t necessarily wrong. However, Time Lines allow you to do much more than just create Instances. You can also end the game through a Time Line, or slow time down or speed it up. You can even pause a Time Line until a certain requirement happens. In the next section, I show you how to use the Time Line to allow the player to progress to the next Room.
Before you add an entire fleet of enemy planes to the Room, try adding a Moment that transitions the player to the next Room. To use the Time Line to transition to a new Room, follow these steps:
The Adding a Moment dialog box appears.
A new Moment appears in the Moments section of the Time Line Properties window.
The Next Room dialog box appears.
The Next Room Action appears in the Actions section of the Time Line Properties window.
Now when you test your game, when Moment 300 happens, the game smoothly transitions to the next Room, and it’s transparent to the player. If your game is set up like mine, the player starts playing the Room with a View (see Chapter 5), which then progresses to the random generator Room, which I made from following the in-software tutorial, Scrolling Shooter.
Boss battles typically occur at the end of a level or Room. A boss battle usually involves the player taking on a stronger-than-normal enemy. In this section, I show you how to add a boss battle in your Time Line for your Room. I was inspired to create this boss battle after I finished the in-software Scrolling Shooter tutorial.
In my boss battle, which I encourage you to improve upon, the boss is represented by the battleship image (see Figure 6-11) that you can find in the Assets folder for the Scrolling Shooter tutorial. In the Assets folder (which is created when you install the tutorial), there is an image called 1945_sprites. You can edit that image to create a new image of the Sprite that you want to use.
The boss appears near the end of the Time Line and moves horizontally across the room instead of vertically. If it reaches the right edge of the Room before the player can destroy it, the boss reverses directions. The boss can take five hits from the player before it’s destroyed, and then the player earns 100 points. The boss shoots guided (tracking) missiles (see Chapter 5).
You create the boss in three main parts. First, you create the Sprite. Then you create the boss Object. Finally, you add the boss to the Time Line. The boss Object includes a Create Event, a Step Event, and a Collision Event.
To create the boss Sprite, follow these steps:
The Sprite Properties window appears (see Figure 6-12).
You can then navigate to where you saved the image on your PC.
The image appears in the Sprite Editor.
Setting the Origin in this way, so that the X axis is at the far right of the image, will help turn the battleship around, because the Origin of the Sprite is at the far right. When the Origin of the image reaches the edge of the Room, the battleship turns around (you configure that in the boss Object). If the Origin was in the center of the Sprite, half of the battleship would go off screen before turning around.
You’ve configured the boss Sprite.
With the boss Sprite set up, it’s time to create an Object for the boss.
In this section, I show you how to create the boss Object, starting with the Create Event. Within the Create Event, you give the boss motion and create a variable to give the boss health (so that it takes more than one shot to destroy the Instance).
To configure the Create Event, follow these steps:
The Object Properties window appears (see Figure 6-13).
A thumbnail of the selected Sprite appears in the Sprite section, and the name of the Sprite appears in the field.
The Create Event appears in the Events section of the Object Properties window.
The Move Fixed Action properties window appears (see Figure 6-14).
The Object will move to the right during game play.
This determines how fast the Object moves during the game.
The Set Variable Action properties window appears (see Figure 6-15).
This gives the boss a health of 5, meaning it will take five hits to destroy an Instance of this Object — that is, if you set up the Collision Effect to cause –1 damage. I get to this later.
This completes the Create Event, which should look like Figure 6-16.
Next, you create the Step Event. This involves setting Test Variables to check for where the Instance of the Object is in the Room, adjusting the direction of the Object, transforming the Sprite, arming the Object, and setting a block of Actions for when the boss loses all health.
To configure the Step Event, follow these steps:
A Step Event appears in the Events section.
The Test Variable Action properties window appears.
This tests to see when the boss reaches the edge of the Room as denoted by the X axis.
The value of room_width equals the width of the Room. So, you can test when the Object’s X variable has a value greater than or equal to the X axis of the Room. This will test to see when the Object reaches the edge of the Room.
By using room_width, you’re directly referencing the width of the Room, regardless of the value. If you typed the actual value of the width of the Room — say, 544 — and then later you change the width of the Room to 600, you have to go back and update the value in the Action. But by using room_width, that isn’t an issue.
Now you need to configure the Move Fixed Action for the Step Event:
The Moved Fixed Action properties window appears.
Between the Move Fixed Action and the preceding Test Variable Action, you just told GameMaker to change the direction of the Instance from moving right to moving left when it reaches the edge of the Room.
The Test Variable Action properties window appears.
This tests to see when the boss reaches the edge of the Room, as denoted by the X axis.
The value of 0 equals the left edge the Room.
Now to configure the Move Fixed Action for the Step Event:
The Moved Fixed Action properties window appears.
Between the Move Fixed Action and the preceding Test Variable Action, you just told GameMaker to change the direction of the Instance from moving left to moving right when it reaches the edge of the Room.
Now to configure the Transform Sprite Action for the Step Event:
The Transform Sprite Action properties window appears.
This Action forces the Sprite to face the direction it’s moving, so if the boss reaches the edge of the Room and needs to turn around, the front of the ship will face to the right instead of the left.
The Test Chance Action Properties window appears.
This determines how often the boss will shoot at the player. In this case, the boss has a 1 in 30 chance (based on a 30-sided dice roll) of performing the next Action for every step of the game.
Now to configure the Create Instance Action for the Step Event:
The Create Instance Action properties window appears.
In this case, the Object will fire a bullet 1 chance out of 30 for every Step, as determined in the Test Chance Action you previously set.
In this Action, you’re going to use Relative and not a set coordinate.
In this Action, you’re going to use Relative and not a set coordinate.
You want the bullet to appear from the location of the Instance — in this case, the boss battleship.
You’re almost done with the Step Event. The next procedure shows you how to finish the Step Event by adding a Test Variable to see when the boss’s health reaches 0. When that happens, the player’s score should increase, the boss should be destroyed, and you can display a message declaring victory!
The following procedure is a continuation of the previous procedure. However, it does provide a great example of setting up a code block to trigger when a Test Variable tests positive. To create a code block for when the boss’s health reaches 0, follow these steps:
The Test Variable Action properties window appears.
You’re testing for when the boss has 0 health.
Now, when the boss health equals 0, the Test Variable Action will trigger the following block of Actions.
A Start Block Action appears in the Actions section.
The Set Score properties window appears.
The player will earn 100 points when the boss’s health reaches 0.
You want the player’s score to increase by 100, and not remain at 100 each time the Set Score Action is triggered.
The Set Score Action properties window is saved and closed.
The Destroy Instance properties window appears.
The Destroy Instance Action will destroy the Instance of the boss Object when the health reaches 0.
The Display Message dialog box appears.
An End Block Action appears in the Actions section. Now, all the Actions within the code block will be triggered when the Test Variable Action checks that the boss’s health has reached 0. The Actions triggered include increasing the player’s score, destroying the Instance of the boss Object, and displaying a message.
That concludes the Step Event, which should look like Figure 6-17.
Next, you create the Collision Event. This involves destroying the Instance, creating the explosion Sprite, adding some code for reducing the boss’s health, and increasing the player’s score if the boss is destroyed. To configure the Collision Event, follow these steps:
A Collision Event for when the player’s bullet hits the boss appears in the Events section.
The Destroy Instance dialog box appears.
This destroys the Instance of the player’s bullet that hit the boss (the Instance that caused the collision). Any other Instances of the player’s bullet will remain in the Room.
The Create Instance properties window appears.
Choose an Object that represents an explosion.
You’re going to use Relative.
The explosion appears where the bullet hits the boss.
The Set Variable Action properties window appears.
The Instance of the boss will lose 1 health for every bullet collision.
You want the boss to lose only 1 health for each collision with a bullet.
That concludes configuring the boss Object. The Collision Event should look like Figure 6-18. Next, you need to add the boss to the Time Line.
To add the boss Object to a Time Line, follow these steps:
The Adding a Moment dialog box appears.
The Create Instance properties window appears.
You just added the boss battle to your game!
Congratulations! You’ve created a boss battle in your Scrolling Shooter game using a Time Line. Now is the time to dig into the details and refine it to meet your satisfaction. For example, what if the player doesn’t destroy the boss but instead flies past it? Then you could add another Moment in the Time Line — say, at position 300 — to either restart the room (by using the Restart Room Action) or repeat the battle (by using the Time Line Position Action — in the Position field, type 200, or wherever the boss battle is set to begin). Those are just a couple ideas to get your creative juices flowing.
3.140.188.244