Created AsteroidGame.hyperJump() for moving the ship to a random x,y
Signed-off-by: Ricky Barrette <rickbarrette@gmail.com>
This commit is contained in:
@@ -58,7 +58,6 @@ public class AsteroidGame extends Thread {
|
|||||||
* @author ricky barrette
|
* @author ricky barrette
|
||||||
*/
|
*/
|
||||||
private void downShip() {
|
private void downShip() {
|
||||||
Random gen = new Random();
|
|
||||||
System.out.println("Ship collision dected");
|
System.out.println("Ship collision dected");
|
||||||
/*
|
/*
|
||||||
* move the players ship's
|
* move the players ship's
|
||||||
@@ -72,15 +71,15 @@ public class AsteroidGame extends Thread {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(s != null){
|
if(s != null){
|
||||||
s.setLocation(gen.nextInt(mGameFrame.getDisplayWidth()), gen.nextInt(mGameFrame.getDispalyHeight()));
|
|
||||||
s.allStop();
|
s.allStop();
|
||||||
|
hyperJump(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
mGameFrame.getStatusBar().decrementShipCount();
|
mGameFrame.getStatusBar().decrementShipCount();
|
||||||
|
|
||||||
if(mGameFrame.getStatusBar().getShipCount() > 0){
|
if(mGameFrame.getStatusBar().getShipCount() > 0){
|
||||||
pauseGame();
|
pauseGame();
|
||||||
mGameFrame.setDisplayText("You died, You can hyper jump to a safe place now...\nPress start when ready.");
|
mGameFrame.setDisplayText("You died, You can hyper jump to a safe place now... Press start when ready.");
|
||||||
} else {
|
} else {
|
||||||
mGameFrame.setDisplayText("Game Over");
|
mGameFrame.setDisplayText("Game Over");
|
||||||
if(s != null)
|
if(s != null)
|
||||||
@@ -97,6 +96,25 @@ public class AsteroidGame extends Thread {
|
|||||||
return mWorld;
|
return mWorld;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Hyperjumps the sip
|
||||||
|
* @param ship
|
||||||
|
* @author ricky barrette
|
||||||
|
*/
|
||||||
|
public void hyperJump(Ship ship) {
|
||||||
|
// boolean isSafe = true;
|
||||||
|
Random gen = new Random();
|
||||||
|
// do{
|
||||||
|
System.out.println("hyper jumping");
|
||||||
|
ship.setLocation(gen.nextInt(mGameFrame.getDisplayWidth()), gen.nextInt(mGameFrame.getDispalyHeight()));
|
||||||
|
// for(int i = 0; i < mWorld.size(); i++)
|
||||||
|
// if(mWorld.get(i) instanceof Collider)
|
||||||
|
// if(((Collider) mWorld.get(i)).checkForCollision(ship))
|
||||||
|
// isSafe = false;
|
||||||
|
// } while (!isSafe);
|
||||||
|
mGameFrame.repaintDispaly();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* populates the world for a new game
|
* populates the world for a new game
|
||||||
* @author ricky barrette
|
* @author ricky barrette
|
||||||
@@ -109,7 +127,7 @@ public class AsteroidGame extends Thread {
|
|||||||
for(int i = 0; i < mGameFrame.getStatusBar().getLevel(); i ++)
|
for(int i = 0; i < mGameFrame.getStatusBar().getLevel(); i ++)
|
||||||
addElement(new Asteroid(gen.nextInt(mGameFrame.getDisplayWidth()), gen.nextInt(mGameFrame.getDispalyHeight()), 1, 10, 50, 3, 3, this));
|
addElement(new Asteroid(gen.nextInt(mGameFrame.getDisplayWidth()), gen.nextInt(mGameFrame.getDispalyHeight()), 1, 10, 50, 3, 3, this));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return true if the world is empty
|
* @return true if the world is empty
|
||||||
* @author ricky barrette
|
* @author ricky barrette
|
||||||
@@ -257,7 +275,7 @@ public class AsteroidGame extends Thread {
|
|||||||
if(item instanceof MovingSpaceObject)
|
if(item instanceof MovingSpaceObject)
|
||||||
((MovingSpaceObject) item).setActive(b);
|
((MovingSpaceObject) item).setActive(b);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return the number of objects in the world
|
* @return the number of objects in the world
|
||||||
* @author ricky barrette
|
* @author ricky barrette
|
||||||
@@ -265,7 +283,7 @@ public class AsteroidGame extends Thread {
|
|||||||
public int size() {
|
public int size() {
|
||||||
return mWorld.size();
|
return mWorld.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Starts the game
|
* Starts the game
|
||||||
* @author ricky barrette
|
* @author ricky barrette
|
||||||
|
|||||||
@@ -25,7 +25,6 @@ import java.awt.event.ActionEvent;
|
|||||||
import java.awt.event.ActionListener;
|
import java.awt.event.ActionListener;
|
||||||
import java.awt.event.KeyEvent;
|
import java.awt.event.KeyEvent;
|
||||||
import java.awt.event.KeyListener;
|
import java.awt.event.KeyListener;
|
||||||
import java.util.Random;
|
|
||||||
|
|
||||||
import javax.swing.JFrame;
|
import javax.swing.JFrame;
|
||||||
import javax.swing.JMenu;
|
import javax.swing.JMenu;
|
||||||
@@ -181,9 +180,7 @@ public class GameFrame extends JFrame implements KeyListener, ActionListener{
|
|||||||
*/
|
*/
|
||||||
case KeyEvent.VK_H:
|
case KeyEvent.VK_H:
|
||||||
if(isKeyPressed){
|
if(isKeyPressed){
|
||||||
Random myRNG = new Random();
|
mGame.hyperJump(ship);
|
||||||
ship.setLocation(myRNG.nextInt(mDisplay.getWidth()), myRNG.nextInt(mDisplay.getHeight()));
|
|
||||||
repaint();
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user