diff --git a/Resources/audio/trashed main.au b/Resources/audio/trashed main.au new file mode 100644 index 0000000..fed3883 Binary files /dev/null and b/Resources/audio/trashed main.au differ diff --git a/Resources/pics/Towers/Metal/armEast.png b/Resources/pics/Towers/Metal/armEast.png new file mode 100644 index 0000000..5ba92e9 Binary files /dev/null and b/Resources/pics/Towers/Metal/armEast.png differ diff --git a/Resources/pics/Towers/Metal/armNorth.png b/Resources/pics/Towers/Metal/armNorth.png new file mode 100644 index 0000000..a8aee40 Binary files /dev/null and b/Resources/pics/Towers/Metal/armNorth.png differ diff --git a/Resources/pics/Towers/Metal/armSouth.png b/Resources/pics/Towers/Metal/armSouth.png new file mode 100644 index 0000000..11af05e Binary files /dev/null and b/Resources/pics/Towers/Metal/armSouth.png differ diff --git a/Resources/pics/Towers/Metal/armWest.png b/Resources/pics/Towers/Metal/armWest.png new file mode 100644 index 0000000..9851123 Binary files /dev/null and b/Resources/pics/Towers/Metal/armWest.png differ diff --git a/Resources/pics/Trash/aluminum.png b/Resources/pics/Trash/aluminum.png new file mode 100644 index 0000000..336aa19 Binary files /dev/null and b/Resources/pics/Trash/aluminum.png differ diff --git a/Resources/pics/Trash/metal.png b/Resources/pics/Trash/metal.png new file mode 100644 index 0000000..930e0dd Binary files /dev/null and b/Resources/pics/Trash/metal.png differ diff --git a/Resources/pics/welcome2.png b/Resources/pics/welcome2.png index 5575679..1c6d475 100644 Binary files a/Resources/pics/welcome2.png and b/Resources/pics/welcome2.png differ diff --git a/Resources/pics/welcome3.png b/Resources/pics/welcome3.png new file mode 100644 index 0000000..f74af17 Binary files /dev/null and b/Resources/pics/welcome3.png differ diff --git a/src/.gitignore b/src/.gitignore new file mode 100644 index 0000000..1831b33 --- /dev/null +++ b/src/.gitignore @@ -0,0 +1 @@ +/WaveGen.java diff --git a/src/Board.java b/src/Board.java index bcd22db..8522ca3 100644 --- a/src/Board.java +++ b/src/Board.java @@ -1,419 +1,449 @@ -import java.awt.Color; -import java.awt.Font; -import java.awt.Graphics; -import java.awt.Graphics2D; -import java.awt.Image; -import java.awt.Toolkit; -import java.io.FileInputStream; -import java.io.FileNotFoundException; -import java.io.IOException; -import java.io.InputStream; -import java.util.ArrayList; -import sun.audio.*; -import javax.swing.ImageIcon; -import javax.swing.JPanel; - - -public class Board extends JPanel implements Runnable { - - /** - * - */ - private static final long serialVersionUID = -5438534791450927749L; - - // Global Variables - - private final int DELAY = 50; - - // Thread for the Board Class to run in seperately from everything else - private Thread animator; - - static Tower pendingTower; - - Util.TrashType[] types = { Util.TrashType.paper, Util.TrashType.plastic }; - private int TRASH_SPEED = 2; - - // Images - private Image background; - private Image landFill; - - // Fonts - private Font bigfont = new Font("Helvetica", Font.BOLD, 25); - private Font smallfont = new Font("Comic Sans", Font.BOLD, 16); - - // Audio Player - AudioStream as; - private static Boolean muted = true; - - /* Game State Variables */ - - // Game State Booleans - public static boolean inBetweenLevels = true; - private boolean ingame = true; - - // Game State Variables - private Integer budget = 3000; - private Double airQual = 1000.0; - private Integer level = 1; - private Integer landFillScore = 0; - - // Game State Lists - static ArrayList messages=new ArrayList(); - ArrayList trash = new ArrayList(); - ArrayList towers = new ArrayList(); // not sure if this should be static but am trying to add towers on button press - ArrayList pathX = new ArrayList(); - ArrayList pathY = new ArrayList(); - - public Board() { - - setDoubleBuffered(true); - - makeBoard(pathX, pathY); - - // My computer wants Board capitalized. -JJ - ImageIcon ii = new ImageIcon(this.getClass().getResource( - "pics/Board.png")); - background = ii.getImage(); - - ii = new ImageIcon(this.getClass().getResource("pics/landfill.png")); - landFill = ii.getImage(); - - WaveGen Wave = new WaveGen(20, 35, TRASH_SPEED, Util.pathPad, types); - - trash = Wave.getWave(); - messages=Wave.getMessages(level); - - } - - public void addNotify() { - super.addNotify(); - animator = new Thread(this); - animator.start(); - } - - public void makeBoard(ArrayList pathX, ArrayList pathY) { - - pathX.add(0); - pathY.add(Util.pathPad); - - pathX.add(Util.boardWidth - Util.pathPad - Util.pathWidth); - pathY.add(Util.pathPad); - - pathX.add(Util.boardWidth - Util.pathPad - Util.pathWidth); - pathY.add(Util.pathPad + Util.pathHeight + Util.gapPad); - - pathX.add(Util.pathPad); - pathY.add(Util.pathPad + Util.pathHeight + Util.gapPad); - - pathX.add(Util.pathPad); - pathY.add(Util.pathPad + Util.pathHeight * 2 + Util.gapPad * 2); - - pathX.add(Util.boardWidth - Util.pathPad - Util.pathWidth); - pathY.add(Util.pathPad + Util.pathHeight * 2 + Util.gapPad * 2); - - pathX.add(Util.boardWidth - Util.pathPad - Util.pathWidth); - pathY.add(Util.boardHeight + Util.pathHeight); - - pathX.add(-Util.pathWidth); - pathY.add(Util.boardHeight + Util.pathHeight); - - pathX.add(-Util.pathWidth); - pathY.add(Util.pathPad); - } - - public void paint(Graphics g) { - super.paint(g); - Graphics2D g2d = (Graphics2D) g; - g2d.drawImage(background, 0, 0, this); - - if (ingame) { - - g2d.drawImage(landFill, 0, 0, this); - // Draw each piece of trash in our trash array onto the frame - for (int i = 0; i < trash.size(); i++) { - Trash curTrash = trash.get(i); - g2d.drawImage(curTrash.getImage(), (int) curTrash.getX(), - (int) curTrash.getY(), this); - } - - for (int i = 0; i < towers.size(); i++) { - Tower curTower = towers.get(i); - g2d.drawImage(curTower.getArmImage(), (int) curTower.getArmX(), - (int) curTower.getArmY(), this); - g2d.drawImage(curTower.getBaseImage(), (int) curTower.getX(), - (int) curTower.getY(), this); - - } - - // JJ - if (pendingTower != null - && (pendingTower.getX() != Integer.MIN_VALUE || pendingTower - .getY() != Integer.MIN_VALUE)) { - g2d.drawImage(pendingTower.getBaseImage(), - (int) pendingTower.getX(), (int) pendingTower.getY(), - this); - } - - - - if(inBetweenLevels) - { - if(messages.size()!=0) - g2d.drawImage(messages.get(0).getImage(),135,135 - ,this); - } - - } else { - g2d.setFont(bigfont); - g2d.drawString("GAME OVER", 250, 300); - - } - g2d.setFont(smallfont); - g2d.setColor(Color.RED); - g2d.drawString("Air Quality: " + airQual.toString() + " | Budget: $" - + budget.toString() + " | Level: " + level.toString() - + " | Trash Left: " + trash.size() + "00 lbs" + " | Landfill " - + landFillScore.toString() + "% Full", 5, 615); - - Toolkit.getDefaultToolkit().sync(); - g.dispose(); - - if (!AudioPlayer.player.isAlive()) { - startMusic(); - } - } - - public static void startWave() { - inBetweenLevels = false; - } - - public void removeMoney(int cost) { - - budget -= cost; - } - - public int getBudget() { - return budget; - } - - public void startMusic() { - String path = System.getProperty("user.dir"); - try { - - path += "/Resources/audio/Menu.au"; - InputStream in = new FileInputStream(path); - as = new AudioStream(in); - AudioPlayer.player.start(as); - - } catch (FileNotFoundException e1) { - e1.printStackTrace(); - } catch (IOException e) { - e.printStackTrace(); - } - muted = false; - } - - public boolean isMuted() { - return muted; - } - - public void stopMusic() { - AudioPlayer.player.stop((as)); - muted = true; - } - - public void run() { - - long beforeTime, timeDiff, sleep; - - beforeTime = System.currentTimeMillis(); - - int counter = 0; - - // startMusic(); - - ingame = true; - - while (true) { - - while (trash.size() > 0) { - counter++; - - long pause = 0; - while (inBetweenLevels) { - repaint(); - } - - for (int i = 0; i < trash.size(); i++) { - - trash.get(i).followPath(pathX, pathY); - - for (int j = 0; j < towers.size(); j++) { - // Windmills don't need to check for collisions - if (towers.get(j).getType() == Util.TowerType.windmill) { - break; - } - //towers.get(j).setFiring(true); - //System.out.println(!trash.get(i).isKilled() +" "+ !towers.get(j).getFiring() +" "+trash.get(i).detectCollisions(towers.get(j),pathX, pathY)); - if (!trash.get(i).isKilled() && !towers.get(j).getFiring() && trash.get(i).detectCollisions(towers.get(j),pathX, pathY)) { - //System.out.println("SHIT"); - calculateScore(towers.get(j),trash.get(i)); - towers.get(j).setFiring(true,trash.get(i)); - trash.get(i).setKilled(); - } - - - - } - - - // Check to make sure trash hasn't exited the board - if (trash.get(i).getY() + 30 > Util.boardHeight) { - trash.remove(i); - landFillScore += 1; - } - if(trash.get(i).getImage()==null){ - trash.remove(i); - } - } - - for(int i=0; i 5) { - break; - } - - } - - ingame = false; - - } - - private void calculateScore(Tower tower, Trash trash){ - - if(tower.type==Util.TowerType.incenerator){ - budget+=15; - airQual-=15; - }else{ - budget+=25; - } - - - } - - private void resetTowers() { - for (int i = 0; i < towers.size(); i++) { - towers.get(i).resetTower(); - } - } - - // Method to determine if the user is adding the tower on top of the path - public boolean inPath(int x, int y) { - - // Inside actual game board - if ((x > 0 && x > Util.boardWidth) || (y > 0 && y > Util.boardHeight)) { - return true; - } - - // First row - if ((x > 0 && x < Util.boardWidth - Util.pathPad - + (Util.towerWidth / 2)) - && (y > Util.pathPad - (Util.towerWidth / 2) && y < Util.pathPad - + Util.pathWidth + (Util.towerWidth / 2))) { - return true; - // First down - } else if ((x < Util.boardWidth - Util.pathPad + (Util.towerWidth / 2) && x > (Util.boardWidth - - Util.pathPad - Util.pathWidth - (Util.towerWidth / 2))) - && (y > Util.pathPad - (Util.towerWidth / 2) && (y < Util.pathPad - + Util.gapPad + (Util.towerWidth / 2)))) { - return true; - // First Switch Back - } else if (x < Util.boardWidth - Util.pathPad + (Util.towerWidth / 2) - && x > Util.pathPad - (Util.towerWidth / 2) - && y > Util.pathPad + Util.pathWidth + Util.gapPad - - (Util.towerWidth / 2) - && y < Util.pathPad + (2 * Util.pathWidth) + Util.gapPad - + (Util.towerWidth / 2)) { - return true; - // Second Down - } else if (x > Util.pathPad - (Util.towerWidth / 2) - && x < Util.pathPad + Util.pathWidth + (Util.towerWidth / 2) - && y > Util.pathPad + Util.pathWidth + Util.gapPad - - (Util.towerWidth / 2) - && y < Util.pathPad + 2 * Util.pathWidth + 2 * Util.gapPad - + (Util.towerWidth / 2)) { - return true; - // Second Switch Back - } else if (x > Util.pathPad - (Util.towerWidth / 2) - && x < Util.boardWidth - Util.pathPad + (Util.towerWidth / 2) - && y > Util.pathPad + 2 * Util.pathWidth + 2 * Util.gapPad - - (Util.towerWidth / 2) - && y < Util.pathPad + (3 * Util.pathWidth) + 2 * Util.gapPad - + (Util.towerWidth / 2)) { - return true; - // Third Down - } else if ((x < Util.boardWidth - Util.pathPad + (Util.towerWidth / 2) && x > (Util.boardWidth - - Util.pathPad - Util.pathWidth - (Util.towerWidth / 2))) - && y > Util.pathPad + (3 * Util.pathWidth) + 2 * Util.gapPad - + (Util.towerWidth / 2)) { - return true; - } - - return false; - } - - // JJ - public void addTower(Tower t) { - towers.add(t); - } - - public static void addPendingTower(Tower t) { - pendingTower = t; - } - - public static void removePendingTower() { - pendingTower = null; - } - - public int getLevel() { - return level; - } -} +import java.awt.Color; +import java.awt.Font; +import java.awt.Graphics; +import java.awt.Graphics2D; +import java.awt.Image; +import java.awt.Toolkit; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.io.InputStream; +import java.util.ArrayList; +import sun.audio.*; +import javax.swing.ImageIcon; +import javax.swing.JPanel; + + +public class Board extends JPanel implements Runnable { + + /** + * + */ + private static final long serialVersionUID = -5438534791450927749L; + + // Global Variables + + private final int DELAY = 50; + + // Thread for the Board Class to run in seperately from everything else + private Thread animator; + + static Tower pendingTower; + + Util.TrashType[] types = { Util.TrashType.paper, Util.TrashType.plastic }; + private int TRASH_SPEED = 2; + + // Images + private Image background; + private Image landFill; + + // Fonts + private Font bigfont = new Font("Helvetica", Font.BOLD, 25); + private Font smallfont = new Font("Comic Sans", Font.BOLD, 16); + + // Audio Player + AudioStream as; + private static Boolean muted = true; + + /* Game State Variables */ + + // Game State Booleans + public static boolean inBetweenLevels = true; + private boolean ingame = true; + + // Game State Variables + private Integer budget = 150; + Double airQual = 1000.0; + private Integer level = 1; + private Integer landFillScore = 0; + private Integer escapedTrash =0; + public Integer getLandFillScore() { + return landFillScore; + } + + // Game State Lists + static ArrayList messages=new ArrayList(); + ArrayList trash = new ArrayList(); + ArrayList towers = new ArrayList(); // not sure if this should be static but am trying to add towers on button press + ArrayList pathX = new ArrayList(); + ArrayList pathY = new ArrayList(); + //Wavegen + WaveGen Wave = new WaveGen(this); + public Board() { + + setDoubleBuffered(true); + + makeBoard(pathX, pathY); + + // My computer wants Board capitalized. -JJ + ImageIcon ii = new ImageIcon(this.getClass().getResource( + "pics/Board.png")); + background = ii.getImage(); + + ii = new ImageIcon(this.getClass().getResource("pics/landfill.png")); + landFill = ii.getImage(); + + + + + } + + public void addNotify() { + super.addNotify(); + animator = new Thread(this); + animator.start(); + } + + public void makeBoard(ArrayList pathX, ArrayList pathY) { + + pathX.add(0); + pathY.add(Util.pathPad); + + pathX.add(Util.boardWidth - Util.pathPad - Util.pathWidth); + pathY.add(Util.pathPad); + + pathX.add(Util.boardWidth - Util.pathPad - Util.pathWidth); + pathY.add(Util.pathPad + Util.pathHeight + Util.gapPad); + + pathX.add(Util.pathPad); + pathY.add(Util.pathPad + Util.pathHeight + Util.gapPad); + + pathX.add(Util.pathPad); + pathY.add(Util.pathPad + Util.pathHeight * 2 + Util.gapPad * 2); + + pathX.add(Util.boardWidth - Util.pathPad - Util.pathWidth); + pathY.add(Util.pathPad + Util.pathHeight * 2 + Util.gapPad * 2); + + pathX.add(Util.boardWidth - Util.pathPad - Util.pathWidth); + pathY.add(Util.boardHeight + Util.pathHeight); + + pathX.add(-Util.pathWidth); + pathY.add(Util.boardHeight + Util.pathHeight); + + pathX.add(-Util.pathWidth); + pathY.add(Util.pathPad); + } + + public void paint(Graphics g) { + super.paint(g); + Graphics2D g2d = (Graphics2D) g; + g2d.drawImage(background, 0, 0, this); + + if (ingame) { + + g2d.drawImage(landFill, 0, 0, this); + // Draw each piece of trash in our trash array onto the frame + for (int i = 0; i < trash.size(); i++) { + Trash curTrash = trash.get(i); + g2d.drawImage(curTrash.getImage(), (int) curTrash.getX(), + (int) curTrash.getY(), this); + } + + for (int i = 0; i < towers.size(); i++) { + Tower curTower = towers.get(i); + g2d.drawImage(curTower.getArmImage(), (int) curTower.getArmX(), + (int) curTower.getArmY(), this); + g2d.drawImage(curTower.getBaseImage(), (int) curTower.getX(), + (int) curTower.getY(), this); + + } + + // JJ + if (pendingTower != null + && (pendingTower.getX() != Integer.MIN_VALUE || pendingTower + .getY() != Integer.MIN_VALUE)) { + g2d.drawImage(pendingTower.getBaseImage(), + (int) pendingTower.getX(), (int) pendingTower.getY(), + this); + } + + + + if(inBetweenLevels) + { + if(messages.size()!=0) + g2d.drawImage(messages.get(0).getImage(),135,135 + ,this); + } + + } else { + g2d.setFont(bigfont); + g2d.drawString("GAME OVER", 250, 300); + + } + g2d.setFont(smallfont); + g2d.setColor(Color.RED); + g2d.drawString("Air Quality: " + airQual.toString() + " | Budget: $" + + budget.toString() + " | Level: " + level.toString() + + " | Trash Left: " + trash.size() + "00 lbs" + " | Landfill " + + landFillScore.toString() + "% Full", 5, 615); + + Toolkit.getDefaultToolkit().sync(); + g.dispose(); + + if (!AudioPlayer.player.isAlive()) { + startMusic(); + } + } + + public static void startWave() { + inBetweenLevels = false; + } + + public void removeMoney(int cost) { + + budget -= cost; + } + + public Integer getBudget() { + return budget; + } + public void setBudget(int aBudget){ + budget = aBudget; + } + + public void startMusic() { + String path = System.getProperty("user.dir"); + try { + + path += "/Resources/audio/Menu.au"; + InputStream in = new FileInputStream(path); + as = new AudioStream(in); + AudioPlayer.player.start(as); + + } catch (FileNotFoundException e1) { + e1.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } + muted = false; + } + + public boolean isMuted() { + return muted; + } + + public void stopMusic() { + AudioPlayer.player.stop((as)); + muted = true; + } + + public void run() { + + long beforeTime, timeDiff, sleep; + + beforeTime = System.currentTimeMillis(); + + int counter = 0; + + // startMusic(); + + ingame = true; + + while (true) { + trash = Wave.getWave(level); + messages=Wave.getMessages(level); + while (trash.size() > 0) { + counter++; + + long pause = 0; + while (inBetweenLevels) { + repaint(); + } + + for (int i = 0; i < trash.size(); i++) { + + trash.get(i).followPath(pathX, pathY); + + for (int j = 0; j < towers.size(); j++) { + // Windmills don't need to check for collisions + if (towers.get(j).getType() == Util.TowerType.windmill) { + break; + } + //towers.get(j).setFiring(true); + //System.out.println(!trash.get(i).isKilled() +" "+ !towers.get(j).getFiring() +" "+trash.get(i).detectCollisions(towers.get(j),pathX, pathY)); + if (!trash.get(i).isKilled() && !towers.get(j).getFiring() && trash.get(i).detectCollisions(towers.get(j),pathX, pathY)) { + //System.out.println("SHIT"); + calculateScore(towers.get(j),trash.get(i)); + towers.get(j).setFiring(true,trash.get(i)); + trash.get(i).setKilled(); + } + + + + } + + if(trash.get(i).getImage()==null){ + trash.remove(i); + } + // Check to make sure trash hasn't exited the board + else if (trash.get(i).getY() + 30 > Util.boardHeight) { + trash.remove(i); + landFillScore += 1; + escapedTrash +=1; + System.out.println(landFillScore); + } + + } + + for(int i=0; i 5) { + break; + } + + } + + ingame = false; + + } + private void calculateBonus(){ + double multiplier = 1; + multiplier = (airQual/1000) * multiplier; + multiplier = (level/4) + multiplier; + multiplier = multiplier - (escapedTrash/100); + + budget += (int)(multiplier*150); + + } + + private void calculateScore(Tower tower, Trash trash){ + + if(tower.type==Util.TowerType.incenerator){ + budget+=15; + airQual-=15; + }else{ + budget+=25; + } + + + } + + private void resetTowers() { + for (int i = 0; i < towers.size(); i++) { + towers.get(i).resetTower(); + } + } + + public boolean onTower(int x, int y){ + for(int i=0; i=x && tY<=y && tY+tH>=y){ + return true; + } + } + return false; + } + // Method to determine if the user is adding the tower on top of the path + public boolean inPath(int x, int y) { + + // Inside actual game board + if ((x > 0 && x > Util.boardWidth) || (y > 0 && y > Util.boardHeight)) { + return true; + } + + // First row + if ((x > 0 && x < Util.boardWidth - Util.pathPad + + (Util.towerWidth / 2)) + && (y > Util.pathPad - (Util.towerWidth / 2) && y < Util.pathPad + + Util.pathWidth + (Util.towerWidth / 2))) { + return true; + // First down + } else if ((x < Util.boardWidth - Util.pathPad + (Util.towerWidth / 2) && x > (Util.boardWidth + - Util.pathPad - Util.pathWidth - (Util.towerWidth / 2))) + && (y > Util.pathPad - (Util.towerWidth / 2) && (y < Util.pathPad + + Util.gapPad + (Util.towerWidth / 2)))) { + return true; + // First Switch Back + } else if (x < Util.boardWidth - Util.pathPad + (Util.towerWidth / 2) + && x > Util.pathPad - (Util.towerWidth / 2) + && y > Util.pathPad + Util.pathWidth + Util.gapPad + - (Util.towerWidth / 2) + && y < Util.pathPad + (2 * Util.pathWidth) + Util.gapPad + + (Util.towerWidth / 2)) { + return true; + // Second Down + } else if (x > Util.pathPad - (Util.towerWidth / 2) + && x < Util.pathPad + Util.pathWidth + (Util.towerWidth / 2) + && y > Util.pathPad + Util.pathWidth + Util.gapPad + - (Util.towerWidth / 2) + && y < Util.pathPad + 2 * Util.pathWidth + 2 * Util.gapPad + + (Util.towerWidth / 2)) { + return true; + // Second Switch Back + } else if (x > Util.pathPad - (Util.towerWidth / 2) + && x < Util.boardWidth - Util.pathPad + (Util.towerWidth / 2) + && y > Util.pathPad + 2 * Util.pathWidth + 2 * Util.gapPad + - (Util.towerWidth / 2) + && y < Util.pathPad + (3 * Util.pathWidth) + 2 * Util.gapPad + + (Util.towerWidth / 2)) { + return true; + // Third Down + } else if ((x < Util.boardWidth - Util.pathPad + (Util.towerWidth / 2) && x > (Util.boardWidth + - Util.pathPad - Util.pathWidth - (Util.towerWidth / 2))) + && y > Util.pathPad + (3 * Util.pathWidth) + 2 * Util.gapPad + + (Util.towerWidth / 2)) { + return true; + } + + return false; + } + + // JJ + public void addTower(Tower t) { + towers.add(t); + } + + public static void addPendingTower(Tower t) { + pendingTower = t; + } + + public static void removePendingTower() { + pendingTower = null; + } + + public Integer getLevel() { + return level; + } +} diff --git a/src/Main.java b/src/Main.java index 310a73d..56b74fc 100644 --- a/src/Main.java +++ b/src/Main.java @@ -1,50 +1,53 @@ -import javax.swing.*; -import java.awt.BorderLayout; -import java.awt.Dimension; -import java.awt.FlowLayout; -import java.awt.GridLayout; - -import javax.swing.BoxLayout; -import javax.swing.JButton; -import javax.swing.JFrame; -import javax.swing.JPanel; - - -public class Main extends JFrame { - - /** - * - */ - private static final long serialVersionUID = 4648172894076113183L; - - Board board; - - //Helps define where different components are -JJ - private BorderLayout LayoutMGR=new BorderLayout(); - - public Main() { - - this.setLayout(LayoutMGR); - - Board board= new Board(); - add(board,BorderLayout.CENTER); - setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); - setSize(900,650); - setLocationRelativeTo(null); - setTitle("Trashed"); - setResizable(false); +import javax.swing.*; +import java.awt.BorderLayout; +import java.awt.Dimension; +import java.awt.FlowLayout; +import java.awt.GridLayout; - - JPanel menu=new Menu(board); - menu.setSize(300, 650); - - menu.setPreferredSize(new Dimension(300,650)); - menu.setMaximumSize(new Dimension(300,650)); - add(menu,BorderLayout.LINE_END); - - setVisible(true); - } - public static void main(String[] args) { - new Main(); - } +import javax.swing.BoxLayout; +import javax.swing.JButton; +import javax.swing.JFrame; +import javax.swing.JPanel; + + +public class Main extends JFrame { + + /** + * + */ + private static final long serialVersionUID = 4648172894076113183L; + + Board board; + + public Main() { + + this.setLayout(null); + + Board board= new Board(); + + setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + setSize(900,650); + setLocationRelativeTo(null); + setTitle("Trashed"); + setResizable(false); + board.setBounds(0, 0, 600, 600); + + + JPanel menu=new Menu(board); + menu.setBounds(600, 0, 300, 550); + + JPanel scoreBoard=new Scoreboard(board); + scoreBoard.setBounds(0,600,900, 50); + + + add(menu); + add(board); + add(scoreBoard); + + + setVisible(true); + } + public static void main(String[] args) { + new Main(); + } } diff --git a/src/Menu.java b/src/Menu.java index 0201a39..245dd39 100644 --- a/src/Menu.java +++ b/src/Menu.java @@ -4,8 +4,13 @@ import java.awt.event.MouseEvent; import javax.swing.JButton; +import javax.swing.JLabel; import javax.swing.JPanel; +import javax.swing.JTextArea; +import javax.swing.JTextPane; +import javax.swing.SwingConstants; import javax.swing.event.MouseInputListener; +import javax.swing.text.JTextComponent; public class Menu extends JPanel implements Runnable { @@ -23,25 +28,46 @@ public class Menu extends JPanel implements Runnable { static private boolean addMetalTower = false; private boolean startWave = false; private String currentTowerDirection = "South"; + private JLabel info = new JLabel(""); public Menu(Board board) { + setDoubleBuffered(true); gameBoard = board; board.addMouseListener(new Mouse()); board.addMouseMotionListener(new Mouse()); - setLayout(layoutMGR); - // ActionListener AL=new ActionListener(); - JButton recycleButton = new JButton("Add Recycling-$200"); + setLayout(null); + + + info.setHorizontalAlignment(SwingConstants.CENTER); + info.setBounds(0,0, 300, 150); + + + JButton recycleButton = new JButton("Recycling-$200"); recycleButton.addActionListener(new RecycleButtonListener()); - JButton inceneratorButton = new JButton("Add Incenerator-$100"); + recycleButton.setBounds(0, 150, 150, 50); + + JButton inceneratorButton = new JButton("Incenerator-$100"); inceneratorButton.addActionListener(new InceneratorButtonListener()); - JButton muteButton = new JButton("Mute"); - muteButton.addActionListener(new MuteButtonListener()); + inceneratorButton.setBounds(150, 150, 150, 50); + + JButton metalButton = new JButton("Scrap Metal-$150"); + metalButton.addActionListener(new MetalButtonListener()); + metalButton.setBounds(0, 200, 150, 50); + + JButton windmillButton = new JButton("Windmill-$300"); + windmillButton.addActionListener(new WindmillButtonListener()); + windmillButton.setBounds(150, 200, 150, 50); + JButton startWaveButton = new JButton("Send Next Wave"); startWaveButton.addActionListener(new StartWaveButtonListener()); - JButton windmillButton = new JButton("Add Windmill-$300"); - windmillButton.addActionListener(new WindmillButtonListener()); - JButton metalButton = new JButton("Add Scrap Metal-$150"); - metalButton.addActionListener(new MetalButtonListener()); + startWaveButton.setBounds(0, 250, 300, 50); + + JButton muteButton = new JButton("Mute"); + muteButton.addActionListener(new MuteButtonListener()); + muteButton.setBounds(0, 300, 100, 50); + + + add(info); add(recycleButton); add(inceneratorButton); add(metalButton); @@ -81,6 +107,7 @@ public void actionPerformed(ActionEvent e) { if (gameBoard.getBudget() >= getCost(Util.TowerType.metal)) { addMetalTower = !addMetalTower; + info.setText("This tower is for picking up scrap metal"); addInceneratorTower = false; addRecycleTower = false; addWindmillTower = false; @@ -95,6 +122,7 @@ private class WindmillButtonListener implements ActionListener { public void actionPerformed(ActionEvent e) { if (gameBoard.getBudget() >= getCost(Util.TowerType.windmill)) { addWindmillTower = !addWindmillTower; + info.setText("Windmills help to reduce energy costs in your town and earn you money throughout the rounds"); addMetalTower = false; addInceneratorTower = false; addRecycleTower = false; @@ -109,6 +137,7 @@ private class RecycleButtonListener implements ActionListener { public void actionPerformed(ActionEvent e) { if (gameBoard.getBudget() >= getCost(Util.TowerType.recycle)) { addRecycleTower = !addRecycleTower; + info.setText("The recycle tower helps to properly dispose of the recycleable trash that is produced in the city. While more expensive than the incenerator, it has less of an imact on the enviorment"); addInceneratorTower = false; addMetalTower = false; addWindmillTower = false; @@ -276,6 +305,7 @@ private void resetButtons() { addInceneratorTower = false; addRecycleTower = false; addWindmillTower = false; + info.setText(""); } public boolean validTower(int x, int y, Util.TowerType type) { @@ -314,7 +344,7 @@ public void run() { while (true) { long pause = 0; - + repaint(); timeDiff = System.currentTimeMillis() - beforeTime; sleep = DELAY - timeDiff; diff --git a/src/Missile.java b/src/Missile.java new file mode 100644 index 0000000..270375f --- /dev/null +++ b/src/Missile.java @@ -0,0 +1,48 @@ +import java.awt.Image; + +public class Missile { + private double destX, destY; + private double x, y, speed, direction; + private Image missilePic = null; + + Missile(int initX, int initY, double destX, double destY, double speed){ + this.destX = destX; + this.destY = destY; + direction = Math.atan2(y-destY, x-destX); + this.speed = speed; + x = initX; + y = initY; + } + + public double getX() { + return x; + } + + public void setX(double x) { + this.x = x; + } + + public double getY() { + return y; + } + + public void setY(double y) { + this.y = y; + } + + public Image getMissileImage(){ + return missilePic; + } + + public void move(){ + this.x -= speed*Math.cos(direction); + this.y -= speed*Math.sin(direction); + } + + public boolean detectCollision(){ + if ((Math.abs(x-destX)+Math.abs(y-destY))<1) { + return true; + } + return false; + } +} diff --git a/src/MissileTower.java b/src/MissileTower.java new file mode 100644 index 0000000..4f2ee5c --- /dev/null +++ b/src/MissileTower.java @@ -0,0 +1,36 @@ +import java.util.ArrayList; + +public class MissileTower extends Tower{ + + ArrayList trash = new ArrayList(); + ArrayList missile = new ArrayList(); + private double missileSpeed; + MissileTower(int initX, int initY, int fireRate, int towerRange, Util.TowerType type, boolean isValid, String dir, double missileSpeed) { + super(initX, initY, fireRate, towerRange, type, isValid, dir); + // TODO Auto-generated constructor stub + this.missileSpeed = missileSpeed; + } + + public void fire() { + for(int i=0; i X, ArrayList Y){ } +private boolean willTowerFire(Tower tower){ + + if(tower.getType()==Util.TowerType.compost){ + if(this.type==Util.TrashType.food){ + return true; + } + }else if(tower.getType()==Util.TowerType.incenerator){ + if (this.type==Util.TrashType.paper || this.type==Util.TrashType.plastic || this.type==Util.TrashType.food){ + return true; + } + }else if(tower.getType()==Util.TowerType.metal){ + if(this.type==Util.TrashType.metal || this.type==Util.TrashType.aluminum){ + return true; + } + }else if(tower.getType()==Util.TowerType.recycle){ + if(this.type==Util.TrashType.paper || this.type==Util.TrashType.plastic){ + return true; + } + } + + return false; + } + public boolean detectCollisions(Tower tower, ArrayList X, ArrayList Y){ - - double distX, distY,angle; - int tempCurPath = curPath; - double tempX = x; - double tempY = y; - - if((tower.getType()==Util.TowerType.recycle && type==Util.TrashType.plastic) || (tower.getType()==Util.TowerType.incenerator && type==Util.TrashType.paper)){ - - for(int i=0; i=X.size()){ - tempCurPath=0; - } - } - angle=Math.atan2(distY, distX); - tempX=tempX+speed*Math.round(Math.cos(angle)); - tempY=tempY+speed*Math.round(Math.sin(angle)); - } - //if any 4 corners of trash inside 4 corners of range: FIRE! - //Tower Coords: - //(x,y) = (curTower.getX, curTower.getY()+2*curTower.getMidY()) - //(x,y) = (curTower.getX, curTower.getY()+2*curTower.getMidY()+curTower.getRange()) - //(x,y) = (curTower.getX + curTower.getWidth, curTower.getY()+2*curTower.getMidY()) - //(x,y) = (curTower.getX + curTower.getWidth, curTower.getY()+2*curTower.getMidY()+curTower.getRange()) - //Trash Coords: - //(x,y) = (x,y) - //(x,y) = (x + trashPic.getWidth(null),y) - //(x,y) = (x,y + trashPic.getHeight(null)) - //(x,y) = (x + trashPic.getWidth(null), y + trashPic.getHeight(null); + if(Math.abs(distX)+Math.abs(distY)=X.size()){ + tempCurPath=0; + } + } + angle=Math.atan2(distY, distX); + tempX=tempX+speed*Math.round(Math.cos(angle)); + tempY=tempY+speed*Math.round(Math.sin(angle)); + } + //if any 4 corners of trash inside 4 corners of range: FIRE! + //Tower Coords: + //(x,y) = (curTower.getX, curTower.getY()+2*curTower.getMidY()) + //(x,y) = (curTower.getX, curTower.getY()+2*curTower.getMidY()+curTower.getRange()) + //(x,y) = (curTower.getX + curTower.getWidth, curTower.getY()+2*curTower.getMidY()) + //(x,y) = (curTower.getX + curTower.getWidth, curTower.getY()+2*curTower.getMidY()+curTower.getRange()) + //Trash Coords: + //(x,y) = (x,y) + //(x,y) = (x + trashPic.getWidth(null),y) + //(x,y) = (x,y + trashPic.getHeight(null)) + //(x,y) = (x + trashPic.getWidth(null), y + trashPic.getHeight(null); - if(tower.getDirection().equalsIgnoreCase("South")){ - if(tempX+trashPic.getWidth(null)/2>=tower.getX()+tower.getWidth()/2-Math.ceil(speed/2) && tempX+trashPic.getWidth(null)/2<=tower.getX() + tower.getWidth()/2+Math.ceil(speed/2)){ - if((tempY>=tower.getY()+tower.getBaseImage().getHeight(null) && tempY<=tower.getY()+tower.getBaseImage().getHeight(null)+tower.getRange())){ - return true; - } - } - }else if(tower.getDirection().equalsIgnoreCase("East")){ - if(tempY+ trashPic.getHeight(null)/2>=tower.getY()+tower.getHeight()/2-Math.ceil(speed/2) && tempY+ trashPic.getHeight(null)/2<=tower.getY()+tower.getHeight()/2+Math.ceil(speed/2)){ - if((tempX>=tower.getX()+tower.getBaseImage().getWidth(null) && tempX<=tower.getX()+tower.getBaseImage().getWidth(null)+tower.getRange())){ - return true; - } - } - }else if(tower.getDirection().equalsIgnoreCase("North")){ - if((tempX+trashPic.getWidth(null)/2>=tower.getX()+tower.getWidth()/2-Math.ceil(speed/2) && tempX+trashPic.getWidth(null)/2<=tower.getX() + tower.getWidth()/2+Math.ceil(speed/2))){ - if((tempY+ trashPic.getHeight(null)<=tower.getY() && tempY+ trashPic.getHeight(null)>=tower.getY()-tower.getRange())){ - return true; - } - } - }else if(tower.getDirection().equalsIgnoreCase("West")){ - if((tempY+ trashPic.getHeight(null)/2>=tower.getY()+tower.getHeight()/2-Math.ceil(speed/2) && tempY+ trashPic.getHeight(null)/2<=tower.getY()+tower.getHeight()/2+Math.ceil(speed/2))){ - if((tempX+ trashPic.getWidth(null)<=tower.getX() && tempX+ trashPic.getWidth(null)>=tower.getX()-tower.getRange())){ - return true; - } - } - } - } - return false; - } - + if(tower.getDirection().equalsIgnoreCase("South")){ + if(tempX+trashPic.getWidth(null)/2>=tower.getX()+tower.getWidth()/2-Math.ceil(speed/2) && tempX+trashPic.getWidth(null)/2<=tower.getX() + tower.getWidth()/2+Math.ceil(speed/2)){ + if((tempY>=tower.getY()+tower.getBaseImage().getHeight(null) && tempY<=tower.getY()+tower.getBaseImage().getHeight(null)+tower.getRange())){ + return true; + } + } + }else if(tower.getDirection().equalsIgnoreCase("East")){ + if(tempY+ trashPic.getHeight(null)/2>=tower.getY()+tower.getHeight()/2-Math.ceil(speed/2) && tempY+ trashPic.getHeight(null)/2<=tower.getY()+tower.getHeight()/2+Math.ceil(speed/2)){ + if((tempX>=tower.getX()+tower.getBaseImage().getWidth(null) && tempX<=tower.getX()+tower.getBaseImage().getWidth(null)+tower.getRange())){ + return true; + } + } + }else if(tower.getDirection().equalsIgnoreCase("North")){ + if((tempX+trashPic.getWidth(null)/2>=tower.getX()+tower.getWidth()/2-Math.ceil(speed/2) && tempX+trashPic.getWidth(null)/2<=tower.getX() + tower.getWidth()/2+Math.ceil(speed/2))){ + if((tempY+ trashPic.getHeight(null)<=tower.getY() && tempY+ trashPic.getHeight(null)>=tower.getY()-tower.getRange())){ + return true; + } + } + }else if(tower.getDirection().equalsIgnoreCase("West")){ + if((tempY+ trashPic.getHeight(null)/2>=tower.getY()+tower.getHeight()/2-Math.ceil(speed/2) && tempY+ trashPic.getHeight(null)/2<=tower.getY()+tower.getHeight()/2+Math.ceil(speed/2))){ + if((tempX+ trashPic.getWidth(null)<=tower.getX() && tempX+ trashPic.getWidth(null)>=tower.getX()-tower.getRange())){ + return true; + } + } + } + } + futureX = tempX; + futureY = tempY; + return false; + } public boolean isKilled(){ return beenKilled; diff --git a/src/Util.java b/src/Util.java index bfd250c..d940d6a 100644 --- a/src/Util.java +++ b/src/Util.java @@ -1,7 +1,7 @@ public class Util { enum TowerType {incenerator, compactor, recycle,windmill,compost,metal}; - enum TrashType {paper, plastic, metal,food}; + enum TrashType {paper, plastic, metal,food, aluminum}; //Board Dimensions used for making the path static final int boardWidth=600; diff --git a/src/WaveGen.java b/src/WaveGen.java index 3085603..301c177 100644 --- a/src/WaveGen.java +++ b/src/WaveGen.java @@ -1,40 +1,62 @@ import java.util.ArrayList; +import javax.swing.ImageIcon; import javax.swing.*; //update public class WaveGen { + Board theBoard; - private ArrayList wave= new ArrayList(); - - - public WaveGen(int num, int spacing, double speed, int initY, Util.TrashType[] types){ - - int curX=-30; - - for(int i=0; i wave= new ArrayList(); + + + public ArrayList getWave(int level){ + int num =0; + int spacing = 0; + int initY= Util.pathPad; + int speed= 0; + ArrayList types = new ArrayList(); + if (level ==1){ + num =10; + spacing = 135; + speed =2; + types.add(Util.TrashType.paper); + + + }else if (level ==2){ + + + num =20; + spacing = 85; + speed =3; + types.add(Util.TrashType.paper); + + } + int curX=-30; + + for(int i=0; i getWave(){ - return wave; + return wave; + + } -public ArrayList getMessages(int level) { + public ArrayList getMessages(int level) { ArrayList temp = new ArrayList(); // JJrandomShit if (level == 1) - temp.add(new ImageIcon(this.getClass().getResource( - "pics/welcome1.png"))); + temp.add(new ImageIcon(this.getClass().getResource("pics/welcome1.png"))); if (level == 2) - temp.add(new ImageIcon(this.getClass().getResource( - "pics/welcome2.png"))); + temp.add(new ImageIcon(this.getClass().getResource("pics/welcome2.png"))); return temp; } }