I would like to code a game that has Liero-style terrain destruction. (Think worms, scorched earth, etc). I get the theory behind what I am trying to do, I am just having trouble thinking about how to translate it into code.
Maps have two bitmaps: the actual fresh, clean map that isn't touched, and the mask, that has the information about which pixels can be destroyed, solid, already empty, etc.
To accomplish this, I need to be able to do this:
http://img258.imageshack.us/img258/7730/masksdn9.png
I do not believe the magic pink color would not work for this method, because there will be multiple colors that I will be checking.
Thank you for your help
What do you mean by 'checking multiple colours'?
You can only (AFAIK) use magic pink or palette[0] as invisible...
EDIT:
I am doing destructable environments in my current game. I haven't started coding it yet, but when I was thinking I ran into a problem: Magic pink is invisible, so drawing that on to something will have no difference. You blit the mask on and then use a couple of nested for loops to convert your mask colour to magic pink. Unless anybody knows of a more elegant solution...
Magic pink is invisible, so drawing that on to something will have no difference.
Unless you use regular blit
I used this post to help me, but it required a lot of changing.
I know, you can only use the magic pink by default. This is why I am not asking anything about the built in functions.
Like i said before, there will be the map that looks all pretty, and then a colored mask for that map. To explain in more detail, the colored mask has different colors to specify what's going on. For example, anything that is black is solid, anything that is grey is destroyable, anything that is red is insta-death, anything that is white is free space. I am horrible about explaining things, so here is a diagram i found:
http://jnrdev.72dpiarmy.com/en/jnrdev5/files/1_bmp2map.gif
that should pretty much explain it. See how the mask is multicolored? Basically i want to use the mask as a cookie cutter. Any pixel on the mask that is white, don't draw it when displaying the map. there are two bitmaps- a mask and a map. The map isn't manipulated at all at runtime, only the mask. Does this make more sense?
Thank you for all your responses.
Er, just use three bitmaps. Draw the entire terrain mask, and when you destroy terrain form that, blit the transparent mask color to it. Then blit the non-destroyable mask over the destroyable mask, that way one cannot destroy the non-destroyable mask.
Thanks for the replies, but my main question still hasn't been answered (although I am getting some good extra information). So people understand, I'll try once more to see if this makes more sense on what I am asking.
I have mask.bmp and map.bmp. They are the same size. How do I get map.bmp to only display what the mask wants?
Here is that picture again:
http://img258.imageshack.us/img258/7730/masksdn9.png
Showing mask.bmp and map.bmp, and the final screen.
The only way I can think of doing this would be to use putpixel and getpixel
1 | BITMAP* terrain; |
2 | BITMAP* mask; |
3 | BITMAP* map; |
4 | PALETTE palette; |
5 | |
6 | terrain = load_bitmap("terrain.bmp", palette); |
7 | mask = load_bitmap("mask.bmp", palette); |
8 | map = create_bitmap(terrain->w, terrain->h); |
9 | |
10 | for(int y = 0; y < terrain->h; y++) |
11 | { |
12 | for(int x = 0; x < terrain->w; x++) |
13 | { |
14 | if(getpixel(mask, x, y) == makecol(/*YOUR MASK COLOR HERE*/)) |
15 | { |
16 | putpixel(map, x, y, getpixel(terrain, x, y)); |
17 | } |
18 | } |
19 | } |
20 | |
21 | destroy_bitmap(terrain); |
22 | destroy_bitmap(mask); |
23 | destroy_bitmap(map); |
I didn't compile that of course. I hope that's what you were looking for.
Exactly what I was looking for, Matthew! Thanks a bunch. Also, thanks to all who inputted, you've given me solutions to other questions too. Cheers.
makecol(/*YOUR MASK COLOR HERE*/))
bitmap_mask_color()
And move it outside the loop. Also, use the "unsafe" versions of getpixel and putpixel to make it a bit less horribly slow. Which leads me to the last point, which is that you don't want to do that every frame - you'll want something along the lines of what CGames suggested.
Yeah, I have a function called update_map() that does what Matt suggested. It is only called at the beginning, and then whenever I need the map to change.
Thanks for the bitmap_mask_color() function.
I have mask.bmp and map.bmp. They are the same size. How do I get map.bmp to only display what the mask wants?
Okay, that was answered in my first post. But apparently you're happy with 3 FPS
Unless you use regular blit
If you use a regular blit you have to apply colour to the whole image.