├── .gitignore ├── FUTUREUPDATES.md ├── Game music final.wav ├── Game over laugh.wav ├── Menu music final.wav ├── MeteorS1.png ├── README.md ├── bin ├── .gitignore └── com │ └── multitask │ └── dannystover │ ├── KeyInput.class │ ├── Menu.class │ ├── Multitask.class │ ├── ScoreTracker.class │ ├── Spawner.class │ ├── Stage1Enemies.class │ ├── Stage1Player.class │ ├── Stage2Enemies.class │ ├── Stage2Player.class │ ├── Stage3Enemies.class │ ├── Stage4Enemies.class │ ├── StageEntities.class │ ├── Updater.class │ └── Window.class ├── pngdonutface.png ├── sonic.png ├── src └── com │ └── multitask │ └── dannystover │ ├── KeyInput.java │ ├── Menu.java │ ├── Multitask.java │ ├── ScoreTracker.java │ ├── Spawner.java │ ├── Stage1Enemies.java │ ├── Stage1Player.java │ ├── Stage2Enemies.java │ ├── Stage2Player.java │ ├── Stage3Enemies.java │ ├── Stage4Enemies.java │ ├── StageEntities.java │ ├── Updater.java │ └── Window.java ├── stage1player final.png ├── stage2asteroid1.png ├── stage2asteroid2.png ├── stage2asteroid3.png ├── stage2asteroid4.png ├── stage2asteroid5.png ├── stage2asteroid6.png └── stage2player final.png /.gitignore: -------------------------------------------------------------------------------- 1 | bin 2 | .classpath 3 | .project 4 | -------------------------------------------------------------------------------- /FUTUREUPDATES.md: -------------------------------------------------------------------------------- 1 | 1. Clear stage 1 asteroids when player reaches stage 2 2 | 2. Resize window based on player's computer screen dimensions 3 | 3. Make sure stage 3 rectangles spawn to the far right 4 | -------------------------------------------------------------------------------- /Game music final.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DstoverVT/Multitask/8cb5b862cec97d8208a4fae31df062fa442093e5/Game music final.wav -------------------------------------------------------------------------------- /Game over laugh.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DstoverVT/Multitask/8cb5b862cec97d8208a4fae31df062fa442093e5/Game over laugh.wav -------------------------------------------------------------------------------- /Menu music final.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DstoverVT/Multitask/8cb5b862cec97d8208a4fae31df062fa442093e5/Menu music final.wav -------------------------------------------------------------------------------- /MeteorS1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DstoverVT/Multitask/8cb5b862cec97d8208a4fae31df062fa442093e5/MeteorS1.png -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Multitask 2 | Use git clone https://github.com/DstoverVT/Multitask.git to copy/access repository 3 | 4 | Multitask is a 2D survival game that tests the player's multitasking abilities through 4 different stages that the player must overcome. 5 | The game never ends, so the goal is to obtain the highest score. Directions on how to play are available on the menu screen of the game. 6 | 7 | Within the Java project's main package, Multitask.java contains the main method that can be executed to play Multitask. 8 | This project is intended for others to use and enjoy, not to edit. 9 | 10 | Currently, the game must be run on a 1920x1080 screen with the text size at 100%. 11 | -------------------------------------------------------------------------------- /bin/.gitignore: -------------------------------------------------------------------------------- 1 | /com/ 2 | -------------------------------------------------------------------------------- /bin/com/multitask/dannystover/KeyInput.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DstoverVT/Multitask/8cb5b862cec97d8208a4fae31df062fa442093e5/bin/com/multitask/dannystover/KeyInput.class -------------------------------------------------------------------------------- /bin/com/multitask/dannystover/Menu.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DstoverVT/Multitask/8cb5b862cec97d8208a4fae31df062fa442093e5/bin/com/multitask/dannystover/Menu.class -------------------------------------------------------------------------------- /bin/com/multitask/dannystover/Multitask.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DstoverVT/Multitask/8cb5b862cec97d8208a4fae31df062fa442093e5/bin/com/multitask/dannystover/Multitask.class -------------------------------------------------------------------------------- /bin/com/multitask/dannystover/ScoreTracker.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DstoverVT/Multitask/8cb5b862cec97d8208a4fae31df062fa442093e5/bin/com/multitask/dannystover/ScoreTracker.class -------------------------------------------------------------------------------- /bin/com/multitask/dannystover/Spawner.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DstoverVT/Multitask/8cb5b862cec97d8208a4fae31df062fa442093e5/bin/com/multitask/dannystover/Spawner.class -------------------------------------------------------------------------------- /bin/com/multitask/dannystover/Stage1Enemies.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DstoverVT/Multitask/8cb5b862cec97d8208a4fae31df062fa442093e5/bin/com/multitask/dannystover/Stage1Enemies.class -------------------------------------------------------------------------------- /bin/com/multitask/dannystover/Stage1Player.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DstoverVT/Multitask/8cb5b862cec97d8208a4fae31df062fa442093e5/bin/com/multitask/dannystover/Stage1Player.class -------------------------------------------------------------------------------- /bin/com/multitask/dannystover/Stage2Enemies.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DstoverVT/Multitask/8cb5b862cec97d8208a4fae31df062fa442093e5/bin/com/multitask/dannystover/Stage2Enemies.class -------------------------------------------------------------------------------- /bin/com/multitask/dannystover/Stage2Player.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DstoverVT/Multitask/8cb5b862cec97d8208a4fae31df062fa442093e5/bin/com/multitask/dannystover/Stage2Player.class -------------------------------------------------------------------------------- /bin/com/multitask/dannystover/Stage3Enemies.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DstoverVT/Multitask/8cb5b862cec97d8208a4fae31df062fa442093e5/bin/com/multitask/dannystover/Stage3Enemies.class -------------------------------------------------------------------------------- /bin/com/multitask/dannystover/Stage4Enemies.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DstoverVT/Multitask/8cb5b862cec97d8208a4fae31df062fa442093e5/bin/com/multitask/dannystover/Stage4Enemies.class -------------------------------------------------------------------------------- /bin/com/multitask/dannystover/StageEntities.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DstoverVT/Multitask/8cb5b862cec97d8208a4fae31df062fa442093e5/bin/com/multitask/dannystover/StageEntities.class -------------------------------------------------------------------------------- /bin/com/multitask/dannystover/Updater.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DstoverVT/Multitask/8cb5b862cec97d8208a4fae31df062fa442093e5/bin/com/multitask/dannystover/Updater.class -------------------------------------------------------------------------------- /bin/com/multitask/dannystover/Window.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DstoverVT/Multitask/8cb5b862cec97d8208a4fae31df062fa442093e5/bin/com/multitask/dannystover/Window.class -------------------------------------------------------------------------------- /pngdonutface.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DstoverVT/Multitask/8cb5b862cec97d8208a4fae31df062fa442093e5/pngdonutface.png -------------------------------------------------------------------------------- /sonic.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DstoverVT/Multitask/8cb5b862cec97d8208a4fae31df062fa442093e5/sonic.png -------------------------------------------------------------------------------- /src/com/multitask/dannystover/KeyInput.java: -------------------------------------------------------------------------------- 1 | package com.multitask.dannystover; 2 | 3 | import java.awt.event.KeyAdapter; 4 | import java.awt.event.KeyEvent; 5 | 6 | public class KeyInput extends KeyAdapter { 7 | 8 | //handler keeps track of each object in game, used here to loop through objects and make sure 9 | //key input only works on those with Player ID so we don't control the enemies too 10 | private Updater updater; 11 | private Multitask mainGame; 12 | //tells whether the key ([0]W [1]S [2]A [3]D) is down or not 13 | //used for smoother movement 14 | private boolean[] stage1PlayerKeyDown = {false, false}; 15 | private boolean[] stage2PlayerKeyDown = {false, false}; 16 | private ScoreTracker scoreTracker; 17 | 18 | public KeyInput(Updater u, Multitask game, ScoreTracker st) { 19 | updater = u; 20 | mainGame = game; 21 | scoreTracker = st; 22 | //true = key is pressed, false = not pressed 23 | 24 | } 25 | 26 | //stores key that is pressed and if it was left/right arrow, changes player's x velocity 27 | //velocity creates a smooth movement due to tick() method of GameObject 28 | public void keyPressed(KeyEvent e) { 29 | int key = e.getKeyCode(); 30 | //loops 31 | for(int i = 0; i < updater.allStageObjects.size(); i++) { 32 | StageEntities temp = updater.allStageObjects.get(i); 33 | 34 | if(temp.getRole().equals("Stage1Player")) { 35 | if(key == KeyEvent.VK_LEFT || key == KeyEvent.VK_A) { 36 | temp.setVelX(-5f); 37 | stage1PlayerKeyDown[0] = true; 38 | } 39 | if(key == KeyEvent.VK_RIGHT || key == KeyEvent.VK_D) { 40 | temp.setVelX(5f); 41 | stage1PlayerKeyDown[1] = true; 42 | } 43 | 44 | if(scoreTracker.getStage() != 1 && scoreTracker.getStage() != 2) { 45 | if(key == KeyEvent.VK_SPACE) { 46 | if(temp.getVelY() == 0) 47 | temp.setVelY(-100); 48 | if(!stage1PlayerKeyDown[0] && !stage1PlayerKeyDown[1]) { 49 | temp.setVelX(0); 50 | } 51 | else if(stage1PlayerKeyDown[1]) { 52 | temp.setVelX(5f); 53 | } 54 | else if(stage1PlayerKeyDown[0]) 55 | temp.setVelX(-5f); 56 | } 57 | } 58 | } 59 | 60 | else if(temp.getRole().equals("Stage2Player")) { 61 | if(key == KeyEvent.VK_W || key == KeyEvent.VK_UP) { 62 | temp.setVelY(-5f); 63 | stage2PlayerKeyDown[0] = true; 64 | } 65 | if(key == KeyEvent.VK_S || key == KeyEvent.VK_DOWN) { 66 | temp.setVelY(5f); 67 | stage2PlayerKeyDown[1] = true; 68 | } 69 | } 70 | 71 | } 72 | 73 | if(key == KeyEvent.VK_ESCAPE) 74 | System.exit(0); 75 | if(key == KeyEvent.VK_P) { 76 | mainGame.menuState = "pause"; 77 | } 78 | 79 | } 80 | 81 | 82 | //when the specified key is released, changes velocity to 0 83 | public void keyReleased(KeyEvent e) { 84 | 85 | int key = e.getKeyCode(); 86 | //loops through the list of objects in handler and only applies the change in position to those with player ID 87 | for(int i = 0; i < updater.allStageObjects.size(); i++) { 88 | StageEntities temp = updater.allStageObjects.get(i); 89 | 90 | if(temp.getRole().equals("Stage1Player")) { 91 | if(key == KeyEvent.VK_LEFT || key == KeyEvent.VK_A) { 92 | stage1PlayerKeyDown[0] = false; 93 | if(stage1PlayerKeyDown[1]) 94 | temp.setVelX(5f); 95 | else 96 | temp.setVelX(0f); 97 | 98 | } 99 | if(key == KeyEvent.VK_RIGHT || key == KeyEvent.VK_D) { 100 | stage1PlayerKeyDown[1] = false; 101 | if(stage1PlayerKeyDown[0]) 102 | temp.setVelX(-5f); 103 | else 104 | temp.setVelX(0f); 105 | } 106 | 107 | //these are so that if keys are tapped rapidly, the player doesn't stop moving 108 | //horizontal stoppage of movement 109 | if(!stage1PlayerKeyDown[0] && !stage1PlayerKeyDown[1]) 110 | temp.setVelX(0f); 111 | } 112 | 113 | 114 | 115 | else if(temp.getRole().equals("Stage2Player")) { 116 | if(key == KeyEvent.VK_W || key == KeyEvent.VK_UP) { 117 | stage2PlayerKeyDown[0] = false; 118 | if(stage2PlayerKeyDown[1]) 119 | temp.setVelY(5f); 120 | else 121 | temp.setVelY(0f); 122 | } 123 | 124 | if(key == KeyEvent.VK_S || key == KeyEvent.VK_DOWN) { 125 | stage2PlayerKeyDown[1] = false; 126 | if(stage2PlayerKeyDown[0]) 127 | temp.setVelY(-5f); 128 | else 129 | temp.setVelY(0f); 130 | } 131 | 132 | if(!stage2PlayerKeyDown[0] && !stage2PlayerKeyDown[1]) 133 | temp.setVelY(0f); 134 | } 135 | 136 | } 137 | 138 | } 139 | } 140 | 141 | -------------------------------------------------------------------------------- /src/com/multitask/dannystover/Menu.java: -------------------------------------------------------------------------------- 1 | package com.multitask.dannystover; 2 | 3 | import java.awt.Color; 4 | import java.awt.Font; 5 | import java.awt.Graphics; 6 | import java.awt.event.MouseAdapter; 7 | import java.awt.event.MouseEvent; 8 | import java.awt.image.BufferedImage; 9 | import java.io.File; 10 | import java.util.Random; 11 | 12 | import javax.imageio.ImageIO; 13 | import javax.sound.sampled.AudioInputStream; 14 | import javax.sound.sampled.AudioSystem; 15 | import javax.sound.sampled.Clip; 16 | 17 | public class Menu extends MouseAdapter{ 18 | 19 | private Multitask multitask; 20 | private int menuTimer; 21 | private int timerVal = 50; 22 | Random r = new Random(); 23 | private Updater updater; 24 | public float[] meteorWidthChoices = {126.4f, 143.6f, 158, 173.8f, 197.5f}; 25 | public float[] meteorHeightChoices = {180, 204.54f, 225, 247.5f, 281.25f}; 26 | private BufferedImage meteor1; 27 | private Spawner spawner; 28 | private ScoreTracker scoreTracker; 29 | public boolean clearMenuObjects = false; 30 | public static String howDied; 31 | public boolean menuSound = true; 32 | private Clip menuClip; 33 | public boolean fastSpeed = false; 34 | public static boolean freakyFast = false; 35 | 36 | public Menu(Multitask game, Updater upd, Spawner spawn, ScoreTracker st) { 37 | multitask = game; 38 | updater = upd; 39 | spawner = spawn; 40 | scoreTracker = st; 41 | 42 | try { 43 | meteor1 = ImageIO.read(new File("MeteorS1.png")); 44 | } 45 | catch(Exception e) { 46 | e.printStackTrace(); 47 | } 48 | try { 49 | File menuSong = new File("Menu music final.wav"); 50 | AudioInputStream musicMenu = AudioSystem.getAudioInputStream(menuSong); 51 | menuClip = AudioSystem.getClip(); 52 | menuClip.open(musicMenu); 53 | menuClip.start(); 54 | } 55 | catch(Exception e) { 56 | e.printStackTrace(); 57 | } 58 | } 59 | 60 | public void mousePressed(MouseEvent e) { 61 | int mouseX = e.getX(); 62 | int mouseY = e.getY(); 63 | 64 | if(multitask.menuState.equals("menu")) { 65 | if(withinTarget(mouseX, mouseY, Multitask.WIDTH/2 - 200, 200, 420, 100)) { 66 | multitask.menuState = "speed choose"; 67 | } 68 | } 69 | 70 | if(multitask.menuState.equals("speed choose")) { 71 | 72 | if(withinTarget(mouseX, mouseY, Multitask.WIDTH/2 - 200, 500, 420, 100)) { 73 | for(int i = 0; i < updater.allStageObjects.size(); i++) { 74 | updater.removeStageObject(updater.allStageObjects.get(i)); 75 | } 76 | clearMenuObjects = true; 77 | multitask.menuState = "game"; 78 | } 79 | 80 | if(withinTarget(mouseX, mouseY, Multitask.WIDTH/2 - 200, 700, 420, 100)) { 81 | for(int i = 0; i < updater.allStageObjects.size(); i++) { 82 | updater.removeStageObject(updater.allStageObjects.get(i)); 83 | } 84 | clearMenuObjects = true; 85 | multitask.menuState = "game"; 86 | fastSpeed = true; 87 | } 88 | if(withinTarget(mouseX, mouseY, Multitask.WIDTH/2 - 200, 900, 420, 100)) { 89 | for(int i = 0; i < updater.allStageObjects.size(); i++) { 90 | updater.removeStageObject(updater.allStageObjects.get(i)); 91 | } 92 | clearMenuObjects = true; 93 | multitask.menuState = "game"; 94 | fastSpeed = true; 95 | freakyFast = true; 96 | } 97 | } 98 | if(multitask.menuState == "game") { 99 | menuClip.stop(); 100 | for(int i = 0; i < updater.allStageObjects.size(); i++) { 101 | StageEntities temp = updater.allStageObjects.get(i); 102 | 103 | if(temp.getRole().equals("Stage4Enemy")) { 104 | if(withinTarget(mouseX, mouseY, (int)temp.getX(), (int)temp.getY(), (int)temp.getWidth(), (int)temp.getHeight())) { 105 | updater.removeStageObject(temp); 106 | } 107 | } 108 | } 109 | } 110 | 111 | if(withinTarget(mouseX, mouseY, Multitask.WIDTH/2 - 200, 400, 420, 100)) { 112 | multitask.menuState = "directions"; 113 | } 114 | 115 | if(withinTarget(mouseX, mouseY, Multitask.WIDTH/2 - 200, 600, 420, 100)) { 116 | multitask.menuState = "secret button"; 117 | } 118 | 119 | if(multitask.menuState.equals("secret button")) { 120 | if(withinTarget(mouseX, mouseY, Multitask.WIDTH/2 - 200, 600, 200, 100)) { 121 | multitask.menuState = "menu"; 122 | } 123 | } 124 | if(multitask.menuState.equals("directions")) { 125 | if(withinTarget(mouseX, mouseY, Multitask.WIDTH/2 - 200, 920, 200, 100)) { 126 | multitask.menuState = "menu"; 127 | } 128 | } 129 | 130 | if(multitask.menuState.equals("pause")) { 131 | if(withinTarget(mouseX, mouseY, Multitask.WIDTH/2 - 200, 200, 420, 100)) { 132 | 133 | multitask.menuState = "game"; 134 | 135 | } 136 | } 137 | 138 | 139 | 140 | 141 | if(multitask.menuState.equals("game over")) { 142 | 143 | 144 | if(withinTarget(mouseX, mouseY, Multitask.WIDTH/2 - 100, 900, 200, 100)) { 145 | multitask.gameOverClip.stop(); 146 | scoreTracker.setStage(1); 147 | scoreTracker.setScore(0); 148 | updater.removeAllStage2Objects(); 149 | spawner.stage2Height = 0; 150 | spawner.stage2Width = 0; 151 | spawner.stage1Height = Multitask.HEIGHT; 152 | spawner.stage1Width = Multitask.WIDTH; 153 | spawner.nextStage = 2; 154 | multitask.musicPlaying = false; 155 | spawner.havePlayers[1] = false; 156 | scoreTracker.setGameState(false); 157 | multitask.menuState = "game"; 158 | } 159 | } 160 | } 161 | 162 | public void mouseReleased(MouseEvent e) { 163 | 164 | } 165 | 166 | private boolean withinTarget(int mouseX, int mouseY, int targetX, int targetY, int width, int height) { 167 | if(mouseX > targetX && mouseX < targetX + width) { 168 | if(mouseY > targetY && mouseY < targetY + height) { 169 | return true; 170 | } 171 | else 172 | return false; 173 | } 174 | else 175 | return false; 176 | } 177 | 178 | public void update() { 179 | menuTimer++; 180 | if(menuTimer >= timerVal) { 181 | menuTimer = 0; 182 | float xValue = r.nextInt(Multitask.WIDTH + 20) -10; 183 | xValue = Multitask.setBounds(xValue, -20, Multitask.WIDTH + 20); 184 | //random number from 0 to 4 185 | int widthHeightIndex = r.nextInt(5); 186 | timerVal = r.nextInt(26)+50; 187 | updater.addStageObject(new Stage1Enemies(xValue, -150, meteorWidthChoices[widthHeightIndex], meteorHeightChoices[widthHeightIndex], meteor1, "Stage1Enemy", spawner, updater, this)); 188 | } 189 | } 190 | 191 | public void render(Graphics g) { 192 | if(multitask.menuState.equals("menu")) { 193 | g.setFont(new Font("arial", 1, 50)); 194 | g.setColor(Color.white); 195 | g.drawString("Menu", Multitask.WIDTH/2 - 60, 100); 196 | 197 | g.drawRect(Multitask.WIDTH/2 - 200, 200, 420, 100); 198 | g.drawRect(Multitask.WIDTH/2 - 200, 400, 420, 100); 199 | g.drawRect(Multitask.WIDTH/2 - 200, 600, 420, 100); 200 | 201 | g.drawString("Play", Multitask.WIDTH/2 - 43, 265); 202 | g.drawString("Directions", Multitask.WIDTH/2 - 100, 465); 203 | g.drawString("Secret Button", Multitask.WIDTH/2 - 150, 665); 204 | } 205 | else if(multitask.menuState.equals("directions")) { 206 | 207 | g.setFont(new Font("arial", Font.ITALIC, 50)); 208 | g.setColor(Color.white); 209 | g.drawString("Directions", Multitask.WIDTH/2 - 60, 100); 210 | 211 | g.setFont(new Font("arial", 0, 40)); 212 | g.drawString("The aim of the game is to survive as long as possible through the 4 stages.", 100, 200); 213 | g.drawString("In order to survive, you must have sufficient multitasking abilities.", 100, 250); 214 | g.drawString("Stage 1: The first stage requires you to move the donut astronaut left and right", 100, 350); 215 | g.drawString("with the ARROW KEYS, dodging falling meteors. Making contact with any meteor will end the game.", 100, 400); 216 | g.drawString("Stage 2: After reaching a score of 1000, the second stage will open, where you must continue to", 100, 500); 217 | 218 | g.setFont(new Font("arial", 0, 35)); 219 | g.drawString("play the first stage while now using W and S to move the donut astronaut up and down, dodging incoming asteroids.", 100, 550); 220 | 221 | g.setFont(new Font("arial", 0, 40)); 222 | g.drawString("Stage 3: After reaching a score of 2000, the third stage will begin.", 100, 650); 223 | g.drawString("During this stage, a new enemy is introduced against the stage 1 player, which is a rectangle that the", 100, 700); 224 | g.drawString("player must jump over with the SPACEBAR. Contact with a rectangle will result in game over.", 100, 750); 225 | g.drawString("Stage 4: After reaching a score of 3000, harmless floating donuts will appear all over the screen.", 100, 850); 226 | g.drawString("The donuts grow in size by the millisecond, and must be CLICKED to disappear so that the user can see.", 100, 900); 227 | 228 | g.drawRect(Multitask.WIDTH/2 - 200, 920, 200, 100); 229 | 230 | g.setColor(Color.white); 231 | g.setFont(new Font("arial", 0, 40)); 232 | g.drawString("Back", Multitask.WIDTH/2 - 150, 980); 233 | 234 | } 235 | else if(multitask.menuState.equals("secret button")) { 236 | g.setColor(Color.pink); 237 | g.setFont(new Font("Times New Roman", 1,130)); 238 | g.drawString("CREATED BY DSTOVERVT", 70, 540); 239 | 240 | g.drawRect(Multitask.WIDTH/2 - 200, 600, 200, 100); 241 | 242 | g.setColor(Color.white); 243 | g.setFont(new Font("arial", 0, 40)); 244 | g.drawString("Back", Multitask.WIDTH/2 - 150, 665); 245 | 246 | 247 | } 248 | else if(multitask.menuState.equals("speed choose")) { 249 | g.setFont(new Font("arial", 2, 50)); 250 | g.setColor(Color.white); 251 | g.drawString("Choose your speed", Multitask.WIDTH/2 - 200, 400); 252 | 253 | g.drawRect(Multitask.WIDTH/2 - 200, 500, 420, 100); 254 | g.drawRect(Multitask.WIDTH/2 - 200, 700, 420, 100); 255 | g.drawRect(Multitask.WIDTH/2 - 200, 900, 420, 100); 256 | 257 | g.setFont(new Font("arial", 1, 50)); 258 | g.drawString("Normal", Multitask.WIDTH/2 - 70, 570); 259 | g.drawString("Fast", Multitask.WIDTH/2 - 55, 770); 260 | g.drawString("Freaky Fast", Multitask.WIDTH/2 - 130, 970); 261 | } 262 | else if(multitask.menuState.equals("pause")) { 263 | 264 | updater.stage1ObjectsRender(g); 265 | g.setFont(new Font("arial", 1, 50)); 266 | g.setColor(Color.white); 267 | g.drawString("Pause", Multitask.WIDTH/2 - 60, 100); 268 | 269 | g.drawRect(Multitask.WIDTH/2 - 200, 200, 420, 100); 270 | g.drawString("Resume", Multitask.WIDTH/2 - 93, 265); 271 | 272 | } 273 | else if(multitask.menuState.equals("game over")) { 274 | updater.removeAllStage1Enemies(); 275 | updater.removeAllStage2Enemies(); 276 | g.setColor(Color.red); 277 | g.setFont(new Font("Serif", Font.BOLD, 300)); 278 | g.drawString("HAH you lose", 50, Multitask.HEIGHT/2); 279 | 280 | g.setColor(Color.white); 281 | g.drawRect(Multitask.WIDTH/2 - 100, 900, 200, 100); 282 | g.setFont(new Font("arial", 0, 40)); 283 | g.drawString("Replay", Multitask.WIDTH/2-50, 960); 284 | 285 | int flashingColor = r.nextInt(10); 286 | g.setColor(spawner.objectColors[flashingColor]); 287 | g.setFont(new Font("arial", 0, 40)); 288 | g.drawString("Score: " + scoreTracker.getScore(), Multitask.WIDTH/2 - 100, Multitask.HEIGHT/2 + 150); 289 | g.drawString("Stage: " + scoreTracker.getStage(), Multitask.WIDTH/2 - 100, Multitask.HEIGHT/2 + 200); 290 | g.drawString(howDied, Multitask.WIDTH/2 - 100, Multitask.HEIGHT/2 + 250); 291 | } 292 | } 293 | 294 | } 295 | -------------------------------------------------------------------------------- /src/com/multitask/dannystover/Multitask.java: -------------------------------------------------------------------------------- 1 | package com.multitask.dannystover; 2 | 3 | import java.awt.Canvas; 4 | import java.awt.Color; 5 | import java.awt.Graphics; 6 | import java.awt.image.BufferStrategy; 7 | import java.io.File; 8 | 9 | import javax.sound.sampled.AudioInputStream; 10 | import javax.sound.sampled.AudioSystem; 11 | import javax.sound.sampled.Clip; 12 | 13 | 14 | //main class that runs the game, window, and background operations 15 | 16 | 17 | public class Multitask extends Canvas implements Runnable{ 18 | 19 | 20 | //dimensions of window/JFrame 21 | public static final int WIDTH = 1920, HEIGHT = 1080; 22 | 23 | 24 | //Entire game runs through this thread 25 | private Thread thread; 26 | 27 | //keeps track of if game is running or not, stops thread if not (in stop() method), runs the 28 | //game loop inside of the run() method, which is called when the Thread is started (start()) 29 | public boolean running = false; 30 | 31 | //OBJECTS 32 | //ScoreTracker keeps track of the score and stage of the game 33 | private ScoreTracker scoreTracker; 34 | 35 | //Updater contains of the game objects and updates and renders them each frame 36 | private Updater mainUpdater; 37 | 38 | //Spawner uses the game loop to keep a timer, which is used to spawn enemies periodically, and 39 | //spawn the players as well as transition between stages. 40 | private Spawner objectSpawner; 41 | 42 | //Allows keys to be registered and serve a function when pressed 43 | private KeyInput keyInput; 44 | 45 | //The Menu holds and maintains everything when the game is not running, so in the beginning menu, 46 | //when you die, and in the pause menu. 47 | private Menu menu; 48 | 49 | //Sound Clips for in-game and when you die 50 | private Clip gameClip; 51 | public Clip gameOverClip; 52 | 53 | //tells whether the in-game music is playing. Public so other classes such as Menu can use it. 54 | public boolean musicPlaying = false; 55 | 56 | //Important- keeps track of the state of the game, so the game provides the graphical interface 57 | //according to what state it is in. 58 | public String menuState = "menu"; 59 | 60 | 61 | 62 | //main method creates a new Multitask() 63 | public Multitask() { 64 | 65 | //creates window that contains this Multitask class as a parameter. 66 | //the Window starts the start() method, which calls the run() method, which calls the render() and update() methods 67 | //that call the Updater update and render methods. So when a Multitask() is created in main, the game starts through this sequence. 68 | 69 | //OBJECT initializations and mouse and keyboard recognition 70 | mainUpdater = new Updater(); 71 | scoreTracker = new ScoreTracker(); 72 | objectSpawner = new Spawner(mainUpdater, scoreTracker); 73 | menu = new Menu(this, mainUpdater, objectSpawner, scoreTracker); 74 | this.addKeyListener(new KeyInput(mainUpdater, this, scoreTracker)); 75 | this.addMouseListener(menu); 76 | new Window(WIDTH, HEIGHT, "Multitask", this); 77 | 78 | 79 | 80 | 81 | } 82 | 83 | 84 | //this method is called when a new Window is created (in the Multitask constructor) 85 | public void start() { 86 | //creates new thread, starts up thread, which starts the game loop 87 | thread = new Thread(this); 88 | //this calls the run() method of whatever was put into the Thread class, in this case "this", which 89 | //refers to the Multitask class what put into the Thread so the Multitask class' run() method is called 90 | thread.start(); 91 | running = true; 92 | 93 | 94 | } 95 | 96 | public void stop() { 97 | //makes sure you can stop at this time, and stops the thread 98 | //when the game loop stops (running = false), this method is called and terminates game 99 | try { 100 | //join method kills off thread 101 | thread.join(); 102 | running = false; 103 | 104 | }catch(Exception e) { 105 | //if error, this is ran (prints in console) 106 | e.printStackTrace(); 107 | } 108 | 109 | } 110 | //method to play in-game saxophone song 111 | public void playMusic() { 112 | try { 113 | File menuSong = new File("Game music final.wav"); 114 | AudioInputStream musicMenu = AudioSystem.getAudioInputStream(menuSong); 115 | //field 116 | gameClip = AudioSystem.getClip(); 117 | gameClip.open(musicMenu); 118 | gameClip.start(); 119 | } 120 | catch(Exception e) { 121 | e.printStackTrace(); 122 | } 123 | } 124 | 125 | //called when Thread is started in start() method 126 | //makes sure update() and render() methods are called each millisecond/frame (a little longer) or so. 127 | public void run() { 128 | 129 | //game loop (while loop), necessary. The rest calculates the frames per second. 130 | //needs to check whether enough time has passed (1/60 sec) 131 | //to refresh the game, and checks whether enough time has 132 | //passed (1 second) to refresh the FPS counter 133 | this.requestFocus(); 134 | long lastTime = System.nanoTime(); //get current time to the nanosecond 135 | double amountOfTicks = 60.0; //set the number of ticks 136 | double ns = 1000000000 / amountOfTicks; //determines how many times we can divide 60 into 1e9 of nano seconds or about 1 second 137 | double delta = 0; //change in time 138 | long timer = System.currentTimeMillis(); //get current time 139 | int frames = 0; //set frame variable 140 | while(running) { 141 | //while loop runs and adds time it took adding it to delta, 142 | //which is 1 and once it reaches 1 delta the game refreshes 143 | //FPS counter 144 | long now = System.nanoTime(); //get current time in nanoseconds during current iteration 145 | delta += (now - lastTime) / ns; //add the amount of change since the last iteration 146 | lastTime = now; //set lastTime to now prepare for next iteration 147 | while(delta >= 1) { 148 | //Renders next frame once 60 frames per one second is reached, so game doesn't run way too fast 149 | update(); 150 | delta--; //lower delta to 0 to start our next frame wait 151 | } 152 | render(); //render visuals of game 153 | frames++; //frame has passed 154 | 155 | //if one second has passed 156 | if(System.currentTimeMillis() - timer > 1000) { 157 | timer += 1000; //add a thousand to timer for next time 158 | System.out.println("FPS: " + frames); //print how many frames have happened in last second 159 | frames = 0; //reset frame count for next second 160 | } 161 | } 162 | stop(); //stop thread if running = false 163 | 164 | } 165 | 166 | private void update() { 167 | //updates each frame 168 | //when game is over or in pause menu, makes sure enemies don't spawn 169 | if(!menuState.equalsIgnoreCase("game over") && !menuState.equals("pause")) 170 | mainUpdater.stage1ObjectsUpdate(); 171 | 172 | if(scoreTracker.getStage() != 1 && !menuState.equals("game over") && !menuState.equals("pause")) 173 | mainUpdater.stage2ObjectsUpdate(); 174 | 175 | //during the game 176 | if(menuState.equals("game")) { 177 | 178 | if(menu.fastSpeed) 179 | mainUpdater.stage1ObjectsUpdate(); 180 | 181 | //game music playing, boolean makes sure it only plays once 182 | if(!musicPlaying) { 183 | playMusic(); 184 | musicPlaying = true; 185 | } 186 | //updates the score object each frame 187 | scoreTracker.update(); 188 | 189 | //updates the spawner object each frame 190 | objectSpawner.update(); 191 | 192 | //after stage 1. Updates stage 2 objects when stage 1 is complete 193 | if(scoreTracker.getStage() != 1 && menu.fastSpeed) 194 | mainUpdater.stage2ObjectsUpdate(); 195 | 196 | //after stage 2. Updates stage 3 objects when stage 2 is complete 197 | if(scoreTracker.getStage() != 1 && scoreTracker.getStage() != 2) { 198 | mainUpdater.stage3ObjectsUpdate(); 199 | } 200 | 201 | //when stage 4 arrives, updates stage 4 objects to track movement 202 | if(scoreTracker.getStage() == 4) { 203 | mainUpdater.stage4ObjectsUpdate(); 204 | } 205 | 206 | //when game ends 207 | if(scoreTracker.getGameState()) { 208 | //stop game music and change state 209 | gameClip.stop(); 210 | menuState = "game over"; 211 | //play game over, laughing sound 212 | try { 213 | File gOLaugh = new File("Game over laugh.wav"); 214 | AudioInputStream musicMenu = AudioSystem.getAudioInputStream(gOLaugh); 215 | gameOverClip = AudioSystem.getClip(); 216 | gameOverClip.open(musicMenu); 217 | gameOverClip.start(); 218 | } 219 | catch(Exception p) { 220 | p.printStackTrace(); 221 | } 222 | } 223 | } 224 | //menu is the only thing that updates when the game is off 225 | else if(!menuState.equals("directions") && !menuState.equals("game")){ 226 | menu.update(); 227 | } 228 | 229 | } 230 | 231 | private void render() { 232 | 233 | //ensures smooth graphics when rendering 234 | BufferStrategy bs = this.getBufferStrategy(); 235 | if(bs == null) { 236 | this.createBufferStrategy(3); 237 | return; 238 | } 239 | //provides as simple drawing and showing graphics 240 | Graphics g = bs.getDrawGraphics(); 241 | 242 | g.setColor(Color.blue.darker()); 243 | g.fillRect(0, 1080-objectSpawner.stage1Height, objectSpawner.stage1Width, objectSpawner.stage1Height); 244 | 245 | //Class render() methods 246 | if(!menuState.equalsIgnoreCase("game over")) 247 | mainUpdater.stage1ObjectsRender(g); 248 | 249 | if(menuState.equals("game")) { 250 | 251 | scoreTracker.render(g); 252 | 253 | //after stage 1 254 | if(scoreTracker.getStage() !=1) { 255 | g.setColor(Color.black); 256 | g.fillRect(WIDTH/2, 1080-objectSpawner.stage2Height, objectSpawner.stage2Width, objectSpawner.stage2Height); 257 | mainUpdater.stage2ObjectsRender(g); 258 | } 259 | if(scoreTracker.getStage() != 1 && scoreTracker.getStage() != 2) { 260 | mainUpdater.stage3ObjectsRender(g); 261 | } 262 | if(scoreTracker.getStage() == 4) { 263 | mainUpdater.stage4ObjectsRender(g); 264 | } 265 | } 266 | else { 267 | menu.render(g); 268 | 269 | } 270 | 271 | g.dispose(); 272 | bs.show(); 273 | 274 | } 275 | 276 | 277 | //method that bounds anything inside a minimum and a maximum value 278 | //used for player's x and y limits 279 | public static float setBounds(float value, float min, float max) { 280 | //returning this means that if var is greater than max it can only return max, so it's position 281 | //can never reach beyond max 282 | if(value >= max) 283 | return value = max; 284 | else if(value <= min) 285 | return value = min; 286 | else 287 | return value; 288 | } 289 | 290 | 291 | public static void main(String[] args) { 292 | 293 | //provides hardware acceleration for rendering 2D games 294 | System.setProperty("sun.java2d.opengl", "true"); 295 | //****calls Game constructor which creates a Window which the start() method, which calls the run() method, which calls the render() and tick() methods 296 | //that call the Handler tick and render methods. So when a Game() is created, the game starts through this sequence. 297 | new Multitask(); 298 | 299 | } 300 | 301 | } 302 | -------------------------------------------------------------------------------- /src/com/multitask/dannystover/ScoreTracker.java: -------------------------------------------------------------------------------- 1 | package com.multitask.dannystover; 2 | 3 | import java.awt.Color; 4 | import java.awt.Font; 5 | import java.awt.Graphics; 6 | import java.io.File; 7 | 8 | import javax.sound.sampled.AudioInputStream; 9 | import javax.sound.sampled.AudioSystem; 10 | import javax.sound.sampled.Clip; 11 | 12 | public class ScoreTracker { 13 | 14 | private int score; 15 | private int stage; 16 | private boolean gameOver; 17 | public Clip gameClip; 18 | 19 | public ScoreTracker() { 20 | score = 0; 21 | stage = 1; 22 | gameOver = false; 23 | 24 | 25 | } 26 | 27 | public void update() { 28 | score++; 29 | 30 | if(score == 1000) 31 | setStage(2); 32 | 33 | if(score == 2000) 34 | setStage(3); 35 | 36 | 37 | if(score == 3000) 38 | setStage(4); 39 | } 40 | 41 | public void render(Graphics g) { 42 | g.setColor(Color.white); 43 | g.setFont(new Font("Animated", 0, 80)); 44 | g.drawString("Score: " + (int)score, 30, 80); 45 | g.drawString("Stage: " + (int)stage, 30, 150); 46 | 47 | if(score >= 0 && score <= 200) { 48 | g.setColor(Color.white); 49 | g.setFont(new Font("Animated", 1, 200)); 50 | g.drawString("1", Multitask.WIDTH/2 - 50, 200); 51 | } 52 | 53 | if(score >= 1000 && score <= 1200) { 54 | g.setColor(Color.white); 55 | g.setFont(new Font("Animated", 1, 200)); 56 | g.drawString("2", Multitask.WIDTH/2 - 150, 200); 57 | } 58 | 59 | if(score >= 2000 && score <= 2200) { 60 | g.setColor(Color.white); 61 | g.setFont(new Font("Animated", 1, 200)); 62 | g.drawString("3", Multitask.WIDTH/2 - 150, 200); 63 | } 64 | 65 | if(score >= 3000 && score <= 3200) { 66 | g.setColor(Color.white); 67 | g.setFont(new Font("Animated", 1, 200)); 68 | g.drawString("4", Multitask.WIDTH/2 - 150, 200); 69 | } 70 | } 71 | 72 | public void setStage(int s) { 73 | stage = s; 74 | } 75 | 76 | public int getStage() { 77 | return stage; 78 | } 79 | 80 | public int getScore() { 81 | return score; 82 | } 83 | 84 | public boolean getGameState() { 85 | return gameOver; 86 | } 87 | 88 | public void setGameState(boolean gs) { 89 | gameOver = gs; 90 | } 91 | 92 | public void setScore(int s) { 93 | score = s; 94 | } 95 | 96 | } 97 | -------------------------------------------------------------------------------- /src/com/multitask/dannystover/Spawner.java: -------------------------------------------------------------------------------- 1 | package com.multitask.dannystover; 2 | 3 | import java.awt.Color; 4 | import java.awt.Graphics; 5 | import java.awt.image.BufferedImage; 6 | import java.io.File; 7 | import java.util.Random; 8 | 9 | import javax.imageio.ImageIO; 10 | 11 | public class Spawner { 12 | 13 | private Updater updater; 14 | //counter from this class to keep track of when to spawn objects 15 | private int stageTimer = 0, stage2Timer =0, stage3Timer=0, stage4Timer = 0, stage4VelocityXTimer = 0, stage4VelocityYTimer = 0; 16 | 17 | //access to ScoreTracker to this class can access the current stage 18 | private ScoreTracker scoreTracker; 19 | //each image for each player/enemy 20 | private BufferedImage meteor1, player1, player2, asteroid1, asteroid2, asteroid3, asteroid4, asteroid5, asteroid6, donut, sonic; 21 | public Stage1Player p; 22 | public Stage2Player p2; 23 | public int stage1Width, stage1Height; 24 | public int stage2Width, stage2Height; 25 | 26 | public float[] meteorWidthChoices = {126.4f, 143.6f, 158, 173.8f, 197.5f}; 27 | public float[] meteorHeightChoices = {180, 204.54f, 225, 247.5f, 281.25f}; 28 | 29 | public BufferedImage[] asteroids; 30 | public float[] asteroidWidthChoices = {142.35f, 124, 176.3f, 154.3f, 150, 150}; 31 | public float[] asteroidHeightChoices = {130.7f, 123.1f, 132.24f, 125.7f, 150, 125}; 32 | private Random r = new Random(); 33 | 34 | public Color[] objectColors = {Color.red, Color.red, Color.red, Color.white, Color.green, Color.pink, Color.black, Color.lightGray, Color.yellow, Color.orange}; 35 | 36 | private int timerVal = 50; 37 | private int timer2Val = 40; 38 | private int timer3Val = 20; 39 | private int timer4Val = 200; 40 | private int timer4VelX = 30; 41 | private int timer4VelY = 20; 42 | public boolean[] havePlayers = {false, false, false, false}; 43 | public int nextStage = 2; 44 | private int firstStage3 = 0; 45 | 46 | public Spawner(Updater u, ScoreTracker st) { 47 | updater = u; 48 | scoreTracker = st; 49 | //images 50 | try { 51 | meteor1 = ImageIO.read(new File("MeteorS1.png")); 52 | player1 = ImageIO.read(new File("stage1player final.png")); 53 | player2 = ImageIO.read(new File("stage2player final.png")); 54 | asteroid1 = ImageIO.read(new File("stage2asteroid1.png")); 55 | asteroid2 = ImageIO.read(new File("stage2asteroid2.png")); 56 | asteroid3 = ImageIO.read(new File("stage2asteroid3.png")); 57 | asteroid4 = ImageIO.read(new File("stage2asteroid4.png")); 58 | asteroid5 = ImageIO.read(new File("stage2asteroid5.png")); 59 | asteroid6 = ImageIO.read(new File("stage2asteroid6.png")); 60 | donut = ImageIO.read(new File("pngdonutface.png")); 61 | sonic = ImageIO.read(new File("sonic.png")); 62 | } 63 | catch(Exception e) { 64 | System.out.println("Stage1 Meteor image not read properly"); 65 | e.printStackTrace(); 66 | } 67 | stage1Width = 1920; 68 | stage1Height = 1080; 69 | 70 | //asteroids array contains each image to randomly generate via index 71 | asteroids = new BufferedImage[6]; 72 | asteroids[0] = asteroid1; 73 | asteroids[1] = asteroid2; 74 | asteroids[2] = asteroid3; 75 | asteroids[3] = asteroid4; 76 | asteroids[4] = asteroid5; 77 | asteroids[5] = asteroid6; 78 | } 79 | 80 | public void update() { 81 | //creation of player 1 82 | if(!havePlayers[0]) { 83 | if(Menu.freakyFast) 84 | p = new Stage1Player(stage1Width/2 - 125, stage1Height - 254, 300, 250, sonic, "Stage1Player", this, updater, scoreTracker); 85 | else if(!Menu.freakyFast) 86 | p = new Stage1Player(stage1Width/2 - 125, stage1Height - 254, 300, 250, player1, "Stage1Player", this, updater, scoreTracker); 87 | updater.addStageObject(p); 88 | havePlayers[0] = true; 89 | } 90 | stageTimer++; 91 | 92 | if(stageTimer >= timerVal) { 93 | stageTimer = 0; 94 | float xValue = r.nextInt(stage1Width+20)-10; 95 | xValue = Multitask.setBounds(xValue, -20, stage1Width + 20); 96 | //random number from 0 to 4 97 | int widthHeightIndex = r.nextInt(5); 98 | if(scoreTracker.getStage() == 1) 99 | timerVal = r.nextInt(31)+15; 100 | else 101 | timerVal = r.nextInt(26)+50; 102 | updater.addStageObject(new Stage1Enemies(xValue, -150, meteorWidthChoices[widthHeightIndex], meteorHeightChoices[widthHeightIndex], meteor1, "Stage1Enemy", this, updater)); 103 | } 104 | 105 | if(scoreTracker.getStage() != 1) { 106 | stage2Timer++; 107 | //transition between stage 1 and 2 108 | if(nextStage == 2) { 109 | stage1Width = 960; 110 | stage2Width = stage1Width; 111 | stage2Height = stage1Height; 112 | updater.removeStageObject(p); 113 | updater.removeAllStage1Enemies(); 114 | havePlayers[0] = false; 115 | 116 | nextStage = 3; 117 | } 118 | //creation of player 2 119 | if(!havePlayers[1]) { 120 | p2 = new Stage2Player(Multitask.WIDTH/2 + 10, stage1Height/2, 300, 250, player2, "Stage2Player", this, updater, scoreTracker); 121 | updater.addStageObject(p2); 122 | havePlayers[1] = true; 123 | } 124 | 125 | //stage 2's objects 126 | if(stage2Timer >= timer2Val) { 127 | stage2Timer = 0; 128 | float yValue = r.nextInt(stage2Height+20)-10; 129 | yValue = Multitask.setBounds(yValue, -10, stage2Height + 10); 130 | //random number from 0 to 5 for asteroid picture 131 | int randomAsteroid = r.nextInt(6); 132 | timer2Val = r.nextInt(26)+50; 133 | updater.addStageObject(new Stage2Enemies(stage2Width*2 + 200, yValue, asteroidWidthChoices[randomAsteroid], asteroidHeightChoices[randomAsteroid], asteroids[randomAsteroid], "Stage2Enemy", updater, this, scoreTracker)); 134 | } 135 | } 136 | 137 | if(scoreTracker.getStage() != 1 && scoreTracker.getStage() != 2) { 138 | stage3Timer++; 139 | if(stage3Timer >= timer3Val) { 140 | stage3Timer = 0; 141 | float width = r.nextInt(21)+10; 142 | float height = r.nextInt(51)+75; 143 | //random number from 0 to 4 144 | if(timer3Val == 20) { 145 | timer3Val = r.nextInt(20)+30; 146 | } 147 | else { 148 | timer3Val = r.nextInt(101)+150; 149 | firstStage3 = 1; 150 | } 151 | int randomColorIndex = r.nextInt(10); 152 | if(firstStage3 == 1) 153 | updater.addStageObject(new Stage3Enemies(stage1Width, stage1Height-height, width, height, "Stage3Enemy", objectColors[randomColorIndex], updater, scoreTracker)); 154 | 155 | } 156 | } 157 | 158 | if(scoreTracker.getStage() == 4) { 159 | stage4Timer++; 160 | stage4VelocityXTimer++; 161 | stage4VelocityYTimer++; 162 | if(stage4Timer >= timer4Val) { 163 | stage4Timer = 0; 164 | //random number from 0 to 4 165 | timer4Val = r.nextInt(301)+200; 166 | int randomXLocation = r.nextInt(Multitask.WIDTH); 167 | int randomYLocation = r.nextInt(Multitask.HEIGHT); 168 | 169 | updater.addStageObject(new Stage4Enemies(randomXLocation, randomYLocation, 50, 50, donut, "Stage4Enemy", updater, scoreTracker)); 170 | } 171 | if(stage4VelocityXTimer >= timer4VelX) { 172 | stage4VelocityXTimer = 0; 173 | timer4VelX = r.nextInt(21)+10; 174 | for(int i = 0; i < updater.allStageObjects.size(); i++) { 175 | if(updater.allStageObjects.get(i).getRole().equals("Stage4Enemy")) { 176 | updater.allStageObjects.get(i).randomizeVelX(); 177 | } 178 | } 179 | } 180 | if(stage4VelocityYTimer >= timer4VelY) { 181 | stage4VelocityYTimer = 0; 182 | timer4VelY = r.nextInt(21)+10; 183 | for(int i = 0; i < updater.allStageObjects.size(); i++) { 184 | if(updater.allStageObjects.get(i).getRole().equals("Stage4Enemy")) { 185 | updater.allStageObjects.get(i).randomizeVelY(); 186 | } 187 | } 188 | } 189 | } 190 | 191 | /* 192 | if(scoreTracker.getStage() != 1 && scoreTracker.getStage() != 2) { 193 | //transition from stage 2 to stage 3 194 | if(nextStage == 3) { 195 | stage1Height = 540; 196 | stage2Height = 540; 197 | stage3Height = 540; 198 | stage3Width = 1920; 199 | updater.removeStageObject(p); 200 | havePlayers[0] = false; 201 | updater.removeStageObject(p2); 202 | havePlayers[1] = false; 203 | updater.removeAllStage1Enemies(); 204 | updater.removeAllStage2Enemies(); 205 | 206 | 207 | nextStage = 4; 208 | } 209 | 210 | } 211 | */ 212 | } 213 | 214 | 215 | 216 | 217 | 218 | } 219 | 220 | 221 | -------------------------------------------------------------------------------- /src/com/multitask/dannystover/Stage1Enemies.java: -------------------------------------------------------------------------------- 1 | package com.multitask.dannystover; 2 | 3 | import java.awt.Graphics; 4 | import java.awt.Polygon; 5 | import java.awt.geom.Area; 6 | import java.awt.geom.Ellipse2D; 7 | import java.awt.image.BufferedImage; 8 | 9 | public class Stage1Enemies extends StageEntities { 10 | 11 | private Spawner spawner; 12 | private Updater updater; 13 | private Menu menu; 14 | //private Area intersection; 15 | 16 | public Stage1Enemies(float ex, float wy, float wid, float ht, BufferedImage imagey, String role, Spawner spawn, Updater u) { 17 | super(ex, wy, wid, ht, imagey, role); 18 | spawner = spawn; 19 | updater = u; 20 | 21 | randomizeVelY(); 22 | //border = poly; 23 | } 24 | 25 | public Stage1Enemies(float ex, float wy, float wid, float ht, BufferedImage imagey, String role, Spawner spawn, Updater u, Menu m) { 26 | super(ex, wy, wid, ht, imagey, role); 27 | spawner = spawn; 28 | updater = u; 29 | menu = m; 30 | 31 | randomizeVelY(); 32 | //border = poly; 33 | } 34 | 35 | 36 | /* 37 | public Polygon getBorder() { 38 | new Polygon(new int[] {(int)x+45, (int)x+115, (int)x+125, (int)x+75, (int)x+35, (int)x+45}, 39 | new int[] {(int) 40 | } 41 | */ 42 | 43 | private Ellipse2D getCircleBorder() { 44 | if(width == spawner.meteorWidthChoices[0]) { 45 | return new Ellipse2D.Float(x+30, y+74, 67, 65); 46 | } 47 | else if(width == spawner.meteorWidthChoices[1]) { 48 | return new Ellipse2D.Float(x+35, y+84, 72, 70); 49 | } 50 | else if(width == spawner.meteorWidthChoices[2]) { 51 | return new Ellipse2D.Float(x+40, y+94, 77, 75); 52 | } 53 | else if(width == spawner.meteorWidthChoices[3]) { 54 | return new Ellipse2D.Float(x+45, y+104, 82, 80); 55 | } 56 | else if(width == spawner.meteorWidthChoices[4]) { 57 | return new Ellipse2D.Float(x+50, y+114, 87, 85); 58 | } 59 | else 60 | return null; 61 | 62 | } 63 | 64 | 65 | public Area getBorder() { 66 | //return new Rectangle((int)x + 40, (int)y+44, 80, 125); 67 | //return null; 68 | return new Area(getCircleBorder()); 69 | } 70 | 71 | /* 72 | public Rectangle getRectBorder() { 73 | return new Rectangle((int)x + 40, (int)y+44, 80, 125); 74 | } 75 | */ 76 | 77 | 78 | public void update() { 79 | y += velY; 80 | 81 | if(y >= 1100) 82 | updater.removeStageObject(this); 83 | if(menu != null) { 84 | if(menu.clearMenuObjects) 85 | updater.removeStageObject(this); 86 | } 87 | } 88 | 89 | public void render(Graphics g) { 90 | 91 | g.drawImage(image, (int)x, (int)y, (int)width, (int)height, null); 92 | 93 | } 94 | 95 | public void randomizeVelX() { 96 | 97 | velX = (float)(Math.random() * (3) + 2); 98 | 99 | } 100 | 101 | public void randomizeVelY() { 102 | 103 | velY = (float)(Math.random() * (3) + 2); 104 | } 105 | 106 | public void reset() { 107 | y = -150; 108 | } 109 | 110 | } 111 | -------------------------------------------------------------------------------- /src/com/multitask/dannystover/Stage1Player.java: -------------------------------------------------------------------------------- 1 | package com.multitask.dannystover; 2 | 3 | import java.awt.Graphics; 4 | import java.awt.Polygon; 5 | import java.awt.geom.Area; 6 | import java.awt.image.BufferedImage; 7 | 8 | public class Stage1Player extends StageEntities { 9 | 10 | private Spawner spawner; 11 | private Updater updater; 12 | private ScoreTracker scoreTracker; 13 | private Area intersection; 14 | 15 | public Stage1Player(float ex, float wy, float wid, float ht, BufferedImage imagey, String role, Spawner sp, Updater upd, ScoreTracker st) { 16 | super(ex, wy, wid, ht, imagey, role); 17 | spawner = sp; 18 | updater = upd; 19 | scoreTracker = st; 20 | } 21 | 22 | public void update() { 23 | 24 | x += velX; 25 | y += velY; 26 | if(y < spawner.stage1Height - 254) { 27 | velY +=1; 28 | } 29 | else 30 | velY = 0; 31 | 32 | velY = Multitask.setBounds(velY, -10, 5); 33 | //System.out.println(y); 34 | x = Multitask.setBounds(x, -80, spawner.stage1Width - 240); 35 | intersection = getBorder(); 36 | 37 | for(int i = 0; i < updater.allStageObjects.size(); i++) { 38 | StageEntities temp = updater.allStageObjects.get(i); 39 | 40 | if(temp.getRole().equals("Stage1Enemy")) { 41 | 42 | intersection.intersect(temp.getBorder()); 43 | 44 | if(!intersection.isEmpty()) { 45 | Menu.howDied = "Death by Stage 1 meteor"; 46 | scoreTracker.setGameState(true); 47 | } 48 | 49 | intersection = new Area(getPolyBorder()); 50 | } 51 | } 52 | //stage 3 object collision 53 | if(scoreTracker.getStage() >= 3) { 54 | for(int i = 0; i < updater.allStageObjects.size(); i++) { 55 | StageEntities temp = updater.allStageObjects.get(i); 56 | 57 | if(temp.getRole().equals("Stage3Enemy")) { 58 | 59 | intersection.intersect(temp.getBorder()); 60 | 61 | if(!intersection.isEmpty()) { 62 | Menu.howDied = "Death by Stage 3 ground rectangles"; 63 | scoreTracker.setGameState(true); 64 | } 65 | 66 | intersection = new Area(getPolyBorder()); 67 | } 68 | } 69 | } 70 | 71 | 72 | } 73 | 74 | private Polygon getPolyBorder() { 75 | return new Polygon(new int[] {(int)x+115, (int)x+200, (int)x+200, (int)x+235, (int)x+230, (int)x+190, (int)x+195, (int)x+180, (int)x+160, (int)x+145, (int)x+125, (int)x+130, (int)x+85, (int)x+80, (int)x+115, (int)x+115}, 76 | new int[] {(int)y+34, (int)y+34, (int)y+99, (int)y+134, (int)y+149, (int)y+134, (int)y+219, (int)y+219, (int)y+184, (int)y+220, (int)y+220, (int)y+139, (int)y+154, (int)y+129, (int)y+99, (int)y+34}, 16); 77 | 78 | } 79 | 80 | 81 | public Area getBorder() { 82 | return new Area(getPolyBorder()); 83 | } 84 | 85 | 86 | public void render(Graphics g) { 87 | g.drawImage(image, (int)x, (int)y, (int)width, (int)height, null); 88 | } 89 | 90 | public void randomizeVelX() { 91 | 92 | velX = (float)(Math.random() * (3) + 1); 93 | 94 | } 95 | 96 | public void randomizeVelY() { 97 | 98 | velY = (float)(Math.random() * (3) + 1); 99 | 100 | } 101 | 102 | } 103 | -------------------------------------------------------------------------------- /src/com/multitask/dannystover/Stage2Enemies.java: -------------------------------------------------------------------------------- 1 | package com.multitask.dannystover; 2 | 3 | import java.awt.Graphics; 4 | import java.awt.Polygon; 5 | import java.awt.Shape; 6 | import java.awt.geom.Area; 7 | import java.awt.geom.Ellipse2D; 8 | import java.awt.image.BufferedImage; 9 | 10 | public class Stage2Enemies extends StageEntities { 11 | 12 | private Updater updater; 13 | private Spawner spawner; 14 | private ScoreTracker scoreTracker; 15 | 16 | public Stage2Enemies(float ex, float wy, float wid, float ht, BufferedImage imagey, String role, Updater u, Spawner s, ScoreTracker st) { 17 | super(ex, wy, wid, ht, imagey, role); 18 | updater = u; 19 | spawner = s; 20 | scoreTracker = st; 21 | 22 | randomizeVelX(); 23 | } 24 | 25 | /* 26 | public Stage2Enemies(float ex, float wy, BufferedImage imagey, String role) { 27 | super(ex, wy, imagey, role); 28 | 29 | randomizeVelX(); 30 | } 31 | */ 32 | 33 | 34 | public Shape getPolyBorder() { 35 | if(width == spawner.asteroidWidthChoices[0]) { 36 | return new Polygon(new int[] {(int)x, (int)x+35, (int)x+55, (int)x+110, (int)x+140, (int)x+105, (int)x+60, (int)x+15, (int)x}, 37 | new int[] {(int)y+70, (int)y+10, (int)y, (int)y, (int)y+55, (int)y+85, (int)y+125, (int)y+110, (int)y+70}, 9); 38 | } 39 | else if(width == spawner.asteroidWidthChoices[1]) { 40 | return getAsteroid2Border(); 41 | } 42 | else if(width == spawner.asteroidWidthChoices[2]) { 43 | return new Polygon(new int[] {(int)x+30, (int)x+45, (int)x+120, (int)x+150, (int)x+150, (int)x+138, (int)x+100, (int)x+60, (int)x+30}, 44 | new int[] {(int)y+25, (int)y+35, (int)y+60, (int)y+85, (int)y+85, (int)y+110, (int)y+105, (int)y+65, (int)y+25}, 9); 45 | } 46 | else if(width == spawner.asteroidWidthChoices[3]) { 47 | return new Polygon(new int[] {(int)x+20, (int)x+35, (int)x+55, (int)x+90, (int)x+125, (int)x+140, (int)x+145, (int)x+125, (int)x+50, (int)x+20,(int)x+20}, 48 | new int[] {(int)y+50, (int)y+20, (int)y+5, (int)y+5, (int)y+35, (int)y+40, (int)y+60, (int)y+120, (int)y+120, (int)y+90, (int)y+50}, 11); 49 | } 50 | else if(width == spawner.asteroidWidthChoices[4]) { 51 | return new Polygon(new int[] {(int)x+5, (int)x+35, (int)x+150, (int)x+130, (int)x+130, (int)x+115, (int)x+55, (int)x+5, (int)x+5}, 52 | new int[] {(int)y+30, (int)y+17, (int)y+17, (int)y+55, (int)y+73, (int)y+110, (int)y+125, (int)y+90, (int)y+30}, 9); 53 | } 54 | else if(width == spawner.asteroidWidthChoices[5]) { 55 | return new Polygon(new int[] {(int)x+10, (int)x+35, (int)x+38, (int)x+65, (int)x+135, (int)x+115, (int)x+80, (int)x+20, (int)x+10, (int)x+10}, 56 | new int[] {(int)y+55, (int)y+35, (int)y+15, (int)y+35, (int)y+50, (int)y+85, (int)y+115, (int)y+100, (int)y+75, (int)y+55}, 10); 57 | } 58 | else 59 | return new Polygon(new int[] {(int)x+20, (int)x+35, (int)x+55, (int)x+90, (int)x+125, (int)x+140, (int)x+145, (int)x+125, (int)x+50, (int)x+20,(int)x+20}, 60 | new int[] {(int)y+50, (int)y+20, (int)y+5, (int)y+5, (int)y+35, (int)y+40, (int)y+60, (int)y+120, (int)y+120, (int)y+90, (int)y+50}, 11); 61 | } 62 | 63 | 64 | private Ellipse2D getAsteroid2Border() { 65 | return new Ellipse2D.Float(x, y, width, height); 66 | } 67 | 68 | public Area getBorder() { 69 | return new Area(getPolyBorder()); 70 | } 71 | 72 | 73 | public void update() { 74 | x += velX; 75 | 76 | if(x <= Multitask.WIDTH/2 - 10) 77 | updater.removeStageObject(this); 78 | if(scoreTracker.getStage() < 2) { 79 | updater.removeStageObject(this); 80 | } 81 | } 82 | 83 | public void render(Graphics g) { 84 | 85 | g.drawImage(image, (int)x, (int)y, (int)width, (int)height, null); 86 | 87 | } 88 | 89 | public void randomizeVelX() { 90 | 91 | velX = (float)((Math.random() * (3) + 2)*-1); 92 | 93 | } 94 | 95 | public void randomizeVelY() { 96 | 97 | velY = (float)(Math.random() * (3) + 2); 98 | } 99 | 100 | } 101 | -------------------------------------------------------------------------------- /src/com/multitask/dannystover/Stage2Player.java: -------------------------------------------------------------------------------- 1 | package com.multitask.dannystover; 2 | 3 | import java.awt.Graphics; 4 | import java.awt.Polygon; 5 | import java.awt.geom.Area; 6 | import java.awt.geom.Ellipse2D; 7 | import java.awt.image.BufferedImage; 8 | 9 | public class Stage2Player extends StageEntities{ 10 | 11 | private Spawner spawner; 12 | private Area intersection; 13 | private Area headIntersection; 14 | private Updater updater; 15 | private ScoreTracker scoreTracker; 16 | 17 | public Stage2Player(float ex, float wy, float wid, float ht, BufferedImage imagey, String role, Spawner sp, Updater upd, ScoreTracker st) { 18 | super(ex, wy, wid, ht, imagey, role); 19 | spawner = sp; 20 | updater = upd; 21 | scoreTracker = st; 22 | 23 | } 24 | 25 | public Area getBorder() { 26 | return new Area(getPolyBorder()); 27 | } 28 | 29 | public Area getHeadBorder() { 30 | return new Area(getCircleBorder()); 31 | } 32 | 33 | public Polygon getPolyBorder() { 34 | return new Polygon(new int[] {(int)x+100, (int)x+115, (int)x+200, (int)x+225, (int)x+200, (int)x+180, (int)x+170, (int)x+173, (int)x+170, (int)x+195, (int)x+190, (int)x+165, (int)x+125, (int)x+105, (int)x+107, (int)x+125, (int)x+125, (int)x+100}, 35 | new int[] {(int)y+180, (int)y+200, (int)y+155, (int)y+145, (int)y+140, (int)y+150, (int)y+135, (int)y+125, (int)y+110, (int)y+95, (int)y+90, (int)y+95, (int)y+105, (int)y+120, (int)y+130, (int)y+125, (int)y+170, (int)y+180}, 18); 36 | 37 | } 38 | 39 | public Ellipse2D getCircleBorder() { 40 | return new Ellipse2D.Float(x+120, y+55, 50, 50); 41 | 42 | } 43 | 44 | 45 | 46 | public void update() { 47 | y += velY; 48 | y = Multitask.setBounds(y, 1010-spawner.stage2Height, spawner.stage2Height-230); 49 | 50 | if(scoreTracker.getStage() < 2) { 51 | updater.removeStageObject(this); 52 | } 53 | 54 | intersection = getBorder(); 55 | headIntersection = getHeadBorder(); 56 | 57 | 58 | if(scoreTracker.getStage() != 1) { 59 | for(int i = 0; i < updater.allStageObjects.size(); i++) { 60 | 61 | StageEntities temp = updater.allStageObjects.get(i); 62 | 63 | if(temp.getRole().equals("Stage2Enemy")) { 64 | 65 | intersection.intersect(temp.getBorder()); 66 | headIntersection.intersect(temp.getBorder()); 67 | 68 | if(!intersection.isEmpty() || !headIntersection.isEmpty()) { 69 | Menu.howDied = "Death by Stage 2 asteroid"; 70 | scoreTracker.setGameState(true); 71 | } 72 | 73 | intersection = getBorder(); 74 | headIntersection = getHeadBorder(); 75 | } 76 | 77 | } 78 | } 79 | 80 | 81 | } 82 | 83 | 84 | public void render(Graphics g) { 85 | 86 | g.drawImage(image, (int)x, (int)y, (int)width, (int)height, null); 87 | } 88 | 89 | public void randomizeVelX() { 90 | 91 | velX = (float)(Math.random() * (3) + 1); 92 | 93 | } 94 | 95 | public void randomizeVelY() { 96 | 97 | velY = (float)(Math.random() * (3) + 1); 98 | 99 | } 100 | 101 | } 102 | -------------------------------------------------------------------------------- /src/com/multitask/dannystover/Stage3Enemies.java: -------------------------------------------------------------------------------- 1 | package com.multitask.dannystover; 2 | 3 | import java.awt.Color; 4 | import java.awt.Graphics; 5 | import java.awt.Rectangle; 6 | import java.awt.geom.Area; 7 | import java.awt.image.BufferedImage; 8 | import java.util.Random; 9 | 10 | public class Stage3Enemies extends StageEntities { 11 | 12 | private Updater updater; 13 | private Color objectColor; 14 | Random r = new Random(); 15 | private ScoreTracker scoreTracker; 16 | 17 | public Stage3Enemies(float ex, float wy, float wid, float ht, String role, Color c, Updater u, ScoreTracker st) { 18 | super(ex, wy, wid, ht, role); 19 | updater = u; 20 | objectColor = c; 21 | scoreTracker = st; 22 | 23 | velX = -3; 24 | } 25 | 26 | /* 27 | public Stage2Enemies(float ex, float wy, BufferedImage imagey, String role) { 28 | super(ex, wy, imagey, role); 29 | 30 | randomizeVelX(); 31 | } 32 | */ 33 | 34 | 35 | public Rectangle getRectBorder() { 36 | return new Rectangle((int)x, (int)y, (int)width, (int)height); 37 | 38 | } 39 | 40 | public Area getBorder() { 41 | return new Area(getRectBorder()); 42 | } 43 | 44 | 45 | public void update() { 46 | x += velX; 47 | 48 | if(x <= -100) 49 | updater.removeStageObject(this); 50 | if(scoreTracker.getStage() < 3) { 51 | updater.removeStageObject(this); 52 | } 53 | } 54 | 55 | public void render(Graphics g) { 56 | 57 | g.setColor(objectColor); 58 | g.fillRect((int)x, (int)y, (int)width, (int)height); 59 | 60 | } 61 | 62 | 63 | public void randomizeVelX() { 64 | 65 | velX = (float)(Math.random() * (3) + 1); 66 | 67 | } 68 | 69 | public void randomizeVelY() { 70 | 71 | velY = (float)(Math.random() * (3) + 1); 72 | 73 | } 74 | 75 | 76 | } 77 | -------------------------------------------------------------------------------- /src/com/multitask/dannystover/Stage4Enemies.java: -------------------------------------------------------------------------------- 1 | package com.multitask.dannystover; 2 | 3 | import java.awt.Color; 4 | import java.awt.Graphics; 5 | import java.awt.Rectangle; 6 | import java.awt.geom.Area; 7 | import java.awt.image.BufferedImage; 8 | import java.util.Random; 9 | 10 | public class Stage4Enemies extends StageEntities { 11 | 12 | private Updater updater; 13 | Random r = new Random(); 14 | private ScoreTracker scoreTracker; 15 | private int growTimer = 0; 16 | 17 | public Stage4Enemies(float ex, float wy, float wid, float ht, BufferedImage imagey, String role, Updater u, ScoreTracker st) { 18 | super(ex, wy, wid, ht, imagey, role); 19 | updater = u; 20 | scoreTracker = st; 21 | 22 | randomizeVelX(); 23 | randomizeVelY(); 24 | } 25 | 26 | /* 27 | public Stage2Enemies(float ex, float wy, BufferedImage imagey, String role) { 28 | super(ex, wy, imagey, role); 29 | 30 | randomizeVelX(); 31 | } 32 | */ 33 | 34 | 35 | public Rectangle getRectBorder() { 36 | return new Rectangle((int)x, (int)y, (int)width, (int)height); 37 | 38 | } 39 | 40 | public Area getBorder() { 41 | return new Area(getRectBorder()); 42 | } 43 | 44 | 45 | public void update() { 46 | x += velX; 47 | y += velY; 48 | 49 | growTimer++; 50 | 51 | if(growTimer >= 10) { 52 | width++; 53 | height++; 54 | if(growTimer >= 20) { 55 | growTimer = 0; 56 | } 57 | } 58 | 59 | if(x >= Multitask.WIDTH-200 || x <= 0) 60 | velX *= -1; 61 | 62 | if(y >= Multitask.HEIGHT-200 || y<= 0) 63 | velY *=-1; 64 | 65 | 66 | x = Multitask.setBounds(x, 0, Multitask.WIDTH - 200); 67 | y = Multitask.setBounds(y, 0, Multitask.HEIGHT - 200); 68 | 69 | if(scoreTracker.getStage() != 4) { 70 | updater.removeStageObject(this); 71 | } 72 | } 73 | 74 | public void render(Graphics g) { 75 | 76 | g.drawImage(image, (int)x, (int)y, (int)width, (int)height, null); 77 | 78 | } 79 | 80 | public void randomizeVelX() { 81 | 82 | velX = (float)(Math.random() * (7) - 4); 83 | 84 | } 85 | 86 | public void randomizeVelY() { 87 | 88 | velY = (float)(Math.random() * (7) - 4); 89 | 90 | } 91 | 92 | 93 | } 94 | -------------------------------------------------------------------------------- /src/com/multitask/dannystover/StageEntities.java: -------------------------------------------------------------------------------- 1 | package com.multitask.dannystover; 2 | 3 | import java.awt.Graphics; 4 | import java.awt.Polygon; 5 | import java.awt.geom.Area; 6 | import java.awt.image.BufferedImage; 7 | 8 | //every enemy and player created in this game will be a subclass of this abstract class so they 9 | //inherit all its methods and instance variables 10 | public abstract class StageEntities{ 11 | 12 | protected float x, y, velX, velY, width, height; 13 | protected String id; 14 | protected BufferedImage image; 15 | 16 | 17 | public StageEntities(float ex, float wy, float wid, float ht, BufferedImage imagey, String role) { 18 | x = ex; 19 | y = wy; 20 | image = imagey; 21 | id = role; 22 | width = wid; 23 | height = ht; 24 | } 25 | 26 | public StageEntities(float ex, float wy, float wid, float ht, String role) { 27 | x = ex; 28 | y = wy; 29 | id = role; 30 | width = wid; 31 | height = ht; 32 | } 33 | 34 | 35 | 36 | /* 37 | public StageEntities(float ex, float wy, BufferedImage imagey, String role) { 38 | x = ex; 39 | y = wy; 40 | image = imagey; 41 | id = role; 42 | } 43 | */ 44 | 45 | //subclasses must 46 | public abstract void update(); 47 | public abstract void render(Graphics g); 48 | public abstract Area getBorder(); 49 | abstract void randomizeVelX(); 50 | abstract void randomizeVelY(); 51 | 52 | //getter/accessor methods 53 | public float getX() { 54 | return x; 55 | } 56 | public float getY() { 57 | return y; 58 | } 59 | public BufferedImage getImage() { 60 | return image; 61 | } 62 | public float getVelX() { 63 | return velX; 64 | } 65 | public float getVelY() { 66 | return velY; 67 | } 68 | public float getWidth() { 69 | return width; 70 | } 71 | public float getHeight() { 72 | return height; 73 | } 74 | public String getRole() { 75 | return id; 76 | } 77 | 78 | //setter/mutator methods 79 | public void setX(float x1) { 80 | x = x1; 81 | } 82 | public void setY(float y1) { 83 | y = y1; 84 | } 85 | public void setVelX(float velocityX) { 86 | velX = velocityX; 87 | } 88 | public void setVelY(float velocityY) { 89 | velY = velocityY; 90 | } 91 | public void setImage(BufferedImage imageicon) { 92 | image = imageicon; 93 | } 94 | public void setWidth(float w) { 95 | width = w; 96 | } 97 | public void setHeight(float h) { 98 | height = h; 99 | } 100 | public void setRole(String role) { 101 | id = role; 102 | } 103 | 104 | 105 | } 106 | -------------------------------------------------------------------------------- /src/com/multitask/dannystover/Updater.java: -------------------------------------------------------------------------------- 1 | package com.multitask.dannystover; 2 | 3 | import java.awt.Graphics; 4 | import java.util.ArrayList; 5 | 6 | public class Updater { 7 | 8 | // this list is all the Updater is, it holds all the GameObjects in the game and 9 | // ensures they are updated each frame. 10 | ArrayList allStageObjects = new ArrayList(); 11 | 12 | // called in Multitask class by Updater 13 | // this stage1ObjectsUpdate method goes through each object and calls its 14 | // update() method, 15 | // updating it depending on what is in its update() method 16 | public void stage1ObjectsUpdate() { 17 | 18 | // loops through each object in ArrayList 19 | for (int i = 0; i < allStageObjects.size(); i++) { 20 | // sets temporary object holder to the current object in list, not necessary but 21 | // okay. 22 | StageEntities temp = allStageObjects.get(i); 23 | 24 | // runs the stage 1 object's update method 25 | if (temp.getRole().substring(0, 6).equals("Stage1")) 26 | temp.update(); 27 | } 28 | 29 | } 30 | 31 | public void stage2ObjectsUpdate() { 32 | 33 | // loops through each object in ArrayList 34 | for (int i = 0; i < allStageObjects.size(); i++) { 35 | // sets temporary object holder to the current object in list, not necessary but 36 | // easier. 37 | StageEntities temp = allStageObjects.get(i); 38 | 39 | // runs t 40 | if (temp.getRole().substring(0, 6).equals("Stage2")) 41 | temp.update(); 42 | } 43 | 44 | } 45 | public void stage3ObjectsUpdate() { 46 | 47 | // loops through each object in ArrayList 48 | for (int i = 0; i < allStageObjects.size(); i++) { 49 | // sets temporary object holder to the current object in list, not necessary but 50 | // easier. 51 | StageEntities temp = allStageObjects.get(i); 52 | 53 | // runs t 54 | if (temp.getRole().substring(0, 6).equals("Stage3")) 55 | temp.update(); 56 | } 57 | 58 | } 59 | 60 | public void stage4ObjectsUpdate() { 61 | 62 | // loops through each object in ArrayList 63 | for (int i = 0; i < allStageObjects.size(); i++) { 64 | // sets temporary object holder to the current object in list, not necessary but 65 | // easier. 66 | StageEntities temp = allStageObjects.get(i); 67 | 68 | // runs t 69 | if (temp.getRole().substring(0, 6).equals("Stage4")) 70 | temp.update(); 71 | } 72 | 73 | } 74 | 75 | // called in Multitask class by Updater 76 | // this stage1ObjectsRender method goes through each object and calls its own 77 | // render method for its graphics 78 | public void stage1ObjectsRender(Graphics g) { 79 | 80 | for (int i = 0; i < allStageObjects.size(); i++) { 81 | 82 | StageEntities temp = allStageObjects.get(i); 83 | 84 | // runs render method on all objects 85 | if (temp.getRole().substring(0, 6).equals("Stage1")) 86 | temp.render(g); 87 | } 88 | 89 | } 90 | 91 | public void stage2ObjectsRender(Graphics g) { 92 | 93 | for (int i = 0; i < allStageObjects.size(); i++) { 94 | 95 | StageEntities temp = allStageObjects.get(i); 96 | 97 | // runs render method on all objects 98 | if (temp.getRole().substring(0, 6).equals("Stage2")) 99 | temp.render(g); 100 | } 101 | 102 | } 103 | 104 | public void stage3ObjectsRender(Graphics g) { 105 | 106 | for (int i = 0; i < allStageObjects.size(); i++) { 107 | 108 | StageEntities temp = allStageObjects.get(i); 109 | 110 | // runs render method on all objects 111 | if (temp.getRole().substring(0, 6).equals("Stage3")) 112 | temp.render(g); 113 | } 114 | 115 | } 116 | 117 | public void stage4ObjectsRender(Graphics g) { 118 | 119 | for (int i = 0; i < allStageObjects.size(); i++) { 120 | 121 | StageEntities temp = allStageObjects.get(i); 122 | 123 | // runs render method on all objects 124 | if (temp.getRole().substring(0, 6).equals("Stage4")) 125 | temp.render(g); 126 | } 127 | 128 | } 129 | 130 | public void removeAllStage1Enemies() { 131 | for (int i = 0; i < allStageObjects.size(); i++) { 132 | StageEntities temp = allStageObjects.get(i); 133 | 134 | if (temp.getRole().equals("Stage1Enemy")) { 135 | removeStageObject(temp); 136 | } 137 | } 138 | } 139 | 140 | public void removeAllStage2Enemies() { 141 | for (int i = 0; i < allStageObjects.size(); i++) { 142 | StageEntities temp = allStageObjects.get(i); 143 | 144 | if (temp.getRole().equals("Stage2Enemy")) { 145 | removeStageObject(temp); 146 | } 147 | } 148 | } 149 | 150 | public void removeAllStage2Objects() { 151 | for (int i = 0; i < allStageObjects.size(); i++) { 152 | StageEntities temp = allStageObjects.get(i); 153 | 154 | if (temp.getRole().substring(0, 6).equals("Stage2")) { 155 | removeStageObject(temp); 156 | } 157 | } 158 | } 159 | 160 | public void removeAllObjects() { 161 | for (int i = 0; i < allStageObjects.size(); i++) { 162 | allStageObjects.remove(i); 163 | } 164 | } 165 | 166 | public void addStageObject(StageEntities object) { 167 | this.allStageObjects.add(object); 168 | } 169 | 170 | public void removeStageObject(StageEntities object) { 171 | this.allStageObjects.remove(object); 172 | } 173 | 174 | } 175 | -------------------------------------------------------------------------------- /src/com/multitask/dannystover/Window.java: -------------------------------------------------------------------------------- 1 | package com.multitask.dannystover; 2 | 3 | import java.awt.Canvas; 4 | import java.awt.Dimension; 5 | import java.awt.GridLayout; 6 | 7 | import javax.swing.JFrame; 8 | 9 | public class Window { 10 | 11 | private JFrame frame; 12 | 13 | public Window(int width, int height, String title, Multitask mainRunner) { 14 | 15 | JFrame frame = new JFrame(title); 16 | 17 | //set size of frame 18 | frame.setPreferredSize(new Dimension(width, height)); 19 | frame.setMaximumSize(new Dimension(width, height)); 20 | frame.setMinimumSize(new Dimension(width, height)); 21 | 22 | //x button, no resizing, center frame, add game into frame 23 | frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 24 | frame.setResizable(false); 25 | frame.setLocationRelativeTo(null); 26 | frame.add(mainRunner); 27 | 28 | //see it and run Game start method 29 | frame.setVisible(true); 30 | //THIS IS WHAT STARTS EVERYTHING IN THE GAME 31 | mainRunner.start(); 32 | } 33 | 34 | } 35 | 36 | 37 | -------------------------------------------------------------------------------- /stage1player final.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DstoverVT/Multitask/8cb5b862cec97d8208a4fae31df062fa442093e5/stage1player final.png -------------------------------------------------------------------------------- /stage2asteroid1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DstoverVT/Multitask/8cb5b862cec97d8208a4fae31df062fa442093e5/stage2asteroid1.png -------------------------------------------------------------------------------- /stage2asteroid2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DstoverVT/Multitask/8cb5b862cec97d8208a4fae31df062fa442093e5/stage2asteroid2.png -------------------------------------------------------------------------------- /stage2asteroid3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DstoverVT/Multitask/8cb5b862cec97d8208a4fae31df062fa442093e5/stage2asteroid3.png -------------------------------------------------------------------------------- /stage2asteroid4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DstoverVT/Multitask/8cb5b862cec97d8208a4fae31df062fa442093e5/stage2asteroid4.png -------------------------------------------------------------------------------- /stage2asteroid5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DstoverVT/Multitask/8cb5b862cec97d8208a4fae31df062fa442093e5/stage2asteroid5.png -------------------------------------------------------------------------------- /stage2asteroid6.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DstoverVT/Multitask/8cb5b862cec97d8208a4fae31df062fa442093e5/stage2asteroid6.png -------------------------------------------------------------------------------- /stage2player final.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DstoverVT/Multitask/8cb5b862cec97d8208a4fae31df062fa442093e5/stage2player final.png --------------------------------------------------------------------------------