Compare commits
4 Commits
5192c8df87
...
d294578a74
| Author | SHA1 | Date | |
|---|---|---|---|
|
d294578a74
|
|||
|
21f4acf6b1
|
|||
|
eba67d7cf8
|
|||
|
e9fc671135
|
@@ -8,6 +8,7 @@ import de.miaurizius.jgame2d.tile.TileManager;
|
||||
import de.miaurizius.jgame2d.tile.interactive.InteractiveTile;
|
||||
|
||||
import javax.sound.sampled.Clip;
|
||||
import javax.sound.sampled.FloatControl;
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.image.BufferedImage;
|
||||
@@ -50,7 +51,7 @@ public class GamePanel extends JPanel implements Runnable {
|
||||
public UI ui = new UI(this);
|
||||
public EventHandler eventH = new EventHandler(this);
|
||||
public Sound se = new Sound();
|
||||
Sound music = new Sound();
|
||||
public Sound music = new Sound();
|
||||
Thread gameThread;
|
||||
|
||||
// ENTITY AND OBJECT
|
||||
@@ -197,7 +198,10 @@ public class GamePanel extends JPanel implements Runnable {
|
||||
|
||||
// MUSIC
|
||||
public void playMusic(int i) {
|
||||
Clip c = se.clips[i];
|
||||
Clip c = music.clips[i];
|
||||
music.clip = c;
|
||||
music.fc = (FloatControl) c.getControl(FloatControl.Type.MASTER_GAIN);
|
||||
music.checkVolume();
|
||||
if(c.isRunning()) c.stop();
|
||||
c.setFramePosition(0);
|
||||
c.start();
|
||||
@@ -208,6 +212,8 @@ public class GamePanel extends JPanel implements Runnable {
|
||||
}
|
||||
public void playSE(int i) {
|
||||
Clip c = se.clips[i];
|
||||
se.fc = (FloatControl) c.getControl(FloatControl.Type.MASTER_GAIN);
|
||||
se.checkVolume();
|
||||
if(c.isRunning()) c.stop();
|
||||
c.setFramePosition(0);
|
||||
c.start();
|
||||
|
||||
@@ -234,7 +234,11 @@ public class UI {
|
||||
|
||||
switch(optionState) {
|
||||
case OVERVIEW -> optionsTop(frameX, frameY);
|
||||
case SCREENNF -> optionsFSNotify(frameX, frameY);
|
||||
case CONTROLS -> optionsControls(frameX, frameY);
|
||||
case QUITNF -> optionsQuitNotify(frameX, frameY);
|
||||
}
|
||||
panel.keyH.spacePressed = false;
|
||||
}
|
||||
public void drawDialogueScreen() {
|
||||
drawPlayerLife();
|
||||
@@ -323,6 +327,7 @@ public class UI {
|
||||
messageCounter.add(0);
|
||||
}
|
||||
|
||||
// OPTIONS UI
|
||||
public void optionsTop(int frameX, int frameY) {
|
||||
int textX, textY;
|
||||
String title = "Options";
|
||||
@@ -336,7 +341,10 @@ public class UI {
|
||||
graphics2d.drawString("Full Screen", textX, textY);
|
||||
if(commandNum == 0) {
|
||||
graphics2d.drawString(">", textX-25, textY);
|
||||
if(panel.keyH.spacePressed) panel.fullscreen = !panel.fullscreen;
|
||||
if(panel.keyH.spacePressed) {
|
||||
optionState = OptionState.SCREENNF;
|
||||
panel.fullscreen = !panel.fullscreen;
|
||||
}
|
||||
}
|
||||
|
||||
// MUSIC
|
||||
@@ -352,39 +360,146 @@ public class UI {
|
||||
// CONTROL
|
||||
textY += panel.tileSize;
|
||||
graphics2d.drawString("Controls", textX, textY);
|
||||
if(commandNum == 3) graphics2d.drawString(">", textX-25, textY);
|
||||
if(commandNum == 3) {
|
||||
graphics2d.drawString(">", textX-25, textY);
|
||||
if(panel.keyH.spacePressed) {
|
||||
optionState = OptionState.CONTROLS;
|
||||
commandNum = 0;
|
||||
}
|
||||
}
|
||||
|
||||
// END GAME
|
||||
textY += panel.tileSize;
|
||||
graphics2d.drawString("Quit Game", textX, textY);
|
||||
if(commandNum == 4) graphics2d.drawString(">", textX-25, textY);
|
||||
if(commandNum == 4) {
|
||||
graphics2d.drawString(">", textX-25, textY);
|
||||
if(panel.keyH.spacePressed) {
|
||||
optionState = OptionState.QUITNF;
|
||||
commandNum = 0;
|
||||
}
|
||||
}
|
||||
|
||||
// BACK
|
||||
textY += panel.tileSize*2;
|
||||
graphics2d.drawString("Back to Game", textX, textY);
|
||||
if(commandNum == 5) graphics2d.drawString(">", textX-25, textY);
|
||||
if(commandNum == 5) {
|
||||
graphics2d.drawString(">", textX-25, textY);
|
||||
if(panel.keyH.spacePressed) panel.gameState = GameState.PLAY;
|
||||
}
|
||||
|
||||
//
|
||||
// FUNCTIONALITY
|
||||
//
|
||||
|
||||
// FULL SCREEN CHECKBOX
|
||||
textX = frameX + (int)(panel.tileSize*4.5);
|
||||
textY = frameY + panel.tileSize*2 - panel.tileSize/2;
|
||||
graphics2d.setStroke(new BasicStroke(3));
|
||||
graphics2d.drawRect(textX, textY, panel.tileSize/2, panel.tileSize/2);
|
||||
if(panel.fullscreen) {
|
||||
graphics2d.fillRect(textX, textY, panel.tileSize/2, panel.tileSize/2);
|
||||
}
|
||||
|
||||
// MUSIC VOLUME
|
||||
textY += panel.tileSize;
|
||||
graphics2d.drawRect(textX, textY, 120, panel.tileSize/2);
|
||||
graphics2d.drawRect(textX, textY, 120, panel.tileSize/2); // 120/5 = 24
|
||||
graphics2d.fillRect(textX, textY, 24 * panel.music.volumeScale, panel.tileSize/2);
|
||||
|
||||
// SFX VOLUME
|
||||
textY += panel.tileSize;
|
||||
graphics2d.drawRect(textX, textY, 120, panel.tileSize/2);
|
||||
graphics2d.drawRect(textX, textY, 120, panel.tileSize/2); // 120/5 = 24
|
||||
graphics2d.fillRect(textX, textY, 24 * panel.se.volumeScale, panel.tileSize/2);
|
||||
}
|
||||
public void optionsControls(int frameX, int frameY) {
|
||||
int textX;
|
||||
int textY;
|
||||
|
||||
// TITLE
|
||||
String text = "Controls";
|
||||
textX = getCenteredX(text);
|
||||
textY = frameY + panel.tileSize;
|
||||
graphics2d.drawString(text, textX, textY);
|
||||
|
||||
textX = frameX + panel.tileSize;
|
||||
textY +=panel.tileSize;
|
||||
String[] options = {"Move", "Confirm/Attack", "Shoot/Cast", "Inventory", "Pause/Settings"};
|
||||
for(String option : options) {
|
||||
graphics2d.drawString(option, textX, textY);
|
||||
textY += panel.tileSize;
|
||||
}
|
||||
|
||||
textX = frameX + panel.tileSize*6;
|
||||
textY = frameY + panel.tileSize*2;
|
||||
options = new String[]{"WASD", "SPACE", "F", "C", "ESC"};
|
||||
for(String option : options) {
|
||||
graphics2d.drawString(option, textX, textY);
|
||||
textY += panel.tileSize;
|
||||
}
|
||||
|
||||
// BACK
|
||||
textX = frameX + panel.tileSize;
|
||||
textY = frameY + panel.tileSize*9;
|
||||
graphics2d.drawString("Back", textX, textY);
|
||||
graphics2d.drawString(">", textX-25, textY);
|
||||
if(panel.keyH.spacePressed) optionState = OptionState.OVERVIEW;
|
||||
}
|
||||
public void optionsFSNotify(int frameX, int frameY) {
|
||||
int textX = frameX + panel.tileSize;
|
||||
int textY = frameY + panel.tileSize*3;
|
||||
|
||||
currentDialogue = "The change will take \neffect after restarting \nthe game";
|
||||
for(String line : currentDialogue.split("\n")) {
|
||||
graphics2d.drawString(line, textX, textY);
|
||||
textY += 40;
|
||||
}
|
||||
|
||||
// BACK
|
||||
textY =frameY + panel.tileSize*9;
|
||||
graphics2d.drawString("Back", textX, textY);
|
||||
if(commandNum == 0) {
|
||||
graphics2d.drawString(">", textX-25, textY);
|
||||
if(panel.keyH.spacePressed) optionState = OptionState.OVERVIEW;
|
||||
}
|
||||
|
||||
}
|
||||
public void optionsQuitNotify(int frameX, int frameY) {
|
||||
int textX = frameX + panel.tileSize;
|
||||
int textY = frameY + panel.tileSize*3;
|
||||
|
||||
currentDialogue = "Quit the game and \nreturn to the title screen?";
|
||||
for(String line : currentDialogue.split("\n")) {
|
||||
graphics2d.drawString(line, textX, textY);
|
||||
textY += 40;
|
||||
}
|
||||
|
||||
// DISPLAY OPTIONS
|
||||
String text = "Yes";
|
||||
textX = getCenteredX(text);
|
||||
textY += panel.tileSize*3;
|
||||
graphics2d.drawString(text, textX, textY);
|
||||
if(commandNum == 0) {
|
||||
graphics2d.drawString(">", textX-25, textY);
|
||||
if(panel.keyH.spacePressed) {
|
||||
panel.gameState = GameState.TITLE;
|
||||
panel.stopMusic();
|
||||
}
|
||||
}
|
||||
|
||||
text = "No";
|
||||
textX = getCenteredX(text);
|
||||
textY += panel.tileSize;
|
||||
graphics2d.drawString(text, textX, textY);
|
||||
if(commandNum == 1) {
|
||||
graphics2d.drawString(">", textX-25, textY);
|
||||
if(panel.keyH.spacePressed) optionState = OptionState.OVERVIEW;
|
||||
}
|
||||
}
|
||||
|
||||
public enum OptionState {
|
||||
OVERVIEW,
|
||||
SCREEN,
|
||||
MUSIC,
|
||||
SFX,
|
||||
SCREENNF,
|
||||
CONTROLS,
|
||||
QUITNF;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ public class KeyHandler implements KeyListener {
|
||||
case KeyEvent.VK_DOWN -> {
|
||||
if(panel.ui.commandNum != 2) panel.ui.commandNum++;
|
||||
}
|
||||
case KeyEvent.VK_ENTER -> {
|
||||
case KeyEvent.VK_ENTER, KeyEvent.VK_SPACE -> {
|
||||
switch (panel.ui.commandNum) {
|
||||
case 0:
|
||||
panel.gameState = GameState.PLAY;
|
||||
@@ -60,6 +60,7 @@ public class KeyHandler implements KeyListener {
|
||||
case KeyEvent.VK_ESCAPE -> {
|
||||
panel.gameState = GameState.PAUSE;
|
||||
panel.ui.optionState = UI.OptionState.OVERVIEW;
|
||||
panel.ui.commandNum = 0;
|
||||
}
|
||||
case KeyEvent.VK_C -> panel.gameState = GameState.CHARACTER;
|
||||
}
|
||||
@@ -71,6 +72,7 @@ public class KeyHandler implements KeyListener {
|
||||
|
||||
switch (panel.ui.optionState) {
|
||||
case OVERVIEW -> maxCommandNum = 5;
|
||||
case QUITNF -> maxCommandNum = 1;
|
||||
}
|
||||
|
||||
switch(code) {
|
||||
@@ -84,10 +86,34 @@ public class KeyHandler implements KeyListener {
|
||||
panel.ui.commandNum++;
|
||||
panel.playSE(9);
|
||||
break;
|
||||
case KeyEvent.VK_LEFT:
|
||||
if(panel.ui.optionState == UI.OptionState.OVERVIEW)
|
||||
if(panel.ui.commandNum == 1 && panel.music.volumeScale > 0) {
|
||||
panel.music.volumeScale--;
|
||||
panel.music.checkVolume();
|
||||
panel.playSE(9);
|
||||
} else if(panel.ui.commandNum == 2 && panel.se.volumeScale > 0) {
|
||||
panel.se.volumeScale--;
|
||||
panel.playSE(9);
|
||||
}
|
||||
break;
|
||||
case KeyEvent.VK_RIGHT:
|
||||
if(panel.ui.optionState == UI.OptionState.OVERVIEW) {
|
||||
if(panel.ui.commandNum == 1 && panel.music.volumeScale < 5) {
|
||||
panel.music.volumeScale++;
|
||||
panel.music.checkVolume();
|
||||
panel.playSE(9);
|
||||
} else if(panel.ui.commandNum == 2 && panel.se.volumeScale < 5) {
|
||||
panel.se.volumeScale++;
|
||||
panel.playSE(9);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
// EXIT STATE
|
||||
if(code == KeyEvent.VK_ESCAPE) panel.gameState = GameState.PLAY;
|
||||
if(code == KeyEvent.VK_ESCAPE)
|
||||
if(panel.ui.optionState == UI.OptionState.OVERVIEW) panel.gameState = GameState.PLAY; else panel.ui.optionState = UI.OptionState.OVERVIEW;
|
||||
}
|
||||
public void handleDialogue(int code) {
|
||||
// EXIT STATE
|
||||
|
||||
@@ -5,15 +5,19 @@ import de.miaurizius.jgame2d.core.Boot;
|
||||
import javax.sound.sampled.AudioInputStream;
|
||||
import javax.sound.sampled.AudioSystem;
|
||||
import javax.sound.sampled.Clip;
|
||||
import javax.sound.sampled.FloatControl;
|
||||
import java.io.File;
|
||||
import java.net.URL;
|
||||
import java.util.logging.Level;
|
||||
|
||||
public class Sound {
|
||||
|
||||
Clip clip;
|
||||
public Clip clip;
|
||||
URL[] soundURL = new URL[30];
|
||||
public Clip[] clips = new Clip[30];
|
||||
public FloatControl fc;
|
||||
public int volumeScale = 3;
|
||||
float volume;
|
||||
|
||||
public Sound() {
|
||||
load(0, "assets/sounds/BlueBoyAdventure.wav");
|
||||
@@ -55,4 +59,16 @@ public class Sound {
|
||||
clip.stop();
|
||||
}
|
||||
|
||||
public void checkVolume() {
|
||||
switch(volumeScale) {
|
||||
case 0 -> volume = -80f;
|
||||
case 1 -> volume = -20f;
|
||||
case 2 -> volume = -12f;
|
||||
case 3 -> volume = -5f;
|
||||
case 4 -> volume = 1f;
|
||||
case 5 -> volume = 6f;
|
||||
}
|
||||
fc.setValue(volume);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user