PDA

View Full Version : How to make it fall down??



MateeC
17-07-2003, 12:52 PM
Hi!

I'm making a simple 2D sidescrolling game with OpenGL...
And I've got a this problem:
http://www.3delavnica.com/portfolio/MateeC/slika1.jpg
When I shoot at the hill the lower part dissappears, but I cant figure out how to make the part of the hill that is in the air fall down... :oops:

I have the whole map in a array, and I've already got a procedure that makes the pixels that have nothing around them come to the ground, but i need help with the procedure for big pieces.

I havent figured out anything yet, so i hope someone will help me, and please be gentle... I'm a beginer and i'm 15 years old.

Thanks!

cairnswm
18-07-2003, 05:39 AM
Why not make another routine that works with bigger peices the same as your pixel routine.

A nice looking process may be to make the hill rain down row by row using your pixel routine.

[You being 15 is to your benifit - I'm 33 and trying to learn game programming still :)]

Traveler
18-07-2003, 10:19 AM
I wonder if it's even possible. But assuming it is, detecting whether or not a piece is allowed to fall is quite an extensive search, which would probably slowdown your game considerably.

There are quite a few things you may have to consider as well. For example what happens when two (or perhaps even more) pieces, one small and one large are next to each other and both are falling. Will you apply gravity to those pieces? Will the smaller one fall on top of the other? Will it roll further down off of the larger piece?

I'm not sure what kind of game you are making, but assuming you're making a worms kind of game. What happens when a large piece is falling and worms are underneath it? Are they killed?

Anway, I'm getting way too enthusiastic again. And now that I read it over, it's actually not even an helpfull answer to you question :(

WILL
18-07-2003, 11:28 PM
I love this question. As a matter of fact this was one of my first programming projects back in the day. Mind you I was programming it in Turing. If you don't know what it is, probably better not to ask. Syntax was alot like Pascal though.

Anyhow, I don't remember getting it to work, but then again, my programming skills have improved greatly since then. What I'd recommend doing is looking at this like the game Connect Four(google for it if you don't know what that is). If not, put another way, take it a colomn at a time. I becomes manageable this way.

1) A Shot rings out! ...and it's in the dirt!
2) You find the magically floating dirt,
3) You determine how tall each colomn is and how far it has to fall and if you care about animation if there is more than one group of dirt in that colomn,
4) You then redraw your dirt per colomn depending on your animation you want to do.
5) Play on!

Working on one colomn at a time makes it quite easy. You could either count the dirt pixels and do a simple redraw when it comes time to animate or you could actually, from the bottom count the "stacks" of dirt in the colomn and mark the starting point of air so you know where each "stack" must stop. Keep in mind that if you have more than 1 stack you much calculate the starting point of your first air pixel + your 1st stack's height, etc. Doing it the way of the later will give you some animation possiblities, but might slow things down a bit more. Up to you how you want it. If it proves to be too slow however, it might serve you to fall back to the simpler way unless you can optimize things some more.

Traveler is right though, this will be a bit of a pause in your game, I'd imagine that your game is turn based? If so that'd help, if not then I'd recommend a way to speed up and dirt detection in your game with inline ASM or something.

Let me know if you finish your algo, I'm quite interested in how it'll end up.

MateeC
19-07-2003, 04:33 PM
I was thinking of doing a algoritem that finds starting and ending points, and then drops the whole rectangle from X1 to X2, Y1 to Y2... but i didnt figure it out so far and it wouldnt be too exact, because it could drop some pixels, that would be in that rectangle but not in the floating dirt.

It would probobaly be more exact if i would do it with columns like will said, but i'd stil need to have a algoritem that would tell if that column is a part of the floating dirt or not.

About the slowdown... its about 40-60fps on my computer without the floating dirt detection procedure, and it still works smooth on 20-25fps at my friends computer, so i hope i can make it fast enough. Too bad i don't know any ASM yet... anyone knows any good tutorials. I should check some ASM stuff out anyway, cause we'll gonna start learning it in school next year.

Anyways... I'm making a game named Djuk Njuk, and it is suposed to look like something like duke nuke 1 and 2, and play like worms.