Advertisement

Sprites on a world

Started by February 21, 2000 03:43 PM
19 comments, last by PsYcHoPrOg 24 years, 6 months ago
I don''t think you should dwell on what Quad Trees are right now, get your game working first.

In a quad tree, you begin with a rectangle that holds the entire map. If the number of units inside the rectangle is above a threshold you divide the rectangle into four pieces of equal size and move the units into their respective rectangle. If any of these smaller rectangles have more units than the threshold it too gets divided into smaller rectangles and so on.

+-------+    +---+---+/    *  /    /   /*  //       / => +---+---+/**   * /    /** / * /+-------+    +---+---+ 


This way you can cull every unit inside a rectangle at once by checking if the rectangle is outside the view.

PS. You do know that you can delete your own posts? If you click on the edit post button there is a button inside that lets you delete the post.
thanks. Cool. Although, I still don''t completely understand the concept of quad trees. I''ll eventually understand it, I guess. Are their any tutorials on it?
D:
Advertisement
There are plenty. But as I said I don''t think you need just yet.
Here is my suggestion (this is what I''m doing for my game of the same type). This will only work if your game is constantly scrolling in only 1 direction, meaning, if once an enemy is passed, it''s passed. What I have is a linked list of all the enemies, sorted by their world y coordinate, greatest to least. This is because the player starts at the end of the map, the greatest y coord in it. Therefore, the first enemy in the list is the closest to the end of the map. When I am processing my enemies, I check to see if any are within the screen area. If they are, then I process them, but because it is sorted, as soon as I find 1 that is above the screen, I can stop looking. Then, as soon as they get below the screen, I can delete them from the list, because they won''t be needed any more. This way, the first enemy in the list that you check will always be the closest to the screen (if it''s not already there) and very little time will be spent checking enemies that won''t be processed right now.
I hope this was clear.

------------------------------
Jonathan Little
invader@hushmail.com
http://www.crosswinds.net/~uselessknowledge
Qoy: That is exactly what I am doing with my attempt at an RTS game... execpt I am using my linked list for Z buffering. Same idea though...

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

"Very funny Scottie, now beam down my clothes."
www.trak.to/rdp

Yanroy@usa.com

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

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

Qoy, I understand what you are saying, and it makes total sense. But where/how do you store the information and locations of the sprites?

Edited by - psychoprog on 2/24/00 11:13:03 AM
D:
Advertisement
You can use this basic structure to hold the location of the sprites:

struct Unit {   Unit *pNextUnit;   Unit *pPrevUnit;  // These are just for the linked list   int XPos;   int YPos;   // This is the units location in map coordinates   ...  // Some extra information needed for the unit, e.g.        // texture, health, AI-state etc}; 


Of course you can put this in a class as well.
Thanks Spellbound, you''re a life saver. I wasn''t sure if I should have used a lookup table or something. And by the way, good luck on getting that masters degree.

"Remember, I'm the monkey, and you're the cheese grater. So no fooling around."
-Grand Theft Auto, London
D:
Thanks, I think I''ll have it nailed before the end of next month.
Hi!

I''m doing one shooter too and I want to ask you: if you use the sorted list aproach, how do you deal with new objects - I mean bullets/explotions and so on -.. do you sort the entire list every time you add a new one? or you have them in a separated list?..
I''m using a linked list for all the objects and I just add the new ones at the end.. it doesn''t seem to affect the performance, even I''m searching the entire list every frame..

Laters!
"Old programmers don't die,they just terminate and stay resident."

This topic is closed to new replies.

Advertisement