Setting up an enemy wave

We need to set up the amount of green balls that get spawned. When we push the WaveButton, a new wave should start. Let's go ahead and add a global variable by right-clicking on the event sheet and adding a global variable. Let's call it waveCount and set its Initial value to 3, as shown in the following screenshot:

Setting up an enemy wave

Create another variable called ballCount. Set its Initial value to 0. The wave count is going to count how many total green balls are going to be spawned in a wave, and the ball count will count how many balls are on screen. We need both of these variables in order to make it work. Generally, you want to try and use the least amount of variables as possible—but often the least amount can still be a lot of variables. Even in some small games I've seen, the variable count exceeds 200.

Once you have created this global variable, let's use it. Add an event to the green ball and select the On created event, as shown in the following screenshot:

Setting up an enemy wave

Once you have these settings in your event sheet, click on Add action to add another action. In this case, we are going to add 1 to the ball count. Navigate to System | Add to and change the settings, as shown in the following screenshot:

Setting up an enemy wave

We need to do this in order to count how many balls are on the screen. As soon as the object is created, we add one to the ball count. Let's add another event. This event will be a Compare variable event, as shown in the following screenshot:

Setting up an enemy wave

We can use this Compare variable event to compare variables. We can compare numbers or other variables. We are going to compare the global variable isWave to 1, as shown in the following screenshot. This means that when the wave is occurring, such as when the game has started, the game starts and the enemies spawn.

Setting up an enemy wave

Click on isWave =1 and press C. This will add another condition. This means in order for the following actions to take place, both of these conditions have to be true. Select System and Compare variable. This time, we will compare ballCount to being less than or equal to waveCount. In the Value field, select waveCount as shown in the following screenshot:

Setting up an enemy wave

Select isWave again and press C. This will add another condition. In this case, we are going to add an Every X seconds condition, as shown in the following screenshot:

Setting up an enemy wave

Your event sheet should look like the following screenshot:

Setting up an enemy wave

Now, we have to add another action. This action is going to be for the start block. Select Spawn another object from the available options in the Add action window, as shown in the following screenshot:

Setting up an enemy wave

We are going to spawn the BallGreen object. We are also going to set the Layer value to 1 with Image point set to 1, as shown in the following screenshot. We need to have the object spawn on the top layer. We haven't discussed image points yet, but we need to set one up.

Setting up an enemy wave

Once you have this in your event sheet, go back to your layout and double-click on the Start box. We then need to add another image point. The image has a default image point called Origin. Any other image point after Origin is called Imagepoint. Click on the Image points dialog box and click on the plus icon, as shown in the following screenshot:

Setting up an enemy wave

Doing so should automatically add an image point. Note that Imagepoint has a different icon than Origin. The image point is not the origin; it is simply a place where we can point to on the sprite. Place the image point outside where you want the green ball to spawn. This is really handy because this would be much harder to do in other environments. Your image box should look something like the following screenshot:

Setting up an enemy wave

Now, we are almost ready. Let's go back to our event sheet and find BallGreen and find Find path to action. Select it and press Ctrl + C to copy the action. Find the BallGreen object's On created event and paste the action. In this case, the order does not matter. Generally, the order of actions does matter; if you are making a game and you find that your game doesn't work properly, go through the action logic and see whether it makes sense. The following screenshots show what it looks like before and after:

Setting up an enemy wave
Setting up an enemy wave

We are almost finished. What we need to do next is add two Compare variable events. Let's compare whether isWave is to equal to 1 and ballCount is equal to 0. The next thing we have to do is add an action. This action will set the value of isWave to 0. The way this works is that once all of the balls have been spawned, we need to turn off the spawner. We do this by setting isWave back to 0.

Your event sheet should look like the following screenshot:

Setting up an enemy wave

Next, let's go to the Projectile on collision with green ball event and add an action. Add a System action and choose Subtract from, as shown in the following screenshot:

Setting up an enemy wave

We are going to subtract from ball count. We are going to set the value of the variable to 1, as shown in the following screenshot. When the projectile destroys the ball, this will subtract the number of balls we have on the screen.

Setting up an enemy wave
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.119.133.160