TGB/BasicTutorial5

From TDN

This page is a Work In Progress.


Contents

Overview

The following links can take you to previous sections of the tutorial:

TGB Shooter Tutorial Part 1 - Importing Images
TGB Shooter Tutorial Part 2 - Level and Player Setup
TGB Shooter Tutorial Part 3 - Know Your Enemy
TGB Shooter Tutorial Part 4 - Picking a Fight
TGB Shooter Tutorial Part 5 - Adding Particle Effects

For Part 5 - Adding Particle Effects, please continue reading below.


TGB Basic Tutorial - Part 5


Making it Pretty


At this point, as far as functionality goes, this game is complete. However, since TGB has a really powerful particle system, it would be a shame to let it go to waste. So, this final section deals with adding particle effects to our game and making things look pretty!


The first particle effect we're going to add is an engine thruster flame to the back of the player ship. First we're going to create a "link point" on the player ship sprite, which we will then "mount" the thruster particle effect to. First, select the player ship and click on the "Edit this objects link points" button:


Image:TGB_Tutorials_Shooter_PlayerShipThrusterMount1.jpg


Next, create a single link point at the back of the engine:


Image:TGB_Tutorials_Shooter_PlayerShipThrusterMount2.jpg


Now go into the Create tab of the level builder and find the Particle Effects section. Click and drag the particle effect named "smallThruster" and drop it near the player's ship.


Image:TGB_Tutorials_Shooter_PlayerShipThrusterMount3.jpg Image:Tgb_jet.gif


After adding the particle effect to the level (feel free to resize it a bit), click on its "Mount this object to another object" button. You'll see a set of yellow crosshairs on the player's ship at the location where you added the link point.


Image:TGB_Tutorials_Shooter_PlayerShipThrusterMount4.jpg


Hover the mouse (which the thruster particle effect is attached to) over the yellow cross hairs until the particle effect snaps to that location, then click once to mount the effect the player ship's link point.


Image:TGB_Tutorials_Shooter_PlayerShipThrusterMount5.jpg


If you run the game now, you'll see the particle effect following the player ship. You'll also see that when the player dies, thethruster particle effect is still visible. To fix this, simply select the particle effect, and check the "Owned By Mount" and "Inherit Attributes" settings in the Mounting section in the Edit tab.


Image:TGB_Tutorials_Shooter_PlayerShipThrusterMountSettings.jpg



Blowing Stuff Up


Now that we have an engine fire for our player ship, let's add a cool explosion that triggers when the player and enemies blow up. To do this requires some reworking of our code.


In player.cs we will be adding some code to the PlayerShip::explode() function. Here is the current code:


function PlayerShip::explode(%this)
{
   %this.isDead = true;
   %this.setEnabled(false);
   %this.schedule(2000, "spawn");  
}


Here is what our new explode function should look like:


function PlayerShip::explode(%this)
{
   %this.isDead = true;
   %explosion = new t2dParticleEffect() 
   {
      scenegraph = %this.scenegraph; 
   };
   
   %explosion.loadEffect("~/data/particles/big_explosion.eff");
   %explosion.setEffectLifeMode("KILL", 1);
   %explosion.setPosition(%this.getPosition());
   %explosion.playEffect();

   %this.setEnabled(false);
   %this.schedule(2000, "spawn");
}


As you can see, we have loaded the big_explosion particle effect into the function so that when the player ship explodes it will play the particle effect at the location the player ship was at when it exploded. We have set it to run once and then kill itself so the effect does not repeat forever.


Inside of enemy.cs, you should change the EnemyShip::explode() function to do the same:


function EnemyShip::explode(%this)
{
   %explosion = new t2dParticleEffect() 
   {
      scenegraph = %this.scenegraph; 
   };
   
   %explosion.loadEffect("~/data/particles/big_explosion.eff");
   %explosion.setEffectLifeMode("KILL", 1);
   %explosion.setPosition(%this.getPosition());
   %explosion.playEffect();
   %this.spawn();
}


After you have made these changes, save the files and run the game again. You'll see some pretty big explosions!


Image:TGB_Tutorials_Shooter_GameWithExplosions.jpg