From 2c2b269639d94c472f9e75d49ea572c7d8e96df2 Mon Sep 17 00:00:00 2001 From: jukanmi Date: Mon, 20 Nov 2023 10:52:55 +0900 Subject: [PATCH 1/2] implement split Function --- src/engine/DrawManager.java | 4 +- src/entity/BossShip.java | 29 +- src/entity/EnemyShip.java | 2 +- src/entity/EnemyShipFormation.java | 1279 ++++++++++++++-------------- 4 files changed, 692 insertions(+), 622 deletions(-) diff --git a/src/engine/DrawManager.java b/src/engine/DrawManager.java index c9c7ed3b..57ebe5d0 100644 --- a/src/engine/DrawManager.java +++ b/src/engine/DrawManager.java @@ -880,7 +880,7 @@ public void drawGameOver(final Screen screen, final boolean acceptsInput, Ship dummyShip2 = new Ship(0, 0, Color.RED, SpriteType.Ship, true); shipskin[i] = dummyShip; shipskin2[i] = dummyShip2; - // ์˜ˆ: ships[i] = new Ship(i * 50, 100, Color.GREEN, SpriteType.Ship, spriteData, false); + // ?˜ˆ: ships[i] = new Ship(i * 50, 100, Color.GREEN, SpriteType.Ship, spriteData, false); drawEntity(shipskin[i], screen.getWidth() / 4 - 13, 172 + 50*i); drawEntity(shipskin2[i], 3*screen.getWidth() / 4 - 13, 172 + 50*i); if(i !=5) { @@ -997,7 +997,7 @@ public void drawGameOver(final Screen screen, final boolean acceptsInput, for (int i = 0; i < 6; i++) { Ship dummyShip = new Ship(0, 0, Color.GREEN, SpriteType.Ship, false); shipskin[i] = dummyShip; - // ์˜ˆ: ships[i] = new Ship(i * 50, 100, Color.GREEN, SpriteType.Ship, spriteData, false); + // ?˜ˆ: ships[i] = new Ship(i * 50, 100, Color.GREEN, SpriteType.Ship, spriteData, false); drawEntity(shipskin[i], screen.getWidth() / 2 - 13, 172 + 50*i); if(i !=5) { try { diff --git a/src/entity/BossShip.java b/src/entity/BossShip.java index 3fe69b89..ea273d52 100644 --- a/src/entity/BossShip.java +++ b/src/entity/BossShip.java @@ -3,15 +3,40 @@ import engine.DrawManager; import engine.GameState; +import java.util.List; + public class BossShip extends EnemyShip { + /** Width of current screen. */ + private static final int WIDTH = 448; + /** Height of current screen. */ + private static final int HEIGHT = 520; + private int splitLevel; //silmeBoss public BossShip (final int positionX, final int positionY, - final DrawManager.SpriteType spriteType, final GameState gameState){ + final DrawManager.SpriteType spriteType, final GameState gameState, final int splitLevel){ super(positionX, positionY, spriteType, gameState); super.HP = 0;//๋”ฐ๋กœ ์ˆ˜์ •; super.pointValue = 0; //๋”ฐ๋กœ์ˆ˜์ • - + this.splitLevel = splitLevel; } + /** + * silmeBoss + * @param Enemyship list of enemy ships + */ + public void split(List Enemyship) { + int currentX = this.positionX, currentY = this.positionY; + if (this.splitLevel <= 0) return; + currentX += 10; + if (currentY < 20) currentY += 50; + if (WIDTH - 20 < currentY) currentY -= 50; + int firstY = currentY - 20, secondY = currentY + 20; + BossShip first = new BossShip(currentX, firstY, DrawManager.SpriteType.EnemyShipA1, this.gameState, this.splitLevel - 1); + BossShip second = new BossShip(currentX, secondY, DrawManager.SpriteType.EnemyShipA1, this.gameState, this.splitLevel - 1); + Enemyship.add(first); + Enemyship.add(second); + } + public void summon(List Enemyship){ + } } diff --git a/src/entity/EnemyShip.java b/src/entity/EnemyShip.java index 5d36702e..bb22f8e0 100644 --- a/src/entity/EnemyShip.java +++ b/src/entity/EnemyShip.java @@ -29,7 +29,7 @@ public class EnemyShip extends Entity { /** Checks if the ship has been hit by a bullet. */ private boolean isDestroyed; /** ๋‚œ์ด๋„ ์กฐ์ ˆ์— ์‚ฌ์šฉํ•  ํ˜„์žฌ ์Šคํ…Œ์ดํŠธ */ - private GameState gameState; + protected GameState gameState; /** Values of the ship, in points, when destroyed. */ protected int pointValue; diff --git a/src/entity/EnemyShipFormation.java b/src/entity/EnemyShipFormation.java index 86944923..37fb3970 100644 --- a/src/entity/EnemyShipFormation.java +++ b/src/entity/EnemyShipFormation.java @@ -1,630 +1,675 @@ package entity; +import engine.*; +import engine.DrawManager.SpriteType; import java.util.*; import java.util.logging.Logger; - -import engine.*; import screen.Screen; -import engine.DrawManager.SpriteType; /** * Groups enemy ships into a formation that moves together. - * + * * @author Roberto Izquierdo Amo - * + * */ public class EnemyShipFormation implements Iterable { - /** Initial position in the x-axis. */ - private static final int INIT_POS_X = 20; - /** Initial position in the y-axis. */ - private static final int INIT_POS_Y = 100; - /** Distance between ships. */ - private static final int SEPARATION_DISTANCE = 40; - /** Proportion of C-type ships. */ - private static final double PROPORTION_C = 0.2; - /** Proportion of B-type ships. */ - private static final double PROPORTION_B = 0.4; - /** Lateral speed of the formation. */ - private static final int X_SPEED = 8; - /** Downwards speed of the formation. */ - private static final int Y_SPEED = 4; - /** Proportion of differences between shooting times. */ - private static final double SHOOTING_VARIANCE = .2; - /** Margin on the sides of the screen. */ - private static final int SIDE_MARGIN = 20; - /** Margin on the bottom of the screen. */ - private static final int BOTTOM_MARGIN = 80; - /** Distance to go down each pass. */ - private static final int DESCENT_DISTANCE = 20; - /** Minimum speed allowed. */ - private static final int MINIMUM_SPEED = 10; - /** DrawManager instance. */ - private DrawManager drawManager; - /** Application logger. */ - private Logger logger; - /** Screen to draw ships on. */ - private Screen screen; - /** current gamestate*/ - private GameState gameState; - /** List of enemy ships forming the formation. */ - private List> enemyShips; - /** Minimum time between shots. */ - private Cooldown shootingCooldown; - /** Number of ships in the formation - horizontally. */ - private int nShipsWide; - /** Number of ships in the formation - vertically. */ - private int nShipsHigh; - /** Time between shots. */ - private int shootingInterval; - /** Variance in the time between shots. */ - private int shootingVariance; - /** Initial ship speed. */ - private int baseSpeed; - /** Speed of the ships. */ - private int movementSpeed; - /** Current direction the formation is moving on. */ - private Direction currentDirection; - /** Direction the formation was moving previously. */ - private Direction previousDirection; - /** Interval between movements, in frames. */ - private int movementInterval; - /** Total width of the formation. */ - private int width; - /** Total height of the formation. */ - private int height; - /** Position in the x-axis of the upper left corner of the formation. */ - private int positionX; - /** Position in the y-axis of the upper left corner of the formation. */ - private int positionY; - /** Width of one ship. */ - private int shipWidth; - /** Height of one ship. */ - private int shipHeight; - /** List of ships that are able to shoot. */ - private List shooters; - /** Number of not destroyed ships. */ - private int shipCount; - /** check where the last ship is. */ - private int flag = 1; - /** Speed of the bullets shot by the members. */ - private int bulletSpeed = 4; - /** need to make complex movements. */ - private boolean moreDiff = false; - /** speed of complex movements. */ - private int complexSpeed; - /** check the last stage. */ - private boolean lastStage = false; - /** setting the x position of the last stage ships. */ - private int setXpos; - /** track the y position of the last stage ships. */ - private int trackYpos; - /** check to print only one log: The last enemy ship moves faster. */ - private int checkFirst = 1; - - /** Directions the formation can move. */ - private enum Direction { - /** Movement to the right side of the screen. */ - RIGHT, - /** Movement to the left side of the screen. */ - LEFT, - /** Movement to the bottom of the screen. */ - DOWN - }; - - /** - * Constructor, sets the initial conditions. - * - * @param gameSettings - * Current game settings. - */ - public EnemyShipFormation(final GameSettings gameSettings, final GameState gameState) { - this.gameState = gameState; - this.drawManager = Core.getDrawManager(); - this.logger = Core.getLogger(); - this.enemyShips = new ArrayList>(); - this.currentDirection = Direction.RIGHT; - this.movementInterval = 0; - this.nShipsWide = gameSettings.getFormationWidth(); - this.nShipsHigh = gameSettings.getFormationHeight(); - this.shootingInterval = gameSettings.getShootingFrecuency(); - this.shootingVariance = (int) (gameSettings.getShootingFrecuency() - * SHOOTING_VARIANCE); - this.baseSpeed = gameSettings.getBaseSpeed(); - this.movementSpeed = this.baseSpeed; - this.positionX = INIT_POS_X; - this.positionY = INIT_POS_Y; - this.shooters = new ArrayList(); - this.setXpos = INIT_POS_X; - SpriteType spriteType; - - this.logger.info("Initializing " + nShipsWide + "x" + nShipsHigh - + " ship formation in (" + positionX + "," + positionY + ")"); - - // Each sub-list is a column on the formation. - for (int i = 0; i < this.nShipsWide; i++) - this.enemyShips.add(new ArrayList()); - - if (nShipsWide > 7) - lastStage = true; - - for (List column : this.enemyShips) { - int ship_index = 0; - for (int i = 0; i < this.nShipsHigh; i++) { - if (i / (float) this.nShipsHigh < PROPORTION_C) - spriteType = SpriteType.EnemyShipC1; - else if (i / (float) this.nShipsHigh < PROPORTION_B - + PROPORTION_C) - spriteType = SpriteType.EnemyShipB1; - else - spriteType = SpriteType.EnemyShipA1; - - EnemyShip enemyShip = null; - - // In the last stage, odd row ships initial position set differently. - if (lastStage) { - if (ship_index%2!=0) { - this.setXpos = 120; - } else { - this.setXpos = positionX; - } - } - - switch (spriteType) - { - case EnemyShipA1: - enemyShip = new EnemyShipA((SEPARATION_DISTANCE - * this.enemyShips.indexOf(column)) - + setXpos, (SEPARATION_DISTANCE * i) - + positionY, spriteType,gameState); - break; - case EnemyShipB1: - enemyShip = new EnemyShipB((SEPARATION_DISTANCE - * this.enemyShips.indexOf(column)) - + setXpos, (SEPARATION_DISTANCE * i) - + positionY, spriteType,gameState); - break; - case EnemyShipC1: - enemyShip = new EnemyShipC((SEPARATION_DISTANCE - * this.enemyShips.indexOf(column)) - + setXpos, (SEPARATION_DISTANCE * i) - + positionY, spriteType,gameState); - break; - default: - enemyShip = new EnemyShip((SEPARATION_DISTANCE - * this.enemyShips.indexOf(column)) - + setXpos, (SEPARATION_DISTANCE * i) - + positionY, spriteType,gameState); - } - column.add(enemyShip); - this.shipCount++; - ship_index++; - } - } - - this.shipWidth = this.enemyShips.get(0).get(0).getWidth(); - this.shipHeight = this.enemyShips.get(0).get(0).getHeight(); - - this.width = (this.nShipsWide - 1) * SEPARATION_DISTANCE - + this.shipWidth; - this.height = (this.nShipsHigh - 1) * SEPARATION_DISTANCE - + this.shipHeight; - - for (List column : this.enemyShips) - this.shooters.add(column.get(column.size() - 1)); - - if (nShipsHigh > 5) - moreDiff = true; - - if (moreDiff) - complexSpeed = 8; - else - complexSpeed = 0; - } - - /** - * Associates the formation to a given screen. - * - * @param newScreen - * Screen to attach. - */ - public final void attach(final Screen newScreen) { - screen = newScreen; - } - - /** - * Draws every individual component of the formation. - */ - public final void draw() { - for (List column : this.enemyShips) - for (EnemyShip enemyShip : column) - drawManager.drawEntity(enemyShip, enemyShip.getPositionX(), - enemyShip.getPositionY()); - } - - /** - * Updates the position of the ships. - */ - public final void update() { - if(this.shootingCooldown == null) { - this.shootingCooldown = Core.getVariableCooldown(shootingInterval, - shootingVariance); - this.shootingCooldown.reset(); - } - cleanUp(); - - int movementX = 0; - int movementY = 0; - double remainingProportion = (double) this.shipCount - / (this.nShipsHigh * this.nShipsWide); - this.movementSpeed = (int) (Math.pow(remainingProportion, 2) - * this.baseSpeed); - this.movementSpeed += MINIMUM_SPEED; - - /** If the number of remain enemyShip is one, it moves quickly in odd row. */ - if(shipCount == 1 && flag == 1){ - if(checkFirst==1){ - this.movementSpeed = 5; - this.logger.info("The last enemy ship moves faster"); - checkFirst++; - } - } - movementInterval++; - if (movementInterval >= this.movementSpeed) { - movementInterval = 0; - - // Consider irregular movements to prevent the formation from going out of the game screen. - if (moreDiff) - positionX += complexSpeed; - - boolean isAtBottom = positionY - + this.height > screen.getHeight() - BOTTOM_MARGIN; - boolean isAtRightSide = positionX - + this.width >= screen.getWidth() - SIDE_MARGIN; - boolean isAtLeftSide = positionX <= SIDE_MARGIN; - boolean isAtHorizontalAltitude = positionY % DESCENT_DISTANCE == 0; - - if (currentDirection == Direction.DOWN) { - if (isAtHorizontalAltitude) { - if (previousDirection == Direction.RIGHT) { - currentDirection = Direction.LEFT; - this.logger.info("Formation now moving left 1"); - } else { - currentDirection = Direction.RIGHT; - this.logger.info("Formation now moving right 2"); - } - } - } else if (currentDirection == Direction.LEFT) { - if (isAtLeftSide) { - if (!isAtBottom) { - previousDirection = currentDirection; - currentDirection = Direction.DOWN; - this.logger.info("Formation now moving down 3"); - trackYpos++; - } else { - currentDirection = Direction.RIGHT; - this.logger.info("Formation now moving right 4"); - } - /** if ship remains one switch flag. - * it works only on odd row - * */ - if (shipCount == 1) flag *= -1; - } - } else { - if (isAtRightSide) { - if (!isAtBottom) { - previousDirection = currentDirection; - currentDirection = Direction.DOWN; - this.logger.info("Formation now moving down 5"); - trackYpos++; - } else { - currentDirection = Direction.LEFT; - this.logger.info("Formation now moving left 6"); - } - /** if ship remains one switch flag. - * it works only on odd row - * */ - if(shipCount==1) flag*= -1; - } - } - - if (currentDirection == Direction.RIGHT) - movementX = X_SPEED; - else if (currentDirection == Direction.LEFT) - movementX = -X_SPEED; - else - movementY = Y_SPEED; - - positionX += movementX; - positionY += movementY; - - // Cleans explosions. - List destroyed; - for (List column : this.enemyShips) { - destroyed = new ArrayList(); - for (EnemyShip ship : column) { - if (ship != null && ship.isDestroyed()) { - destroyed.add(ship); - this.logger.info("Removed enemy " - + column.indexOf(ship) + " from column " - + this.enemyShips.indexOf(column)); - } - } - column.removeAll(destroyed); - } - - // From level 4, the ships moves more complicatedly. - if (moreDiff) { - for (List column : this.enemyShips) { - for (EnemyShip enemyShip : column) { - if ((int)((enemyShip.getpositionY()-100)/40)%2!=0) { - enemyShip.move(complexSpeed, 0); - } else - enemyShip.move(-complexSpeed, 0); - } - } - complexSpeed = -complexSpeed; - } - - // Change movementX value according to trackYpos variable only in last stage. - if (lastStage) { - if (trackYpos > 1) { - movementX = -movementX; - } - } - - for (List column : this.enemyShips) - for (EnemyShip enemyShip : column) { - // In the last stage, the enemy's ships started out in different positions, - // so their coordinates changed accordingly. - if (lastStage) { - if ((int)((enemyShip.getpositionY() - 100) / 40) % 2 != 0) { - enemyShip.move(-movementX, movementY); - } else { - enemyShip.move(movementX, movementY); - } - } else { - enemyShip.move(movementX, movementY); - } - enemyShip.update(); - } - } - } - - /** - * Cleans empty columns, adjusts the width and height of the formation. - */ - private void cleanUp() { - Set emptyColumns = new HashSet(); - int maxColumn = 0; - int minPositionY = Integer.MAX_VALUE; - for (List column : this.enemyShips) { - if (!column.isEmpty()) { - // Height of this column - int columnSize = column.get(column.size() - 1).positionY - - this.positionY + this.shipHeight; - maxColumn = Math.max(maxColumn, columnSize); - minPositionY = Math.min(minPositionY, column.get(0) - .getPositionY()); - } else { - // Empty column, we remove it. - emptyColumns.add(this.enemyShips.indexOf(column)); - } - } - for (int index : emptyColumns) { - this.enemyShips.remove(index); - logger.info("Removed column " + index); - } - - int leftMostPoint = 0; - int rightMostPoint = 0; - - for (List column : this.enemyShips) { - if (!column.isEmpty()) { - if (leftMostPoint == 0) - leftMostPoint = column.get(0).getPositionX(); - rightMostPoint = column.get(0).getPositionX(); - } - } - - this.width = rightMostPoint - leftMostPoint + this.shipWidth; - this.height = maxColumn; - - this.positionX = leftMostPoint; - this.positionY = minPositionY; - } - - /** - * Shoots a bullet downwards. - * - * @param bullets - * Bullets set to add the bullet being shot. - */ - public final void shoot(final Set bullets) { - // For now, only ships in the bottom row are able to shoot. - - if (this.shootingCooldown.checkFinished()) { - this.shootingCooldown.reset(); - /** if shipcount remains one, Bullet_speed is speed up. */ - if(shipCount == 1) { - if (flag == 1){ - bulletSpeed = 8; - } - else{ - bulletSpeed = 4; - } - } - ArrayList shot = new ArrayList<>();// ์ ์ด ํ•œ๋ฒˆ๋งŒ ๋ฐœ์‚ฌ - for (int i=0;i column : this.enemyShips) - for (int i = 0; i < column.size(); i++) - if (column.get(i).equals(destroyedShip)) { - column.get(i).destroy(); - int row = this.enemyShips.indexOf(column); - this.logger.info("Destroyed ship in (" - + row + "," + i + ")"); - } - - if (this.shooters.contains(destroyedShip)) { - int destroyedShipIndex = this.shooters.indexOf(destroyedShip); - int destroyedShipColumnIndex = -1; - - for (List column : this.enemyShips) - if (column.contains(destroyedShip)) { - destroyedShipColumnIndex = this.enemyShips.indexOf(column); - break; - } - - EnemyShip nextShooter = getNextShooter(this.enemyShips - .get(destroyedShipColumnIndex)); - - if (nextShooter != null) - this.shooters.set(destroyedShipIndex, nextShooter); - else { - this.shooters.remove(destroyedShipIndex); - this.logger.info("Shooters list reduced to " - + this.shooters.size() + " members."); - if (this.shooters.isEmpty()) - SoundManager.playSound("SFX/S_LevelClear", "level_start_count", false, false); - } - } - if (destroyedShip.isDestroyed()) this.shipCount--; - } - - /** - * Destroys a ship by bomb. - * - * @param destroyedShip - * Ship to be destroyed first. - * - * @return destroyedByBombEnemyShips - * List of Enemy ships destroyed by bomb. - */ - public final List destroyByBomb(final EnemyShip destroyedShip) { - List destroyedByBombEnemyShips = new ArrayList<>(); - int howManyEnemyIsDead = 0; - - int[] dx = {0, 0, 1, 1, 1, -1, -1, -1}; - int[] dy = {-1, 1, -1, 0, 1, -1, 0, 1}; - - for (int i = 0; i < this.enemyShips.size(); i++){ - for (int j = 0; j < this.enemyShips.get(i).size(); j++) { - if (this.enemyShips.get(i).get(j) == destroyedShip) { - destroyedByBombEnemyShips.add(this.enemyShips.get(i).get(j)); - this.enemyShips.get(i).get(j).destroyByBomb(); - this.logger.info("Destroyed ship in (" - + i + "," + j + ")"); - howManyEnemyIsDead++; - - int xPos = destroyedShip.positionX; - int yPos = destroyedShip.positionY; - - for(int n = 0; n < 8; n++){ - int nx = i + dx[n]; int ny = j + dy[n]; - if(!(nx >= 0 && nx <= this.enemyShips.size() - 1 && ny >= 0 && ny <= this.enemyShips.get(nx).size() - 1)) continue; - EnemyShip enemyShip = this.enemyShips.get(nx).get(ny); - if(enemyShip.positionX - xPos > 40 || enemyShip.positionX - xPos < -40) continue; - if(enemyShip.positionY - yPos > 40 || enemyShip.positionY - yPos < -40) continue; - if(enemyShip.isDestroyed()) continue; - - destroyedByBombEnemyShips.add(enemyShip); - enemyShip.destroyByBomb(); - this.logger.info("Destroyed ship in (" - + nx + "," + ny + ")"); - howManyEnemyIsDead++; - } - } - } - } - for(EnemyShip enemyShip : destroyedByBombEnemyShips) - if (this.shooters.contains(enemyShip)) { - int destroyedShipIndex = this.shooters.indexOf(enemyShip); - int destroyedShipColumnIndex = -1; - - for (List column : this.enemyShips) - if (column.contains(enemyShip)) { - destroyedShipColumnIndex = this.enemyShips.indexOf(column); - break; - } - - EnemyShip nextShooter = getNextShooter(this.enemyShips - .get(destroyedShipColumnIndex)); - - if (nextShooter != null) - this.shooters.set(destroyedShipIndex, nextShooter); - else { - this.shooters.remove(destroyedShipIndex); - this.logger.info("Shooters list reduced to " - + this.shooters.size() + " members."); - if (this.shooters.isEmpty()) - SoundManager.playSound("SFX/S_LevelClear", "level_start_count", false, false); - } - } - - this.shipCount -= howManyEnemyIsDead; - return destroyedByBombEnemyShips; - - } - - /** - * Gets the ship on a given column that will be in charge of shooting. - * - * @param column - * Column to search. - * @return New shooter ship. - */ - public final EnemyShip getNextShooter(final List column) { - Iterator iterator = column.iterator(); - EnemyShip nextShooter = null; - while (iterator.hasNext()) { - EnemyShip checkShip = iterator.next(); - if (checkShip != null && !checkShip.isDestroyed()) - nextShooter = checkShip; - } - - return nextShooter; - } - - /** - * Returns an iterator over the ships in the formation. - * - * @return Iterator over the enemy ships. - */ - @Override - public final Iterator iterator() { - Set enemyShipsList = new HashSet(); - - for (List column : this.enemyShips) - for (EnemyShip enemyShip : column) - enemyShipsList.add(enemyShip); - - return enemyShipsList.iterator(); - } - - /** - * Checks if there are any ships remaining. - * - * @return True when all ships have been destroyed. - */ - public final boolean isEmpty() { - return this.shipCount <= 0; - } + /** Initial position in the x-axis. */ + private static final int INIT_POS_X = 20; + /** Initial position in the y-axis. */ + private static final int INIT_POS_Y = 100; + /** Distance between ships. */ + private static final int SEPARATION_DISTANCE = 40; + /** Proportion of C-type ships. */ + private static final double PROPORTION_C = 0.2; + /** Proportion of B-type ships. */ + private static final double PROPORTION_B = 0.4; + /** Lateral speed of the formation. */ + private static final int X_SPEED = 8; + /** Downwards speed of the formation. */ + private static final int Y_SPEED = 4; + /** Proportion of differences between shooting times. */ + private static final double SHOOTING_VARIANCE = .2; + /** Margin on the sides of the screen. */ + private static final int SIDE_MARGIN = 20; + /** Margin on the bottom of the screen. */ + private static final int BOTTOM_MARGIN = 80; + /** Distance to go down each pass. */ + private static final int DESCENT_DISTANCE = 20; + /** Minimum speed allowed. */ + private static final int MINIMUM_SPEED = 10; + /** DrawManager instance. */ + private DrawManager drawManager; + /** Application logger. */ + private Logger logger; + /** Screen to draw ships on. */ + private Screen screen; + /** current gamestate*/ + private GameState gameState; + /** List of enemy ships forming the formation. */ + private List> enemyShips; + /** Minimum time between shots. */ + private Cooldown shootingCooldown; + /** Number of ships in the formation - horizontally. */ + private int nShipsWide; + /** Number of ships in the formation - vertically. */ + private int nShipsHigh; + /** Time between shots. */ + private int shootingInterval; + /** Variance in the time between shots. */ + private int shootingVariance; + /** Initial ship speed. */ + private int baseSpeed; + /** Speed of the ships. */ + private int movementSpeed; + /** Current direction the formation is moving on. */ + private Direction currentDirection; + /** Direction the formation was moving previously. */ + private Direction previousDirection; + /** Interval between movements, in frames. */ + private int movementInterval; + /** Total width of the formation. */ + private int width; + /** Total height of the formation. */ + private int height; + /** Position in the x-axis of the upper left corner of the formation. */ + private int positionX; + /** Position in the y-axis of the upper left corner of the formation. */ + private int positionY; + /** Width of one ship. */ + private int shipWidth; + /** Height of one ship. */ + private int shipHeight; + /** List of ships that are able to shoot. */ + private List shooters; + /** Number of not destroyed ships. */ + private int shipCount; + /** check where the last ship is. */ + private int flag = 1; + /** Speed of the bullets shot by the members. */ + private int bulletSpeed = 4; + /** need to make complex movements. */ + private boolean moreDiff = false; + /** speed of complex movements. */ + private int complexSpeed; + /** check the last stage. */ + private boolean lastStage = false; + /** setting the x position of the last stage ships. */ + private int setXpos; + /** track the y position of the last stage ships. */ + private int trackYpos; + /** check to print only one log: The last enemy ship moves faster. */ + private int checkFirst = 1; + + /** Directions the formation can move. */ + private enum Direction { + /** Movement to the right side of the screen. */ + RIGHT, + /** Movement to the left side of the screen. */ + LEFT, + /** Movement to the bottom of the screen. */ + DOWN, + } + + /** + * Constructor, sets the initial conditions. + * + * @param gameSettings + * Current game settings. + */ + public EnemyShipFormation( + final GameSettings gameSettings, + final GameState gameState + ) { + this.gameState = gameState; + this.drawManager = Core.getDrawManager(); + this.logger = Core.getLogger(); + this.enemyShips = new ArrayList>(); + this.currentDirection = Direction.RIGHT; + this.movementInterval = 0; + this.nShipsWide = gameSettings.getFormationWidth(); + this.nShipsHigh = gameSettings.getFormationHeight(); + this.shootingInterval = gameSettings.getShootingFrecuency(); + this.shootingVariance = + (int) (gameSettings.getShootingFrecuency() * SHOOTING_VARIANCE); + this.baseSpeed = gameSettings.getBaseSpeed(); + this.movementSpeed = this.baseSpeed; + this.positionX = INIT_POS_X; + this.positionY = INIT_POS_Y; + this.shooters = new ArrayList(); + this.setXpos = INIT_POS_X; + SpriteType spriteType; + + this.logger.info( + "Initializing " + + nShipsWide + + "x" + + nShipsHigh + + " ship formation in (" + + positionX + + "," + + positionY + + ")" + ); + + // Each sub-list is a column on the formation. + for (int i = 0; i < this.nShipsWide; i++) this.enemyShips.add( + new ArrayList() + ); + + if (nShipsWide > 7) lastStage = true; + + for (List column : this.enemyShips) { + int ship_index = 0; + for (int i = 0; i < this.nShipsHigh; i++) { + if (i / (float) this.nShipsHigh < PROPORTION_C) spriteType = + SpriteType.EnemyShipC1; else if ( + i / (float) this.nShipsHigh < PROPORTION_B + PROPORTION_C + ) spriteType = SpriteType.EnemyShipB1; else spriteType = + SpriteType.EnemyShipA1; + + EnemyShip enemyShip = null; + + // In the last stage, odd row ships initial position set differently. + if (lastStage) { + if (ship_index % 2 != 0) { + this.setXpos = 120; + } else { + this.setXpos = positionX; + } + } + + switch (spriteType) { + case EnemyShipA1: + enemyShip = + new EnemyShipA( + (SEPARATION_DISTANCE * this.enemyShips.indexOf(column)) + + setXpos, + (SEPARATION_DISTANCE * i) + positionY, + spriteType, + gameState + ); + break; + case EnemyShipB1: + enemyShip = + new EnemyShipB( + (SEPARATION_DISTANCE * this.enemyShips.indexOf(column)) + + setXpos, + (SEPARATION_DISTANCE * i) + positionY, + spriteType, + gameState + ); + break; + case EnemyShipC1: + enemyShip = + new EnemyShipC( + (SEPARATION_DISTANCE * this.enemyShips.indexOf(column)) + + setXpos, + (SEPARATION_DISTANCE * i) + positionY, + spriteType, + gameState + ); + break; + default: + enemyShip = + new EnemyShip( + (SEPARATION_DISTANCE * this.enemyShips.indexOf(column)) + + setXpos, + (SEPARATION_DISTANCE * i) + positionY, + spriteType, + gameState + ); + } + column.add(enemyShip); + this.shipCount++; + ship_index++; + } + } + + this.shipWidth = this.enemyShips.get(0).get(0).getWidth(); + this.shipHeight = this.enemyShips.get(0).get(0).getHeight(); + + this.width = (this.nShipsWide - 1) * SEPARATION_DISTANCE + this.shipWidth; + this.height = (this.nShipsHigh - 1) * SEPARATION_DISTANCE + this.shipHeight; + + for (List column : this.enemyShips) this.shooters.add( + column.get(column.size() - 1) + ); + + if (nShipsHigh > 5) moreDiff = true; + + if (moreDiff) complexSpeed = 8; else complexSpeed = 0; + } + + /** + * Associates the formation to a given screen. + * + * @param newScreen + * Screen to attach. + */ + public final void attach(final Screen newScreen) { + screen = newScreen; + } + + /** + * Draws every individual component of the formation. + */ + public final void draw() { + for (List column : this.enemyShips) for (EnemyShip enemyShip : column) drawManager.drawEntity( + enemyShip, + enemyShip.getPositionX(), + enemyShip.getPositionY() + ); + } + + /** + * Updates the position of the ships. + */ + public final void update() { + if (this.shootingCooldown == null) { + this.shootingCooldown = + Core.getVariableCooldown(shootingInterval, shootingVariance); + this.shootingCooldown.reset(); + } + cleanUp(); + + int movementX = 0; + int movementY = 0; + double remainingProportion = (double) this.shipCount / + (this.nShipsHigh * this.nShipsWide); + this.movementSpeed = + (int) (Math.pow(remainingProportion, 2) * this.baseSpeed); + this.movementSpeed += MINIMUM_SPEED; + + /** If the number of remain enemyShip is one, it moves quickly in odd row. */ + if (shipCount == 1 && flag == 1) { + if (checkFirst == 1) { + this.movementSpeed = 5; + this.logger.info("The last enemy ship moves faster"); + checkFirst++; + } + } + movementInterval++; + if (movementInterval >= this.movementSpeed) { + movementInterval = 0; + + // Consider irregular movements to prevent the formation from going out of the game screen. + if (moreDiff) positionX += complexSpeed; + + boolean isAtBottom = + positionY + this.height > screen.getHeight() - BOTTOM_MARGIN; + boolean isAtRightSide = + positionX + this.width >= screen.getWidth() - SIDE_MARGIN; + boolean isAtLeftSide = positionX <= SIDE_MARGIN; + boolean isAtHorizontalAltitude = positionY % DESCENT_DISTANCE == 0; + + if (currentDirection == Direction.DOWN) { + if (isAtHorizontalAltitude) { + if (previousDirection == Direction.RIGHT) { + currentDirection = Direction.LEFT; + this.logger.info("Formation now moving left 1"); + } else { + currentDirection = Direction.RIGHT; + this.logger.info("Formation now moving right 2"); + } + } + } else if (currentDirection == Direction.LEFT) { + if (isAtLeftSide) { + if (!isAtBottom) { + previousDirection = currentDirection; + currentDirection = Direction.DOWN; + this.logger.info("Formation now moving down 3"); + trackYpos++; + } else { + currentDirection = Direction.RIGHT; + this.logger.info("Formation now moving right 4"); + } + /** if ship remains one switch flag. + * it works only on odd row + * */ + if (shipCount == 1) flag *= -1; + } + } else { + if (isAtRightSide) { + if (!isAtBottom) { + previousDirection = currentDirection; + currentDirection = Direction.DOWN; + this.logger.info("Formation now moving down 5"); + trackYpos++; + } else { + currentDirection = Direction.LEFT; + this.logger.info("Formation now moving left 6"); + } + /** if ship remains one switch flag. + * it works only on odd row + * */ + if (shipCount == 1) flag *= -1; + } + } + + if (currentDirection == Direction.RIGHT) movementX = X_SPEED; else if ( + currentDirection == Direction.LEFT + ) movementX = -X_SPEED; else movementY = Y_SPEED; + + positionX += movementX; + positionY += movementY; + + // Cleans explosions. + List destroyed; + for (List column : this.enemyShips) { + destroyed = new ArrayList(); + for (EnemyShip ship : column) { + if (ship != null && ship.isDestroyed()) { + destroyed.add(ship); + this.logger.info( + "Removed enemy " + + column.indexOf(ship) + + " from column " + + this.enemyShips.indexOf(column) + ); + } + } + column.removeAll(destroyed); + } + + // From level 4, the ships moves more complicatedly. + if (moreDiff) { + for (List column : this.enemyShips) { + for (EnemyShip enemyShip : column) { + if ((int) ((enemyShip.getpositionY() - 100) / 40) % 2 != 0) { + enemyShip.move(complexSpeed, 0); + } else enemyShip.move(-complexSpeed, 0); + } + } + complexSpeed = -complexSpeed; + } + + // Change movementX value according to trackYpos variable only in last stage. + if (lastStage) { + if (trackYpos > 1) { + movementX = -movementX; + } + } + + for (List column : this.enemyShips) for (EnemyShip enemyShip : column) { + // In the last stage, the enemy's ships started out in different positions, + // so their coordinates changed accordingly. + if (lastStage) { + if ((int) ((enemyShip.getpositionY() - 100) / 40) % 2 != 0) { + enemyShip.move(-movementX, movementY); + } else { + enemyShip.move(movementX, movementY); + } + } else { + enemyShip.move(movementX, movementY); + } + enemyShip.update(); + } + } + } + + /** + * Cleans empty columns, adjusts the width and height of the formation. + */ + private void cleanUp() { + Set emptyColumns = new HashSet(); + int maxColumn = 0; + int minPositionY = Integer.MAX_VALUE; + for (List column : this.enemyShips) { + if (!column.isEmpty()) { + // Height of this column + int columnSize = + column.get(column.size() - 1).positionY - + this.positionY + + this.shipHeight; + maxColumn = Math.max(maxColumn, columnSize); + minPositionY = Math.min(minPositionY, column.get(0).getPositionY()); + } else { + // Empty column, we remove it. + emptyColumns.add(this.enemyShips.indexOf(column)); + } + } + for (int index : emptyColumns) { + this.enemyShips.remove(index); + logger.info("Removed column " + index); + } + + int leftMostPoint = 0; + int rightMostPoint = 0; + + for (List column : this.enemyShips) { + if (!column.isEmpty()) { + if (leftMostPoint == 0) leftMostPoint = column.get(0).getPositionX(); + rightMostPoint = column.get(0).getPositionX(); + } + } + + this.width = rightMostPoint - leftMostPoint + this.shipWidth; + this.height = maxColumn; + + this.positionX = leftMostPoint; + this.positionY = minPositionY; + } + + /** + * Shoots a bullet downwards. + * + * @param bullets + * Bullets set to add the bullet being shot. + */ + public final void shoot(final Set bullets) { + // For now, only ships in the bottom row are able to shoot. + + if (this.shootingCooldown.checkFinished()) { + this.shootingCooldown.reset(); + /** if shipcount remains one, Bullet_speed is speed up. */ + if (shipCount == 1) { + if (flag == 1) { + bulletSpeed = 8; + } else { + bulletSpeed = 4; + } + } + ArrayList shot = new ArrayList<>(); // ? ?ด ?•œ๋ฒˆ๋งŒ ๋ฐœ์‚ฌ + for (int i = 0; i < this.shooters.size(); i++) shot.add(false); + for (int i = 0; i < gameState.getLevel(); i++) { + int index = (int) (Math.random() * (this.shooters.size() - 1)); + if (shot.get(index)) continue; + shot.set(index, true); + EnemyShip shooter = this.shooters.get(index); + shooter.shoot(bullets, shootingCooldown); + SoundManager.playSound("SFX/S_Enemy_Shoot", "EnemyShoot", false, false); + } + } + } + + /** + * Destroys a ship. + * + * @param destroyedShip + * Ship to be destroyed. + */ + public final void destroy(final EnemyShip destroyedShip) { + for (List column : this.enemyShips) for ( + int i = 0; + i < column.size(); + i++ + ) if (column.get(i).equals(destroyedShip)) { + column.get(i).destroy(); + int row = this.enemyShips.indexOf(column); + this.logger.info("Destroyed ship in (" + row + "," + i + ")"); + } + + if (this.shooters.contains(destroyedShip)) { + int destroyedShipIndex = this.shooters.indexOf(destroyedShip); + int destroyedShipColumnIndex = -1; + + for (List column : this.enemyShips) if ( + column.contains(destroyedShip) + ) { + destroyedShipColumnIndex = this.enemyShips.indexOf(column); + break; + } + + EnemyShip nextShooter = getNextShooter( + this.enemyShips.get(destroyedShipColumnIndex) + ); + + if (nextShooter != null) this.shooters.set( + destroyedShipIndex, + nextShooter + ); else { + this.shooters.remove(destroyedShipIndex); + this.logger.info( + "Shooters list reduced to " + this.shooters.size() + " members." + ); + if (this.shooters.isEmpty()) SoundManager.playSound( + "SFX/S_LevelClear", + "level_start_count", + false, + false + ); + } + } + if (destroyedShip.isDestroyed()) this.shipCount--; + } + + /** + * Destroys a ship by bomb. + * + * @param destroyedShip + * Ship to be destroyed first. + * + * @return destroyedByBombEnemyShips + * List of Enemy ships destroyed by bomb. + */ + public final List destroyByBomb(final EnemyShip destroyedShip) { + List destroyedByBombEnemyShips = new ArrayList<>(); + int howManyEnemyIsDead = 0; + + int[] dx = { 0, 0, 1, 1, 1, -1, -1, -1 }; + int[] dy = { -1, 1, -1, 0, 1, -1, 0, 1 }; + + for (int i = 0; i < this.enemyShips.size(); i++) { + for (int j = 0; j < this.enemyShips.get(i).size(); j++) { + if (this.enemyShips.get(i).get(j) == destroyedShip) { + destroyedByBombEnemyShips.add(this.enemyShips.get(i).get(j)); + this.enemyShips.get(i).get(j).destroyByBomb(); + this.logger.info("Destroyed ship in (" + i + "," + j + ")"); + howManyEnemyIsDead++; + + int xPos = destroyedShip.positionX; + int yPos = destroyedShip.positionY; + + for (int n = 0; n < 8; n++) { + int nx = i + dx[n]; + int ny = j + dy[n]; + if ( + !( + nx >= 0 && + nx <= this.enemyShips.size() - 1 && + ny >= 0 && + ny <= this.enemyShips.get(nx).size() - 1 + ) + ) continue; + EnemyShip enemyShip = this.enemyShips.get(nx).get(ny); + if ( + enemyShip.positionX - xPos > 40 || + enemyShip.positionX - xPos < -40 + ) continue; + if ( + enemyShip.positionY - yPos > 40 || + enemyShip.positionY - yPos < -40 + ) continue; + if (enemyShip.isDestroyed()) continue; + + destroyedByBombEnemyShips.add(enemyShip); + enemyShip.destroyByBomb(); + this.logger.info("Destroyed ship in (" + nx + "," + ny + ")"); + howManyEnemyIsDead++; + } + } + } + } + for (EnemyShip enemyShip : destroyedByBombEnemyShips) if ( + this.shooters.contains(enemyShip) + ) { + int destroyedShipIndex = this.shooters.indexOf(enemyShip); + int destroyedShipColumnIndex = -1; + + for (List column : this.enemyShips) if ( + column.contains(enemyShip) + ) { + destroyedShipColumnIndex = this.enemyShips.indexOf(column); + break; + } + + EnemyShip nextShooter = getNextShooter( + this.enemyShips.get(destroyedShipColumnIndex) + ); + + if (nextShooter != null) this.shooters.set( + destroyedShipIndex, + nextShooter + ); else { + this.shooters.remove(destroyedShipIndex); + this.logger.info( + "Shooters list reduced to " + this.shooters.size() + " members." + ); + if (this.shooters.isEmpty()) SoundManager.playSound( + "SFX/S_LevelClear", + "level_start_count", + false, + false + ); + } + } + + this.shipCount -= howManyEnemyIsDead; + return destroyedByBombEnemyShips; + } + + /** + * Gets the ship on a given column that will be in charge of shooting. + * + * @param column + * Column to search. + * @return New shooter ship. + */ + public final EnemyShip getNextShooter(final List column) { + Iterator iterator = column.iterator(); + EnemyShip nextShooter = null; + while (iterator.hasNext()) { + EnemyShip checkShip = iterator.next(); + if (checkShip != null && !checkShip.isDestroyed()) nextShooter = + checkShip; + } + + return nextShooter; + } + + /** + * Returns an iterator over the ships in the formation. + * + * @return Iterator over the enemy ships. + */ + @Override + public final Iterator iterator() { + Set enemyShipsList = new HashSet(); + + for (List column : this.enemyShips) for (EnemyShip enemyShip : column) enemyShipsList.add( + enemyShip + ); + + return enemyShipsList.iterator(); + } + + /** + * Checks if there are any ships remaining. + * + * @return True when all ships have been destroyed. + */ + public final boolean isEmpty() { + return this.shipCount <= 0; + } } From dd33e8b6455b635f542c6fbc089c13b5c1cfd57a Mon Sep 17 00:00:00 2001 From: jukanmi Date: Wed, 22 Nov 2023 14:45:51 +0900 Subject: [PATCH 2/2] addBossClassDefalut --- src/engine/GameSettings.java | 4 +- src/entity/BossShip.java | 35 ++++++++++++--- src/entity/EnemyShip.java | 2 +- src/entity/EnemyShipA.java | 68 ++++++++++++++++++------------ src/entity/EnemyShipFormation.java | 31 +------------- 5 files changed, 73 insertions(+), 67 deletions(-) diff --git a/src/engine/GameSettings.java b/src/engine/GameSettings.java index b333c547..042cebc8 100644 --- a/src/engine/GameSettings.java +++ b/src/engine/GameSettings.java @@ -18,6 +18,7 @@ public class GameSettings { private int shootingFrecuency; /** Speed of item dropping. */ private double itemSpeed; + private boolean bossStage; /** * Constructor. * @@ -31,12 +32,13 @@ public class GameSettings { * Frecuency of enemy shootings, +/- 30%. */ public GameSettings(final int formationWidth, final int formationHeight, - final int baseSpeed, final int shootingFrecuency, final double itemSpeed) { + final int baseSpeed, final int shootingFrecuency, final double itemSpeed, final boolean bossStage) { this.formationWidth = formationWidth; this.formationHeight = formationHeight; this.baseSpeed = baseSpeed; this.shootingFrecuency = shootingFrecuency; this.itemSpeed = itemSpeed; + this.bossStage = bossStage; } /** diff --git a/src/entity/BossShip.java b/src/entity/BossShip.java index ea273d52..cbc33f2a 100644 --- a/src/entity/BossShip.java +++ b/src/entity/BossShip.java @@ -3,28 +3,32 @@ import engine.DrawManager; import engine.GameState; +import java.util.ArrayList; import java.util.List; public class BossShip extends EnemyShip { + private List SplitList; + private final int SpeedX = -2; /** Width of current screen. */ private static final int WIDTH = 448; /** Height of current screen. */ private static final int HEIGHT = 520; + private int splitLevel; - private int splitLevel; //silmeBoss public BossShip (final int positionX, final int positionY, final DrawManager.SpriteType spriteType, final GameState gameState, final int splitLevel){ super(positionX, positionY, spriteType, gameState); super.HP = 0;//๋”ฐ๋กœ ์ˆ˜์ •; super.pointValue = 0; //๋”ฐ๋กœ์ˆ˜์ • this.splitLevel = splitLevel; + SplitList = new ArrayList<>(); + SplitList.add(this); } /** - * silmeBoss - * @param Enemyship list of enemy ships + * when slime Boss dead this function */ - public void split(List Enemyship) { + public void split() { int currentX = this.positionX, currentY = this.positionY; if (this.splitLevel <= 0) return; currentX += 10; @@ -33,10 +37,27 @@ public void split(List Enemyship) { int firstY = currentY - 20, secondY = currentY + 20; BossShip first = new BossShip(currentX, firstY, DrawManager.SpriteType.EnemyShipA1, this.gameState, this.splitLevel - 1); BossShip second = new BossShip(currentX, secondY, DrawManager.SpriteType.EnemyShipA1, this.gameState, this.splitLevel - 1); - Enemyship.add(first); - Enemyship.add(second); + SplitList.add(first); + SplitList.add(second); } - public void summon(List Enemyship){ + /** + * when Boss Die this function execute + */ + public void Death(){ + + } + + /** + * when Boss attack this function execute + */ + public void Attack() { + + } + + /** + * when Boss attack this function execute + */ + public void Move(){ } } diff --git a/src/entity/EnemyShip.java b/src/entity/EnemyShip.java index bb22f8e0..921d63fb 100644 --- a/src/entity/EnemyShip.java +++ b/src/entity/EnemyShip.java @@ -27,7 +27,7 @@ public class EnemyShip extends Entity { /** Cooldown between sprite changes. */ protected Cooldown animationCooldown; /** Checks if the ship has been hit by a bullet. */ - private boolean isDestroyed; + protected boolean isDestroyed; /** ๋‚œ์ด๋„ ์กฐ์ ˆ์— ์‚ฌ์šฉํ•  ํ˜„์žฌ ์Šคํ…Œ์ดํŠธ */ protected GameState gameState; /** Values of the ship, in points, when destroyed. */ diff --git a/src/entity/EnemyShipA.java b/src/entity/EnemyShipA.java index ed87e210..546cfb20 100644 --- a/src/entity/EnemyShipA.java +++ b/src/entity/EnemyShipA.java @@ -3,38 +3,50 @@ import engine.Cooldown; import engine.DrawManager; import engine.GameState; - import java.util.Set; public class EnemyShipA extends EnemyShip { - /** HP์˜ ๋ฐฐ์œจ */ - private final double HPPOWER = .8; - /** ์ด์•Œ์˜ ์†๋„ ๋ฐฐ์œจ */ - private final double BULLETSPEEDPOWER = 0.5; - /** ์ŠˆํŒ… ์ฟจ๋‹ค์šด ๋ฐฐ์œจ */ - private final double BULLETCOOLDOWN = 0; - /** ์ œ๊ฑฐ์‹œ ์˜ฌ๋ผ๊ฐ€๋Š” ์ ์ˆ˜ */ - private final int POINT = 30; - public EnemyShipA(final int positionX, final int positionY, - final DrawManager.SpriteType spriteType, final GameState gameState) { - super(positionX, positionY, spriteType, gameState); - super.HP = (int)(super.HP * HPPOWER); - super.pointValue = POINT; - } + /** HPภว น่ภฒ */ + private final double HPPOWER = .8; + /** รัพหภว ผำตต น่ภฒ */ + private final double BULLETSPEEDPOWER = 5; + /** ฝดฦร ฤ๐ดูฟ๎ น่ภฒ */ + private final double BULLETCOOLDOWN = 0; + /** มฆฐลฝร ฟรถ๓ฐกดย มกผ๖ */ + private final int POINT = 30; - public final void update() { - if (this.animationCooldown.checkFinished()) { - this.animationCooldown.reset(); - if (spriteType == DrawManager.SpriteType.EnemyShipA1) - spriteType = DrawManager.SpriteType.EnemyShipA2; - else - spriteType = DrawManager.SpriteType.EnemyShipA1; - } - } - public final void shoot(final Set bullets, Cooldown shootingCooldown) { - bullets.add(BulletPool.getBullet(positionX - + width / 2, positionY, (int)(super.BULLET_SPEED * BULLETSPEEDPOWER),0)); - shootingCooldown.timedown(BULLETCOOLDOWN); + public EnemyShipA( + final int positionX, + final int positionY, + final DrawManager.SpriteType spriteType, + final GameState gameState + ) { + super(positionX, positionY, spriteType, gameState); + super.HP = (int) (super.HP * HPPOWER); + super.pointValue = POINT; + } + + public final void update() { + if (this.animationCooldown.checkFinished()) { + this.animationCooldown.reset(); + if (spriteType == DrawManager.SpriteType.EnemyShipA1) spriteType = + DrawManager.SpriteType.EnemyShipA2; else spriteType = + DrawManager.SpriteType.EnemyShipA1; } + } + public final void shoot( + final Set bullets, + Cooldown shootingCooldown + ) { + bullets.add( + BulletPool.getBullet( + positionX + width / 2, + positionY, + (int) (super.BULLET_SPEED * BULLETSPEEDPOWER), + 0 + ) + ); + shootingCooldown.timedown(BULLETCOOLDOWN); + } } diff --git a/src/entity/EnemyShipFormation.java b/src/entity/EnemyShipFormation.java index 37fb3970..180ce295 100644 --- a/src/entity/EnemyShipFormation.java +++ b/src/entity/EnemyShipFormation.java @@ -92,8 +92,6 @@ public class EnemyShipFormation implements Iterable { private boolean moreDiff = false; /** speed of complex movements. */ private int complexSpeed; - /** check the last stage. */ - private boolean lastStage = false; /** setting the x position of the last stage ships. */ private int setXpos; /** track the y position of the last stage ships. */ @@ -157,8 +155,6 @@ public EnemyShipFormation( new ArrayList() ); - if (nShipsWide > 7) lastStage = true; - for (List column : this.enemyShips) { int ship_index = 0; for (int i = 0; i < this.nShipsHigh; i++) { @@ -170,14 +166,6 @@ public EnemyShipFormation( EnemyShip enemyShip = null; - // In the last stage, odd row ships initial position set differently. - if (lastStage) { - if (ship_index % 2 != 0) { - this.setXpos = 120; - } else { - this.setXpos = positionX; - } - } switch (spriteType) { case EnemyShipA1: @@ -384,25 +372,8 @@ public final void update() { complexSpeed = -complexSpeed; } - // Change movementX value according to trackYpos variable only in last stage. - if (lastStage) { - if (trackYpos > 1) { - movementX = -movementX; - } - } - for (List column : this.enemyShips) for (EnemyShip enemyShip : column) { - // In the last stage, the enemy's ships started out in different positions, - // so their coordinates changed accordingly. - if (lastStage) { - if ((int) ((enemyShip.getpositionY() - 100) / 40) % 2 != 0) { - enemyShip.move(-movementX, movementY); - } else { - enemyShip.move(movementX, movementY); - } - } else { - enemyShip.move(movementX, movementY); - } + enemyShip.move(movementX, movementY); enemyShip.update(); } }