Game Development Community

Totally Confused (embarassingly n00b question)

by Shawn LeBlanc · in Torque Game Builder · 02/08/2007 (10:06 pm) · 4 replies

I'm messing around with the mini platformer ninja tutorial, and I'd like to be able to make the ninja guy throw a ninja star when I hit a button. The problem is that it's not clear to me how to actually create the ninja star without having to include it inside the level itself. I've found what I think are examples and forum threads of what I want, but I'm not even sure. I would imagine it's a pretty basic thing to do, but I'm just stuck.

Thanks!
Shawn

#1
02/09/2007 (12:13 am)
Easiest way most likely is to have a t2dSceneObjectDatablock "NinjaStar" then you could just create it when hitting the key, assign it to the current level scene graph and give it an impulse to throw it.

I do a similar thing in angelic layer, works very well (beside the fact that my projectile is a dummy and thus is completely setup on creation.

Thats how it looks like
%vec = t2dVectorSub($MouseX SPC $MouseY,%this.getPosition());
           %vec = t2dVectorScale(%vec ,100.0/t2dVectorLength( %vec));
           %imgMap   = particles1ImageMap;
           %projectile = new t2DStaticSprite()
           { AutoRotation="360"; sceneGraph = $SceneGraph; Lifetime = "4.0"; LinearVelocity = %vec;
             position = %this.getPosition(); imageMap=%imgMap; frame="3"; CollisionResponseMode = "RIGID";
             CollisionDetectionMode = "CIRCLE"; CollisionActiveSend = "1"; CollisionCircleScale = ".2";
             CollisionLayers = "-1"; CollisionPhysicsSend = "1"; Restitution = ".5"; };
           %this.canFire   = false;
           %this.schedule(250,enableFire);
           %collGroup = "";
           for(%i=0; %i < 32; %i++)
           {
              if(%i != %this.getGraphGroup())
               %collGroup = %collGroup @ " " @ %i;
           }
           %projectile.setCollisionGroups(trim(%collGroup));

%this is just the Angel (a t2dSceneObject) which is fireing.

The collision group stuff most likely wouldn't be needed, you could simply just set a predefined value there.
Did that to seperate the collisions of the different angles for other, more tricky collision based stuff planned to be added.
#2
02/09/2007 (5:27 am)
Thanks Marc!

One thing that I haven't yet understood is how datablocks work. In the previous post's example code, I can't find any reference to the t2SceneObjectDatablock you mentioned.

I come from a C++ background, and I haven't yet been able to mentally map certain things (or most things! :) ) to their equivalents in TorqueScript. Say I want the ninja star to be it's own "class" (or whatever TS equivalent), with its own methods that I can call, how would I declare a new type/class for the ninja star? How would this change how spawning is done?

Thanks!
Shawn
#3
02/09/2007 (6:24 am)
@Shawn, TS is a scripting langauge, and as such, most things are dynamic, and vars are also typeless -- for a C++ coder, this might be hard to grasp if you've never stretched your wings into the scripting world ...

The following is an example of a class "declaration":

function CLASSNAME::method(%param)
{
}

Yup, we didn't "declare" the class, we just added functions to it -- to make the star a member of the class, in the "new t2dStaticSprite()" statement, just put "class = "CLASSNAME"" and the star will then have access to "method(%param)" --

I'm pretty sure theres a fairly decent intro to all this on the TDN, however, it is most likely not "TGB Specific"
#4
02/09/2007 (8:38 am)
It's clearer to me now. It'll see what I can do with it.

Thanks for the help guys,
Shawn