Setting up the bricks.
In this tutorial we’ll set up 2 schematics for counting and destroying the bricks. Destroying a brick will additionally check if all bricks have been destroyed and display a victory notification in that case.
Bricks will have a health, i.e. we can control how many times a brick has to be hit by the ball to be destroyed – the health will be stored in the int object variable health. We’ll set up 3 different bricks.
First, we’ll create the schematic to count the bricks. This schematic will be added to the bricks and simply increase the global int variable bricks by 1. We could also just set the global variable to the number of bricks when starting the game, but this would result in having to adjust it each time we change the number of bricks (e.g. in additional levels). By having the bricks count themselfs when the level starts, we don’t need to manually do this for each level.
Open the Makinom editor, navigate to Schematics and create a new schematic. Change the following settings.
Add Node > Value > Variable > Change Variables
We’ll use this node to increase the global variable bricks by 1.
Click on Add Variable to add a variable change.
That’s it for this schematic – click on Save Schematic and save it as BrickCount in Assets/Schematics/.
Next, we’ll create the schematic handling the destruction of the brick. After the brick is destroyed (when the health was reduced to 0), it’ll check if all bricks have been destroyed. If all bricks are destroyed, a victory notification is displayed and the level is reloaded.
Create a new schematic and change the following settings.
A particle effect should be displayed when a brick is destroyed, we’ll add it as a prefab.
Click on Add Prefab Resource to add a prefab resource.
We’ll use this node to reduce the health of the brick by 1.
Add Node > Value > Variable > Check Variables
We’ll use this node to check if the health has reached 0.
Click on Add Variable to add a variable condition.
Add Node > Audio > Audio > Play Sound (Channel)
We’ll use this node to play an explosion sound effect when the brick is destroyed.
This node is connected to the Success slot of the previous Check Variables node (i.e. the health has reached 0).
Now that the brick is destroyed, we’ll reduce the number of bricks and increase the player’s score. The points the player earns for a brick is stored in the object int variable points.
Copy the previous variable change and change the following settings.
Add Node > Game Object > Prefab > Spawn Prefab
We’ll use this step to spawn the particle effect.
Add Node > Game Object > Prefab > Destroy Prefab
Next, we’ll destroy the prefab after 5 seconds.
Add Node > Game Object > Game Object > Destroy Object
We’ll use this node to destroy the brick (machine object). We’ll need to disable Stop On Destroy in the Collision Machine used to play this schematic to prevent it from being stopped here.
Now, we’ll check if all bricks have been destroyed.
Add Node > Game > Game > Change Game State
All bricks have been destroyed – we’ll use this node to set Game Running to Inactive.
This node is connected to the Success slot of the previous Check Variables node (i.e. all bricks have been destroyed).
Click on Add Game State to add a state change.
Add Node > UI > Dialogue > Show Dialogue
We’ll use this node to display a victory notification to the player. It’ll be displayed for 3 seconds and automatically close afterwards.
We haven’t set up the UI box yet, but that doesn’t matter as Makinom automatically creates a default UI box in a new project. We can just use that, but the actual UI setup still has to be done at a later point.
Before reloading the level, we’ll reset the global variables used for the game (lives to 3, bricks to 0, ballInPlay to false).
Click on Add Variable again to add another variable change.
Add Node > Game > Scene > Load Scene
We’ll use this node to reload the scene.
Finally, we’ll set Game Running to Active again – the game continues.
And that’s it for this schematic – click on Save Schematic and save it as Brick in Assets/Schematics/.
The setup for all 3 bricks is the same (except for minimal differences in the Object Variables). The following component setup can be repeated for all brick prefabs, or you can just copy the components and paste them on the other bricks.
You can copy a component by right-clicking on the component’s name and selecting Copy Component in the context menu. To paste the component on a game object, right-click on any component’s name and select Paste Component As New in the context menu.
The brick prefabs (Brick 1, Brick 2 and Brick 3) can be found at Assets/Tutorial Resources/Prefabs/.
First, we’ll set up the object variables of the bricks. Add an object variable component to the prefabs (e.g. using the component menu: Makinom > Scenes > Object Variables). Change the following settings.
Click on Add Variable to add an object variable.
Copy the variable and change the following settings.
That’s it for the object variables.
Next, we’ll add the Brick Count schematic using an auto machine component. The schematic will increase the bricks count by 1 for each brick that’s added to the scene.
Add the component to the brick prefabs (e.g. using the component menu: Makinom > Machines > Auto Machine). Change the following settings.
Finally, we’ll add the Brick schematic using a collision machine component.
Add the component to the brick prefabs (e.g. using the component menu: Makinom > Machines > Collision Machine). Change the following settings.
And that’s it for the prefabs – we don’t need to apply the changes, since we worked on the prefabs directly. The bricks in the scene should have been updated automatically with the new components.
Hit Play to test the game. You can now destroy the bricks by hitting them with the ball – some bricks take more hits and give more points than others.
When all bricks have been destroyed, a message is displayed (although we don’t see it yet) and the level reloads. But we’re not done yet, if you miss the ball, it just continues falling down, making the game unplayable.
The next tutorial will handle loosing a life.
© 2015 Gaming is Love e.U.
Disclosure: This site may contain affiliate links, which means I may receive a commission if you click a link and purchase something that I have recommended. While clicking these links won’t cost you any money, they will help me fund my development projects while recommending great assets!