Adding a spawner

Now, we need to add a spawner. A spawner spawns game objects. Go ahead and add a sprite; it should look something like the following screenshot. Rename it Spawner.

Adding a spawner

What we need to do is change the size of the spawner. Double-click on the spawner and select Resize, as shown in the following screenshot:

Adding a spawner

Then resize it to 50 by 50 with the help of the Resize option. Then, click on the paint bucket tool and fill in the color. We do this because otherwise we won't be able to see the spawner. I suggest making the spawner a bright and obvious color. We're going to make our spawner pink, as shown in the following screenshot:

Adding a spawner

After this, click on Close. Now, we have to copy the spawners and put them in the playing area. You can press Ctrl and drag the spawner to copy quickly. If that doesn't work, you can use the copy-and-paste method. The game area should look like the following screenshot:

Adding a spawner

Now, we need to add functionality to the spawners. Go back to the event sheet and add an Every X seconds event, as shown in the following screenshot:

Adding a spawner

Let's add a time interval of 2.0 seconds in the Parameters for System: Every X seconds dialog box, as shown in the following screenshot. This will spawn an enemy at each spawner location every 2 seconds.

Adding a spawner

Add an action to this event by navigating to Add action | Spawner | Spawn another object. We want to spawn the enemy, so we select Enemy in the Parameters for Spawner: Spawn another object dialog box. This is shown in the following screenshot:

Adding a spawner

Your project should look like the following screenshot when you click on Done:

Adding a spawner

What we need to do now is add some logic for when the enemy hits the player. For this, we will restart the layout.

Adding a spawner

Then, we will add an action. Go to System, then select Restart layout. This should restart the layout.

Adding a spawner

Go ahead and try out the game. There you go, you have a shooter! What you can do now is modify this code as much as you want. You have a basic shooter to play with—it's your job to add more functionality. Add more projectiles, enemies, and other cool game mechanics.

..................Content has been hidden....................

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