Dynamic 2D Landscape

BlitzMax Forums/BlitzMax Programming/Dynamic 2D Landscape

Scaremonger(Posted 2012) [#1]
Hi all,

I've been looking to rewrite a game I produced in the 80's which requires a landscape that is dynamic.

Think "Defender" and you'll get a rough idea, the difference is that the landscape at the bottom is solid instead of a line. One feature of the game is a crawling mass of "Red Weed" that transforms the landscape from Green to Red.

In the early version, the landscape was blocks of colour held in an array but today's graphics require a higher resolution than this. I have tried using 4x4 pixel blocks in an array and have tried the same size objects in a Tlist (and an array so they can reference their neighbours to spread), but storing the landscape in "active-pixels" is a few hundred thousand objects at best and slows down the FPS to the point of being un-useable.

Does anyone have any suggestions on how I should approach this?

My test code:


Last edited 2012


slenkar(Posted 2012) [#2]
how did worms do it?

the only way i can think of is using polygons that form and split with the landscape but that seems very complicated


Kryzon(Posted 2012) [#3]
You need to delegate this to the hardware.

Worms used masking. If we were in Blitz3D, you'd draw black circles over your environment image where the projectiles hit. Since black is masked automatically in Blitz3D, the circle would "chop" out a piece of the environment and the pixel-perfect collision system would consider that as empty space, and using DrawImage would draw the environment with transparent holes where the projectiles hit.

With BlitzMax, under the hood, masking is done with alpha blending.

You need to get the pointer to your pixmap's pixels and manually set their alpha value to zero in a radius or whatever shape you want - just make sure you don't try to read outside the limits.
You can also use WritePixel and set a value of ARGB [255,0,0,0] so these pixels are considered empty space when drawn with ALPHABLEND or when processed with ImagesCollide().
Also make sure to clean any loose pixels left (like a single pixel floating in air) just to avoid having ugly chunks flying in mid air, potentially causing bugged collisions.

Study Pixmaps, they're the way to go.

Last edited 2012


InvisibleKid(Posted 2012) [#4]
i only skimmed over the posts but saw mention of worms, and remembered a tiny test example i put together a few years ago that may or may not be relivant. either way your welcome to check it out and take from it what you will.

Old Post Here


therevills(Posted 2012) [#5]
I did a quick worms clone awhile ago:

http://www.blitzbasic.com/Community/posts.php?topic=89848#1021110


Scaremonger(Posted 2012) [#6]
I think my title for this post may have been mis-understood.

Although having a dynamically created landscape is part of my project, the problem I am having is more to do with the landscape being dynamic AFTER it is created.

For example, red weed that spreads, things that grow and die. Using an object for each pixel in the landscape is a huge Tlist.. There must be a better way.


Kryzon(Posted 2012) [#7]
Try using arrays instead of TLists of objects.

That is, arrays representing the full landscape. One array for the class of objects, one for the attributes of objects etc.

Last edited 2012


Jesse(Posted 2012) [#8]
why don't you create them in groups of pixels as in an organism being developed. maybe a square of 8x8 10x10 16x16 pixels etc... of which each pixel don't have to be created at the same time. treat them as a bunch of mini maps being connected together. When a pixel is grown into the edge of the square it can spread into another square. also when the square is full(mature) you can ignore the individual pixels for a certain time until it starts to die or your desired condition.

Just an idea.

Last edited 2012


SLotman(Posted 2012) [#9]
Have 2 maps. One for dynamic things, other for "static" things.
Just update the dynamic ones.

If something happens, and turn a "static" tile into a dynamic one, just move it to the second list. If a dynamic tile "dies", move it to a static, and so on.

This should help a little bit :)


Scaremonger(Posted 2012) [#10]
Thanks guys; thats given me some ideas to try out. :)