Game Development Community

Platform demo

by Tom Feni · in Torque Game Builder · 01/13/2006 (1:44 am) · 12 replies

I started with the platform resource over at TDN and began adding to it with some help form the guys in the torque t2d chat room.. :)

I figured I would post a little bit of what I have.. sans source code tho.. If you would like to see the code let me know I can post it up in this thread..

its nothing too spectacular but I found it quite informative..

use q to go left e to go right and w to jump.. left mouse drops a coin at the mouse position..

I am trying to figure out how to have it delete the coins with the right mouse.. if anyone has an idea please drop my a clue.. :)

this is where I am now..

function t2dSceneWindow::onMouseDown( %this, %keyMods, %worldPos, %clicks )
{

   createItems(%worldPos);

} // end fxSceneWindow2D::onMouseDown

function t2dSceneWindow::onRightMouseDown( %this, %keyMods, %worldPos, %clicks )
{



} //

home.comcast.net/~berkingstock/BerksQuestDemo.jpg
anyways enjoy.. :)

Platformer demo

TomFeni

#1
01/13/2006 (2:51 am)
This is the way i would go about it, there probably is a better way to do this. And i'm unsure of the actual code.

function removeCoin(%worldPos)
{

    //Create a list of objects at mouse location
    %objects = yourScene.pickPoint(%worldPos);
    
    //Count how many elements are in the list.
    %objCount = getWordCount(%objects);        

    //Loop through each object in the list.
    for(%i=0;%i<%objCount;%i++)
    {
        //Create the object corresponding to the loop
        %selectedObject = getWord(%object, %i);
        //Delete Object
        %selectedObject.safeDelete();
    }
}

Then put a call to that function on onMouseDown. I *think* that should cycle through a list of objects which are at your mouse position. There needs to be additional checks for whether the object you have is an object you want to be delete.

I got info for that from a tutorial written by Matthew "King BoB" Langley on TDN called Object Selection 1: The Simple Method which can be found here
#2
01/16/2006 (12:53 am)
Ok new updated demo available..

keybinds

W : jump
Q : left
E : right

leftmouse : spawn a coin

S : save coin layout
L : load coin layout (also if you dont load and restart after saving it will auto load last save)

to remove all coins just collect them all and then save again.. it will clear the level.. :)

If anyone would like the .cs files I will host them as a seperate file.. soon I will probably stop updating as I am getting into a position where I need to keep some things secret :)
but for now I would like to share, but only if people find it useful.. everything I have so far has been found by perusing the forums and TDN and alot of help from Biggz :)

TomFeni

* and the link up top is the one thats new.. :)
#3
01/18/2006 (3:52 pm)
Nice! I am going to try to work on a platformer myself soon. :)

@Tom: I am definitely interested in your scripts.. would be nice if you uploaded them or sent them via eMail :)
#4
01/18/2006 (4:01 pm)
Tom,

Very cool to run around in, gotta love platformers :)

-J
#5
01/18/2006 (4:32 pm)
Would you believe I lost everything yesterday in a massive hard disk crash..

all the work I did over the last 3 weeks on this is now gone..

But not all is lost I have posted the coin stuff here and the core of the code I got from the TDN resource for platformers.. So I plan to recompile all the data in the next few days and I will post what I come up with here in this post.. :)

but for now you can check out the main coin placement code here...

www.garagegames.com/mg/forums/result.thread.php?qt=38726

the fixed code is towards the bottom..

I will try to get this finished in a few days I hope.. :)
#6
01/22/2006 (9:02 pm)
Well I am almost back to were I started.. just have to fine tune a few things and I will post some stuff up.. :)
need to organize stuff and fix a few little bugs.. and maybe add some moving platforms.. :)
#7
01/23/2006 (1:19 am)
Hiya! :)

In the meanwhile I almost finished working on my own little platform game... I think I will present my work here in a few days. :)

How are you going to make moving platforms? :)
#8
01/23/2006 (1:44 am)
Well funny you should ask..
:)
I have this so far..

// ----------------------------------------------------------------------------
// initial moving platform
// ----------------------------------------------------------------------------

function createMovers()
{
     $mover = new t2dStaticSprite() { scenegraph = t2dScene; };
     $mover.setPosition("-10 90");
     $mover.setSize( "14 3" );
     $mover.setImageMap( woodImageMap );
     $mover.setCollisionActive(false, true);
     $mover.setCollisionPhysics(true, false);
     $mover.setCollisionResponse(CLAMP);
     $mover.setCollisionCallback(true);
     $mover.setLayer($platformLayer);
     $mover.setGroup($platformGroup);

     moveUp();

}

function moveUp()
{
    $mover.setLinearVelocity( "0 -8" );

}

function resetMover()
{
    $mover.setWorldLimit(OFF);
    $mover.safeDelete();
    createMovers();
}

but its not working how I had planned..

I added triggers form the tutorial over at TDN and the trigger code is like this..
// --------------------------------------------------------------------------
// triggers
// --------------------------------------------------------------------------

new SimGroup(TriggerCheckGroup);

function createTrigger(%pos, %size, %enter, %stay, %leave)
{
   %trigger = new t2dSceneObject()
   {
      scenegraph = t2dscene;
   };
   %trigger.setPosition(%pos);
   %trigger.setSize(%size);
   %trigger.setGroup($triggerGroup);
   %trigger.setCollisionMasks(BIT($playerGroup), BIT($playerLayer));
   %trigger.setLayer($platformLayer);
   %trigger.setCollisionActive(true, false);
   %trigger.enterAction = %enter;
   %trigger.stayAction = %stay;
   %trigger.leaveAction = %leave;
   %trigger.setDebugOn(BIT(5));
   
}

function collidePlayerTrigger(%trigger)
{
   TriggerCheckGroup.add(%trigger);
   %trigger.inNow = true;
}

function checkTrigger(%trigger)
{
   if (!%trigger.inPrev && %trigger.inNow)
      schedule(0, 0, "eval", %trigger.enterAction);

   else if (%trigger.inPrev && %trigger.inNow)
      schedule(0, 0, "eval", %trigger.stayAction);

   else if (%trigger.inPrev && !%trigger.inNow)
   {
      schedule(0, 0, "eval", %trigger.leaveAction);
      TriggerCheckGroup.remove(%trigger);
   }

   %trigger.inPrev = %trigger.inNow;
   %trigger.inNow = false;
}

it respawns the platform when it hits the trigger if I use $playerLayer and $playerGroup, but if I do that it (the platform) doesnt collide with the player.. otherwise if i do it this way the player can ride it but then it only respawns if I am on the platform, if I am not then the platform rides thru it..

weird..

anyways hope to have more soon.. :)
#9
06/07/2006 (12:38 pm)
Anyone have help regarding movement in a platformer. I followed the platformer demo to a T and found it extremely unhelpful. If anyone could send me a few code snippets to get my character moving properly I would be very appreciative.

I am looking to have fluid movement and include a few animations. Also, looking to be able to run left if I hold the right arrow down then press the left then let go of the right.

I was working with this actionmap:

new ActionMap(moveMap); 
moveMap.bind(keyboard, left, "moveLeft");
moveMap.bind(keyboard, right, "moveRight");
moveMap.bind(keyboard, space, "jump");
moveMap.push();



function moveLeft(%val)
{
	$moveLeft = %val;
	echo("left");
	echo($moveLeft);
	}

function moveRight(%val)
{
	$moveRight = %val;
	echo("right");
	echo($moveRight);
	
}

function jump(%val)
{
	$jump = %val;
	echo("jump");
	echo($jump);

}
and it returns the proper values Im looking for to do what i need to do but everytime I try to pass these values to a movement function containing the statement
%move = $moveright - $moveLeft;
I get either nothing or sporadic movement. Anyone have any resources or especially code snippets I could look at for this.

I work best with actual working code so I can see what is the proper way to do things.
Thanks for any and all help
#10
06/20/2006 (8:03 am)
Make an array with your actions , then in the keydown and keyup functions set the values to true/false respectively , this will give you much greater control than the if-else statements as proposed by the tutorials
#11
07/19/2006 (9:34 pm)
Is it just me or do white lines flash between every tile for everyone? Stuff like this seems to happen alot for me...
#12
08/15/2006 (11:21 am)
@ Le Roi - can you explain that a little more? Do you mean an array that contains the moveMap.bind() functions? or does it contain the "moveLeft" and "moveRight" etc. functions? or am I completely wrong?

I have a vague idea of what you are saying, but I need a little more clarification. It almost make sense.