Game Development Community

Creating a 2d Tile map with C++ instead of tile map editor

by CHRISTIAN ROY · in Torque Game Builder · 03/20/2006 (7:24 am) · 6 replies

Hi,

Just wanted to know if there is any information available on the map format used, so we could generate a random base terrain and add built-in collisions, triggers etc... directly in C++ code or in script code instead of having a set of predefinded maps.

And also, if map format is closed, would like to store it after in a database or file for game saving/loading. Does T2D support XML with a multi-platform lib, i would really like to not break the multi-platform feature.

Thanks

About the author

I work as a professionnal game programmer


#1
03/20/2006 (7:47 am)
You have the source code to the engine. Take a look inside the engine directory for the TileMap and ActiveTile code. Sorting through this will give you an idea of how the tilemaps are put together so that you can generate your own using whatever schema you wish.

XML Parse resource
XML Persistence resource
ODBC Support in Torque

If you search with your specific criteria for database support, etc, you should be able to find more information.
#2
03/20/2006 (8:09 am)
Thanks, this points to excellent ressources and adress exactly what i need.
#3
03/20/2006 (12:57 pm)
@Christian roy: if for some reason you get bogged down in the c++ and need a simpler 'hack', dont forget that you can generate torquescript on-the-fly, and execute it, allowing for you to programatically define this stuff in torquescript too.

Though yes, the c++ approach you are taking IS the best way.. though for some things, if you get stuck, you can always fall back to the procedurally generated torquescript, so you can continue to make progress, and then 'fix' it later.

-Jason
#4
03/20/2006 (1:55 pm)
Well i think the best approach would probably to generate/execute torque script on the fly and then use the XML persistence ressource article to dump it in XML when i want to save it for later reload. We all know it would make sense sometimes to get the same randomly generated map to reload for replay at a later time.

The more i dig into the torque ressources, the more i am happy to find that i may not even need to use C++, though i have glanced that we can make polymorphism but i am not sure about how everything works. Are dynamic Fields the only way to derive a new object ? because i would rather make classes in C++ for full object inheritance and encapsulation.
#5
03/21/2006 (2:24 pm)
@Christian: unless there is a xml resource available for torquescript (which there probably is on the TGE side, which we might not have access to) you should probably consider doing the xml load/parsing in C++, generate the torquescript on the C++ side, instead of trying to do that 'dynamically' using torquescript itself.

the reason why: you can use existing xml libraries that exist in c++. I suppose you could write an xml parser in torquescript, but i dont think that's a good idea.

------------------------------

EDIT: duh, i just saw the linked resources on xml above... so yeah, you probably dont have to do stuff in c++ :)
#6
03/21/2006 (6:16 pm)
@Jason : Well in fact there must certainly be an open source lib somewhere we can use out of the box, i will certainly look at the XMLPickler source to get things going but in any cases you are right, i will load the stuff directly in C++, i am way more familiar with that environment and the level of integration is easier. In any cases it does not look very hard to expose a library to torque script, we will go for minimum hassle and proven libs. As always its like design paterns, you do not need to reinvent the weel if somebody made it for you.

I was wondering today if polymorphism was working in torque script, let me explain : For example you have a state class for an AI agent like "CAttackState : CAIState", would it be possible to pass to an agent class something like Agent::ChangState(*CAIState) in script to make the agent switch to attack mode. It is simpler to implement than a series of if then or case, wich frankly i thrust to be unoptimised in Script. So to summarise, is it possible to pass on a derived object (CAttackState) to a function wich accept a base object (CAIState). The reason i ask this is that the wiki document on script his not very deep on the subject. Of course i could try to implement it and see, but just asking if anybody has similar stuff that already work to let me take time to look into other stuff. I do not want to do publicity here, but this technique is taken from the book "Programming Game Ai by Exemple" wich shows a very improved Finite state machine system for AI. I Know i could do it all in C++ but if i can i would like to do everything in script else recompiling every time a new version comes out can be pain. Oh yeah and does scripts support object derivation like in C++ ?