Skip to content
34 changes: 22 additions & 12 deletions src/engine/Core.java
Original file line number Diff line number Diff line change
Expand Up @@ -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. */
Expand Down Expand Up @@ -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:
Expand All @@ -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;

currentScreen = new GameScreen(gameState,
gameSettings.get(gameState.getLevel() - 1),
Expand All @@ -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.");
Expand Down
14 changes: 7 additions & 7 deletions src/engine/DrawManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand All @@ -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);
Ship dummyShip = new Ship(0, 0);
for (int i = 0; i < lives; i++)
backBufferGraphics.drawString(Integer.toString(player1), 20, 25);
Ship dummyShip = new Ship(0, 0, true);
for (int i = 0; i < player1; i++)
drawEntity(dummyShip, 40 + 35 * i, 10);
}

Expand Down Expand Up @@ -559,4 +559,4 @@ else if (number != 0)
drawCenteredBigString(screen, "GO!", screen.getHeight() / 2
+ fontBigMetrics.getHeight() / 3);
}
}
}
91 changes: 66 additions & 25 deletions src/engine/GameState.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand All @@ -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;
}

/**
Expand All @@ -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_p1;
}

/**
* @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;
}
}
3 changes: 2 additions & 1 deletion src/entity/EnemyShip.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion src/entity/EnemyShipFormation.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -25,7 +26,7 @@ public class EnemyShipFormation implements Iterable<EnemyShip> {
/** 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. */
Expand Down
6 changes: 3 additions & 3 deletions src/entity/Ship.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -110,4 +110,4 @@ public final boolean isDestroyed() {
public final int getSpeed() {
return SPEED;
}
}
}
Loading