Landers | Creating an invader game object.
- In the assets panel, inside the 'main' folder, create a game object with the 'Name' property set to be, 'invader'.
Note, this is not to be created in the main.collection because we want to use a factory to spawn multiple instances of the invader later. We don't want to manually create each invader in the collection. We do this with the player controlled ship because there is only one object and we always want to see it on the screen.
Step-by-step guide
- In the assets panel, right click, 'main' and select, 'New...', 'Game object'.
- Set the 'Name' to be, 'invader' and click, 'Create Game Object'.
- Add a sprite to the invader game object and assign it the animation, 'alien' from the graphics atlas.
Step-by-step guide
- In the outline panel, right click, 'Game Object' and select, 'Add Component', 'Sprite'.
- Set the 'Image' property to be '/maingraphics.atlas'.
- Set the 'Default Animation' property to be 'alien'.
- In the outline panel, right click, 'Game Object' and select, 'Add Component', 'Sprite'.
Space invaders is different to many other games because although the invaders move, fire and die individually, they have a swarm behaviour too. An invader changes direction, not when it reaches the edge of the screen, but when any invader reaches the edge of the screen. An invader only fires if it is the bottom invader in the column. Therefore the invaders have to have an awareness of each other. There are many ways to achieve this, perhaps the most obvious might be through message passing. However, the easiest implementation would be to create a swarm game object that controls all the individual invaders.
- Save the changes by pressing CTRL-S or 'File', 'Save All'.
Later we will return to the invader game object to handle colliding with a missile, but for now we'll continue getting them to spawn. Stage 3b >