Thank you very much for such a detailed response. I thought arrays were the way to go, but I probably wouldn't have programmed it quite as eloquently as you set out.
Thanks again -Liam On Nov 16, 2:01 pm, Darcey Lloyd <[email protected]> wrote: > For just a dodge the rock game, I would start with something like this: > > 1. Create away3D setup > 2. Create asteroid class > 3. Create ship class > 4. Generate asteroids at randomly timed intervals (calling new asteroid()) > storing each in an array, removing references and disposing accordingly when > out of screen > 5. On render check for collision between asteroid and ship (loop through > array) > 6. On collision detected, asteroid class would have it's own handlers for > destruction animation or dispose for a new class called > destruction(vector3D); > > So this would translate to: > > 1. Main.as (Away3D setup and generation of ship and asteroids and collision > detection) > 2. Asteroid.as (asteroid animation on z axis - random x and y) > 3. Ship.as (player ship handling key events for itself) > 4. Explosion.as (explosion scene taking vector3D) > > *Main.as* > private var asteroids:Array(); > private var ship:Ship(); > private function setupAway3D(); > private function render(); > private function checkCollision(); // Called in render() > private function removeIndexFromArray(); // When asteroid is no longer > needed in array, clean up etc > private function collision(arrayIndexOfCollidedObj:Number){ > // loop through array stopping all asteroid animations > var explosionLocation:Vector3D = (asteroids[arrayIndexOfCollidedObj] as > Asteroid).position; // Get location of collision from > asteroids[arrayIndexOfCollidedObj] > (asteroids[arrayIndexOfCollidedObj] as Asteroid).dispose(); // dispose > of asteroid that has been collided making way for explosion > ship.dipose(); // dispose of ship > new Explosion(explosionLocation); > > } > > *Asteroid.as* > private function setupAsteroid(); // at random x and y > private function animate(); // Animation of asteroid on z axis > private function dispose(); // clean up of class variables, references and > removal of object from scene etc > public function position():Vector 3D{} // Return position of asteroid on > request > > *Ship.as* > private function setupShip(); > private function keyDownHandler(); // Movement handler > private function keyUpHandler(); // Movement handler > private function dispose(); clean up of class variables, references and > removal of object from scene etc > > *Explosion.as* > private function createExplosion(){} // Do what you want for explosion at > location inputted by constructor > private function dispose() // clean up of class, references etc after all is > done > > Dispatch events for the following: > > 1. For Main.as to remove asteroid from array > 2. For Main.as to handle what happens next after Explosion.as has done its > thing. > > On 16 November 2010 13:25, Liam Jones <[email protected]> wrote: > > > > > > > > > Hi all, up to now I've been able to find a solution to most of my > > problems in other peoples posts, but unfortunately on this occasion my > > problem has dumbfounded me for too long. > > > I'm looking to create a 3D asteroids style game where everything moves > > in the Z axis towards the players avatar, which can avoid them by > > moving around its X and Y axis. > > > My issue is that there are potentially going to be around 10 - 15 > > debris on the screen at anyone time, and I had intended to create them > > using a function that adds the asteroid child as a local variable, > > allowing for a single function to spawn all of the debris using one > > archetype debris. This means that each piece of debris will not have a > > unique name. Couple that with the use of projectiles that are created > > in a similar fashion, and I have hit a brick wall as to how to detect > > collisions between the none unique objects and allow the projectiles > > to destroy the debris. > > > I was thinking that I could create the debris in a local variable and > > then add it to an array or possibly to one of 4 arrays depending on > > what section of the screen it was spawning in, allowing for localised > > collision detection, and do the same for the lasers. I've yet to see > > if this would work though, and before starting it I wanted to ask the > > experts whether or not they had any better ideas. > > > Thanks in advance > > > -Liam
