Updated conventions, cleaned up comments and code
Signed-off-by: Ricky Barrette <rickbarrette@gmail.com>
This commit is contained in:
@@ -26,14 +26,14 @@ import java.awt.Graphics;
|
|||||||
* This class will be used to make astroids, to destroy the ship!
|
* This class will be used to make astroids, to destroy the ship!
|
||||||
* @author ricky barrette
|
* @author ricky barrette
|
||||||
*/
|
*/
|
||||||
public class Asteroid extends MovingSpaceObject implements Collider, Drawable {
|
public class Asteroid extends MovingSpaceObject implements Collider {
|
||||||
|
|
||||||
private final int mNumberSplit;
|
private final int mNumberSplit;
|
||||||
private final int mHitsLeft;
|
private final int mHitsLeft;
|
||||||
private final int mRadius;
|
private final int mRadius;
|
||||||
private final double mMinVelocity;
|
private final double mMinVelocity;
|
||||||
private final double mMaxVelocity;
|
private final double mMaxVelocity;
|
||||||
private AsteroidGame mGame;
|
private final AsteroidGame mGame;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new Asteroid
|
* Creates a new Asteroid
|
||||||
|
|||||||
@@ -50,7 +50,7 @@ public class AsteroidGame extends Thread {
|
|||||||
* @param add
|
* @param add
|
||||||
* @author ricky barrette
|
* @author ricky barrette
|
||||||
*/
|
*/
|
||||||
public synchronized void addElement(Object o) {
|
public synchronized void addElement(final Object o) {
|
||||||
mWorld.add(o);
|
mWorld.add(o);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -102,7 +102,7 @@ public class AsteroidGame extends Thread {
|
|||||||
* @param ship
|
* @param ship
|
||||||
* @author ricky barrette
|
* @author ricky barrette
|
||||||
*/
|
*/
|
||||||
public void hyperJump(Ship ship) {
|
public void hyperJump(final Ship ship) {
|
||||||
// boolean isSafe = true;
|
// boolean isSafe = true;
|
||||||
Random gen = new Random();
|
Random gen = new Random();
|
||||||
// do{
|
// do{
|
||||||
@@ -162,6 +162,7 @@ public class AsteroidGame extends Thread {
|
|||||||
startGame();
|
startGame();
|
||||||
|
|
||||||
notification("Level "+ mGameFrame.getStatusBar().getLevel());
|
notification("Level "+ mGameFrame.getStatusBar().getLevel());
|
||||||
|
mGameFrame.repaintDispaly();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -201,7 +202,7 @@ public class AsteroidGame extends Thread {
|
|||||||
* @param o object to be removed
|
* @param o object to be removed
|
||||||
* @author ricky barrette
|
* @author ricky barrette
|
||||||
*/
|
*/
|
||||||
public synchronized void removeElement(Object o) {
|
public synchronized void removeElement(final Object o) {
|
||||||
if(o instanceof Asteroid) {
|
if(o instanceof Asteroid) {
|
||||||
mGameFrame.getStatusBar().incrementScore(2);
|
mGameFrame.getStatusBar().incrementScore(2);
|
||||||
}
|
}
|
||||||
@@ -305,7 +306,7 @@ public class AsteroidGame extends Thread {
|
|||||||
* @param b
|
* @param b
|
||||||
* @author ricky barrette
|
* @author ricky barrette
|
||||||
*/
|
*/
|
||||||
public void setMovingSpaceObjectsEnabled(boolean b) {
|
public void setMovingSpaceObjectsEnabled(final boolean b) {
|
||||||
for(Object item : mWorld)
|
for(Object item : mWorld)
|
||||||
if(item instanceof MovingSpaceObject)
|
if(item instanceof MovingSpaceObject)
|
||||||
((MovingSpaceObject) item).setActive(b);
|
((MovingSpaceObject) item).setActive(b);
|
||||||
|
|||||||
@@ -26,6 +26,6 @@ package com.RickBarrette.asteroids;
|
|||||||
*/
|
*/
|
||||||
public interface Collider {
|
public interface Collider {
|
||||||
|
|
||||||
public boolean checkForCollision(Object o);
|
public boolean checkForCollision(final Object o);
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
/**
|
/**
|
||||||
java * Display.java
|
* Display.java
|
||||||
* @date Mar 31, 2012
|
* @date Mar 31, 2012
|
||||||
* @author ricky barrette
|
* @author ricky barrette
|
||||||
*
|
*
|
||||||
@@ -35,10 +35,9 @@ import javax.swing.JPanel;
|
|||||||
public class Display extends JPanel {
|
public class Display extends JPanel {
|
||||||
|
|
||||||
private static final long serialVersionUID = -9105117186423881937L;
|
private static final long serialVersionUID = -9105117186423881937L;
|
||||||
private AsteroidGame mGame;
|
private final AsteroidGame mGame;
|
||||||
private Container mContainer;
|
private final Font mFont;
|
||||||
private String mText;
|
private String mText;
|
||||||
private Font mFont;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new Dispay
|
* Creates a new Dispay
|
||||||
@@ -46,11 +45,10 @@ public class Display extends JPanel {
|
|||||||
* @param g
|
* @param g
|
||||||
* @author ricky barrette
|
* @author ricky barrette
|
||||||
*/
|
*/
|
||||||
public Display(Container c, AsteroidGame g) {
|
public Display(final Container c, final AsteroidGame g) {
|
||||||
mGame = g;
|
mGame = g;
|
||||||
mContainer = c;
|
|
||||||
this.setBackground(new Color(0, 0, 0));
|
this.setBackground(new Color(0, 0, 0));
|
||||||
mContainer.add(this, BorderLayout.CENTER);
|
c.add(this, BorderLayout.CENTER);
|
||||||
int screenRes = Toolkit.getDefaultToolkit().getScreenResolution();
|
int screenRes = Toolkit.getDefaultToolkit().getScreenResolution();
|
||||||
int fontSize = (int)Math.round(14.0 * screenRes / 72.0);
|
int fontSize = (int)Math.round(14.0 * screenRes / 72.0);
|
||||||
mFont = new Font("Arial", Font.PLAIN, fontSize);
|
mFont = new Font("Arial", Font.PLAIN, fontSize);
|
||||||
@@ -61,9 +59,8 @@ public class Display extends JPanel {
|
|||||||
* @see javax.swing.JComponent#paintComponent(java.awt.Graphics)
|
* @see javax.swing.JComponent#paintComponent(java.awt.Graphics)
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void paintComponent(Graphics g) {
|
public void paintComponent(final Graphics g) {
|
||||||
super.paintComponent(g);
|
super.paintComponent(g);
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Move & Draw the world's objects
|
* Move & Draw the world's objects
|
||||||
@@ -93,7 +90,12 @@ public class Display extends JPanel {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setDisplayText(String string) {
|
/**
|
||||||
|
* Sets the text to be displayed in the center of the game's display
|
||||||
|
* @param string
|
||||||
|
* @author ricky barrette
|
||||||
|
*/
|
||||||
|
public void setDisplayText(final String string) {
|
||||||
mText = string;
|
mText = string;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -27,6 +27,6 @@ import java.awt.Graphics;
|
|||||||
*/
|
*/
|
||||||
public interface Drawable {
|
public interface Drawable {
|
||||||
|
|
||||||
public void draw(Graphics g);
|
public void draw(final Graphics g);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -40,16 +40,16 @@ public class GameFrame extends JFrame implements KeyListener, ActionListener{
|
|||||||
|
|
||||||
private static final long serialVersionUID = -2051298505681885632L;
|
private static final long serialVersionUID = -2051298505681885632L;
|
||||||
|
|
||||||
private Status mStatusBar;
|
private final Status mStatusBar;
|
||||||
private Display mDisplay;
|
private final Display mDisplay;
|
||||||
private AsteroidGame mGame;
|
private final AsteroidGame mGame;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new GameFrame
|
* Creates a new GameFrame
|
||||||
* @param g
|
* @param g
|
||||||
* @author ricky barrette
|
* @author ricky barrette
|
||||||
*/
|
*/
|
||||||
public GameFrame(AsteroidGame g) {
|
public GameFrame(final AsteroidGame g) {
|
||||||
super("ASTEROIDS");
|
super("ASTEROIDS");
|
||||||
mGame = g;
|
mGame = g;
|
||||||
|
|
||||||
@@ -103,10 +103,9 @@ public class GameFrame extends JFrame implements KeyListener, ActionListener{
|
|||||||
* (non-Javadoc)
|
* (non-Javadoc)
|
||||||
* @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
|
* @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
|
||||||
*/
|
*/
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(final ActionEvent e) {
|
||||||
if (e.getActionCommand().equals("New Game")) {
|
if (e.getActionCommand().equals("New Game")) {
|
||||||
mGame.newGame();
|
mGame.newGame();
|
||||||
mDisplay.repaint();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (e.getActionCommand().equals("Start")) {
|
if (e.getActionCommand().equals("Start")) {
|
||||||
@@ -127,7 +126,7 @@ public class GameFrame extends JFrame implements KeyListener, ActionListener{
|
|||||||
* @param isKeyPressed
|
* @param isKeyPressed
|
||||||
* @author ricky barrette
|
* @author ricky barrette
|
||||||
*/
|
*/
|
||||||
private void driveShip(KeyEvent e, boolean isKeyPressed) {
|
private void driveShip(final KeyEvent e, final boolean isKeyPressed) {
|
||||||
Ship ship = null;
|
Ship ship = null;
|
||||||
//get the user's ship
|
//get the user's ship
|
||||||
for (Object item : mGame.getWorld()) {
|
for (Object item : mGame.getWorld()) {
|
||||||
@@ -223,7 +222,7 @@ public class GameFrame extends JFrame implements KeyListener, ActionListener{
|
|||||||
* @see java.awt.event.KeyListener#keyPressed(java.awt.event.KeyEvent)
|
* @see java.awt.event.KeyListener#keyPressed(java.awt.event.KeyEvent)
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void keyPressed(KeyEvent e) {
|
public void keyPressed(final KeyEvent e) {
|
||||||
|
|
||||||
switch(e.getKeyCode()){
|
switch(e.getKeyCode()){
|
||||||
/*
|
/*
|
||||||
@@ -247,12 +246,12 @@ public class GameFrame extends JFrame implements KeyListener, ActionListener{
|
|||||||
* @see java.awt.event.KeyListener#keyReleased(java.awt.event.KeyEvent)
|
* @see java.awt.event.KeyListener#keyReleased(java.awt.event.KeyEvent)
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void keyReleased(KeyEvent e) {
|
public void keyReleased(final KeyEvent e) {
|
||||||
driveShip(e, false);
|
driveShip(e, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void keyTyped(KeyEvent e) {
|
public void keyTyped(final KeyEvent e) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -278,7 +277,7 @@ public class GameFrame extends JFrame implements KeyListener, ActionListener{
|
|||||||
* @param string to be displayed
|
* @param string to be displayed
|
||||||
* @author ricky barrette
|
* @author ricky barrette
|
||||||
*/
|
*/
|
||||||
public void setDisplayText(String string) {
|
public void setDisplayText(final String string) {
|
||||||
mDisplay.setDisplayText(string);
|
mDisplay.setDisplayText(string);
|
||||||
this.repaint();
|
this.repaint();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,16 +25,20 @@ package com.RickBarrette.asteroids;
|
|||||||
* @author ricky barrette
|
* @author ricky barrette
|
||||||
*/
|
*/
|
||||||
public class Main {
|
public class Main {
|
||||||
|
|
||||||
public static final boolean DEBUG = false;
|
public static final boolean DEBUG = false;
|
||||||
|
private static final AsteroidGame mGame;
|
||||||
|
|
||||||
|
static {
|
||||||
|
mGame = new AsteroidGame();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new Main
|
* Creates a new Main
|
||||||
* @author ricky barrette
|
* @author ricky barrette
|
||||||
*/
|
*/
|
||||||
public Main() {
|
public Main() {
|
||||||
AsteroidGame game = new AsteroidGame();
|
mGame.newGame();
|
||||||
game.newGame();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -25,11 +25,11 @@ package com.RickBarrette.asteroids;
|
|||||||
*/
|
*/
|
||||||
public interface Moveable {
|
public interface Moveable {
|
||||||
|
|
||||||
public void move(int scrnWidth, int scrnHeight);
|
public void move(final int scrnWidth, final int scrnHeight);
|
||||||
|
|
||||||
public void setAccelerating(boolean accelerating);
|
public void setAccelerating(final boolean accelerating);
|
||||||
|
|
||||||
public void setTurningLeft(boolean turningLeft);
|
public void setTurningLeft(final boolean turningLeft);
|
||||||
|
|
||||||
public void setTurningRight(boolean turningRight);
|
public void setTurningRight(final boolean turningRight);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ package com.RickBarrette.asteroids;
|
|||||||
* This class will track the information required for moving objects.
|
* This class will track the information required for moving objects.
|
||||||
* @author ricky barrette
|
* @author ricky barrette
|
||||||
*/
|
*/
|
||||||
public class MovingSpaceObject extends SpaceObject implements Moveable{
|
public abstract class MovingSpaceObject extends SpaceObject implements Moveable{
|
||||||
|
|
||||||
protected double mAngle;
|
protected double mAngle;
|
||||||
protected double mVelocityDecay = 1;
|
protected double mVelocityDecay = 1;
|
||||||
@@ -83,7 +83,7 @@ public class MovingSpaceObject extends SpaceObject implements Moveable{
|
|||||||
* @see com.RickBarrette.asteroids.Moveable#move(int, int)
|
* @see com.RickBarrette.asteroids.Moveable#move(int, int)
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void move(int scrnWidth, int scrnHeight) {
|
public void move(final int scrnWidth, final int scrnHeight) {
|
||||||
if(isActive){
|
if(isActive){
|
||||||
/*
|
/*
|
||||||
* this is backwards from typical polar coordinates
|
* this is backwards from typical polar coordinates
|
||||||
@@ -135,7 +135,7 @@ public class MovingSpaceObject extends SpaceObject implements Moveable{
|
|||||||
* @see com.RickBarrette.asteroids.Moveable#setAccelerating(boolean)
|
* @see com.RickBarrette.asteroids.Moveable#setAccelerating(boolean)
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void setAccelerating(boolean accelerating) {
|
public void setAccelerating(final boolean accelerating) {
|
||||||
this.isAccelerating = accelerating; // start or stop accelerating the ship
|
this.isAccelerating = accelerating; // start or stop accelerating the ship
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -144,7 +144,7 @@ public class MovingSpaceObject extends SpaceObject implements Moveable{
|
|||||||
* @param active
|
* @param active
|
||||||
* @author ricky barrette
|
* @author ricky barrette
|
||||||
*/
|
*/
|
||||||
public void setActive(boolean active) {
|
public void setActive(final boolean active) {
|
||||||
this.isActive = active; // used when the game is paused or unpaused
|
this.isActive = active; // used when the game is paused or unpaused
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -154,7 +154,7 @@ public class MovingSpaceObject extends SpaceObject implements Moveable{
|
|||||||
* @see com.RickBarrette.asteroids.Moveable#setTurningLeft(boolean)
|
* @see com.RickBarrette.asteroids.Moveable#setTurningLeft(boolean)
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void setTurningLeft(boolean turningLeft) {
|
public void setTurningLeft(final boolean turningLeft) {
|
||||||
this.isTurningLeft = turningLeft; // start or stop turning the ship
|
this.isTurningLeft = turningLeft; // start or stop turning the ship
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -164,7 +164,7 @@ public class MovingSpaceObject extends SpaceObject implements Moveable{
|
|||||||
* @see com.RickBarrette.asteroids.Moveable#setTurningRight(boolean)
|
* @see com.RickBarrette.asteroids.Moveable#setTurningRight(boolean)
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void setTurningRight(boolean turningRight) {
|
public void setTurningRight(final boolean turningRight) {
|
||||||
this.isTurningRight = turningRight;
|
this.isTurningRight = turningRight;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -173,7 +173,7 @@ public class MovingSpaceObject extends SpaceObject implements Moveable{
|
|||||||
* when it goes out of the screen's bounds
|
* when it goes out of the screen's bounds
|
||||||
* @author ricky barrette
|
* @author ricky barrette
|
||||||
*/
|
*/
|
||||||
public void wrapSpace(int scrnHeight, int scrnWidth) {
|
public void wrapSpace(final int scrnHeight, final int scrnWidth) {
|
||||||
if (mX < 0)
|
if (mX < 0)
|
||||||
mX += scrnHeight;
|
mX += scrnHeight;
|
||||||
else if (mX > scrnHeight)
|
else if (mX > scrnHeight)
|
||||||
|
|||||||
@@ -26,21 +26,17 @@ import java.awt.Graphics;
|
|||||||
* This class will be the user's ship. I will be used to destroy the asteroids, with it's laser! Pew Pew Pew!!!
|
* This class will be the user's ship. I will be used to destroy the asteroids, with it's laser! Pew Pew Pew!!!
|
||||||
* @author ricky barrette
|
* @author ricky barrette
|
||||||
*/
|
*/
|
||||||
public class Ship extends MovingSpaceObject implements Drawable {
|
public class Ship extends MovingSpaceObject {
|
||||||
|
|
||||||
private final int[] mOrigXpoints = { 14, -10, -6, -10 };
|
private final int[] mOrigXpoints = { 14, -10, -6, -10 };
|
||||||
private final int[] mOrigYpoints = { 0, -8, 0, 8 };
|
private final int[] mOrigYpoints = { 0, -8, 0, 8 };
|
||||||
private final int[] mOrigFlameXpoints = { -6, -23, -6 };
|
private final int[] mOrigFlameXpoints = { -6, -23, -6 };
|
||||||
private final int[] mOrigFlameYpoints = { -3, 0, 3 };
|
private final int[] mOrigFlameYpoints = { -3, 0, 3 };
|
||||||
|
private final int shotDelay;
|
||||||
/*
|
private int[] mXpoints = new int[4], mYpoints = new int[4], mFlameXpoints = new int[3], mFlameYpoints = new int[3];
|
||||||
* store the current locations of the points used to draw the ship and its
|
private int shotDelayLeft;
|
||||||
* flame
|
|
||||||
*/
|
|
||||||
int[] mXpoints = new int[4], mYpoints = new int[4], mFlameXpoints = new int[3], mFlameYpoints = new int[3];
|
|
||||||
int shotDelay, shotDelayLeft; // used to determine the rate of firing
|
|
||||||
|
|
||||||
/*
|
/**
|
||||||
* radius of circle used to approximate the ship
|
* radius of circle used to approximate the ship
|
||||||
*/
|
*/
|
||||||
private final int mRadius = 6;
|
private final int mRadius = 6;
|
||||||
@@ -56,8 +52,7 @@ public class Ship extends MovingSpaceObject implements Drawable {
|
|||||||
* @param shotDelay of the ship
|
* @param shotDelay of the ship
|
||||||
* @author ricky barrette
|
* @author ricky barrette
|
||||||
*/
|
*/
|
||||||
public Ship(double x, double y, double angle, double acceleration, double velocityDecay, double rotationalSpeed, int shotDelay) {
|
public Ship(final double x, final double y, final double angle, final double acceleration, final double velocityDecay, final double rotationalSpeed, final int shotDelay) {
|
||||||
// this.x refers to the Ship's x, x refers to the x parameter
|
|
||||||
this.mX = x;
|
this.mX = x;
|
||||||
this.mY = y;
|
this.mY = y;
|
||||||
this.mAngle = angle;
|
this.mAngle = angle;
|
||||||
@@ -81,9 +76,11 @@ public class Ship extends MovingSpaceObject implements Drawable {
|
|||||||
* @author ricky barrette
|
* @author ricky barrette
|
||||||
*/
|
*/
|
||||||
public boolean canShoot() {
|
public boolean canShoot() {
|
||||||
if (shotDelayLeft > 0) // checks to see if the ship is ready to
|
/*
|
||||||
|
* check if the shot delay has been satifiyed
|
||||||
|
*/
|
||||||
|
if (shotDelayLeft > 0)
|
||||||
return false;
|
return false;
|
||||||
// shoot again yet or if it needs to wait longer
|
|
||||||
else
|
else
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -94,36 +91,50 @@ public class Ship extends MovingSpaceObject implements Drawable {
|
|||||||
* @see com.RickBarrette.asteroids.Drawable#draw(java.awt.Graphics)
|
* @see com.RickBarrette.asteroids.Drawable#draw(java.awt.Graphics)
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void draw(Graphics g) {
|
public void draw(final Graphics g) {
|
||||||
|
|
||||||
if(Main.DEBUG)
|
if(Main.DEBUG)
|
||||||
System.out.println("draw()"+ mX + ", "+ mY);
|
System.out.println("draw()"+ mX + ", "+ mY);
|
||||||
|
|
||||||
// rotate the points, translate them to the ship's location (by
|
/*
|
||||||
// adding x and y), then round them by adding .5 and casting them
|
* rotate the points, translate them to the ship's location (by
|
||||||
// as integers (which truncates any decimal place)
|
* adding x and y), then round them by adding .5 and casting them
|
||||||
if (isAccelerating && isActive) { // draw flame if accelerating
|
* as integers (which truncates any decimal place)
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* draw the ship's flame, if accelerating
|
||||||
|
*/
|
||||||
|
if (isAccelerating && isActive) {
|
||||||
for (int i = 0; i < 3; i++) {
|
for (int i = 0; i < 3; i++) {
|
||||||
mFlameXpoints[i] = (int) (mOrigFlameXpoints[i] * Math.cos(mAngle) - mOrigFlameYpoints[i] * Math.sin(mAngle) + mX + .5);
|
mFlameXpoints[i] = (int) (mOrigFlameXpoints[i] * Math.cos(mAngle) - mOrigFlameYpoints[i] * Math.sin(mAngle) + mX + .5);
|
||||||
mFlameYpoints[i] = (int) (mOrigFlameXpoints[i] * Math.sin(mAngle) + mOrigFlameYpoints[i] * Math.cos(mAngle) + mY + .5);
|
mFlameYpoints[i] = (int) (mOrigFlameXpoints[i] * Math.sin(mAngle) + mOrigFlameYpoints[i] * Math.cos(mAngle) + mY + .5);
|
||||||
}
|
}
|
||||||
|
|
||||||
g.setColor(Color.red); // set color of flame
|
/*
|
||||||
|
* draw the flame
|
||||||
|
*/
|
||||||
|
g.setColor(Color.red);
|
||||||
g.fillPolygon(mFlameXpoints, mFlameYpoints, 3);
|
g.fillPolygon(mFlameXpoints, mFlameYpoints, 3);
|
||||||
}
|
}
|
||||||
// calculate the polygon for the ship, then draw it
|
|
||||||
|
/*
|
||||||
|
* calculate the polygon for the ship, then draw it
|
||||||
|
*/
|
||||||
for (int i = 0; i < 4; i++) {
|
for (int i = 0; i < 4; i++) {
|
||||||
this.mXpoints[i] = (int) (this.mOrigXpoints[i] * Math.cos(mAngle) - this.mOrigYpoints[i] * Math.sin(mAngle) + mX + .5);
|
this.mXpoints[i] = (int) (this.mOrigXpoints[i] * Math.cos(mAngle) - this.mOrigYpoints[i] * Math.sin(mAngle) + mX + .5);
|
||||||
this.mYpoints[i] = (int) (this.mOrigXpoints[i] * Math.sin(mAngle) + this.mOrigYpoints[i] * Math.cos(mAngle) + mY + .5);
|
this.mYpoints[i] = (int) (this.mOrigXpoints[i] * Math.sin(mAngle) + this.mOrigYpoints[i] * Math.cos(mAngle) + mY + .5);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* draw the ship dark gray if the game is paused
|
||||||
|
*/
|
||||||
if (isActive)
|
if (isActive)
|
||||||
g.setColor(mColor);
|
g.setColor(mColor);
|
||||||
else
|
else
|
||||||
// draw the ship dark gray if the game is paused
|
|
||||||
g.setColor(Color.darkGray);
|
g.setColor(Color.darkGray);
|
||||||
|
|
||||||
g.fillPolygon(mXpoints, mYpoints, 4); // 4 is the number of points
|
g.fillPolygon(mXpoints, mYpoints, 4);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -156,7 +167,7 @@ public class Ship extends MovingSpaceObject implements Drawable {
|
|||||||
* @see com.RickBarrette.asteroids.MovingSpaceObject#move(int, int)
|
* @see com.RickBarrette.asteroids.MovingSpaceObject#move(int, int)
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void move(int scrnWidth, int scrnHeight) {
|
public void move(final int scrnWidth, final int scrnHeight) {
|
||||||
/*
|
/*
|
||||||
* move() is called every frame that the game
|
* move() is called every frame that the game
|
||||||
* is run, so this ticks down the shot delay
|
* is run, so this ticks down the shot delay
|
||||||
|
|||||||
@@ -26,19 +26,19 @@ import java.awt.Graphics;
|
|||||||
* This class will bt the shots fired bt the ship. Their job is to destroy the asteroids
|
* This class will bt the shots fired bt the ship. Their job is to destroy the asteroids
|
||||||
* @author ricky barrette
|
* @author ricky barrette
|
||||||
*/
|
*/
|
||||||
public class Shot extends MovingSpaceObject implements Drawable {
|
public class Shot extends MovingSpaceObject {
|
||||||
|
|
||||||
public static final int TOTAL_DRAWS = 50;
|
public static final int TOTAL_DRAWS = 50;
|
||||||
public static final int SPEED = 10;
|
public static final int SPEED = 10;
|
||||||
|
private final AsteroidGame mGame;;
|
||||||
private int mCount = 0;
|
private int mCount = 0;
|
||||||
private AsteroidGame mGame;;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new shot
|
* Creates a new shot
|
||||||
* @author ricky barrette
|
* @author ricky barrette
|
||||||
* @param mGame
|
* @param mGame
|
||||||
*/
|
*/
|
||||||
public Shot(double x, double y, double angle, double shipXVel, double shipYVel, AsteroidGame game) {
|
public Shot(final double x, final double y, final double angle, final double shipXVel, final double shipYVel, final AsteroidGame game) {
|
||||||
mX = x;
|
mX = x;
|
||||||
mY = y;
|
mY = y;
|
||||||
mAngle = angle;
|
mAngle = angle;
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ import java.awt.Color;
|
|||||||
* More accuractly the object's location and color.
|
* More accuractly the object's location and color.
|
||||||
* @author ricky barrette
|
* @author ricky barrette
|
||||||
*/
|
*/
|
||||||
public class SpaceObject {
|
public abstract class SpaceObject implements Drawable{
|
||||||
|
|
||||||
protected Color mColor;
|
protected Color mColor;
|
||||||
protected double mX;
|
protected double mX;
|
||||||
@@ -61,7 +61,7 @@ public class SpaceObject {
|
|||||||
* @param c
|
* @param c
|
||||||
* @author ricky barrette
|
* @author ricky barrette
|
||||||
*/
|
*/
|
||||||
public void setColor(Color c) {
|
public void setColor(final Color c) {
|
||||||
this.mColor = c;
|
this.mColor = c;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -71,7 +71,7 @@ public class SpaceObject {
|
|||||||
* @param y1
|
* @param y1
|
||||||
* @author ricky barrette
|
* @author ricky barrette
|
||||||
*/
|
*/
|
||||||
public void setLocation(int x, int y) {
|
public void setLocation(final int x, final int y) {
|
||||||
mX = x;
|
mX = x;
|
||||||
mY = y;
|
mY = y;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ import javax.swing.JPanel;
|
|||||||
public class Status extends JPanel {
|
public class Status extends JPanel {
|
||||||
|
|
||||||
private static final long serialVersionUID = -169321993637429941L;
|
private static final long serialVersionUID = -169321993637429941L;
|
||||||
private JLabel status;
|
private final JLabel status;
|
||||||
private StringBuffer mBuffer;
|
private StringBuffer mBuffer;
|
||||||
private int mShotCount = 0;
|
private int mShotCount = 0;
|
||||||
private int mAsteroidCount = 0;
|
private int mAsteroidCount = 0;
|
||||||
@@ -48,7 +48,7 @@ public class Status extends JPanel {
|
|||||||
* @param g
|
* @param g
|
||||||
* @author ricky barrette
|
* @author ricky barrette
|
||||||
*/
|
*/
|
||||||
public Status(Container container, AsteroidGame g) {
|
public Status(final Container container, final AsteroidGame g) {
|
||||||
JPanel northSubPanel = new JPanel();
|
JPanel northSubPanel = new JPanel();
|
||||||
status = new JLabel("Missiles 0 Asteroids 0 Ships 0 Score 0 Time: 0");
|
status = new JLabel("Missiles 0 Asteroids 0 Ships 0 Score 0 Time: 0");
|
||||||
northSubPanel.add(status);
|
northSubPanel.add(status);
|
||||||
@@ -79,7 +79,7 @@ public class Status extends JPanel {
|
|||||||
* @param score
|
* @param score
|
||||||
* @author ricky barrette
|
* @author ricky barrette
|
||||||
*/
|
*/
|
||||||
public synchronized void decrementScore(int score) {
|
public synchronized void decrementScore(final int score) {
|
||||||
if(this.mScore - mScore > 0)
|
if(this.mScore - mScore > 0)
|
||||||
this.mScore -= mScore;
|
this.mScore -= mScore;
|
||||||
}
|
}
|
||||||
@@ -107,7 +107,7 @@ public class Status extends JPanel {
|
|||||||
* @param mTime
|
* @param mTime
|
||||||
* @author ricky barrette
|
* @author ricky barrette
|
||||||
*/
|
*/
|
||||||
public synchronized void decrementTime(long mTime) {
|
public synchronized void decrementTime(final long mTime) {
|
||||||
if(this.mTime - mTime > 0)
|
if(this.mTime - mTime > 0)
|
||||||
this.mTime -= mTime;
|
this.mTime -= mTime;
|
||||||
}
|
}
|
||||||
@@ -175,7 +175,7 @@ public class Status extends JPanel {
|
|||||||
* @param score
|
* @param score
|
||||||
* @author ricky barrette
|
* @author ricky barrette
|
||||||
*/
|
*/
|
||||||
public synchronized void incrementScore(int score) {
|
public synchronized void incrementScore(final int score) {
|
||||||
this.mScore += score;
|
this.mScore += score;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -200,7 +200,7 @@ public class Status extends JPanel {
|
|||||||
* @param mTime
|
* @param mTime
|
||||||
* @author ricky barrette
|
* @author ricky barrette
|
||||||
*/
|
*/
|
||||||
public synchronized void incrementTime(long mTime) {
|
public synchronized void incrementTime(final long mTime) {
|
||||||
this.mTime += mTime;
|
this.mTime += mTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -210,7 +210,7 @@ public class Status extends JPanel {
|
|||||||
* @return formated string
|
* @return formated string
|
||||||
* @author ricky barrette
|
* @author ricky barrette
|
||||||
*/
|
*/
|
||||||
private String padTime(int time){
|
private String padTime(final int time){
|
||||||
if (time <= 9)
|
if (time <= 9)
|
||||||
return "0"+ time;
|
return "0"+ time;
|
||||||
return ""+ time;
|
return ""+ time;
|
||||||
@@ -219,42 +219,42 @@ public class Status extends JPanel {
|
|||||||
/**
|
/**
|
||||||
* @param mAsteroidCount the mAsteroidCount to set
|
* @param mAsteroidCount the mAsteroidCount to set
|
||||||
*/
|
*/
|
||||||
public synchronized void setAsteroidCount(int mAsteroidCount) {
|
public synchronized void setAsteroidCount(final int mAsteroidCount) {
|
||||||
this.mAsteroidCount = mAsteroidCount;
|
this.mAsteroidCount = mAsteroidCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param level the level to set
|
* @param level the level to set
|
||||||
*/
|
*/
|
||||||
public void setLevel(int level) {
|
public void setLevel(final int level) {
|
||||||
this.mLevel = level;
|
this.mLevel = level;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param mScore the mScore to set
|
* @param mScore the mScore to set
|
||||||
*/
|
*/
|
||||||
public synchronized void setScore(long mScore) {
|
public synchronized void setScore(final long mScore) {
|
||||||
this.mScore = mScore;
|
this.mScore = mScore;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param mShipCount the mShipCount to set
|
* @param mShipCount the mShipCount to set
|
||||||
*/
|
*/
|
||||||
public synchronized void setShipCount(int mShipCount) {
|
public synchronized void setShipCount(final int mShipCount) {
|
||||||
this.mShipCount = mShipCount;
|
this.mShipCount = mShipCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param mShotCount the mShotCount to set
|
* @param mShotCount the mShotCount to set
|
||||||
*/
|
*/
|
||||||
public synchronized void setShotCount(int mShotCount) {
|
public synchronized void setShotCount(final int mShotCount) {
|
||||||
this.mShotCount = mShotCount;
|
this.mShotCount = mShotCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param mTime the mTime to set
|
* @param mTime the mTime to set
|
||||||
*/
|
*/
|
||||||
public synchronized void setTime(long mTime) {
|
public synchronized void setTime(final long mTime) {
|
||||||
this.mTime = mTime;
|
this.mTime = mTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -264,12 +264,11 @@ public class Status extends JPanel {
|
|||||||
* @return human readable hour : minutes format
|
* @return human readable hour : minutes format
|
||||||
* @author ricky barrette
|
* @author ricky barrette
|
||||||
*/
|
*/
|
||||||
private String stringTime(long mills){
|
private String stringTime(final long mills){
|
||||||
int hours = (int) (mills / 3600000);
|
final int hours = (int) (mills / 3600000);
|
||||||
mills = mills - (hours * 3600000);
|
final long millsMinusHours = mills - (hours * 3600000);
|
||||||
int minutes = (int) ( mills / 60000);
|
final int minutes = (int) ( millsMinusHours / 60000);
|
||||||
int seconds = (int) (mills % 60000);
|
final int seconds = ((int) (millsMinusHours % 60000)) / 1000;
|
||||||
seconds = seconds / 1000;
|
|
||||||
return hours +" : "+ padTime(minutes) +" : "+ padTime(seconds);
|
return hours +" : "+ padTime(minutes) +" : "+ padTime(seconds);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user