Adding object during game play

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
empirepro
Posts: 71
Joined: Thu Dec 27, 2007 5:41 am

Adding object during game play

Post by empirepro »

I am now working on a 2nd project (I like to have more then one project going at a time so I can go back and forth between projects Keeps me from getting bored with a project) My 2nd project is a Life simulation game called My Life. Its a game kind of like the sims where you can create a family and then build a house for them and buy them stuff.

I was wondering what the best way would be to program it so that you can add items during game play? I know you have to make the stuff in a 3d program first but how would I program it so that for example when I click on buy on the GUI a menu pops up with a bunch of items then you select which item you want and click on the screen where ever you want it to go and it appears on the screen?
sfncook
Posts: 36
Joined: Sun Jul 01, 2007 6:32 pm

Post by sfncook »

That sounds like about five different questions in one. It sounds like what you want to know is how to make something your character has bought appear on the screen. Is this what you really want to know? If so then here is a quick (and very simplified ) series of steps:

1) make the mesh in a 3D program (like Blender, 3dsMax or Maya, for instance).

2) In the code, make sure to add the directory folder that contains the mesh file:

Code: Select all

device->getFileSystem()->addFolderFileArchive ( "C:\\MyGame\\res\\images\\GPIcons" );
3) Load the mesh and add it to the scene:

Code: Select all

irr::scene::IAnimatedMesh* myAnimatedMesh = smgr->getMesh("houseplant.obj");
irr::core::ISceneNode *newNode = smgr->addAnimatedMeshSceneNode(myAnimatedMesh);
Don't forget to set the texture, lighting and such for 'newNode'.
empirepro
Posts: 71
Joined: Thu Dec 27, 2007 5:41 am

Post by empirepro »

Thanks for the reply but I don't think that really answers my question. I don't want the objects to be placed at the start of the game. I want the player to be able to place items them self
Swarmer
Posts: 100
Joined: Mon Apr 16, 2007 7:23 am

Post by Swarmer »

You would have to make a list of some sort that can hold new objects.

Irrlicht has an some useful templates for arrays and lists and stuff. When the player wants to add something, make a new instance of it and push it onto the array or list.

For example, here is the documentation for array: http://irrlicht.sourceforge.net/docu/cl ... array.html

You would make an array of your object like this:

Code: Select all

irr::core::array<myItemClass*> myArray();
Then whenever the player makes an object, you could put it into the array like this:

Code: Select all

myItemClass* theNewItemObject();
myArray.push_back(theNewItemObject);
This way, you can make as many objects as you want, and store them.

However, it's probably much better to use a map instead of an array. That way you can name your name your objects with a key and so you can find them much easier when you need them again.
rogerborg
Admin
Posts: 3590
Joined: Mon Oct 09, 2006 9:36 am
Location: Scotland - gonnae no slag aff mah Engleesh
Contact:

Re: Adding object during game play

Post by rogerborg »

Have you tried using divide and conquer reasoning?
empirepro wrote:I was wondering what the best way would be to program it so that you can add items during game play? I know you have to make the stuff in a 3d program first
Step 1: Model the item.
empirepro wrote:but how would I program it so that for example when I click on buy on the GUI
Step 2: write a GUI, following the examples in the tutorials.
empirepro wrote:a menu pops up with a bunch of items
Step 3: Add items to the GUI (listbox?) using an idiom that's entirely dependent on your application.

empirepro wrote:then you select which item you want
Step 4: Standard GUI functionality, mapping to your item idiom.
empirepro wrote:and click on the screen where ever you want it to go
Step 5: Find the position of the mouse cursor in your world, which is entirely dependent on your application. There are a plethora of examples of how to do mouse picking/intersection with a world. You'll need to be more specific if you want help with this.
empirepro wrote:and it appears on the screen?
Step 6: Create a new game object for the item (using an idiom dependent on your application) and an Irrlicht representation of it using (most likely) addAnimatedMeshSceneNode(), unless of course you really are using 2D, in which case you might want addBillboardSceneNode(), or in fact just have your game item draw it itself in the render loop using IVideoDriver::draw2DImage(). It's really, uh, dependent on your application.
Please upload candidate patches to the tracker.
Need help now? IRC to #irrlicht on irc.freenode.net
How To Ask Questions The Smart Way
empirepro
Posts: 71
Joined: Thu Dec 27, 2007 5:41 am

Post by empirepro »

Would it be possible to have the GUI load all thumbnails from a predefined folder? Each thumbnail would be associated with a object. So for example you have a folder in the game directory call Kitchen. In the Kitchen folder you have .3DS files called stove.3DS and Microwave.3DS theres also a folder called thumbnails under the kitchen folder that has the thumbnails for stove.3ds and mircowave.3ds Is it possible to instead of saying look for stove.3ds and microwave.3ds just predefine the folder Kitchen and have it load the thumbnails for all the objects found in the kitchen folder so if the player puts in lets say sink.3ds and in the thumbnail directory put sink.jpg it will not only load stove.3ds and microwave.3ds but sink.3ds as well? I hope this makes since.
JP
Posts: 4526
Joined: Tue Sep 13, 2005 2:56 pm
Location: UK
Contact:

Post by JP »

That's very possible, but it will require a bit of work on your part.

Basically all you have to do is get a list of the files in the Kitchen folder (irrlicht's filereading functions may provide this operation) and then load each accordinly.

so you might have this:

Code: Select all

Kitchen
  Thumbnails
    - stove.jpg
    - mwave.jpg
  - stove.3ds
  - mwave.3ds
So you'd get your list of contents of the Kitchen folder, the files would be stove.3ds and mwave.3ds so you'd load them and knowing their names you could then look in the thumbnails folder for stove.jpg and mwave.jpg.
Image Image Image
Post Reply