Skip to main content
GameDev.net gamedev.net
🔒 Locked

Sparse Object Space Game

Started by farmersckn Nov 29, 2001 at 9:02 PM 6 replies 400+ views
Original Post
farmersckn
farmersckn
I am making a game similar to Asteroids where the player fights other ships. The game map will be larger than the screen in almost every case. I intend to have small bases and mazes and the sort, similar to this: .............0........................................... ................................................... .....0........................0.................... .......XX..XX........................................... ......X......X...................................... .....X....0...X..............9................ .....X...o....X........0.................... .....X........X........................... ......XXXXXXXX............................................ Anyways, the Xs represent walls, and the numbers represent rocks and small obstacles. Tiles will be about 16x16 for the most part. My first question is this: What would be the best method of storing wall and asteroids/rock/obstacle positions for collision detection? I''ve got a couple of ideas: Treat each wall segment as an individual object in the game. For instance: X is a segment. Test each segment for collision between ships/bullets/etc.. every frame. This method is probably slow, but easy to implement. Treat each wall as an individual, variable size object in the game. For instance XXXXXXXXXXXXXXXX is a single object. Faster than previous, similar to checking ball collision with a paddle in pong, possibly harder to implement. Have a multidimensional array of Bools, solely for collision testing. Walls can''t move, so this would work well. This might be hard to implement. Not to mention the math needed to convert ship positions to indexes into array involves some division, and since ships are about 2.2 times larger than tiles, this would involve checking ~ 9 tiles per ship per frame. I don''t know what I should do! Any other ideas or maybe suggestions? Also, I would like to have a parralax starfield behind the ship the player is controling. Since the ship moves a viewport within the map, I want the stars to move with the ship, but also scroll every time he moves one viewport in any direction... I also want the starfield to look different for every viewport position in the map. Make sense? I am completely bewildered at this. I thought of having a random num gen and seeding it with something like: viewportX^2 + viewportY whenever the ship enters a new section, and then generating a new starfield. Also, the starfield does not move. Like i said, it is parallax. When the ship moves, the position of the bottom layer only changes by .25 of the players movement... and so on. ANy ideas?
Yesterday is the past, tomorrow is the future. Today is a gift, that is why we call it the present.
Shannon Barber
Shannon Barber
Loose Quadtree?

Magmai Kai Holmlor
- Not For Rent
The trade-off between price and quality does not exist in Japan. Rather, the idea that high quality brings on cost reduction is widely accepted.-- Tajima & Matsubara
farmersckn
farmersckn
What is a loose quadtree?
Yesterday is the past, tomorrow is the future. Today is a gift, that is why we call it the present.
amemorex
amemorex
good luck getting an answer besides "look it up in a book"!
Mayrel
Mayrel
Hmm.

I guess the easiest way to do this with a level of efficiency is to divide the map into a number of what I''m calling ''cells'' (I''m sure there''s a technical name for it, but I don''t recall). Each cell might be 8x8 tiles in size, and holds a list of objects that are within that cell. Each time you want to check if two objects are colliding, find the cell that the objects are in. If they''re in the same cell, or adjacent cells, they might be colliding. Since there''ll probably be a fairly short list of objects to test in each cell, you should be able to do that quite quickly.

Quadtrees are an important optimisation on the cell technique. I''ve never used them, myself, although I do use their 3D cousin, the octree. You can find info on quadtrees all over the net, and on gamedev.



Just Plain Wrong
CaptainJester
CaptainJester
To build on top of what Mayerl said, you could use the same technique and set up a second set of cells for the startfield.
Generate the starfield at the start of the game and store it. This way it is always the same for each section and your code is a lot faster because your are computing the startfield each frame, you are just looking it up.

---
Make it work.
Make it right.
Make it fast.
"None of us learn in a vacuum; we all stand on the shoulders of giants such as Wirth and Knuth and thousands of others. Lend your shoulders to building the future!" - Michael Abrash[JavaGaming.org][The Java Tutorial][Slick][LWJGL][
TerranFury
TerranFury
I doubt you need a quadtree. Chances are, a simple array of pointers to objects would do the trick for everything. Just make a base object class, and derive the rest from it. Wall segments can have additional properties, like endpoints.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.