Game Development Community

TGB and destructable terrain?

by Andre Lind · in Torque Game Builder · 11/28/2006 (12:49 pm) · 16 replies

Well, the title says it all...

Im making a 2D shooter a la Contra/Metal Slug and would like to have destructable terrain, something like Worms...
Is it possible to do with TGB?

#1
11/28/2006 (1:01 pm)
Yes, but you're going to have to be very creative or modify some source code.
#2
11/28/2006 (1:07 pm)
I don't think you'd need to modify the source. Just define a class for a tile/sprite that can change states. How much damage a weapon/explosion does to your tile will determine which state to jump to. Each state has a deformed image and its own collision polygon. The final state just deletes the tile out of existence.

You'll have to be clever with the collisions since TGB won't do concave polygons, but I bet you could approximate it nicely with small enough tiles.

Does that make sense?
#3
11/28/2006 (8:19 pm)
Yes, that is a good way to do it if you want predefined damage states. Using that method you can't have the terrain deform at the exact point of contact, but if deciding on where damage will occur ahead of time is fine then that method works great.
#4
11/28/2006 (10:41 pm)
@Ben

Ya, I think you were thinking fancier than me. That might be what Andre wants. I've thought about writing a Worms clone before. I seem to recall when playing it that it seemed like the same predefined blast holes popped up over and over. It'd be slick if someone came up with a true deformation function, like you're suggesting.
#5
11/29/2006 (12:08 am)
Have you ever seen Pocket Tanks? The very pixel where your shell hits is the pixel that is blown up first! It is very accurate with its deformations. I haven't played worms (hangs head in shame) so I'm not familiar with that method.

www.atpm.com/9.05/images/pt-beware-the-pineapple.gifwww.atpm.com/9.05/images/pt-atpm-wins-again.gif
#6
11/29/2006 (12:40 am)
Worms' terrain destruction was indeed pixel perfect, and unlike Pocket Tanks (at least from what I can gather from the screenshots above) does not "fill in" the holes in the terrain. ie, you can actually "tunnel" your way through a terrain feature. There's good and bad about that, naturally, but it generally leaves a much cooler looking path of destruction at the end of a match.

The coolest pixel-perfect destruction I've seen recently, though, is in Cortex Command. Good combination of bits of dirt falling down, yet overall allowing you to tunnel through without the terrain flattening out.
#7
11/29/2006 (4:46 am)
I've done a t2dTerrain class about a year ago. It features terrain destruction like in Pocket Tanks. Here is a link to the show off post:

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

If you are interested I can send you the latest version (TGB Pro needed). However I doubt it would work from something like Metal Slug.

-Michael
#8
11/29/2006 (6:49 am)
Michael: That looks really nice! I would love to take a peek at your code :)
I have TGB Pro. Did you do it with TGB 1.1.2 or earlier versions?
Could you mail me at andre.lind [at] macmail.com

Thanx a lot for all answers :)
Expect a little shooter in the near future!
#9
11/29/2006 (7:48 am)
Hey Michael I would also be interested in the code.
#10
11/29/2006 (10:25 am)
You can download the source files and some documentation here.

The code was written for some beta version of TGB. So there is no editor integration and I have not tried it with a newer version.
You'll have to add the files to your VS project and recompile. Then you should be able to use t2dTerrain from script. The doc lists the available methods.

Edit:
The password for the zip-file is "tgb".
#11
11/29/2006 (4:16 pm)
Worms was pixel perfect? That's pretty cool. I guess it did have very smooth burrowing tunnels and that sort of thing. I've still got a pretty good Worms-clone idea. Don't know if I'll go the pixel-perfect route if I end up doing that as my next project. :)
#12
11/29/2006 (4:38 pm)
Now that I think about it - were the levels in Worms simply images? So the levels were really just tilemaps with tiny tiles. If you do it at that resolution, it might run slowly - but that would be a fun problem to work on. *ponders*
#13
12/11/2006 (6:24 am)
Yes, levels in Worms, at least the Amiga originals I know, could be replaced with a bitmap of your own design.
One certain colour was the transparent/no content indicator which sprites fell through. The rest was just munched
away by the different weapon impact algorithms.

If you can get pixel access in TGB, it should be possible. You'd need to make copies of all original tiles, and then
modify the copy. I dunno how that would be done, as I'm still struggling with getting TGB to even run :P
#14
04/23/2009 (1:00 pm)
I'm currently interested in doing destructible terrain too.
The example that Micheal W. had uses physics so that the terrain will "fall".
I'm more interested in just deforming it so that I can leave holes in the terrain and have the ability to tunnel through.
Is the only way to do this is by changing the engine source code like what Michael did?

I experimented with using a tilelayer that has a 1x1 pixel size for each tile. It seems the collisions work except I can't figure out how to assign my terrain image to properly be set to each tile so that it can be cleared via the tilelayer.
#15
04/24/2009 (11:24 am)
@Michael: I thought I would take a look at your code and recompile the engine but I seem to be missing terrainCustomCollision.h file. It would compile fine if I comment it out but when I try to create it via "$tt = new t2dTerrain();" and run it, I get "Unable to instantiate non-conobject class t2dTerrain."
Any thoughts?

EDIT: Figured out that there's 2 .exe files involved (one for builder and one for game) and I have to add the new class to both TGBGame and TorqueGameBuilder projects.(I only added to one of them initially)

One down, another one to go: I have to figure out why I am getting "Vector<T>::operator[] - out of bounds array access!" message :(

EDIT #2: The error message went away when I put the initialization inside a separate cs file instead of in the game.cs file. Somehow it didn't like the "scenegraph = sceneWindow2D.getSceneGraph()" line of code.


If only I can figure out how to create the terrain now. The code below seems to just create a box :(

function terrain::onLevelLoaded(%this, %scenegraph)
{

$tt = new t2dTerrain()
{
scenegraph = %scenegraph;
generateFunc = sineWave;
doHeightAdjustment = true;

};
$tt.setImageMap("groundImageMap");
$tt.setSpriteSize("1 1");
$tt.generateTerrain(4);

}

$count = 1;
function sineWave(%xx)
{
%val = mSin(%xx);
echo(%xx SPC %val);
return %val;
}
#16
03/11/2010 (11:15 am)
Can someone repost the zip file? The url is broken :-(