In this game, we will be using the Overlord, the master controller of the game, to control the spawning of enemies, monitor the player's lives, and deal with the win/lose condition. The win condition will simply be to survive for two minutes against waves of enemies. The lose condition will be that the player runs out of lives.
We need to start by creating the wave of enemies, so that the game is playable. For this, we will utilize a looping timeline to spawn the various enemies. We are going to have three different waves, each one spawning a different enemy every two seconds.
scr_Wave_Strafer
, scr_Wave_SpaceMine
, and scr_Wave_FloatBot
.scr_Wave_Strafer
:instance_create(room_width - 64, room_height/2 - 64, obj_Strafer); instance_create(room_width - 64, room_height/2 + 64, obj_Strafer);
Here we spawn two instances of the Strafer located 64
pixels off the right-hand side of the screen. This will ensure that we don't see them pop into existence. We have also offset them by 64
pixels from the vertical center of the room.
scr_Wave_SpaceMine
:placeY = irandom_range(64, room_height - 64); instance_create(room_width - 64, placeY, obj_SpaceMine);
We are creating a variable called placeY
to hold a value for the vertical position. GameMaker: Studio has a special function, irandom_range
, which will return a whole number between any two numbers passed to it. The numbers we used will ensure that the SpaceMine will remain at least 64 pixels away from the top and bottom of the screen. We then use the placeY
variable when we create the instance.
scr_Wave_FloatBot
:placeY = irandom_range(80, room_height - 80); instance_create(room_width - 32, placeY, obj_FloatBot); instance_create(room_width - 64,placeY - 32, obj_FloatBot); instance_create(room_width - 64, placeY + 32, obj_FloatBot);
Here we are using the placeY
variable again, but the range of numbers is narrower. We need some extra padding, so that all three planes stay onscreen. The first instance created is the front unit of the formation. The next two instances spawn 32 pixels behind and offset 32 pixels above and below the first.
tm_Wave_Spawning
.60
, and apply the scr_Wave_FloatBot
script. This will spawn the first enemy into the game for two seconds.120
, and apply the scr_Wave_SpaceMine
script.180
, and apply the scr_Wave_Strafer
script. The Time Line is now ready to be used and should look like the following screenshot:We are now ready to start building the Overlord and apply our spawning system.
obj_Overlord
.scr_Overlord_Create
, and write the following code:timeline_index = tm_Wave_Spawning; timeline_running = true; timeline_loop = true;
The first line of code defines what Time Line we want to run, in our case we only have one: tm_Wave_Spawning
. Next, we start the Time Line and then tell it to loop. These last two are Boolean variables, which means that they can only be turned on and off.
The game now has enemies! It will take a couple of seconds for the first enemy, the FloatBots, to appear, but after that the enemies will continue to spawn forever. At this point we have most of the core gameplay implemented as follows:
The only element remaining is very obvious when playing the game at this stage; the player can die, but the game doesn't stop. We need to implement the win/lose condition.
18.217.150.123