Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 17 additions & 5 deletions src/engine/Core.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,7 @@
import java.util.logging.Level;
import java.util.logging.Logger;

import screen.GameScreen;
import screen.HighScoreScreen;
import screen.ScoreScreen;
import screen.Screen;
import screen.TitleScreen;
import screen.*;

/**
* Implements core game logic.
Expand Down Expand Up @@ -172,6 +168,22 @@ public static void main(final String[] args) {
returnCode = frame.setScreen(currentScreen);
LOGGER.info("Closing high score screen.");
break;
case 4:
// Help.
currentScreen = new HelpScreen(width, height, FPS);
LOGGER.info("Starting " + WIDTH + "x" + HEIGHT
+ " help screen at " + FPS + " fps.");
returnCode = frame.setScreen(currentScreen);
LOGGER.info("Closing help screen.");
break;
case 5:
// Settings.
currentScreen = new SettingsScreen(width, height, FPS);
LOGGER.info("Starting " + WIDTH + "x" + HEIGHT
+ " settings screen at " + FPS + " fps.");
returnCode = frame.setScreen(currentScreen);
LOGGER.info("Closing settings screen.");
break;
default:
break;
}
Expand Down
100 changes: 89 additions & 11 deletions src/engine/DrawManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -283,15 +283,18 @@ public void drawHorizontalLine(final Screen screen, final int positionY) {
*/
public void drawTitle(final Screen screen) {
String titleString = "Invaders";
String instructionsString =
"select with w+s / arrows, confirm with space";
String[] instructionsStrings = {"Select with w+s / arrows", "Confirm with space"};
int i = 0;

backBufferGraphics.setColor(Color.GRAY);
drawCenteredRegularString(screen, instructionsString,
screen.getHeight() / 2);
for (String instructionString : instructionsStrings) {
drawCenteredRegularString(screen, instructionString,
screen.getHeight() * 4 / 15 + fontRegularMetrics.getHeight() * 2 * i);
i++;
}

backBufferGraphics.setColor(Color.GREEN);
drawCenteredBigString(screen, titleString, screen.getHeight() / 3);
drawCenteredBigString(screen, titleString, screen.getHeight() / 6);
}

/**
Expand All @@ -305,26 +308,40 @@ public void drawTitle(final Screen screen) {
public void drawMenu(final Screen screen, final int option) {
String playString = "Play";
String highScoresString = "High scores";
String exitString = "exit";
String helpString = "Help";
String settingsString = "Settings";
String exitString = "Exit";

if (option == 2)
backBufferGraphics.setColor(Color.GREEN);
else
backBufferGraphics.setColor(Color.WHITE);
drawCenteredRegularString(screen, playString,
screen.getHeight() / 3 * 2);
screen.getHeight() * 11 / 20);
if (option == 3)
backBufferGraphics.setColor(Color.GREEN);
else
backBufferGraphics.setColor(Color.WHITE);
drawCenteredRegularString(screen, highScoresString, screen.getHeight()
/ 3 * 2 + fontRegularMetrics.getHeight() * 2);
drawCenteredRegularString(screen, highScoresString,
screen.getHeight() * 11 / 20 + fontRegularMetrics.getHeight() * 2);
if (option == 4)
backBufferGraphics.setColor(Color.GREEN);
else
backBufferGraphics.setColor(Color.WHITE);
drawCenteredRegularString(screen, helpString,
screen.getHeight() * 11 / 20 + fontRegularMetrics.getHeight() * 4);
if (option == 5)
backBufferGraphics.setColor(Color.GREEN);
else
backBufferGraphics.setColor(Color.WHITE);
drawCenteredRegularString(screen, settingsString,
screen.getHeight() * 11 / 20 + fontRegularMetrics.getHeight() * 6);
if (option == 0)
backBufferGraphics.setColor(Color.GREEN);
else
backBufferGraphics.setColor(Color.WHITE);
drawCenteredRegularString(screen, exitString, screen.getHeight() / 3
* 2 + fontRegularMetrics.getHeight() * 4);
drawCenteredRegularString(screen, exitString,
screen.getHeight() * 11 / 20 + fontRegularMetrics.getHeight() * 8);
}

/**
Expand Down Expand Up @@ -487,6 +504,67 @@ public void drawHighScores(final Screen screen,
}
}

/**
* Draws help screen
*
* @param screen
* Screen to draw on.
*/
public void drawHelp(final Screen screen) {
String helpString = "Help";
String instructionsString = "Press Space to return";
String[] rule1 = {"Press the arrow keys", "(or the A or D keys)", "to move your ship"};
String[] rule2 = {"Press space to shoot", "missiles at the enemy ships"};
String[] rule3 = {"Avoid the missiles shot", "by the enemy ships"};
String[] rule4 = {"The color of an enemy ship", "depends on their remaining", "health points"};
String[][] rules = {rule1, rule2, rule3, rule4};
int i = 0;
int j = 0;

backBufferGraphics.setColor(Color.GREEN);
drawCenteredBigString(screen, helpString, screen.getHeight() / 8);

backBufferGraphics.setColor(Color.GRAY);
drawCenteredRegularString(screen, instructionsString,
screen.getHeight() / 5);

backBufferGraphics.setColor(Color.WHITE);
for (String[] rule : rules) {
for (String ruleString : rule) {
drawCenteredRegularString(screen, ruleString,
screen.getHeight() * 3 / 10
+ fontRegularMetrics.getHeight() * i
+ fontRegularMetrics.getHeight() * 2 * j);
i++;
}
j++;
}
}

/**
* Draws settings screen
*
* @param screen
* Screen to draw on.
*/
public void drawSettings(final Screen screen) {
String settingsString = "Settings";
String[] instructionsStrings = {"Press Space to return", "Use the arrow keys to", "enable/disable settings"};
int i = 0;

backBufferGraphics.setColor(Color.GREEN);
drawCenteredBigString(screen, settingsString, screen.getHeight() / 8);

backBufferGraphics.setColor(Color.GRAY);
for (String instructionsString : instructionsStrings) {
drawCenteredRegularString(screen, instructionsString,
(int) (screen.getHeight() / 5 + Math.round(fontRegularMetrics.getHeight() * 1.5 * i)));
i++;
}

backBufferGraphics.setColor(Color.WHITE);
}

/**
* Draws a centered string on regular font.
*
Expand Down
64 changes: 64 additions & 0 deletions src/screen/HelpScreen.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package screen;

import java.awt.event.KeyEvent;
import java.io.IOException;
import java.util.List;

import engine.Core;
import engine.Score;

/**
* Implements the help screen, it shows the player instructions on how to play the game.
*/

public class HelpScreen extends Screen {
/**
* Constructor, establishes the properties of the screen.
*
* @param width
* Screen width.
* @param height
* Screen height.
* @param fps
* Frames per second, frame rate at which the game is run.
*/
public HelpScreen(final int width, final int height, final int fps) {
super(width, height, fps);

this.returnCode = 1;
}

/**
* Starts the action.
*
* @return Next screen code.
*/
public final int run() {
super.run();

return this.returnCode;
}

/**
* Updates the elements on screen and checks for events.
*/
protected final void update() {
super.update();

draw();
if (inputManager.isKeyDown(KeyEvent.VK_SPACE)
&& this.inputDelay.checkFinished())
this.isRunning = false;
}

/**
* Draws the elements associated with the screen.
*/
private void draw() {
drawManager.initDrawing(this);

drawManager.drawHelp(this);

drawManager.completeDrawing(this);
}
}
64 changes: 64 additions & 0 deletions src/screen/SettingsScreen.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package screen;

import java.awt.event.KeyEvent;
import java.io.IOException;
import java.util.List;

import engine.Core;
import engine.Score;

/**
* Implements the help screen, it shows the player instructions on how to play the game.
*/

public class SettingsScreen extends Screen {
/**
* Constructor, establishes the properties of the screen.
*
* @param width
* Screen width.
* @param height
* Screen height.
* @param fps
* Frames per second, frame rate at which the game is run.
*/
public SettingsScreen(final int width, final int height, final int fps) {
super(width, height, fps);

this.returnCode = 1;
}

/**
* Starts the action.
*
* @return Next screen code.
*/
public final int run() {
super.run();

return this.returnCode;
}

/**
* Updates the elements on screen and checks for events.
*/
protected final void update() {
super.update();

draw();
if (inputManager.isKeyDown(KeyEvent.VK_SPACE)
&& this.inputDelay.checkFinished())
this.isRunning = false;
}

/**
* Draws the elements associated with the screen.
*/
private void draw() {
drawManager.initDrawing(this);

drawManager.drawSettings(this);

drawManager.completeDrawing(this);
}
}
4 changes: 2 additions & 2 deletions src/screen/TitleScreen.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ protected final void update() {
* Shifts the focus to the next menu item.
*/
private void nextMenuItem() {
if (this.returnCode == 3)
if (this.returnCode == 5)
this.returnCode = 0;
else if (this.returnCode == 0)
this.returnCode = 2;
Expand All @@ -90,7 +90,7 @@ else if (this.returnCode == 0)
*/
private void previousMenuItem() {
if (this.returnCode == 0)
this.returnCode = 3;
this.returnCode = 5;
else if (this.returnCode == 2)
this.returnCode = 0;
else
Expand Down