Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
gdevelop5:tutorials:tank-shooter [2019/03/08 00:53]
4ian
gdevelop5:tutorials:tank-shooter [2019/03/08 00:59] (current)
4ian
Line 174: Line 174:
 {{ :​gdevelop5:​tutorials:​timer-value-condition-parameters.png?​nolink |}} {{ :​gdevelop5:​tutorials:​timer-value-condition-parameters.png?​nolink |}}
  
-We aren't done yet! We want to shoot bullets every 0.25 seconds. To do that, we need to reset the timer to start from 0 after 0.25 seconds. So let's add an action: "​Timers and time" ​ "Reset a timer"​. This action will be placed just below our "​movement"​ action in the same event. ​+We aren't done yet! We want to shoot bullets every 0.25 seconds. To do that, we need to reset the timer to start from 0 after 0.25 seconds. So let's add an action: "​Timers and time" ​ "Start (or reset) ​scene timer"​. This action will be placed just below our "​movement"​ action in the same event. ​
 {{ :​gdevelop5:​tutorials:​reset-timer-action.png?​nolink |}} {{ :​gdevelop5:​tutorials:​reset-timer-action.png?​nolink |}}
 Enter “firerate” as the parameter which is the name of our timer ( again, be aware of the quotes! ). Enter “firerate” as the parameter which is the name of our timer ( again, be aware of the quotes! ).
Line 225: Line 225:
  
 ==== Enemy AI ==== ==== Enemy AI ====
-Let's go back to the game. We want the enemies ​moving ​toward the turret. ​ Go to the "​Event"​ editorAdd a new event. ​Now, we want to create an enemy every second. Add a condition "​Timers and time";  ​"Value of a scene timer"​. Enter 1 in the "Time in seconds"​ and EnemyCreation” for the "​Timer'​s name"​. ​+Let's go back to the game. We want the enemies ​to move toward the turret. ​ 
 +Go to the "​Event"​ editor ​and Add a new event. ​We want to create an enemy every second. Add a condition, that can be found in category ​"​Timers and time", called ​"Value of a scene timer"​. Enter 1 as the "Time in seconds"​ and "EnemyCreation" ​for the "​Timer'​s name"​. ​
 //​Don'​t forget the quotes when you enter the name of the timer.// //​Don'​t forget the quotes when you enter the name of the timer.//
  
-The next step is to add an action to create an enemy object. ​This is done using the "Add an action"​"​Common action for all objects","​Objects"​"​Create an object"​. Select "​enemy"​ in the first "​Object to  create"​ parameter. For the second "X position"​ parameter, enter the expression Random(800). This entry will return a random number between 0 and 800. When each enemy is created, it will have a different screen position. For the Y position, enter -50. This value will create the enemies outside of the screen area. Creating the enemies off screen keeps the game's player from feeling that an enemy tank appeared from nowhere.+The next step is to add an action to create an enemy object. ​Click on "Add an action"​. Search for "​Common action for all objects",​ "​Objects" ​and choose ​"​Create an object"​. Select "​enemy"​ in the first "​Object to create"​ parameter. 
 + 
 +For the second "X position"​ parameter, enter the expression ​`Random(800)`. This expression ​will return a random number between 0 and 800.  When each enemy is created, it will have a different screen position. ​ 
 + 
 +For the Y position, enter -50. This value will create the enemies outside of the screen area. Creating the enemies off screen keeps the game's player from feeling that an enemy tank appeared from nowhere.
    
-Finally, let's add an action to reset the timer ( "​Timers and time",  ​Reset a timer". “EnemyCreation” ​should be entered in the parameter. Again, don't forget the quotes when you enter the name of the timer.+Finally, let's add an action to reset the timer ( "​Timers and time",  ​"Start (or reset) ​scene timer"​). Enter “EnemyCreation” ​as the name of the timer. Again, don't forget the quotes when you enter the name of the timer. 
 At this point, our event will look like this: At this point, our event will look like this:
 {{ :​gdevelop5:​tutorials:​create-enemy-event.png?​nolink |}} {{ :​gdevelop5:​tutorials:​create-enemy-event.png?​nolink |}}
  
 If we run a preview now, we won't notice anything. Since the enemies are created off the screen, they can't be seen. If we run a preview now, we won't notice anything. Since the enemies are created off the screen, they can't be seen.
-In order to see the enemy, we need to move the enemies toward the player. To create ​this action add another event. This event has no condition. Choose "Add action"​. ​Then from the popup panel, select ​"​Common action for all objects",​ "​Movement"​"Add a force to move toward an object"​.+In order to see the enemy, we need to move the enemies toward the player. ​ 
 + 
 +To do this, add another event. This event has no condition. Choose "Add action"​. ​Select ​"​Common action for all objects",​ "​Movement" ​and choose ​"Add a force to move toward an object"​.
 {{ :​gdevelop5:​tutorials:​move-object-toward-other-event.png?​nolink |}} {{ :​gdevelop5:​tutorials:​move-object-toward-other-event.png?​nolink |}}
  
Line 243: Line 251:
  
 Now, if we run a preview, we will see that our enemies moving toward the turret. However, you might notice that the enemies don't actually rotate toward the turret. Let's do something about that. Now, if we run a preview, we will see that our enemies moving toward the turret. However, you might notice that the enemies don't actually rotate toward the turret. Let's do something about that.
-Let's add a second action after the movement: "​Common action for all objects",​ "​Angle",​ "​Rotate toward position"​. For the first parameter on the right of the panel, select "​enemy"​. We want to rotate the enemy. For the X and Y position, we are going to use an expression to get the Centre point of the turret and make the enemies rotate toward that point with an angular speed of 0. An angular speed of 0  causes immediate object rotation.+ 
 +Add a second action after the movement: "​Common action for all objects",​ "​Angle",​ "​Rotate toward position"​. For the first parameter on the right of the panel, select "​enemy"​. We want to rotate the enemy. For the X and Y position, we are going to use an expression to get the Centre point of the turret and make the enemies rotate toward that point with an angular speed of 0. An angular speed of 0  causes immediate object rotation. 
 {{ :​gdevelop5:​tutorials:​rotate-object-toward-position.png?​nolink |}} {{ :​gdevelop5:​tutorials:​rotate-object-toward-position.png?​nolink |}}
 +
 At this point, our enemy event will look like this: At this point, our enemy event will look like this:
 +
 {{ :​gdevelop5:​tutorials:​create-rotate-move-enemies-event.png?​nolink |}} {{ :​gdevelop5:​tutorials:​create-rotate-move-enemies-event.png?​nolink |}}
  
 If we run the preview now, our enemies will move and rotate toward the turret. If we run the preview now, our enemies will move and rotate toward the turret.
 +
 {{ :​gdevelop5:​tutorials:​turret-screenshot-enemies-moving.png?​nolink |}} {{ :​gdevelop5:​tutorials:​turret-screenshot-enemies-moving.png?​nolink |}}
 +
 ==== Adding explosions ==== ==== Adding explosions ====
 +
 It time to destroy the tanks! First, when a bullet collides with a tank, we need an explosion at the position of the tank.  It time to destroy the tanks! First, when a bullet collides with a tank, we need an explosion at the position of the tank. 
 Add a new sprite object, name it "​explosion",​ and add all the images to the animation beginning with Explosion_ Add a new sprite object, name it "​explosion",​ and add all the images to the animation beginning with Explosion_