Game Development Tutorial
0 – Introduction
We will develop a simple game where the main player is a dog and the objective is to protect his owner from the spiders’ attack before the time runs out.
I – Creating the project and choosing the environment
Open Livit Studio, create a new project called “Survive”, we will only need one scene for this project, we will call it here “S1”.
After creating the project, choose the environment “Clinic”.
II – Adding objects to the scene
- The Dog that will be the main player, call him “player”, add the animation “idle”, then add to the dog a sound for Eating or Munching.
- A random character that will act as the owner of the dog, we chose Girl1, Call her “girl”, place her at a corner of the room, add the animation “sitting pose”, then add to the girl 2 sounds: Win and Lose (Available in Livit Studio sounds).
- A spider and place it at the other side of the room, add the animation “walk”.
- Place the main camera at the back of the girl.
III – UI elements
Add 3 text objects as following:
- Name it “StatusText”, position it at the Top Middle of the camera view. This will be used to inform you about the status of your game. Set its initial text as: “Save The Girl From The Spiders Before The Time Runs Out!”.
- Name it “TimerText”, position it at the Bottom Left of the camera view. Set its initial text as: “Timer”.
- Name it “TimerNumText”, position it Under “TimerText”. Set its initial text as: “30” (For 30 seconds).
IV – Code
Here is a list of all the variables we are going to use through the game development. You can create them all from the beginning or one by one as we go through the tutorial.
|gameOver||Bool||False||To indicate that the game is over.|
|Timer||Int||30||To store the remaining time.|
|stopMovement||Bool||False||To stop the movement of spiders when the level is completed successfully.|
- Disable the game object on start.
- When it is enabled, look at the girl in order to move at its direction then start moving forward a distance10 in time20.
On collision with another game object, check if it is the player, if this is true, get the player game object and play the eating sound, then disable the spider game object, reset it to its initial position then enable it again
On collision with another game object, check if it is the girl, if this is true, set the gameOver variable to true in order to stop the game.
In a repeat block, check if the stopMovement variable is true, if it is,stop all the movement and stop the animation
After finishing the scripts, enable physics for this object and check the “kinematic object” box.
Duplicate the spider, make another 3 copies of it and place them as follows
Another tip: move each spider backward until they disappear behind the room walls as following
Here we will add 2 scripts that control general aspects of the game.
Here we will enable the spiders for the first time, we will enable them gradually, each one after 3 seconds.
Onstart, wait for 3 seconds then get the “spider-1” game object to enable it, then repeat the previous blocks (Wait, Get GameObject, Enable GameObject) to enable the remaining 3 spiders.
Here we will control the timer and change the “StatusText” to “Game Over!” or “Level Completed!”.
- On start, set the timer variable to 30.
- Make a For loop with counter 30.
- On each loop, check if gameOver is equal to false, wait for 1 second and decrease the timer variable by 1.
- Display the new timer.
- If the gameOver is equal to true, break the loop.
- When done, stop the animation, write “Game Over!”, then play the Lose sound if gameOver is true, write “Level Completed!” and set the stopMovement variable to true, then play the Win sound if gameOver is false.
After finishing the script, enable physics for this object.
Script 1: Forward and backward movement
- Forward movement: when you press the Up Arrow key, check first if the gameOver variable is false (this indicates that the game isn’t finished yet and you are able to move), then get the forward direction of the car and move it in this direction with a distance 2 in time 0.5.
- Backward movement: when you press the Down Arrow key, check first if the gameOver variable is false, then get the backward direction of the car and move it in this direction with a distance 2 in time 0.5.
Script 2: Forward and backward movement
- Right movement: when you press the Right Arrow key, check first if the gameOver variable is false, then Rotate with angle 30 in time 0.5.
- Left movement: when you press the Left Arrow key, check first if the gameOver variable is false, then Rotate with angle -30 in time 0.5.
Script 3: animation
when you press the Up Arrow key, check first if the gameOver variable is false, then play the animation “running”.
Do the same for the Down Arrow key.