Advertisement

Blowuppable land

Started by January 15, 2001 01:19 PM
8 comments, last by Pierspo 24 years ago
I am partway through a ganja farmer style game and it contains a randomly generated 2d landskape at the bottom of the screen. There are also bombs which fall and they are meant to blow circular holes in the land (worms style).The height of the land at each x value is srored in an array ground[x]i just cant figure out how to do it. except a long way round which involves getpixel(). anyway i use djgpp and allegro. thanks.
yeah boy
Why don''t you store the land as a bitmap, then you could simply plot a black circle at the right place to blow a hole in the land. You could use the land bitmap for collision detection:-

if(getpixel(land, bomb.x, bomb.y) != 0)
bomb.explode();

hope that helps.

Zaph.
Advertisement
The reason i did not store it as a bitmap is that then colission detection for bombs then requires a getpixel call which is slower
than simply.
  if(bommb.y<ground[bomb.x])  

although that will have to suffice if i cant find another way. Thanks anyway.

Edited by - pierspo on January 16, 2001 10:16:00 AM

Edited by - Pierspo on January 16, 2001 10:19:14 AM
yeah boy
well you have your circle center (g,h) where the thing explodes.

you have some predefined radius (r).



your circle equation is:
(x - g)^2 + (y - h)^2 = r^2

Messing this around gets:
(1)y^2 + (-2h)y + (x^2 - 2gx + g^2 + h^2 - r^2) = 0

the bits in brackets are a,b and c. i.e:

a = 1
b = -2h
c = x^2 - 2gx + g^2 + h^2 - r^2

to get y you do:
y = -(b +- sqrt(b^2 - 4ac))/2a

so for every x you can get two values for y. One for the top semicircle and one for the bottom. Obviously you want the bottom. i.e. the smallest.

So start at x=g-r and go until x=g+r-1. At each iteration if ground[x]>y then set ground[x]=y .

That should work.

ro


Edited by - rowbot on January 16, 2001 10:52:44 AM
Thanks rowbot, but is there any way to do it without the square root?
yeah boy
When I started programming "real" games (aka with DirectX), I promised myself that, barring a serious speed problem, I would only optimize my code to the point where it is still simple. I would not do all kinds of crazy stuff just to get rid of a square root. For instance, in my latest game, the bitmap rotation function (called at bare minimum once a frame) uses both sin() and cos(), as well as all of the unit motion functions. I detected a loss of about 2ms per frame draw, which comes out to something like 1000/50 vs 1000/52, or a difference of about .7 fps I don''t think a square root is much worse than a couple of trig functions.

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


You are not a real programmer until you end all your sentences with semicolons; (c) 2000 ROAD Programming


You are unique. Just like everybody else.


"Mechanical engineers design weapons; civil engineers design targets."

Yanroy@usa.com

Visit the ROAD Programming Website for more programming help.

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

You are not a real programmer until you end all your sentences with semicolons; (c) 2000 ROAD Programming
You are unique. Just like everybody else.
"Mechanical engineers design weapons; civil engineers design targets."
"Sensitivity is adjustable, so you can set it to detect elephants and other small creatures." -- Product Description for a vibration sensor

Yanroy@usa.com

Advertisement
Pierspo,

If you''re going to steal my source code I sent you, at least acknowledge that it''s not actually your own code you''re referring to . For the rest of you, basically I know this guy, and I sent him the source to my latest game, which involves the land generation / degradation methods he''s reffering to, the bomb dropping et al - basically the game he''s making. I only meant for it to ''educate'' him, but it seems he''s simply taken to leeching whole lumps of code from it, which slightly annoys me. Basically, that''s all my code, my idea. Not that it''s amazing, but I don''t like the way he''s ripped it off completely. For those wondering why I stored the ground in an array, it was really just practice, and it allowed me to generate one screen wide solid random landscapes, and provide an easy method for collision detection. I''d done all the methods suggested before. I just like to experiment .

With regards to the bomb explosion question, well PiersPo, you should''ve just asked me... in the lastest version of my game (which you are not going to see ) i''ve sorted the problem of making proper bomb blasts in the ground... it was very simple. I guess you''d actually know that, had you written the code yourself. Sorry, this is turning into a rant, but I just couldn''t help it. I just hate people taking credit for what i''ve done... I know he''s not taking credit, but he''s taken something i''ve done, claimed it as his own, and then due to the fact he doesn''t fully understand it he''s come crawling for help. Bah. Well, that''s enough for now... oh, and by the way PiersPo, the answer involves math as simple as addition... no square root, multiplication, anything. That''ll teach ya .

Insomnia




Insomnia
I take a guess as to how it works:

You have a variables for the center of where the bomb blast is to be:

  int bombX, bombY;  


Next, we have another, smaller array filled with the values that a semicircle would make:

  int BlastArray[5] = {1,3,6,3,1}; // probably not actual circle values, fill with your own// you''ll probably want a larger array too  


Now, you just loop through:

  int i = 0;for(i = 0; i < 5; i++){     if(Terrain[bombX - halfArraySize + i] > (bombY - BlastArray[i]{        Terrain[bombX - halfArraySize + i] = bombY - BlastArray[i];     }}  


The source tags probably didn''t work right, and don''t straight copy this code, I haven''t tested it. It''s just a theory, but it should make a semicircle hole in the location of you choice.
[/source]

Sorry about the lack of code
Insomnia youre talking shit.
I talked to you about my game and in the beginning I used an array just as you had done to store the values of ground height it seemed like a good idea(its my first ever project greater than like 50 lines of code). I have barely read your source though
because its difficult to understand much of it because its all classes and stuff and i dont know c++ only c(and not that much). As to the ground I have decided to do away with the array storing heights. In fact im taking Zaphod's advice and just checking the bitmap, because its a memory bitmap i can access it as an array (I didnt know this before) nice and fast and when a bomb explodes i just blit a color 0 circle onto it wherever. I ask you for advice from time to time (maybe even quite often), but even so you have no idea what ive done with your code and your accusing me of "leeching whole lumps of code from it" im not taking credit for what youve done all you did was say you stored the heights in an array when i was having problems with my land and i dont mind admitting it, it was insomnias idea i COPIED IT. I didnt think it was relavent to state that in a conversation a few weeks back with someone i know i used one of their ideas in my game. But there you go ill be more careful now abut stating peoples rights to ideas.

BTW no code has been leeched.

And thankyou everyone else for youre advice. I hope you dont mind if i take some of your advice and program my game accordingly.




Edited by - Pierspo on January 19, 2001 10:41:49 AM
yeah boy
OK, fine, I''ll do it then.

BLOWUPPABLE???? What is that?

There obviously aren''t too many holes being blown in YOUR gonja crops! :->

This topic is closed to new replies.

Advertisement