From ad03760f379bdff842f03973aec5849c9700c273 Mon Sep 17 00:00:00 2001 From: rasauq1122 Date: Tue, 8 Dec 2020 17:50:49 +0900 Subject: [PATCH 1/7] =?UTF-8?q?Feat:=20GameScreen=20=EB=82=B4=20=EC=88=98?= =?UTF-8?q?=ED=8F=89=EC=84=A0=20=EB=82=AE=EC=B6=94=EA=B8=B0=20=EB=B0=8F=20?= =?UTF-8?q?=EA=B7=B8=EC=97=90=20=EB=94=B0=EB=A5=B8=20=EC=84=B8=EB=B6=80=20?= =?UTF-8?q?=EC=A1=B0=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit JIRA ISSUE KEY : IN-21 --- src/entity/EnemyShip.java | 3 ++- src/entity/EnemyShipFormation.java | 3 ++- src/screen/GameScreen.java | 6 +++--- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/entity/EnemyShip.java b/src/entity/EnemyShip.java index 19d9958ad..fa6ea7f9a 100644 --- a/src/entity/EnemyShip.java +++ b/src/entity/EnemyShip.java @@ -5,6 +5,7 @@ import engine.Cooldown; import engine.Core; import engine.DrawManager.SpriteType; +import screen.GameScreen; /** * Implements a enemy ship, to be destroyed by the player. @@ -72,7 +73,7 @@ public EnemyShip(final int positionX, final int positionY, * known starting properties. */ public EnemyShip() { - super(-32, 60, 16 * 2, 7 * 2, Color.RED); + super(-32, 60 + GameScreen.SEPARATION_LINE_HEIGHT, 16 * 2, 7 * 2, Color.RED); this.spriteType = SpriteType.EnemyShipSpecial; this.isDestroyed = false; diff --git a/src/entity/EnemyShipFormation.java b/src/entity/EnemyShipFormation.java index 04bf96326..7785c6ec4 100644 --- a/src/entity/EnemyShipFormation.java +++ b/src/entity/EnemyShipFormation.java @@ -7,6 +7,7 @@ import java.util.Set; import java.util.logging.Logger; +import screen.GameScreen; import screen.Screen; import engine.Cooldown; import engine.Core; @@ -25,7 +26,7 @@ public class EnemyShipFormation implements Iterable { /** Initial position in the x-axis. */ private static final int INIT_POS_X = 20; /** Initial position in the x-axis. */ - private static final int INIT_POS_Y = 100; + private static final int INIT_POS_Y = 100 + GameScreen.SEPARATION_LINE_HEIGHT; /** Distance between ships. */ private static final int SEPARATION_DISTANCE = 40; /** Proportion of C-type ships. */ diff --git a/src/screen/GameScreen.java b/src/screen/GameScreen.java index 4e76259d0..1d34f4c09 100644 --- a/src/screen/GameScreen.java +++ b/src/screen/GameScreen.java @@ -36,7 +36,7 @@ public class GameScreen extends Screen { /** Time from finishing the level to screen change. */ private static final int SCREEN_CHANGE_INTERVAL = 1500; /** Height of the interface separation line. */ - private static final int SEPARATION_LINE_HEIGHT = 40; + public static final int SEPARATION_LINE_HEIGHT = 40; /** Current game difficulty settings. */ private GameSettings gameSettings; @@ -232,7 +232,7 @@ private void draw() { // Interface. drawManager.drawScore(this, this.score); drawManager.drawLives(this, this.lives); - drawManager.drawHorizontalLine(this, SEPARATION_LINE_HEIGHT - 1); + drawManager.drawHorizontalLine(this, 2*SEPARATION_LINE_HEIGHT - 1); // Countdown to game start. if (!this.inputDelay.checkFinished()) { @@ -257,7 +257,7 @@ private void cleanBullets() { Set recyclable = new HashSet(); for (Bullet bullet : this.bullets) { bullet.update(); - if (bullet.getPositionY() < SEPARATION_LINE_HEIGHT + if (bullet.getPositionY() < 2*SEPARATION_LINE_HEIGHT || bullet.getPositionY() > this.height) recyclable.add(bullet); } From a9a4e6ee35dc55a3c2bb8b8a286f81e15c215322 Mon Sep 17 00:00:00 2001 From: rasauq1122 Date: Tue, 8 Dec 2020 18:10:23 +0900 Subject: [PATCH 2/7] =?UTF-8?q?Feat:=20GameState=20=EA=B5=AC=EC=A1=B0=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD=20=EB=B0=8F=20=ED=95=B4=EB=8B=B9=20=ED=81=B4?= =?UTF-8?q?=EB=9E=98=EC=8A=A4=EB=A5=BC=20=EC=82=AC=EC=9A=A9=ED=95=98?= =?UTF-8?q?=EB=8A=94=20=EB=A9=94=EC=86=8C=EB=93=9C=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit JIRA ISSUE KEY : IN-22 --- src/engine/Core.java | 32 ++++++++----- src/engine/GameState.java | 91 +++++++++++++++++++++++++++---------- src/screen/GameScreen.java | 10 ++-- src/screen/ScoreScreen.java | 10 ++-- 4 files changed, 98 insertions(+), 45 deletions(-) diff --git a/src/engine/Core.java b/src/engine/Core.java index 35cc8274c..47cb585ac 100644 --- a/src/engine/Core.java +++ b/src/engine/Core.java @@ -116,7 +116,7 @@ public static void main(final String[] args) { int returnCode = 1; do { - gameState = new GameState(1, 0, MAX_LIVES, 0, 0); + gameState = new GameState(1, 0, MAX_LIVES, 0, 0, 0, MAX_LIVES, 0, 0); switch (returnCode) { case 1: @@ -133,7 +133,7 @@ public static void main(final String[] args) { // One extra live every few levels. boolean bonusLife = gameState.getLevel() % EXTRA_LIFE_FRECUENCY == 0 - && gameState.getLivesRemaining() < MAX_LIVES; + && gameState.getLivesRemainingP1() < MAX_LIVES; // will remove currentScreen = new GameScreen(gameState, gameSettings.get(gameState.getLevel() - 1), @@ -146,20 +146,30 @@ public static void main(final String[] args) { gameState = ((GameScreen) currentScreen).getGameState(); gameState = new GameState(gameState.getLevel() + 1, - gameState.getScore(), - gameState.getLivesRemaining(), - gameState.getBulletsShot(), - gameState.getShipsDestroyed()); + gameState.getScoreP1(), + gameState.getLivesRemainingP1(), + gameState.getBulletsShotP1(), + gameState.getShipsDestroyedP1(), + gameState.getScoreP2(), + gameState.getLivesRemainingP2(), + gameState.getBulletsShotP2(), + gameState.getShipsDestroyedP2()); - } while (gameState.getLivesRemaining() > 0 + } while (gameState.getLivesRemainingP1() > 0 // will remove && gameState.getLevel() <= NUM_LEVELS); LOGGER.info("Starting " + WIDTH + "x" + HEIGHT + " score screen at " + FPS + " fps, with a score of " - + gameState.getScore() + ", " - + gameState.getLivesRemaining() + " lives remaining, " - + gameState.getBulletsShot() + " bullets shot and " - + gameState.getShipsDestroyed() + " ships destroyed."); + + gameState.getScoreP1() + ", " + + gameState.getLivesRemainingP1() + " lives remaining, " + + gameState.getBulletsShotP1() + " bullets shot and " + + gameState.getShipsDestroyedP1() + " ships destroyed."); + LOGGER.info("PLAYER 2 " + WIDTH + "x" + HEIGHT + + " score screen at " + FPS + " fps, with a score of " + + gameState.getScoreP2() + ", " + + gameState.getLivesRemainingP2() + " lives remaining, " + + gameState.getBulletsShotP2() + " bullets shot and " + + gameState.getShipsDestroyedP2() + " ships destroyed."); currentScreen = new ScoreScreen(width, height, FPS, gameState); returnCode = frame.setScreen(currentScreen); LOGGER.info("Closing score screen."); diff --git a/src/engine/GameState.java b/src/engine/GameState.java index 03fe4ebe8..de71a52dd 100644 --- a/src/engine/GameState.java +++ b/src/engine/GameState.java @@ -10,15 +10,23 @@ public class GameState { /** Current game level. */ private int level; - /** Current score. */ - private int score; - /** Lives currently remaining. */ - private int livesRemaining; - /** Bullets shot until now. */ - private int bulletsShot; - /** Ships destroyed until now. */ - private int shipsDestroyed; - + /** Current score by p1. */ + private int score_p1; + /** Lives currently remaining by p1. */ + private int livesRemaining_p1; + /** Bullets shot until now by p1. */ + private int bulletsShot_p1; + /** Ships destroyed until now by p1. */ + private int shipsDestroyed_p1; + /** Current score by p2. */ + private int score_p2; + /** Lives currently remaining by p2. */ + private int livesRemaining_p2; + /** Bullets shot until now by p2. */ + private int bulletsShot_p2; + /** Ships destroyed until now by p2. */ + private int shipsDestroyed_p2; + /** * Constructor. * @@ -33,14 +41,20 @@ public class GameState { * @param shipsDestroyed * Ships destroyed until now. */ - public GameState(final int level, final int score, - final int livesRemaining, final int bulletsShot, - final int shipsDestroyed) { + public GameState(final int level, final int score_p1, + final int livesRemaining_p1, final int bulletsShot_p1, + final int shipsDestroyed_p1,final int score_p2, + final int livesRemaining_p2, final int bulletsShot_p2, + final int shipsDestroyed_p2) { this.level = level; - this.score = score; - this.livesRemaining = livesRemaining; - this.bulletsShot = bulletsShot; - this.shipsDestroyed = shipsDestroyed; + this.score_p1 = score_p1; + this.livesRemaining_p1 = livesRemaining_p1; + this.bulletsShot_p1 = bulletsShot_p1; + this.shipsDestroyed_p1 = shipsDestroyed_p1; + this.score_p2 = score_p2; + this.livesRemaining_p2 = livesRemaining_p2; + this.bulletsShot_p2 = bulletsShot_p2; + this.shipsDestroyed_p2 = shipsDestroyed_p2; } /** @@ -53,29 +67,56 @@ public final int getLevel() { /** * @return the score */ - public final int getScore() { - return score; + public final int getScoreP1() { + return score_p1; } /** * @return the livesRemaining */ - public final int getLivesRemaining() { - return livesRemaining; + public final int getLivesRemainingP1() { + return livesRemaining_p1; } /** * @return the bulletsShot */ - public final int getBulletsShot() { - return bulletsShot; + public final int getBulletsShotP1() { + return bulletsShot_p1; } /** * @return the shipsDestroyed */ - public final int getShipsDestroyed() { - return shipsDestroyed; + public final int getShipsDestroyedP1() { + return shipsDestroyed_p2; + } + + /** + * @return the score + */ + public final int getScoreP2() { + return score_p2; + } + + /** + * @return the livesRemaining + */ + public final int getLivesRemainingP2() { + return livesRemaining_p2; } -} + /** + * @return the bulletsShot + */ + public final int getBulletsShotP2() { + return bulletsShot_p2; + } + + /** + * @return the shipsDestroyed + */ + public final int getShipsDestroyedP2() { + return shipsDestroyed_p2; + } +} \ No newline at end of file diff --git a/src/screen/GameScreen.java b/src/screen/GameScreen.java index 1d34f4c09..662100f84 100644 --- a/src/screen/GameScreen.java +++ b/src/screen/GameScreen.java @@ -95,12 +95,12 @@ public GameScreen(final GameState gameState, this.gameSettings = gameSettings; this.bonusLife = bonusLife; this.level = gameState.getLevel(); - this.score = gameState.getScore(); - this.lives = gameState.getLivesRemaining(); + this.score = gameState.getScoreP1(); + this.lives = gameState.getLivesRemainingP1(); if (this.bonusLife) this.lives++; - this.bulletsShot = gameState.getBulletsShot(); - this.shipsDestroyed = gameState.getShipsDestroyed(); + this.bulletsShot = gameState.getBulletsShotP1(); + this.shipsDestroyed = gameState.getShipsDestroyedP1(); } /** @@ -336,6 +336,8 @@ private boolean checkCollision(final Entity a, final Entity b) { */ public final GameState getGameState() { return new GameState(this.level, this.score, this.lives, + this.bulletsShot, this.shipsDestroyed, + this.score, this.lives, this.bulletsShot, this.shipsDestroyed); } } \ No newline at end of file diff --git a/src/screen/ScoreScreen.java b/src/screen/ScoreScreen.java index ff215715d..8a7a61e4b 100644 --- a/src/screen/ScoreScreen.java +++ b/src/screen/ScoreScreen.java @@ -62,10 +62,10 @@ public ScoreScreen(final int width, final int height, final int fps, final GameState gameState) { super(width, height, fps); - this.score = gameState.getScore(); - this.livesRemaining = gameState.getLivesRemaining(); - this.bulletsShot = gameState.getBulletsShot(); - this.shipsDestroyed = gameState.getShipsDestroyed(); + this.score = gameState.getScoreP1(); + this.livesRemaining = gameState.getLivesRemainingP1(); + this.bulletsShot = gameState.getBulletsShotP1(); + this.shipsDestroyed = gameState.getShipsDestroyedP1(); this.isNewRecord = false; this.name = "AAA".toCharArray(); this.nameCharSelected = 0; @@ -180,4 +180,4 @@ private void draw() { drawManager.completeDrawing(this); } -} +} \ No newline at end of file From 5b83aba83888e0e3f58fec5b9ef44abb9de6a757 Mon Sep 17 00:00:00 2001 From: rasauq1122 Date: Tue, 8 Dec 2020 18:13:54 +0900 Subject: [PATCH 3/7] =?UTF-8?q?Feat:=20Player=201,=202=20=EB=B3=80?= =?UTF-8?q?=EC=88=98=20=EB=B0=8F=20=EC=9D=B4=EB=8F=99=20=ED=82=A4=20?= =?UTF-8?q?=EB=B6=84=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit JIRA ISSUE KEY : IN-16 --- src/engine/DrawManager.java | 12 +-- src/screen/GameScreen.java | 143 ++++++++++++++++++++++++------------ 2 files changed, 103 insertions(+), 52 deletions(-) diff --git a/src/engine/DrawManager.java b/src/engine/DrawManager.java index 3d61ca503..76f71980e 100644 --- a/src/engine/DrawManager.java +++ b/src/engine/DrawManager.java @@ -236,10 +236,10 @@ private void drawGrid(final Screen screen) { * @param score * Current score. */ - public void drawScore(final Screen screen, final int score) { + public void drawScore(Screen screen, int player1, int player2) { backBufferGraphics.setFont(fontRegular); backBufferGraphics.setColor(Color.WHITE); - String scoreString = String.format("%04d", score); + String scoreString = String.format("%04d", player1); backBufferGraphics.drawString(scoreString, screen.getWidth() - 60, 25); } @@ -251,12 +251,12 @@ public void drawScore(final Screen screen, final int score) { * @param lives * Current lives. */ - public void drawLives(final Screen screen, final int lives) { + public void drawLives(Screen screen, int player1, int player2) { backBufferGraphics.setFont(fontRegular); backBufferGraphics.setColor(Color.WHITE); - backBufferGraphics.drawString(Integer.toString(lives), 20, 25); + backBufferGraphics.drawString(Integer.toString(player1), 20, 25); Ship dummyShip = new Ship(0, 0); - for (int i = 0; i < lives; i++) + for (int i = 0; i < player1; i++) drawEntity(dummyShip, 40 + 35 * i, 10); } @@ -559,4 +559,4 @@ else if (number != 0) drawCenteredBigString(screen, "GO!", screen.getHeight() / 2 + fontBigMetrics.getHeight() / 3); } -} +} \ No newline at end of file diff --git a/src/screen/GameScreen.java b/src/screen/GameScreen.java index 662100f84..190aec5db 100644 --- a/src/screen/GameScreen.java +++ b/src/screen/GameScreen.java @@ -45,7 +45,9 @@ public class GameScreen extends Screen { /** Formation of enemy ships. */ private EnemyShipFormation enemyShipFormation; /** Player's ship. */ - private Ship ship; + private Ship ship_1; + /** Player's ship. */ + private Ship ship_2; /** Bonus enemy ship that appears sometimes. */ private EnemyShip enemyShipSpecial; /** Minimum time between bonus ship appearances. */ @@ -57,13 +59,21 @@ public class GameScreen extends Screen { /** Set of all bullets fired by on screen ships. */ private Set bullets; /** Current score. */ - private int score; + private int score_p1; + /** Player lives left. */ + private int lives_p1; + /** Total bullets shot by the player. */ + private int bulletsShot_p1; + /** Total ships destroyed by the player. */ + private int shipsDestroyed_p1; + /** Current score. */ + private int score_p2; /** Player lives left. */ - private int lives; + private int lives_p2; /** Total bullets shot by the player. */ - private int bulletsShot; + private int bulletsShot_p2; /** Total ships destroyed by the player. */ - private int shipsDestroyed; + private int shipsDestroyed_p2; /** Moment the game starts. */ private long gameStartTime; /** Checks if the level is finished. */ @@ -95,12 +105,19 @@ public GameScreen(final GameState gameState, this.gameSettings = gameSettings; this.bonusLife = bonusLife; this.level = gameState.getLevel(); - this.score = gameState.getScoreP1(); - this.lives = gameState.getLivesRemainingP1(); + this.score_p1 = gameState.getScoreP1(); + this.lives_p1 = gameState.getLivesRemainingP1(); + if (this.bonusLife) + this.lives_p1++; // will remove + this.bulletsShot_p1 = gameState.getBulletsShotP1(); + this.shipsDestroyed_p1 = gameState.getShipsDestroyedP1(); + + this.score_p2 = gameState.getScoreP2(); + this.lives_p2 = gameState.getLivesRemainingP2(); if (this.bonusLife) - this.lives++; - this.bulletsShot = gameState.getBulletsShotP1(); - this.shipsDestroyed = gameState.getShipsDestroyedP1(); + this.lives_p2++; // will remove + this.bulletsShot_p2 = gameState.getBulletsShotP2(); + this.shipsDestroyed_p2 = gameState.getShipsDestroyedP2(); } /** @@ -111,7 +128,8 @@ public final void initialize() { enemyShipFormation = new EnemyShipFormation(this.gameSettings); enemyShipFormation.attach(this); - this.ship = new Ship(this.width / 2, this.height - 30); + this.ship_1 = new Ship(this.width / 2, this.height - 30); + this.ship_2 = new Ship(this.width / 2, this.height - 30); // will change // Appears each 10-30 seconds. this.enemyShipSpecialCooldown = Core.getVariableCooldown( BONUS_SHIP_INTERVAL, BONUS_SHIP_VARIANCE); @@ -135,8 +153,10 @@ public final void initialize() { public final int run() { super.run(); - this.score += LIFE_SCORE * (this.lives - 1); - this.logger.info("Screen cleared with a score of " + this.score); + this.score_p1 += LIFE_SCORE * (this.lives_p1 - 1); // will remove? + this.logger.info("Screen cleared with a score of " + this.score_p1); + this.score_p2 += LIFE_SCORE * (this.lives_p2 - 1); // will remove? + this.logger.info("Screen cleared with a score of " + this.score_p2); return this.returnCode; } @@ -148,27 +168,45 @@ protected final void update() { super.update(); if (this.inputDelay.checkFinished() && !this.levelFinished) { + + if (!this.ship_1.isDestroyed()) { + boolean moveRight = inputManager.isKeyDown(KeyEvent.VK_D); + boolean moveLeft = inputManager.isKeyDown(KeyEvent.VK_A); - if (!this.ship.isDestroyed()) { - boolean moveRight = inputManager.isKeyDown(KeyEvent.VK_RIGHT) - || inputManager.isKeyDown(KeyEvent.VK_D); - boolean moveLeft = inputManager.isKeyDown(KeyEvent.VK_LEFT) - || inputManager.isKeyDown(KeyEvent.VK_A); + boolean isRightBorder = this.ship_1.getPositionX() + + this.ship_1.getWidth() + this.ship_1.getSpeed() > this.width - 1; + boolean isLeftBorder = this.ship_1.getPositionX() + - this.ship_1.getSpeed() < 1; + + if (moveRight && !isRightBorder) { + this.ship_1.moveRight(); + } + if (moveLeft && !isLeftBorder) { + this.ship_1.moveLeft(); + } + if (inputManager.isKeyDown(KeyEvent.VK_G)) + if (this.ship_1.shoot(this.bullets)) + this.bulletsShot_p1++; + } + + if (!this.ship_2.isDestroyed()) { + boolean moveRight = inputManager.isKeyDown(KeyEvent.VK_RIGHT); + boolean moveLeft = inputManager.isKeyDown(KeyEvent.VK_LEFT); - boolean isRightBorder = this.ship.getPositionX() - + this.ship.getWidth() + this.ship.getSpeed() > this.width - 1; - boolean isLeftBorder = this.ship.getPositionX() - - this.ship.getSpeed() < 1; + boolean isRightBorder = this.ship_2.getPositionX() + + this.ship_2.getWidth() + this.ship_2.getSpeed() > this.width - 1; + boolean isLeftBorder = this.ship_2.getPositionX() + - this.ship_2.getSpeed() < 1; if (moveRight && !isRightBorder) { - this.ship.moveRight(); + this.ship_2.moveRight(); } if (moveLeft && !isLeftBorder) { - this.ship.moveLeft(); + this.ship_2.moveLeft(); } - if (inputManager.isKeyDown(KeyEvent.VK_SPACE)) - if (this.ship.shoot(this.bullets)) - this.bulletsShot++; + if (inputManager.isKeyDown(KeyEvent.VK_SLASH)) + if (this.ship_2.shoot(this.bullets)) + this.bulletsShot_p2++; } if (this.enemyShipSpecial != null) { @@ -190,7 +228,8 @@ else if (this.enemyShipSpecialExplosionCooldown.checkFinished()) this.logger.info("The special ship has escaped"); } - this.ship.update(); + this.ship_1.update(); + this.ship_2.update(); this.enemyShipFormation.update(); this.enemyShipFormation.shoot(this.bullets); } @@ -199,7 +238,7 @@ else if (this.enemyShipSpecialExplosionCooldown.checkFinished()) cleanBullets(); draw(); - if ((this.enemyShipFormation.isEmpty() || this.lives == 0) + if ((this.enemyShipFormation.isEmpty() || this.lives_p1 == 0) // will change && !this.levelFinished) { this.levelFinished = true; this.screenFinishedCooldown.reset(); @@ -216,8 +255,10 @@ else if (this.enemyShipSpecialExplosionCooldown.checkFinished()) private void draw() { drawManager.initDrawing(this); - drawManager.drawEntity(this.ship, this.ship.getPositionX(), - this.ship.getPositionY()); + drawManager.drawEntity(this.ship_1, this.ship_1.getPositionX(), + this.ship_1.getPositionY()); + drawManager.drawEntity(this.ship_2, this.ship_2.getPositionX(), + this.ship_2.getPositionY()); if (this.enemyShipSpecial != null) drawManager.drawEntity(this.enemyShipSpecial, this.enemyShipSpecial.getPositionX(), @@ -230,8 +271,8 @@ private void draw() { bullet.getPositionY()); // Interface. - drawManager.drawScore(this, this.score); - drawManager.drawLives(this, this.lives); + drawManager.drawScore(this, this.score_p1, this.score_p2); + drawManager.drawLives(this, this.lives_p1, this.lives_p2); drawManager.drawHorizontalLine(this, 2*SEPARATION_LINE_HEIGHT - 1); // Countdown to game start. @@ -272,12 +313,21 @@ private void manageCollisions() { Set recyclable = new HashSet(); for (Bullet bullet : this.bullets) if (bullet.getSpeed() > 0) { - if (checkCollision(bullet, this.ship) && !this.levelFinished) { + if (checkCollision(bullet, this.ship_1) && !this.levelFinished) { + recyclable.add(bullet); + if (!this.ship_1.isDestroyed()) { + this.ship_1.destroy(); + this.lives_p1--; + this.logger.info("Hit on player ship, " + this.lives_p1 + + " lives remaining."); + } + } + if (checkCollision(bullet, this.ship_2) && !this.levelFinished) { recyclable.add(bullet); - if (!this.ship.isDestroyed()) { - this.ship.destroy(); - this.lives--; - this.logger.info("Hit on player ship, " + this.lives + if (!this.ship_2.isDestroyed()) { + this.ship_2.destroy(); + this.lives_p2--; + this.logger.info("Hit on player ship, " + this.lives_p2 + " lives remaining."); } } @@ -285,20 +335,21 @@ private void manageCollisions() { for (EnemyShip enemyShip : this.enemyShipFormation) if (!enemyShip.isDestroyed() && checkCollision(bullet, enemyShip)) { - this.score += enemyShip.getPointValue(); - this.shipsDestroyed++; + this.score_p1 += enemyShip.getPointValue(); + this.shipsDestroyed_p1++; this.enemyShipFormation.destroy(enemyShip); recyclable.add(bullet); } if (this.enemyShipSpecial != null && !this.enemyShipSpecial.isDestroyed() && checkCollision(bullet, this.enemyShipSpecial)) { - this.score += this.enemyShipSpecial.getPointValue(); - this.shipsDestroyed++; + this.score_p1 += this.enemyShipSpecial.getPointValue(); + this.shipsDestroyed_p1++; this.enemyShipSpecial.destroy(); this.enemyShipSpecialExplosionCooldown.reset(); recyclable.add(bullet); } + // will check bullet owner } this.bullets.removeAll(recyclable); BulletPool.recycle(recyclable); @@ -335,9 +386,9 @@ private boolean checkCollision(final Entity a, final Entity b) { * @return Current game state. */ public final GameState getGameState() { - return new GameState(this.level, this.score, this.lives, - this.bulletsShot, this.shipsDestroyed, - this.score, this.lives, - this.bulletsShot, this.shipsDestroyed); + return new GameState(this.level, this.score_p1, this.lives_p1, + this.bulletsShot_p1, this.shipsDestroyed_p1, + this.score_p2, this.lives_p2, + this.bulletsShot_p2, this.shipsDestroyed_p2); } } \ No newline at end of file From 86354b7aa40d643fcd3a76edbc54f5433c5aeb1e Mon Sep 17 00:00:00 2001 From: rasauq1122 Date: Tue, 8 Dec 2020 18:26:58 +0900 Subject: [PATCH 4/7] =?UTF-8?q?Feat:=20Player=202=EC=9D=98=20Ship=20?= =?UTF-8?q?=EC=83=89=EA=B9=94=EC=9D=80=20=EB=85=B8=EB=9E=80=EC=83=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit JIRA ISSUE KEY : IN-25 --- src/engine/DrawManager.java | 2 +- src/entity/Ship.java | 6 +++--- src/screen/GameScreen.java | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/engine/DrawManager.java b/src/engine/DrawManager.java index 76f71980e..226398de0 100644 --- a/src/engine/DrawManager.java +++ b/src/engine/DrawManager.java @@ -255,7 +255,7 @@ public void drawLives(Screen screen, int player1, int player2) { backBufferGraphics.setFont(fontRegular); backBufferGraphics.setColor(Color.WHITE); backBufferGraphics.drawString(Integer.toString(player1), 20, 25); - Ship dummyShip = new Ship(0, 0); + Ship dummyShip = new Ship(0, 0, true); for (int i = 0; i < player1; i++) drawEntity(dummyShip, 40 + 35 * i, 10); } diff --git a/src/entity/Ship.java b/src/entity/Ship.java index fd007fde1..a205dbbf2 100644 --- a/src/entity/Ship.java +++ b/src/entity/Ship.java @@ -35,8 +35,8 @@ public class Ship extends Entity { * @param positionY * Initial position of the ship in the Y axis. */ - public Ship(final int positionX, final int positionY) { - super(positionX, positionY, 13 * 2, 8 * 2, Color.GREEN); + public Ship(final int positionX, final int positionY, final boolean isPlayer1) { + super(positionX, positionY, 13 * 2, 8 * 2, (isPlayer1 ? Color.GREEN : Color.YELLOW)); this.spriteType = SpriteType.Ship; this.shootingCooldown = Core.getCooldown(SHOOTING_INTERVAL); @@ -110,4 +110,4 @@ public final boolean isDestroyed() { public final int getSpeed() { return SPEED; } -} +} \ No newline at end of file diff --git a/src/screen/GameScreen.java b/src/screen/GameScreen.java index 190aec5db..d6cbf63e1 100644 --- a/src/screen/GameScreen.java +++ b/src/screen/GameScreen.java @@ -128,8 +128,8 @@ public final void initialize() { enemyShipFormation = new EnemyShipFormation(this.gameSettings); enemyShipFormation.attach(this); - this.ship_1 = new Ship(this.width / 2, this.height - 30); - this.ship_2 = new Ship(this.width / 2, this.height - 30); // will change + this.ship_1 = new Ship(this.width / 2, this.height - 30, true); + this.ship_2 = new Ship(this.width / 2, this.height - 30, false); // will change // Appears each 10-30 seconds. this.enemyShipSpecialCooldown = Core.getVariableCooldown( BONUS_SHIP_INTERVAL, BONUS_SHIP_VARIANCE); From 1dd8d7fe0592faa29710d26912629308be206cab Mon Sep 17 00:00:00 2001 From: rasauq1122 Date: Tue, 8 Dec 2020 19:12:40 +0900 Subject: [PATCH 5/7] =?UTF-8?q?Feat:=20Bullet=EC=9D=B4=20=EC=96=B4?= =?UTF-8?q?=EB=96=A4=20Ship=EC=9C=BC=EB=A1=9C=EB=B6=80=ED=84=B0=20?= =?UTF-8?q?=EB=B0=9C=EC=82=AC=EB=90=90=EB=8A=94=EC=A7=80=20=EA=B5=AC?= =?UTF-8?q?=EB=B6=84=ED=95=98=EA=B3=A0=20=EA=B7=B8=EC=97=90=20=EB=94=B0?= =?UTF-8?q?=EB=A5=B8=20=EC=A0=90=EC=88=98=20=ED=9A=8D=EB=93=9D=20=EC=A1=B0?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit JIRA ISSUE KEY : IN-26 --- src/screen/GameScreen.java | 156 ++++++++++++++++++++++++++----------- 1 file changed, 112 insertions(+), 44 deletions(-) diff --git a/src/screen/GameScreen.java b/src/screen/GameScreen.java index d6cbf63e1..eab9b5939 100644 --- a/src/screen/GameScreen.java +++ b/src/screen/GameScreen.java @@ -57,7 +57,11 @@ public class GameScreen extends Screen { /** Time from finishing the level to screen change. */ private Cooldown screenFinishedCooldown; /** Set of all bullets fired by on screen ships. */ - private Set bullets; + private Set bullets_en; + /** Set of all bullets fired by on screen ships. */ + private Set bullets_p1; + /** Set of all bullets fired by on screen ships. */ + private Set bullets_p2; /** Current score. */ private int score_p1; /** Player lives left. */ @@ -129,7 +133,7 @@ public final void initialize() { enemyShipFormation = new EnemyShipFormation(this.gameSettings); enemyShipFormation.attach(this); this.ship_1 = new Ship(this.width / 2, this.height - 30, true); - this.ship_2 = new Ship(this.width / 2, this.height - 30, false); // will change + this.ship_2 = new Ship(this.width / 2, this.height - 30, false); // Appears each 10-30 seconds. this.enemyShipSpecialCooldown = Core.getVariableCooldown( BONUS_SHIP_INTERVAL, BONUS_SHIP_VARIANCE); @@ -137,7 +141,9 @@ public final void initialize() { this.enemyShipSpecialExplosionCooldown = Core .getCooldown(BONUS_SHIP_EXPLOSION); this.screenFinishedCooldown = Core.getCooldown(SCREEN_CHANGE_INTERVAL); - this.bullets = new HashSet(); + this.bullets_p1 = new HashSet(); + this.bullets_p2 = new HashSet(); + this.bullets_en = new HashSet(); // Special input delay / countdown. this.gameStartTime = System.currentTimeMillis(); @@ -185,7 +191,7 @@ protected final void update() { this.ship_1.moveLeft(); } if (inputManager.isKeyDown(KeyEvent.VK_G)) - if (this.ship_1.shoot(this.bullets)) + if (this.ship_1.shoot(this.bullets_p1)) this.bulletsShot_p1++; } @@ -205,7 +211,7 @@ protected final void update() { this.ship_2.moveLeft(); } if (inputManager.isKeyDown(KeyEvent.VK_SLASH)) - if (this.ship_2.shoot(this.bullets)) + if (this.ship_2.shoot(this.bullets_p2)) this.bulletsShot_p2++; } @@ -231,7 +237,7 @@ else if (this.enemyShipSpecialExplosionCooldown.checkFinished()) this.ship_1.update(); this.ship_2.update(); this.enemyShipFormation.update(); - this.enemyShipFormation.shoot(this.bullets); + this.enemyShipFormation.shoot(this.bullets_en); } manageCollisions(); @@ -266,9 +272,16 @@ private void draw() { enemyShipFormation.draw(); - for (Bullet bullet : this.bullets) + for (Bullet bullet : this.bullets_p1) + drawManager.drawEntity(bullet, bullet.getPositionX(), + bullet.getPositionY()); + for (Bullet bullet : this.bullets_p2) + drawManager.drawEntity(bullet, bullet.getPositionX(), + bullet.getPositionY()); + for (Bullet bullet : this.bullets_en) drawManager.drawEntity(bullet, bullet.getPositionX(), bullet.getPositionY()); + // Interface. drawManager.drawScore(this, this.score_p1, this.score_p2); @@ -296,14 +309,38 @@ private void draw() { */ private void cleanBullets() { Set recyclable = new HashSet(); - for (Bullet bullet : this.bullets) { + for (Bullet bullet : this.bullets_p1) { + bullet.update(); + if (bullet.getPositionY() < 2*SEPARATION_LINE_HEIGHT + || bullet.getPositionY() > this.height) + recyclable.add(bullet); + } + + this.bullets_p1.removeAll(recyclable); + BulletPool.recycle(recyclable); + recyclable = new HashSet(); + + for (Bullet bullet : this.bullets_p2) { + bullet.update(); + if (bullet.getPositionY() < 2*SEPARATION_LINE_HEIGHT + || bullet.getPositionY() > this.height) + recyclable.add(bullet); + } + + this.bullets_p2.removeAll(recyclable); + BulletPool.recycle(recyclable); + recyclable = new HashSet(); + + for (Bullet bullet : this.bullets_en) { bullet.update(); if (bullet.getPositionY() < 2*SEPARATION_LINE_HEIGHT || bullet.getPositionY() > this.height) recyclable.add(bullet); } - this.bullets.removeAll(recyclable); + + this.bullets_en.removeAll(recyclable); BulletPool.recycle(recyclable); + recyclable = new HashSet(); } /** @@ -311,48 +348,79 @@ private void cleanBullets() { */ private void manageCollisions() { Set recyclable = new HashSet(); - for (Bullet bullet : this.bullets) - if (bullet.getSpeed() > 0) { - if (checkCollision(bullet, this.ship_1) && !this.levelFinished) { - recyclable.add(bullet); - if (!this.ship_1.isDestroyed()) { - this.ship_1.destroy(); - this.lives_p1--; - this.logger.info("Hit on player ship, " + this.lives_p1 - + " lives remaining."); - } + for (Bullet bullet : this.bullets_en) { + if (checkCollision(bullet, this.ship_1) && !this.levelFinished) { + recyclable.add(bullet); + if (!this.ship_1.isDestroyed()) { + this.ship_1.destroy(); + this.lives_p1--; + this.logger.info("Hit on player1 ship, " + this.lives_p1 + + " lives remaining."); } - if (checkCollision(bullet, this.ship_2) && !this.levelFinished) { - recyclable.add(bullet); - if (!this.ship_2.isDestroyed()) { - this.ship_2.destroy(); - this.lives_p2--; - this.logger.info("Hit on player ship, " + this.lives_p2 - + " lives remaining."); - } + } + if (checkCollision(bullet, this.ship_2) && !this.levelFinished) { + recyclable.add(bullet); + if (!this.ship_2.isDestroyed()) { + this.ship_2.destroy(); + this.lives_p2--; + this.logger.info("Hit on player2 ship, " + this.lives_p2 + + " lives remaining."); } - } else { - for (EnemyShip enemyShip : this.enemyShipFormation) - if (!enemyShip.isDestroyed() - && checkCollision(bullet, enemyShip)) { - this.score_p1 += enemyShip.getPointValue(); - this.shipsDestroyed_p1++; - this.enemyShipFormation.destroy(enemyShip); - recyclable.add(bullet); - } - if (this.enemyShipSpecial != null - && !this.enemyShipSpecial.isDestroyed() - && checkCollision(bullet, this.enemyShipSpecial)) { - this.score_p1 += this.enemyShipSpecial.getPointValue(); + } + } + + this.bullets_en.removeAll(recyclable); + BulletPool.recycle(recyclable); + recyclable = new HashSet(); + + for (Bullet bullet : this.bullets_p1) { + for (EnemyShip enemyShip : this.enemyShipFormation) + if (!enemyShip.isDestroyed() + && checkCollision(bullet, enemyShip)) { + this.score_p1 += enemyShip.getPointValue(); this.shipsDestroyed_p1++; - this.enemyShipSpecial.destroy(); - this.enemyShipSpecialExplosionCooldown.reset(); + this.enemyShipFormation.destroy(enemyShip); + recyclable.add(bullet); + } + if (this.enemyShipSpecial != null + && !this.enemyShipSpecial.isDestroyed() + && checkCollision(bullet, this.enemyShipSpecial)) { + this.score_p1 += this.enemyShipSpecial.getPointValue(); + this.shipsDestroyed_p1++; + this.enemyShipSpecial.destroy(); + this.enemyShipSpecialExplosionCooldown.reset(); + recyclable.add(bullet); + } + } + + this.bullets_p1.removeAll(recyclable); + BulletPool.recycle(recyclable); + recyclable = new HashSet(); + + for (Bullet bullet : this.bullets_p2) { + for (EnemyShip enemyShip : this.enemyShipFormation) + if (!enemyShip.isDestroyed() + && checkCollision(bullet, enemyShip)) { + this.score_p2 += enemyShip.getPointValue(); + this.shipsDestroyed_p2++; + this.enemyShipFormation.destroy(enemyShip); recyclable.add(bullet); } - // will check bullet owner + if (this.enemyShipSpecial != null + && !this.enemyShipSpecial.isDestroyed() + && checkCollision(bullet, this.enemyShipSpecial)) { + this.score_p2 += this.enemyShipSpecial.getPointValue(); + this.shipsDestroyed_p2++; + this.enemyShipSpecial.destroy(); + this.enemyShipSpecialExplosionCooldown.reset(); + recyclable.add(bullet); } - this.bullets.removeAll(recyclable); + } + + this.bullets_p2.removeAll(recyclable); BulletPool.recycle(recyclable); + recyclable = new HashSet(); + } /** From a0f681f438c5e4b5b92c2e1472a6ecfdedf58a3c Mon Sep 17 00:00:00 2001 From: rasauq1122 Date: Tue, 8 Dec 2020 19:21:33 +0900 Subject: [PATCH 6/7] =?UTF-8?q?Fix:=20GameState=EC=9D=98=20=EC=9D=BC?= =?UTF-8?q?=EB=B6=80=20getter=EA=B0=80=20=EC=9D=98=EB=8F=84=EB=90=98?= =?UTF-8?q?=EC=A7=80=20=EC=95=8A=EC=9D=80=20=EA=B0=92=EC=9D=84=20=EB=A6=AC?= =?UTF-8?q?=ED=84=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit JIRA ISSUE KEY : IN-40 --- src/engine/GameState.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/engine/GameState.java b/src/engine/GameState.java index de71a52dd..e071a9c13 100644 --- a/src/engine/GameState.java +++ b/src/engine/GameState.java @@ -89,7 +89,7 @@ public final int getBulletsShotP1() { * @return the shipsDestroyed */ public final int getShipsDestroyedP1() { - return shipsDestroyed_p2; + return shipsDestroyed_p1; } /** From acbcdc75e0ec22e15f826e105e7966437411fdee Mon Sep 17 00:00:00 2001 From: rasauq1122 Date: Sat, 12 Dec 2020 17:49:49 +0900 Subject: [PATCH 7/7] =?UTF-8?q?Feat:=20=EA=B2=8C=EC=9E=84=EC=9D=98=20?= =?UTF-8?q?=EC=A2=85=EB=A3=8C=20=EC=A1=B0=EA=B1=B4=20=EB=B3=80=EA=B2=BD=20?= =?UTF-8?q?(=20=EB=AC=B4=ED=95=9C=20=EB=B6=80=ED=99=9C=20+=20=EB=A0=88?= =?UTF-8?q?=EB=B2=A8=20=EB=81=9D=EB=82=98=EC=95=BC=EC=A7=80=EB=A7=8C=20?= =?UTF-8?q?=EC=A2=85=EB=A3=8C=20)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit JIRA ISSUE KEY : IN-20 --- src/engine/Core.java | 4 ++-- src/graphics | 12 ++++++++++++ src/scores | 8 ++++++++ src/screen/GameScreen.java | 10 ++-------- 4 files changed, 24 insertions(+), 10 deletions(-) create mode 100644 src/graphics create mode 100644 src/scores diff --git a/src/engine/Core.java b/src/engine/Core.java index 47cb585ac..c20743e8d 100644 --- a/src/engine/Core.java +++ b/src/engine/Core.java @@ -30,7 +30,7 @@ public final class Core { private static final int FPS = 60; /** Max lives. */ - private static final int MAX_LIVES = 3; + private static final int MAX_LIVES = 1; /** Levels between extra life. */ private static final int EXTRA_LIFE_FRECUENCY = 3; /** Total number of levels. */ @@ -133,7 +133,7 @@ public static void main(final String[] args) { // One extra live every few levels. boolean bonusLife = gameState.getLevel() % EXTRA_LIFE_FRECUENCY == 0 - && gameState.getLivesRemainingP1() < MAX_LIVES; // will remove + && gameState.getLivesRemainingP1() < MAX_LIVES; currentScreen = new GameScreen(gameState, gameSettings.get(gameState.getLevel() - 1), diff --git a/src/graphics b/src/graphics new file mode 100644 index 000000000..ea318b6a5 --- /dev/null +++ b/src/graphics @@ -0,0 +1,12 @@ +00001111000111110001111100011111000111110111111111111111011111110001111100011111000111110001111100001111 +00000100000000010001001100000011000001111011001100001111001011110000001100101111010010010000010000000011 +100001111110000 +000011111100001 +001110010111100101111010011011101110110011111010111110101110110001101110011110100111100100111001 +001110000111101001111111011011011110110011111010111110101110110001101101011111110111101000111000 +000000000000111000011000101111100110110100111101001111000011110101101101101111100001100000001110 +000000000111100000011101101111100110110000111100001111000011110001101100101111100001110101111000 +000000000000000000011010001111010110100011111100111111000110100000111101000110100000000000000000 +000000000000000000011001001110100110110111111010111110100110110100111010000110010000000000000000 +0000100000110000111100110111011111011111001110100111111011111101110100111110001111100110111001111000011000000100 +0001000100100101000100010100100000101000100000000010001010000010010100010001010010010001000 \ No newline at end of file diff --git a/src/scores b/src/scores new file mode 100644 index 000000000..a4cc05c7a --- /dev/null +++ b/src/scores @@ -0,0 +1,8 @@ +ROB +6500 +PAT +6000 +KOF +5500 +BYR +5000 \ No newline at end of file diff --git a/src/screen/GameScreen.java b/src/screen/GameScreen.java index eab9b5939..fda803114 100644 --- a/src/screen/GameScreen.java +++ b/src/screen/GameScreen.java @@ -111,15 +111,11 @@ public GameScreen(final GameState gameState, this.level = gameState.getLevel(); this.score_p1 = gameState.getScoreP1(); this.lives_p1 = gameState.getLivesRemainingP1(); - if (this.bonusLife) - this.lives_p1++; // will remove this.bulletsShot_p1 = gameState.getBulletsShotP1(); this.shipsDestroyed_p1 = gameState.getShipsDestroyedP1(); this.score_p2 = gameState.getScoreP2(); this.lives_p2 = gameState.getLivesRemainingP2(); - if (this.bonusLife) - this.lives_p2++; // will remove this.bulletsShot_p2 = gameState.getBulletsShotP2(); this.shipsDestroyed_p2 = gameState.getShipsDestroyedP2(); } @@ -159,9 +155,7 @@ public final void initialize() { public final int run() { super.run(); - this.score_p1 += LIFE_SCORE * (this.lives_p1 - 1); // will remove? this.logger.info("Screen cleared with a score of " + this.score_p1); - this.score_p2 += LIFE_SCORE * (this.lives_p2 - 1); // will remove? this.logger.info("Screen cleared with a score of " + this.score_p2); return this.returnCode; @@ -353,7 +347,7 @@ private void manageCollisions() { recyclable.add(bullet); if (!this.ship_1.isDestroyed()) { this.ship_1.destroy(); - this.lives_p1--; + this.score_p1 -= Math.min(50,score_p1); this.logger.info("Hit on player1 ship, " + this.lives_p1 + " lives remaining."); } @@ -362,7 +356,7 @@ private void manageCollisions() { recyclable.add(bullet); if (!this.ship_2.isDestroyed()) { this.ship_2.destroy(); - this.lives_p2--; + this.score_p2 -= Math.min(50,score_p2); this.logger.info("Hit on player2 ship, " + this.lives_p2 + " lives remaining."); }