Updated AsteroidsGame.run() to use mWorld.toArray()
Signed-off-by: Ricky Barrette <rickbarrette@gmail.com>
This commit is contained in:
@@ -21,7 +21,6 @@ package com.RickBarrette.asteroids;
|
|||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
import java.util.Vector;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class maintain's the game logic. It is the main driver
|
* This class maintain's the game logic. It is the main driver
|
||||||
@@ -173,6 +172,9 @@ public class AsteroidGame extends Thread {
|
|||||||
public void run() {
|
public void run() {
|
||||||
boolean hasOneUped = false;
|
boolean hasOneUped = false;
|
||||||
int asteroidCount = 0, shotCount = 0;
|
int asteroidCount = 0, shotCount = 0;
|
||||||
|
Object o;
|
||||||
|
Collider c;
|
||||||
|
Object[] world;
|
||||||
while (true){
|
while (true){
|
||||||
if(isStarted) {
|
if(isStarted) {
|
||||||
|
|
||||||
@@ -185,18 +187,16 @@ public class AsteroidGame extends Thread {
|
|||||||
/*
|
/*
|
||||||
* check for collsions
|
* check for collsions
|
||||||
*/
|
*/
|
||||||
Object o;
|
world = mWorld.toArray();
|
||||||
Collider c;
|
for (int i = 0; i < world.length; i++){
|
||||||
Vector<Object> wolrd = new Vector<Object>(mWorld);
|
o = world[i];
|
||||||
for (int i = 0; i < wolrd.size(); i++){
|
|
||||||
o = wolrd.get(i);
|
|
||||||
if(o instanceof Collider){
|
if(o instanceof Collider){
|
||||||
asteroidCount++;
|
asteroidCount++;
|
||||||
c = (Collider) o;
|
c = (Collider) o;
|
||||||
for(int index = 0; index < wolrd.size(); index++)
|
for(int index = 0; index < world.length; index++)
|
||||||
if(c.checkForCollision(wolrd.get(index)))
|
if(c.checkForCollision(world[index]))
|
||||||
//check to see if the ship blew up
|
//check to see if the ship blew up
|
||||||
if(wolrd.get(index) instanceof Ship)
|
if(world[index] instanceof Ship)
|
||||||
downShip();
|
downShip();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user