Welcome, Guest. Please login or register.

Login with username, password and session length

 
Advanced search

1411488 Posts in 69377 Topics- by 58433 Members - Latest Member: graysonsolis

April 29, 2024, 12:02:39 PM

Need hosting? Check out Digital Ocean
(more details in this thread)
TIGSource ForumsDeveloperTechnical (Moderator: ThemsAllTook)Pondering 2d per-pixel terrain destruction...
Pages: [1]
Print
Author Topic: Pondering 2d per-pixel terrain destruction...  (Read 5584 times)
kavs
Level 2
**


Brad Kavanagh


View Profile WWW
« on: April 08, 2009, 06:50:27 PM »

Alright, sorry for the wordy title, but hopefully I can explain myself properly. I'm hoping this is the appropriate forum to post this in; let me beg for forgiveness in advance if it's not.

I have a game concept in my head that I'd like to explore some more and work toward prototyping the game mechanics. One very critical mechanic I'd like to have is destructible terrain. The game's art style would be 2D pixel-art-ish (for a very similar example, think the camera/style of the Worms series), and I'd like the player to be able to use explosives/weapons to break through parts of the world on a per-pixel level.

I didn't do such a good job of explaining that, so I've got a couple pieces of reference to help do the explaining for me.

Tank Wars (DOS):


Worms Series:


(Worms is more relevant; my concept doesn't involve falling terrain like in Tank Wars)

Now, I'm no programmer, so I don't really understand how this works on a technical level.

For Worms, I think I have a theory... 2 images; a foreground detail image with an alpha map, and a background image with a generic tiled rockwall or dirt texture. The player/weapon collision is done by the alpha map of the foreground image. When an explosion goes off, it checks to see which pixels were hit by it, and changes the pixels in the alpha map in the foreground image where the explosion goes off to transparent, revealing the background image. Since the alpha has changed, so has the player collision. Maybe?  Epileptic

That description might be a bit of a stretch... but does anyone have any experience with this sort of system? I'm no programmer, but I'd like to at least know where I need to start looking to learn something like this. If a platform/language is helpful to use as example, I'd be looking to do something like this in C# or Flash.

Thanks in advance for any help.  Beer!
Logged

Snakey
Level 2
**


View Profile WWW
« Reply #1 on: April 08, 2009, 07:23:54 PM »

The complexity is dependent on the resolution of the 2D collision map. However, it may be better to use vector instead, since you could have an infinite resolution and have an easier time calculating collisions which is sort of a win - win situation to me.
Logged

I like turtles.
Alex May
...is probably drunk right now.
Level 10
*


hen hao wan


View Profile WWW
« Reply #2 on: April 09, 2009, 01:36:45 AM »

You got the description pretty much bang on I think; that is how I'd do it anyway.

2D vector CSG is a nontrivial problem. Do it the bitmap way if you're not too hot with maths/programming.
Logged

Core Xii
Level 10
*****


the resident dissident


View Profile WWW
« Reply #3 on: April 09, 2009, 01:42:29 AM »

I second the recommendation for vectors. The General Polygon Clipper can easily make holes for you.

If you're decided on pixels though, use a 1-bit array to save memory, don't need all 8 bits of an alpha mask.
Logged
Eclipse
Level 10
*****


0xDEADC0DE


View Profile WWW
« Reply #4 on: April 09, 2009, 01:45:35 AM »

go for the bitmap, also you can "paint" on the map a lot of different shapes that way, like digging tunnels and so on, all using the same stuff, using vector IS a mess, because the convex shapes you will find and so on if you don't use a sort of grid method, that will be equal to using pixels, only less detailed
Logged

<Powergloved_Andy> I once fapped to Dora the Explorer
Shuger
Level 0
**


View Profile
« Reply #5 on: April 09, 2009, 06:43:15 AM »

You should try Cortex Command or game called Liero.
I don't want to discourage but i'm guessing it's not so simple to do as it may seem... Also, you propably will need some experience before aproaching this problem.
As for vectors/polygons i think it's way harder to do destructible terrain with them than with bitmaps. With bitmaps you delete pixels where terrain/explosion overlap(which may be hard depending on enviroment/libraries you want to use), with polygons you need some polygon cutting algorithms, texture remapping and stuff.

Logged
Cthulhu32
Level 6
*


Brawp


View Profile WWW
« Reply #6 on: April 09, 2009, 09:51:43 AM »

One kind of cool thing about using polygon clipping (and this is for something probably WAY more advanced than you are looking for) is the ability to look for disconnected sections of the image fairly easily. For example, if you had a cliff explorer game where you had to dig into the sides of walls and make nice cliffs, but you risk having cave-ins, you could use the poly clipping when the user blows up a hole, check the affected polygon for separation, and then add gravity to the polygons that no longer connect to the main polygon.

 You could still do something with the ceiling collapsing or land masses disconnecting in a bitmap situation, but the cost is a lot higher because you have to loop through pixels.
Logged

Zaphos
Guest
« Reply #7 on: April 09, 2009, 01:30:58 PM »

You could still do something with the ceiling collapsing or land masses disconnecting in a bitmap situation, but the cost is a lot higher because you have to loop through pixels.
It's basically a flood fill in the bitmap ... it's not really that expensive, especially if the geometry is not changing every frame.  (If you did have small changes every frame, then as an optimization you can check each pixel you're deleting to see if deleting it will change the topology; if topology doesn't change then the flood fill isn't needed)
Logged
Jesseyay
Level 0
***



View Profile
« Reply #8 on: April 09, 2009, 06:52:01 PM »

Hey, I'm doing a similar sort of thing for my current game in flash. We just used a bitmap and "drew" the explosion shape on it with BlendMode.ERASE. It's probably slower than it could be, but if you don't have explosions too often it should be okay.
Logged
kavs
Level 2
**


Brad Kavanagh


View Profile WWW
« Reply #9 on: April 12, 2009, 12:38:43 AM »

You should try Cortex Command or game called Liero.

I downloaded and gave Cortex Command a try, and I'm glad I did; their system is pretty much exactly what I am envisioning, so thanks for the great technical reference.  Beer!

Hey, I'm doing a similar sort of thing for my current game in flash. We just used a bitmap and "drew" the explosion shape on it with BlendMode.ERASE. It's probably slower than it could be, but if you don't have explosions too often it should be okay.

Thanks for mentioning the method you're using in Flash. I'll definitely look into that when I start tearing into Flash more.

http://www.riemers.net/eng/Tutorials/XNA/Csharp/Series2D/Adding_craters.php

there's a tutorial on it. It uses XNA though. Code will still be helpful though

My brother is learning XNA/C#, so this is very helpful. Thanks. :D

I'm realizing now that I really really am out of my league here for programming such things, but I've read up on Cortex Command and they seem to offer some pretty decent mod support... I might have to look into creating a mod for the sake of prototyping gameplay ideas rather than coding from scratch, for now.

Thanks for the input! Grin
Logged

Ryan
Level 1
*



View Profile
« Reply #10 on: April 16, 2009, 08:49:56 PM »

Loover has a nice tutorial over here:

http://forums.tigsource.com/index.php?topic=152.0
Logged
Pages: [1]
Print
Jump to:  

Theme orange-lt created by panic