Skip to content

Commit

Permalink
Merge pull request #168 from georgeness/master
Browse files Browse the repository at this point in the history
Added controls menu and empty graphics menu
  • Loading branch information
micycle1 authored Dec 26, 2024
2 parents fdfce03 + 11340e9 commit b256516
Show file tree
Hide file tree
Showing 5 changed files with 275 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/main/java/project_16x16/SideScroller.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,13 @@ public static DebugType get(int value) {
private static MultiplayerMenu mMenu;
private static MultiplayerHostMenu mHostMenu;
private static MultiplayerClientMenu mClientMenu;
private static GraphicsSettings graphicsSettings;
private static AudioSettings audioSettings;
private static ControlsSettings controlsSettings;

public enum GameScenes {
MAIN_MENU(menu), GAME(game), PAUSE_MENU(pmenu), SETTINGS_MENU(settings), MULTIPLAYER_MENU(mMenu),
HOST_MENU(mHostMenu), CLIENT_MENU(mClientMenu), AUDIO_SETTINGS(audioSettings);
HOST_MENU(mHostMenu), CLIENT_MENU(mClientMenu), GRAPHICS_SETTINGS(graphicsSettings), AUDIO_SETTINGS(audioSettings), CONTROLS_SETTINGS(controlsSettings);

PScene scene;

Expand Down Expand Up @@ -199,7 +201,9 @@ public void setup() {
mMenu = new MultiplayerMenu(this);
mHostMenu = new MultiplayerHostMenu(this);
mClientMenu = new MultiplayerClientMenu(this);
graphicsSettings = new GraphicsSettings(this);
audioSettings = new AudioSettings(this);
controlsSettings = new ControlsSettings(this);
swapToScene(GameScenes.MAIN_MENU);

// Camera
Expand Down
1 change: 1 addition & 0 deletions src/main/java/project_16x16/scene/AudioSettings.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
* @author micycle1
*
*/

public final class AudioSettings extends PScene {

private SideScroller game;
Expand Down
174 changes: 174 additions & 0 deletions src/main/java/project_16x16/scene/ControlsSettings.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,174 @@
package project_16x16.scene;

import processing.core.PApplet;
import processing.core.PConstants;
import processing.event.KeyEvent;
import processing.event.MouseEvent;
import project_16x16.Audio;
import project_16x16.Constants;
import project_16x16.Options;
import project_16x16.Options.Option;
import project_16x16.SideScroller;
import project_16x16.ui.Button;
import project_16x16.ui.Notifications;
import project_16x16.ui.Slider;

public final class ControlsSettings extends PScene {

private SideScroller game;

private Button quit;
private Button apply;
private Button changeJumpKey;
private Button changeDashKey;
private Button changeMoveLeftKey;
private Button changeMoveRightKey;

// Stores key configurations
private int newJumpKey;
private int newDashKey;
private int newMoveLeftKey;
private int newMoveRightKey;

private int originalJumpKey;
private int originalDashKey;
private int originalMoveLeftKey;
private int originalMoveRightKey;

private Button activeButton;

public ControlsSettings(SideScroller a) {
super(a);
game = a;

apply = new Button(applet);
apply.setText("Apply");
apply.setPosition(a.width / 2, 500);

quit = new Button(a);
quit.setText("Quit");
quit.setPosition(a.width / 2, 600);

changeJumpKey = new Button(a);
changeJumpKey.setText("Change Jump Key: " + PApplet.str(Options.jumpKey));
changeJumpKey.setPosition(a.width / 2, 150);

changeDashKey = new Button(a);
changeDashKey.setText("Change Dash Key: " + PApplet.str(Options.dashKey));
changeDashKey.setPosition(a.width / 2, 200);

changeMoveLeftKey = new Button(a);
changeMoveLeftKey.setText("Change Move Left Key: " + PApplet.str(Options.moveLeftKey));
changeMoveLeftKey.setPosition(a.width / 2, 250);

changeMoveRightKey = new Button(a);
changeMoveRightKey.setText("Change Move Right Key: " + PApplet.str(Options.moveRightKey));
changeMoveRightKey.setPosition(a.width / 2, 300);

newJumpKey = Options.jumpKey;
newDashKey = Options.dashKey;
newMoveLeftKey = Options.moveLeftKey;
newMoveRightKey = Options.moveRightKey;

activeButton = null;
}

@Override
public void switchTo() {
originalJumpKey = Options.jumpKey;
originalDashKey = Options.dashKey;
originalMoveLeftKey = Options.moveLeftKey;
originalMoveRightKey = Options.moveRightKey;
super.switchTo();
}

@Override
public void drawUI() {
game.background(Constants.Colors.MENU_GREY);
apply.display();
quit.display();

changeJumpKey.display();
changeDashKey.display();
changeMoveLeftKey.display();
changeMoveRightKey.display();

if (activeButton != null) {
game.fill(255, 0, 0);
game.textAlign(PConstants.CENTER);
game.text("Press a key to change the control!", game.width / 2, 100);
}
}

@Override
void mouseReleased(MouseEvent e) {
apply.update();
quit.update();
changeJumpKey.update();
changeDashKey.update();
changeMoveLeftKey.update();
changeMoveRightKey.update();

if (quit.hover()) {
newJumpKey = originalJumpKey;
newDashKey = originalDashKey;
newMoveLeftKey = originalMoveLeftKey;
newMoveRightKey = originalMoveRightKey;
changeJumpKey.setText("Change Jump Key: " + PApplet.str(originalJumpKey));
changeDashKey.setText("Change Dash Key: " + PApplet.str(originalDashKey));
changeMoveLeftKey.setText("Change Move Left Key: " + PApplet.str(originalMoveLeftKey));
changeMoveRightKey.setText("Change Move Right Key: " + PApplet.str(originalMoveRightKey));

game.returnScene();
return;
}
if (apply.hover()) {
Options.save(Option.jumpKey, newJumpKey);
Options.save(Option.dashKey, newDashKey);
Options.save(Option.moveLeftKey, newMoveLeftKey);
Options.save(Option.moveRightKey, newMoveRightKey);
Options.jumpKey = newJumpKey;
Options.dashKey = newDashKey;
Options.moveLeftKey = newMoveLeftKey;
Options.moveRightKey = newMoveRightKey;

Notifications.addNotification("Controls Settings Applied", "Your configuration has been successfully applied.");
game.returnScene();
}

if (changeJumpKey.hover()) {
activeButton = changeJumpKey;
} else if (changeDashKey.hover()) {
activeButton = changeDashKey;
} else if (changeMoveLeftKey.hover()) {
activeButton = changeMoveLeftKey;
} else if (changeMoveRightKey.hover()) {
activeButton = changeMoveRightKey;
} else {
activeButton = null;
}
}

@Override
void keyReleased(KeyEvent e) {
if (activeButton != null) {
int key = e.getKeyCode();
if (activeButton == changeJumpKey) {
newJumpKey = key;
changeJumpKey.setText("Change Jump Key: " + PApplet.str(key));
} else if (activeButton == changeDashKey) {
newDashKey = key;
changeDashKey.setText("Change Dash Key: " + PApplet.str(key));
} else if (activeButton == changeMoveLeftKey) {
newMoveLeftKey = key;
changeMoveLeftKey.setText("Change Move Left Key: " + PApplet.str(key));
} else if (activeButton == changeMoveRightKey) {
newMoveRightKey = key;
changeMoveRightKey.setText("Change Move Right Key: " + PApplet.str(key));
}
activeButton = null;
} else if (e.getKeyCode() == PConstants.ESC) {
game.returnScene();
}
}
}
87 changes: 87 additions & 0 deletions src/main/java/project_16x16/scene/GraphicsSettings.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
package project_16x16.scene;

import processing.core.PApplet;
import processing.core.PConstants;
import processing.event.KeyEvent;
import processing.event.MouseEvent;
import project_16x16.Audio;
import project_16x16.Constants;
import project_16x16.Options;
import project_16x16.Options.Option;
import project_16x16.SideScroller;
import project_16x16.ui.Button;
import project_16x16.ui.Notifications;
import project_16x16.ui.Slider;

public final class GraphicsSettings extends PScene {

private SideScroller game;

private Button quit;
private Button apply;

public GraphicsSettings(SideScroller a) {
super(a);

game = a;

apply = new Button(applet);
apply.setText("Apply");
apply.setPosition(a.width / 2, 500);

quit = new Button(a);
quit.setText("Quit");
quit.setPosition(a.width / 2, 600);

}

@Override
public void switchTo() {
// TODO properly align audio value and slider position
//volumeBGM.setValue(PApplet.map(originalVolumeBGM, -60, 0, 0, 1));
//volumeSFX.setValue(PApplet.map(originalVolumeSFX, -60, 0, 0, 1));
super.switchTo();
}

@Override
public void drawUI() {
game.background(Constants.Colors.MENU_GREY);
apply.display();
quit.display();

}

@Override
void mouseDragged(MouseEvent e) {

}

@Override
void mouseReleased(MouseEvent e) {
apply.update();
quit.update();

if (quit.hover()) {
// revert sound changes if menu is quit
game.returnScene();
return;
}
if (apply.hover()) {
Notifications.addNotification("Graphics Settings Applied", "Your configuration has been successfully applied.");
game.returnScene();
}

}

@Override
void keyReleased(KeyEvent e) {
switch (e.getKeyCode()) {
case PConstants.ESC : // Pause
game.returnScene();
break;
default :
break;
}
}

}
8 changes: 8 additions & 0 deletions src/main/java/project_16x16/scene/Settings.java
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,9 @@ void mouseReleased(MouseEvent e) {
private void update() {
quit.update();
apply.update();
pressGraphicsOptions.update();
pressSoundOptions.update();
pressControlsOptions.update();
if (quit.hover()) {
game.returnScene();
return;
Expand All @@ -109,9 +111,15 @@ private void update() {
Notifications.addNotification("Options Applied", "Your configuration has been successfully applied.");
return;
}
if (pressGraphicsOptions.hover()) {
game.swapToScene(GameScenes.GRAPHICS_SETTINGS);
}
if (pressSoundOptions.hover()) {
game.swapToScene(GameScenes.AUDIO_SETTINGS);
}
if (pressControlsOptions.hover()) {
game.swapToScene(GameScenes.CONTROLS_SETTINGS);
}
}

private void displayWindow() {
Expand Down

0 comments on commit b256516

Please sign in to comment.