Game Development Community

Door Code

by Levi Putna · in Torque Game Engine · 11/23/2006 (7:29 pm) · 7 replies

Hello boys and girls,

I have just created a few door to add into my game, I was wondering if anyone is interested in having a look over my code and helping me improve it.

If everything works out and people like my doors, I will create a few more and see if I can turn it into a resource.

There are three doors so far,
Just download the RAR and place the door1 folder in your "starter.fps\data\shapes" folder or your equivalent.

Place the door.sc in your "starter.fps\server\scripts" folder or your equivalent and execute in your game.cs
exec("./door.cs");

#1
11/23/2006 (7:35 pm)
Here is a copy of the code for anyone just wants to have a look over it.
I have tried to keep this code as simple as possible but I am pretty sure there is a better way to do this.

DOORS
Door1 stranded door
Door2 two sides swinging door like you see in hospitals
Door3 space age door that open upwards

////////////////////////////////////////////////////////////////////
//                      Door Data By Levi Putna                   //
//                            24 Nov 2006                         //
////////////////////////////////////////////////////////////////////

function StaticShapeData::create(%block)
{
   // The mission editor invokes this method when it
   // wants to create an object of the given datablock
   // type.  You only need one of these methods for any
   // class/datablock type (in this case StaticShape).
%obj = new StaticShape()
{
dataBlock = %block;
state = "close";
};
return(%obj);
}

//Door1 stranded door 
datablock StaticShapeData(door1)
{
   // The category variable determins where the item
   // shows up in the mission editor's creator tree.  
  category = "Door";
    
  //this defines the initial state of our door
   state = "close";
    // Next, we'll tell the mission editor where to find the .dts shape file 
	// that defines our door geometry.
    shapeFile = "~/data/shapes/door1/door1.dts";
};

//Door2 two sides swinging door like you see in hospitals
datablock StaticShapeData(door2)
{
   // The category variable determins where the item
   // shows up in the mission editor's creator tree.  
  category = "Door";
    
  //this defines the initial state of our door
   state = "close";
    // Next, we'll tell the mission editor where to find the .dts shape file 
	// that defines our door geometry.
    shapeFile = "~/data/shapes/door1/door2.dts";
};

//Door3 space age door that open upwards 
datablock StaticShapeData(door3)
{
   // The category variable determins where the item
   // shows up in the mission editor's creator tree.  
  category = "Door";
    
  //this defines the initial state of our door
   state = "close";
    // Next, we'll tell the mission editor where to find the .dts shape file 
	// that defines our door geometry.
    shapeFile = "~/data/shapes/door1/door3.dts";
}; 

/////////////////////////////////////////////////////////////////////////////////////
// the door will open or close on collision with the player depending on the state //
/////////////////////////////////////////////////////////////////////////////////////

function door1::onCollision( %this, %obj, %col )
{
   %obj.toggle();
   if (%obj.state $= "close"){
      %obj.playThread(0,"open");
      %obj.state = "open";
   }else{
      %obj.playThread(0,"close");
      %obj.state = "close";
   }
}

function door2::onCollision( %this, %obj, %col )
{
   %obj.toggle();
   if (%obj.state $= "close"){
      %obj.playThread(0,"open");
      %obj.state = "open";
   }else{
      %obj.playThread(0,"close");
      %obj.state = "close";
   }
}

function door3::onCollision( %this, %obj, %col )
{
   %obj.toggle();
   if (%obj.state $= "close"){
      %obj.playThread(0,"open");
      %obj.state = "open";
   }else{
      %obj.playThread(0,"close");
      %obj.state = "close";
   }
}
#2
03/24/2009 (11:38 am)
Hey thanks for your work, I will try to use. But where is the rar?
#3
03/24/2009 (11:45 am)
Seems like it could be really useful, I'll have a look at how it works
#4
03/27/2009 (3:32 am)
WOW, only 3 years to get a response.

I think this resource got deleted when I did a rebuild of my website, ill see if I can find a copy and put it back up.
#5
03/27/2009 (8:36 am)
sincerely I will thank you
#6
03/28/2009 (6:18 am)
lol hadn't noticed it was 3 years old!!
#7
04/10/2009 (8:30 pm)
Gracias por el codigo, le estudiare para apender, cualquier duda te pregunto. Gracias