February 04, 2012, 03:13:56 PM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News: Please report any bugs or issues that you might be encountering with the Beta in the Support System so that we can better keep track of any oustanding issues that may come up.

GameCore Support System
 
   Home   Help Search Login Register  
Pages: [1] 2 3
  Print  
Author Topic: Building a "Builder"...  (Read 2928 times)
Steely Dane
Sr. Member
****
Posts: 287


View Profile
« on: August 06, 2009, 11:28:39 PM »

I'm not really sure what angle I should approach this with so I'm throwing it out there for some suggestions. I don't want to get into what I'm going to do for my project personally, so I'm going to use an example.
I'll call it, "The Custom House Builder", and it goes like this:

You have, oh, say, 6 basic house designs to start with. A 4 sided box, a 5 sided box, etc, etc,...
Now, in your options, you have several roof styles, windows, doors, sidings (brick, aluminium siding, stucco), etc., paint schemes, exterior lights, the list could be endless really.
For this example, each of the add-on's have certain benefits over the others (otherwise, why have options right?) besides being purely cosmetic as surely some of them are as well.
In this "house builder" the whole house can be spun around in 360, and the accessories attached in real time.
When it is complete to your satisfaction, you can enter the "real" world with your house and away you go.

There should be a couple of panels that indicate the cost of said accessories, their attributes, and what not, and it would be cool to possibly have an animated "constructor" that picks the accessories from a "rack" and attaches them to the basic house.

I know most of these things have been done in one form or another with varying degrees of complexity.
I've seen Ron's setup for building his race cars, as an example. I'm looking to do something like a cross between that sort of thing, the Army Painter from Dawn Of War, and possibly every shipbuilder from every space game ever made, with a heaping helping of Steely Dane sex appeal that would make an Amsterdam red light district patron blush....

I have some assumptions on where to start with this, starting with the fact that it would be an actual "first" level(world) in the game. Maybe I'm wrong on that, but that's why I started this thread!
(actually, I'd love to make it a stand alone app, and you can use what you build in it for the actual game online, or possibly even sell your creations to other sucker...excuse me, users, on line for use in the multi-player game, but that is a little advanced at this stage...)
I know what I want to do, I have enough assets to get a prototype up and running, but I am missing some fundamental Knowledge on how to get started.

I'm not asking for someone to give me all of the answers, but get me going in the right direction.
I have no idea how to "attach" one thing to another aside from say, wheels on a car.
In fact, I just have no idea, period, and am not ashamed to admit it.

Have at it experts and amateurs alike...I'm sure the outcome will benefit us all (well me, anyway, hardy har-har!)


Logged
Ron
Sr. Member
****
Posts: 326


View Profile
« Reply #1 on: August 07, 2009, 12:05:54 AM »

May not be the best way, but here is what I am doing for vehicle customization:

(1) For items that absolutely cannot be shared between different vehicles, I load the objects in the opr file and set the visibility to zero. I then toggle visibility on and off with the game script.

Code:
LoadObject 1941WillysHood.obj
ObjectName Hood1
ObjectVisibility 0

LoadObject 1941WillysHoodOpen.obj
ObjectName Hood2
ObjectVisibility 0

LoadObject HoodCowl2.obj
ObjectName Hood3
ObjectVisibility 0

LoadObject HoodCowl4.obj
ObjectName Hood4
ObjectVisibility 0

LoadObject HoodCowl6.obj
ObjectName Hood5
ObjectVisibility 0

(2) For items that can be shared between different vehicles (wheels for example), I put a marker for the location in the opr and then add the item to the player inventory as needed

Code:
AddNullObject Wheelie_Bar_Location
ObjectPosition 0.0 -0.1 2.35

AddNullObject Driver_Location
ObjectPosition -0.1 0.18 0.3

AddNullObject Engine_Location
ObjectPosition 0.0 -0.05 0.55

(3) Finally, in the save game file, I save each configuration parameter.
Logged
Steely Dane
Sr. Member
****
Posts: 287


View Profile
« Reply #2 on: August 07, 2009, 01:10:56 AM »

I think what I'm looking for is more along the line of option 2.
What I am having difficulty understanding is how to attach objects "in game".
Like for instance: I click on roof 3. The "crane" or whatever, picks it up and swings it over and attaches it to the house. Sort of a variation on picking up a weapon I suppose, but more like an AI player picking up the weapon and giving it to the player.
Does that make any sense?

And am I correct in assuming that I basically create this interface in a "world" of it's own, so to speak?

(Just as an aside, I have put the whole battleship game I was working on , on indefinite hold....these inquiries are about a whole different project...found something similiar to what I was working on and decided to go in a completely different direction...hopefully groundbreaking)
« Last Edit: August 07, 2009, 02:15:43 AM by Steely Dane » Logged
Steely Dane
Sr. Member
****
Posts: 287


View Profile
« Reply #3 on: August 07, 2009, 02:17:30 AM »

And with any luck, and a little help from all y'all, I will have something I can post in the projects forum in a month or two...
Logged
Ron
Sr. Member
****
Posts: 326


View Profile
« Reply #4 on: August 07, 2009, 02:29:23 AM »

hopefully when some others chime in here too, I can also learn. From my understanding.... (keep in mind my coding style is a little chaotic), when you add a item to inventory, it goes to 0,0,0 of the object you are adding it to unless you have an attachment point like above. My vehicle hoods for example, this is not a problem since if you merged the hood and body, the hood is already pre-offset to the correct position.

For my wheels, I could not do this because I wanted to share the wheels with all the different bodies, wheelbases, widths,.... thats when I had to add the attachment point.

With all the above though, its an instant effect. For a crane to move something and see it moving over time, its going to be a bit more involved. I am guessing you would script something like

- Move the crane hook to pickup position

- Add the object to the hooks inventory

- Move the hook to drop off position

- Remove the item from the hooks inventory and add it the the receiving objects position.

You also may want to look into the Chess example project. Its on my to do list also, but in a short script, it manages to snap the movements right into position and even have constraints on where objects are allowed to be moved. You could almost do something similar with the player picking up the object and adding it into the vicinity of where it should go, then it 'snaps' in.

My next big scripting project is going to be making a track editor, so I will also soon be jumping in head first  Smiley
Logged
Steely Dane
Sr. Member
****
Posts: 287


View Profile
« Reply #5 on: August 07, 2009, 09:01:30 AM »

Yeah, never thought of the chess thing, that would definitely be along the right path.....I was also kind of thinking with the crane idea, that the actual picking up and moving thing could be done as an animation, without it actually picking anything up or putting it down. More of an illusion that it does. But I like the restricted-movement=snap-into-position idea that the chess game uses.....
Logged
Steely Dane
Sr. Member
****
Posts: 287


View Profile
« Reply #6 on: August 09, 2009, 02:54:03 AM »

I have a question for you, Ron.
Do you use the menu editor to create your option page?
I'm not entirely clear on how I set this up....or where to put the example scripts you provided, for instance....
I would appreciate a quick explanation on how to do this (without giving up anything you consider a personal secret  Wink ) and taking up to much of your time.
thanks!
Logged
Ron
Sr. Member
****
Posts: 326


View Profile
« Reply #7 on: August 09, 2009, 03:29:54 AM »

Both of the codes above are just in the opr files of the object. I do not use the menu editor, just edit the menu script directly (I am sure the menu editor would work, but I started before it was available and just stuck with that method).

For the main game script on the options screen, I load the previous vehicle configuration before the while (true) loop. There is really nothing in the while (true) { delay} section. I then have the menu buttons in the game control the configuration

   Button MenuX
   {
   ....
      OnPress
      {
         - remove xxx item from player inventory
         - add yyy item player inventory
         - save game configuration variable for this particular configuration item
      }
   }

Here is a example of the code I use for the wheelie bars (keep in mind this code is a mess, thats my latest task is re-writing everything in a cleaner and more efficient way. Also, this is a "dangerous" way of doing it, I am assuming the savegame file contents actually matches the vehicle on the screen. I am sure there is a way that it could have the savegame thinking wheelie bars are on, but in reality, for some reason they may not be. In this case it would kick out a error. I'm not sure how to improve it at the moment, but it should be programmed to avoid this type of possible error.

Code:
Button WheelieBars
{
TextPlain Whl Bars
Size 109 26
Location 125 111
Style OvalMenuBlackSprite

        OnPress
        {

if (GetSaveGameVariableInt("SelectedCar") < 25 || GetSaveGameVariableInt("SelectedCar") > 28)
{
if (GetSaveGameVariableInt( "WheelieBars") == 1)
{
SetSaveGameVariableInt( "WheelieBars", 0);
GetGameManager().GetWorld().GetObject( "WheelieBars").Delete();
}
else
{
SetSaveGameVariableInt( "WheelieBars", 1);
Object@ WheelieBars = GetGameManager().GetWorld().AddObject( "WheelieBars", "../Objects/Cars/WheelieBars.opr");
Player@ player = GetGameManager().GetPlayer( "Player");
player.AddToInventory( WheelieBars);
}
}
else
{
if (GetSaveGameVariableInt( "WheelieBars") == 1)
{
SetSaveGameVariableInt( "WheelieBars", 0);
GetGameManager().GetWorld().GetObject( "WheelieBars").Delete();
}
else
{
SetSaveGameVariableInt( "WheelieBars", 1);
Object@ WheelieBars = GetGameManager().GetWorld().AddObject( "WheelieBars", "../Objects/Cars/WheelieBarsDragster.opr");
Player@ player = GetGameManager().GetPlayer( "Player");
player.AddToInventory( WheelieBars);
}
}

        }

}
Logged
Steely Dane
Sr. Member
****
Posts: 287


View Profile
« Reply #8 on: August 09, 2009, 03:47:55 AM »

cool.
I've finally figured out where the controller scripts for the chess game are (it's the board, not the pieces...probably seems obvious, but I'm a flaming n00b, so yeehaw!), and am trying to grasp what it all means...

I wouldn't worry about not impressing me with your chaos, lol...I barely have the foggiest clue what I'm looking at...it could be pure genius, for all I know  Wink......I'm just thankful for the help.

I figure that I would have to make the "main" object I'm adding optional pieces to a "player", so it has an inventory....my goal is to be able to click on the option pieces, and drag them over to the main "player" piece, where it will be able to attach, possibly in multiple different places depending on it's function (like windows, or lights, for instance), hence the need for it to be added to an inventory.
It will kind of be a hybrid between the chess pieces and fps weapons, crossed with the chessboard and lego dude, I suppose.....
Also, I like the idea of the highlight showing up where the piece will attach.
Does that sound correct to you, or anyone else who is happening to follow this confab?
« Last Edit: August 09, 2009, 04:04:40 AM by Steely Dane » Logged
Ron
Sr. Member
****
Posts: 326


View Profile
« Reply #9 on: August 09, 2009, 04:05:56 AM »

That actually sounds look a great idea. I had not went through the chess example yet, but that makes perfect sense. The genius lies within the engine and the examples we are provided (thanks GC crew Smiley), thats where I try to learn everything then consult the manual for reference when I get confused.
Logged
Steely Dane
Sr. Member
****
Posts: 287


View Profile
« Reply #10 on: August 09, 2009, 04:46:29 AM »

My big issue is, I'm not sure what I'm looking at....So the plan is to do what you (or it might have been Squat?) suggested to me in another thread. I'm going to make duplicate copies of those templates and slowly remove stuff until I figure out what does what. Some is obvious, some not so much...the first thing I'm going to try and wrap my head around is which line of code is controlling the mouse picking up and moving the pieces.
Seems like the logical place to start.
I'm guessing this process would be of a great deal of interest to a lot of users on here, as these functions are transferable to a lot of things, including an RTS kind of deal, as that is the primary way to select and move troops about (click on unit and then click on where you want them to go...) since there is no template as of yet for that sort of game....I'll post as I progress and hopefully I'll have some examples in a few days.
I'm on a 3 day weekend, so it's Redbull and a marathon session ahead of me. I want to make some progress on this sucker.....
Logged
Ron
Sr. Member
****
Posts: 326


View Profile
« Reply #11 on: August 09, 2009, 04:57:16 AM »

Thats what I do, in hindsight, I wish I would have made a bloopers video. Sometimes my code errors create some really funny situations. A few times when I hit the brakes on the vehicle, the body stops and the wheels and driver keep going, I had it launch straight up in the air like a rocket before, bounce like a beach volleyball, spin out of control like a helicopter blade, sink into the pavement like quicksand and who knows what else I have forgotten  Grin
Logged
Steely Dane
Sr. Member
****
Posts: 287


View Profile
« Reply #12 on: August 09, 2009, 05:18:31 AM »

I expect I will be making several hundred copies...I've been through 8 already. Nothing weird yet, just complete failure to run....mostly a blank screen and a big scripting error notification, sigh....

ok, yeah...this is melting my brain.
« Last Edit: August 09, 2009, 10:12:40 AM by Steely Dane » Logged
Steely Dane
Sr. Member
****
Posts: 287


View Profile
« Reply #13 on: August 09, 2009, 08:57:19 PM »

Ok, maybe someone can correct me on this, but I think I've narrowed down this chunk of script (the red) as that which allows you to move the pieces to specific places on the chessboard.

This thread is getting to be more of a scripting thing rather than a world editor thing, so feel free to move it if you wish mods,  Smiley.......


//
//   bool HandleEvent( Object@ object, const String& in event, GameEventParams@ params)
//
//      All of the keys that can be pressed for this object are
//      passed to this function every frame.
//
//   Parameters:
//
//      object - The object that this controller is to act upon.
//
//      event - Name of the event type
//
//      params - Parameters for the event (specific to each event type)
//
//   Return values:
//
//      Return true if this event was handled, false otherwise
//

bool HandleEvent( Object@ object, const String& in event, GameEventParams@ params)
{
   if (!readyToPlay) return false;

   // if not in inventory then don't respond to events
   if (params.player == null)
      return false;
    if( !params.player.InInventory( object))
      return false;
   
   if (event == "Input")
   {
      if (params.stringValue == "MouseRelativeX")
      {
         lookLeftRight += params.floatValue * MOUSE_LOOK_MULTIPLY;
         return true;
      }
      if (params.stringValue == "MousePositionX")
      {
         mouseX = params.floatValue;
         return true;
      }
      if (params.stringValue == "MousePositionY")
      {
         mouseY = params.floatValue;

         if (!rightClicked && !gameOver && (darkTurn == localPlayerDark || twoPlayers))
         {
            // find the ray that goes through the mouse position
            Viewport@ view = GetGameManager().GetViewport( "Main");
            Vector cameraPos = view.GetCameraPos();
            Vector clickDirection = view.ProjectInverseFromScreen( mouseX, mouseY, 1) - cameraPos;

            // determine what game piece the mouse is over
            if (!clicked)
            {
               float distance = 2.0;
               Vector intersect;
               Vector normal;

               Object@ newObject = GetGameManager().GetWorld().RayCast( cameraPos, clickDirection, distance, intersect, normal, false);
               if (@newObject == @object)
                  @newObject = null;      // don't select the chess board
               if (newObject != null)
               {
                  bool darkPiece = newObject.GetName().Contains( "dark");
                  if (darkTurn != darkPiece)
                     @newObject = null;   // piece is for wrong player
               }
               if (@newObject != @selectedObject)
               {
                  if (selectedObject != null)
                  {
                     // un-highlight the old object
                     selectedObject.GetMesh( 0).GetSurface( 0).SetLuminosity( 0);
                  }
                  if (newObject != null)
                  {
                     newObject.GetMesh( 0).GetSurface( 0).SetLuminosity( 10);   // super bright... make it glow white
                     selectedPoint = intersect;
                     selectedPosition = newObject.GetPosition();
                  }
                  @selectedObject = newObject;
               }
            }
            else
            {
               if (selectedObject != null)
               {
                  Vector intersect;
                  if (IntersectPlane( clickDirection, cameraPos, Vector( 0, 1, 0), selectedPoint, intersect))
                  {
                     Vector newPosition = intersect - selectedPoint + selectedPosition;
                     selectedObject.SetPosition( newPosition);

                     newPosition.x = floor( newPosition.x / BOARD_SQUARE_SIZE) * BOARD_SQUARE_SIZE + (BOARD_SQUARE_SIZE * 0.5f);
                     newPosition.z = floor( newPosition.z / BOARD_SQUARE_SIZE) * BOARD_SQUARE_SIZE + (BOARD_SQUARE_SIZE * 0.5f);

                     if (IsValidMove( selectedObject, selectedPosition, newPosition))
                     {
                        newPosition.y = squareHighlight.GetPosition().y;
                        squareHighlight.SetPosition( newPosition);
                        squareHighlight.Show();
                     }
                     else
                        squareHighlight.Hide();
                  }
               }
            }
         }

         return true;
      }
      if (params.stringValue == "Click")
      {
         if (!rightClicked)
         {
            bool newClicked = (params.floatValue > 0.5);
            if (newClicked != clicked)
            {
               clicked = newClicked;
               if (!clicked)
               {
                  // piece was let go
                  if (selectedObject != null)
                  {
                     // un-highlight the object
                     selectedObject.GetMesh( 0).GetSurface( 0).SetLuminosity( 0);

                     // snap to the squares on the board
                     Vector newPosition = selectedObject.GetPosition();
                     newPosition.x = floor( newPosition.x / BOARD_SQUARE_SIZE) * BOARD_SQUARE_SIZE + (BOARD_SQUARE_SIZE * 0.5f);
                     newPosition.z = floor( newPosition.z / BOARD_SQUARE_SIZE) * BOARD_SQUARE_SIZE + (BOARD_SQUARE_SIZE * 0.5f);

                     // check that this was a valid move
                     bool moveValid = IsValidMove( selectedObject, selectedPosition, newPosition);
                     if (moveValid)
                     {
                        PlayMove( selectedObject, newPosition, true);
                     }
                     else
                     {
                        // leave position as the original object position so it snaps back to where it was
                        selectedObject.SetPosition( selectedPosition);
                     }

                     @selectedObject = null;
                  }
                  squareHighlight.Hide();
               }
            }
         }
         return true;
      }
      if (params.stringValue == "RightClick")
      {
         if (!clicked)
         {
            bool newClicked = (params.floatValue > 0.5);
            if (newClicked != rightClicked)
            {
               rightClicked = newClicked;
               if (rightClicked)
               {
                  if (selectedObject != null)
                  {
                     // un-highlight the old object
                     selectedObject.GetMesh( 0).GetSurface( 0).SetLuminosity( 0);
                     @selectedObject = null;
                     squareHighlight.Hide();
                  }
                  SetRelativeMouseMode( true);
               }
               else
                  SetRelativeMouseMode( false);
            }
         }
         return true;
      }

      return false;   // key not handled
   }

   return false;
}


void TryAIMove( Object@ piece)
{
   if (!piece.IsVisible())
      return;

   // try a bunch of different positions for this object to find a valid move
   for (int i = 0; i < 50; i++)
   {
      int x = RandomInt( 0, 7);
      int z = RandomInt( 0, 7);

      Vector pos;
      pos.x = (x * BOARD_SQUARE_SIZE) - (BOARD_SQUARE_SIZE * 3.5);
      pos.y = piece.GetPosition().y;
      pos.z = (z * BOARD_SQUARE_SIZE) - (BOARD_SQUARE_SIZE * 3.5);

      if (IsValidMove( piece, piece.GetPosition(), pos))
      {
         PlayMove( piece, pos, true);
         return;
      }
   }
}
Logged
Ron
Sr. Member
****
Posts: 326


View Profile
« Reply #14 on: August 10, 2009, 01:46:07 AM »

The HandleEvent is where all your player input comes in (mouse or keyboard). Looks like its also checking to make sure its a valid input. If its valid, then it calls the subroutine PlayMove( selectedObject, newPosition, true); further up in the script.

Side note, looks like a ton of good information and learning in that script, looking forward to when I get a chance to go through it too.
Logged
Pages: [1] 2 3
  Print  
 
Jump to:  

 
Powered by MySQL Powered by PHP bluBlur Skin © 2006, hbSkins
Powered by SMF 1.1.14 | SMF © 2006-2011, Simple Machines LLC
Valid XHTML 1.0! Valid CSS!