Game Development Community

Initial Inventory problems

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

I am trying to have a basic pickup inventory function but all it does is move the coin around.. :)

in items.cs
function createItems(%item)

{
   $starCoin = new t2dShape3D() { scenegraph = t2dScene; };
   $starCoin.setShape("./shapes/starcoin.dts");
   
   $starCoin.setCollisionActive(true, true);
   $starCoin.setCollisionPhysics(true, true);
   $starCoin.setCollisionCallback(true);
   //$starCoin.setLayer($playerLayer);
   //$starCoin.setGroup($playerGroup);
   $starCoin.setPosition( "40 96" );
   // Orientate the shape in 3D.
   $starCoin.setShapeRotation( "0 90 0" );
   // Set Detail Level.
   $starCoin.setDetailLevel( 0 );
   $starCoin.setShapeScale( "0.1 1 0.1" );


   $starCoin.setSize( 6 );
   //%shape.setLayer($playerLayer);
   //%shape.setGroup($playerGroup);

   // Automatically rotate the shape in 3D.
   $starCoin.setShapeAngularVelocity( "0 90 0" );

}

in inventory.cs
function item()
{
  $item = %item;
}

function pickup()
{
   %item.onPickup( %item );
   %item.setHidden();
}

function addInv()
{

   $player.setInventory++;
   
}

in player.cs
function createPlayer()
{
....
setInventory();
}

function setInventory()
{

   $playerInventory = 0;
}

in game.cs

function createLevel()
{
   $gravity = 200;
   $spawnPoint = "-80 90";
   $starCoin = %item;
   %testMap = new t2dTileMap()
   {
      scenegraph = t2dscene;
   };

    %testMap.loadTileMap("BerksQuest/client/maps/level02.map");

    //-----------------------------------
    // collision
    //-----------------------------------
    %collayer = %testMap.getTileLayer(0);
    %collayer.setPosition("50 50");
    %collayer.setLayer($platformLayer);
    %collayer.setGroup($platformGroup);
    %collayer.setTileSize("4 4");
    %collayer.setCollisionActive(false, true);
    //%colLayer.setCollisionPhysics(true, true);
    //%collayer.setCollisionMasks(BIT(1), BIT(1));
    %collayer.setCollisionMaterial(collisionMaterial);

    // ------------------------------------
    // boxes
    // ------------------------------------
    %boxlayer = %testMap.getTileLayer(1);
    %boxlayer.setPosition("50 50");
    %boxlayer.setTileSize("4 4");
    %boxlayer.setLayer($platformLayer);
    %boxlayer.setGroup($platformGroup);
    %boxlayer.setCollisionActive(false, true);
    //%boxLayer.setCollisionPhysics(true, true);
    //%boxlayer.setCollisionMasks(BIT(1), BIT(1));

    // --------------------------------------
    // ladders
    // --------------------------------------
    %ladlayer = %testMap.getTileLayer(2);
    %ladlayer.setPosition("50 50");
    %ladlayer.setLayer($platformLayer);
    %ladlayer.setGroup($platformGroup);
    %ladlayer.setTileSize("4 4");
    %ladlayer.setCollisionActive(false, true);
    //%ladLayer.setCollisionPhysics(true, true);
    //%ladlayer.setCollisionMasks(BIT(1), BIT(1));

    // ---------------------------------------
    // water
    // ---------------------------------------
    %watlayer = %testMap.getTileLayer(3);
    %watlayer.setPosition("50 50");
    %watlayer.setLayer($platformLayer);
    %watlayer.setGroup($platformGroup);
    %watlayer.setTileSize("4 4");
    %watlayer.setCollisionActive(false, true);
    //%watLayer.setCollisionPhysics(true, true);
    //%watlayer.setCollisionMasks(BIT(1), BIT(1));

    // ----------------------------------------
    // Triggers
    // ----------------------------------------
    %trilayer = %testMap.getTileLayer(4);
    %trilayer.setPosition("50 50");
    %trilayer.setLayer($platformLayer);
    %trilayer.setGroup($platformGroup);
    %trilayer.setTileSize("4 4");
    %trilayer.setCollisionActive(false, true);
    //%triLayer.setCollisionPhysics(true, true);
    //%trilayer.setCollisionMasks(BIT(1), BIT(1));

   $camera.setLimits(%collayer.getArea());
   createItems();
   movingBoxs();
   setInventory();
   resetPlayer($spawnPoint);

}

function t2dSceneObject::onCollision(%srcObj, %dstObj, %srcRef,
   %dstRef, %time, %normal, %contactCount, %contacts)
{
   switch (%srcObj.getGroup())
   {
      case $playerGroup:
         switch (%dstObj.getGroup())
         {
            case $platformGroup:
               collidePlayerPlatform(%normal);
         }
   }
   
   if (%srcObj == $playergroup)

         {
         if (%dstObj == %starCoin)
            {
            addInv();
            pickup();
            
            echo("anything happening yet");
           // $player.setImpulseForcePolar( getRandom()*360, 2000);

            }
          }
}



I think thats all the relevant code..

just curious since I dont know much about coding.. and I figured someone would know whats going on.. :)

I looked for some examples of inventory systems and all I find is the database one.. which is way more then I need.. :)

thanks in advance..


TomFeni

#1
01/11/2006 (4:32 am)
I'm not quite sure what's trying to happen but one thing that i picked up on...

in t2dSceneObject::onCollision , all the if section seems a little wrong to me. If looks like with that you're trying to test if the player collides with a coin, and that can be done above in the switch sections like so
switch (%srcObj.getGroup())
   {
      case $playerGroup:
         switch (%dstObj.getGroup())
         {
            case $platformGroup:
               collidePlayerPlatform(%normal);
            case $starGroup:
               addInv();
               pickup(%dstObj);
            
               echo("anything happening yet");
         }
   }
I've altered the bit at case $starGroup, but for this to work you need to add the coin objects to its own Group, and i'm not sure how good a practice this is if you have lots of objects all with a separate %object.setGroup($something);

It looks like the pickUp() function needs an object passed into it so i've added %dstObj as a paramter, the function definition will need to change to reflect this.
function pickup(%item)
{
   %item.onPickup( %item );
   %item.setHidden();
}

I've searched the reference for .onPickup() and .setHidden() and i cant find them so i cant help you with the contents of that function.

I'm not sure if this will help you much but at least its something to get started with, also i have to put my usual disclaimer that i've only had t2d a week and i hope i've not given you misinformation. I'm not quite sure of myself when it comes to t2d :P

You say this only moves the coin around but what is the overall effect you are trying to acheive with this? Touch the coin, make it disappear and then what?

Biggz