public void shootProjectile() { // called when the player shoots (presses up) if (!playerProj.isVisible() && player.isVisible() && thereAreInvaders()) { // Cannot shoot during win time playerProjX = player.getPositionX() + 17; // Center playerProj.setPosition(playerProjX, PLAYER_START_Y); playerProj.setLocation(playerProjX, PLAYER_START_Y); playerProj.setVisible(true); // Start it from they player's x, and starting y (constant) } // The player cannot shoot while the projectile is visible (exists) }
public void moveProjectile() { // if the player's shot exists if (playerProj.isVisible()) { playerProj.setPositionY(playerProj.getPositionY() - 5); // Move it down (higher edge of the screen) playerProj.setLocation(playerProjX, playerProj.getPositionY()); // Check for hit checkForHit(); } if (playerProj.getPositionY() <= ceiling.getLocation().getY() + 5) { playerProj.setVisible(false); } checkForHit(); }
@Override public void actionPerformed(ActionEvent ae) { // Event cmd = ae.getActionCommand(); if (cmd.equals("Exit")) { playing = false; System.exit(0); } else if (cmd.equals("Easy")) { easy(); } else if (cmd.equals("Medium")) { medium(); } else if (cmd.equals("Hard")) { hard(); } else if (cmd.equals("Insane")) { insane(); } else if (cmd.equals("Restart")) { // Restart EVERYTHING speed = 20; playing = true; won = false; lost = false; for (int y = 0; y < 4; y++) { for (int x = 0; x < 10; x++) { enemies[y][x].setLocation(enemies[y][x].getStartX(), enemies[y][x].getStartY()); enemies[y][x].setPosition(enemies[y][x].getStartX(), enemies[y][x].getStartY()); enemies[y][x].resetHealth(); enemies[y][x].setVisible(true); } } for (int i = 0; i < 3; i++) { livesImages[i].setVisible(true); } for (int i = 0; i < projectileAmount; i++) { enemyProjX[i] = 0; enemyProj[i].setPosition(0, 0); enemyProj[i].setLocation(0, 0); enemyProj[i].setVisible(false); } playerProj.setVisible(false); playerProj.setPosition(PLAYER_START_X, PLAYER_START_Y); playerProj.setLocation(PLAYER_START_X, PLAYER_START_Y); outcomeLabel.setVisible(false); velocityX = 0; player.setLocation(PLAYER_START_X, PLAYER_START_Y); player.getPosition().setPosition(PLAYER_START_X, PLAYER_START_Y); playerProj.setVisible(false); playerProjX = player.getPositionX(); player.setVisible(true); lives = 2; score = 0; ticks = 0; direction = 1; // ask difficulty askDifficulty(); } }