Game Development Community

Plastic Gem #27: Zapper Tesla Coil

by Paul Dana · 07/16/2008 (9:47 pm) · 3 comments

Download Code File


i936.photobucket.com/albums/ad202/vincismurf/banner.jpg


Plastic Gem # 27: Zapper Tesla Coil

Difficulty: Easy

NOTE: The .zip file was too large for GG resource so get it here.

Before following this gem, you must follow the instructions in Gem #20, Gem #25 and #26, which require Gem #2, Gem #25, and optionally Gem #3 if you want ease, which you do.

www.plasticgames.com/dev/blog_images/droids_zapper.gif[b]The Zapper has a Tesla Coil effect between those knobby things there


Hi Paul Dana from Plastic Games again. Building on the previous gem, this gem will add a Tesla Coil effect to the PlasticZapper defined in the previous gem. A Tesla Coil effect, in this case, means an electrical zappy effect between a couple of posts.

1) Unzipping the files

Remember you must first follow the instructions in Gem #20, Gem #25, Gem #26, Gem #2, Gem #25 (and optionally Gem #3). This will give you the thread upgrade and the zapper shape itself and a first shot at zapper.cs. Next unzip the pg27_zapperTeslaCoil.zip file that comes with this gem. In there you will find a script file called zapper.cs that defines the PlasticZapper class with this gem's updaes, as well as a folder called shocker. Copy the shocker folder to your ~/data/shapes folder.

2) Updating the script

Copy the zapper.cs file from this gem's zip file over the zapper.cs you created in the previous gem. This version has all the stuff from last time, plust new stuff to create the Tesla Coil effect.

3) Testing it out

Just run the mission you made in the previous gem. The Tesla Coil effect should just show up.

4) Looking at the code

In the fan example from Gem #18, I just gave you a dump of ALL the code to make the fan work without describing how it all actaully worked. For the PlasticZapper object I am building up the functionality a bit at a time and try to explain a bit more what is going on as well. Let's take a look at what has changed in the code in zapper.cs.

First we defined a new datablock for the electricy effect called PlasticElectrode.

// ok this object is electric effect for the tesla coil
datablock StaticShapeData(PlasticZapperElectrode)
{
   shapeFile = "~/data/shapes/shocker/shocker.dts";
};

This is used in the new code you can see added to the ::onAdd() method:

// this shows dynamic creation from Gem #20...otherwise you would have to do this: %electrode = new StaticShape() { dataBlock = PlasticZapperElectrode; };  MissionCleanup.add(%electrode);
  %electrode = PlasticZapperElectrode.createStaticShape();

  // mount electrode effect
  %obj.mountObject(%electrode,1);
  %obj.electrode = %electrode;
  %electrode.playThread(0,"electrode");
  %electrode.setThreadSpeed(0, 0.5);
}

Notice we are using the StaticShapeData.createStaticShape() dynamic creation method from Gem #20.

Notice that the ::onAdd() method simply creates the effect...mounts it on the Zapper object and then just runs the electrifying effect anim on that object.

The Next Gem

That's all for this gem. Tomorrow's gem will show how to make a managed trigger for this object that will control the mechanical arm, causing it to swing down when a player enters the trigger and swings back when the player leaves the area.

#1
07/17/2008 (2:50 am)
I'm getting a page not found error on the zip download link.
These Gems are awesome tho. Looking forward to working with this one too. :-)
#2
07/17/2008 (10:38 am)
Mike - sorry about the .zip file not working I have fixed the link. It works now.
#3
08/09/2009 (1:20 pm)
Where did the zip files go. I wants to follow the steps but am unable to :/