added display for player stats
This commit is contained in:
@@ -145,7 +145,7 @@ public class GamePanel extends JPanel implements Runnable {
|
||||
long passed = drawEnd - drawStart;
|
||||
|
||||
// DEBUG
|
||||
if(keyH.checkDrawTime) {
|
||||
if(keyH.debug) {
|
||||
graphics2d.setColor(Color.white);
|
||||
graphics2d.drawString("Draw Time: " + passed, 10, 400);
|
||||
graphics2d.drawString("FPS: " + fpsMeasure, 10, 400+tileSize);
|
||||
|
||||
@@ -49,6 +49,9 @@ public class UI {
|
||||
case TITLE:
|
||||
drawTitleScreen();
|
||||
break;
|
||||
case CHARACTER:
|
||||
drawCharacterScreen();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -141,6 +144,53 @@ public class UI {
|
||||
graphics2d.drawString(text, x, y);
|
||||
if(commandNum == 2) graphics2d.drawString(">", x-panel.tileSize, y);
|
||||
}
|
||||
public void drawCharacterScreen() {
|
||||
// DRAW FRAME
|
||||
final int frameX = panel.tileSize;
|
||||
final int frameY = panel.tileSize;
|
||||
final int frameWidth = panel.tileSize*5;
|
||||
final int frameHeight = panel.tileSize*10;
|
||||
drawSubWindow(frameX, frameY, frameWidth, frameHeight);
|
||||
|
||||
// TEXT
|
||||
graphics2d.setColor(Color.white);
|
||||
graphics2d.setFont(graphics2d.getFont().deriveFont(22F));
|
||||
|
||||
int textX = frameX + 20;
|
||||
int textY = frameY + panel.tileSize;
|
||||
final int lineHeight = 35;
|
||||
|
||||
// NAMES
|
||||
String[] names = {"Level", "Life", "Strength", "Dexterity", "Attack", "Defense", "Exp", "Next Level", "Coins", "Weapon", "Shield"};
|
||||
for(String name : names) {
|
||||
graphics2d.drawString(name, textX, textY);
|
||||
textY += lineHeight + (name.equals("Coins") ? 20 : (name.equals("Weapon") ? 15 : 0));
|
||||
}
|
||||
|
||||
// VALUES
|
||||
int tailX = (frameX + frameWidth) - 30;
|
||||
textY = frameY + panel.tileSize;
|
||||
String[] values = {
|
||||
String.valueOf(panel.player.level),
|
||||
(panel.player.life + "/" + panel.player.maxLife),
|
||||
String.valueOf(panel.player.strength),
|
||||
String.valueOf(panel.player.dexterity),
|
||||
String.valueOf(panel.player.attack),
|
||||
String.valueOf(panel.player.defense),
|
||||
String.valueOf(panel.player.exp),
|
||||
String.valueOf(panel.player.nextLevelExp),
|
||||
String.valueOf(panel.player.coins)
|
||||
};
|
||||
for(String value : values) {
|
||||
textX = getAlignedToRightX(value, tailX);
|
||||
graphics2d.drawString(value, textX, textY);
|
||||
textY += lineHeight;
|
||||
}
|
||||
|
||||
graphics2d.drawImage(panel.player.currentWeapon.down1, tailX - panel.tileSize, textY-14, null);
|
||||
textY += panel.tileSize;
|
||||
graphics2d.drawImage(panel.player.currentShield.down1, tailX - panel.tileSize, textY-14, null);
|
||||
}
|
||||
|
||||
// UTILITY
|
||||
public void drawSubWindow(int x, int y, int width, int height) {
|
||||
@@ -153,5 +203,8 @@ public class UI {
|
||||
public int getCenteredX(String text) {
|
||||
return panel.screenWidth / 2 - (int) graphics2d.getFontMetrics().getStringBounds(text, graphics2d).getWidth() / 2;
|
||||
}
|
||||
public int getAlignedToRightX(String text, int tailX) {
|
||||
return tailX - (int) graphics2d.getFontMetrics().getStringBounds(text, graphics2d).getWidth() / 2;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -6,5 +6,6 @@ public enum GameState {
|
||||
PAUSE,
|
||||
DIALOGUE,
|
||||
TITLE,
|
||||
CHARACTER,
|
||||
|
||||
}
|
||||
|
||||
@@ -10,80 +10,93 @@ public class KeyHandler implements KeyListener {
|
||||
|
||||
public boolean upPressed, downPressed, leftPressed, rightPressed, spacePressed;
|
||||
public GamePanel panel;
|
||||
// DEBUG
|
||||
public boolean checkDrawTime = false;
|
||||
public boolean debug;
|
||||
|
||||
public KeyHandler(GamePanel panel) {
|
||||
this.panel = panel;
|
||||
}
|
||||
|
||||
// STATE SPECIFIC KEYBIND CONFIGURATION
|
||||
public void handleTitle(int code) {
|
||||
switch (code) {
|
||||
case KeyEvent.VK_UP -> {
|
||||
if(panel.ui.commandNum != 0) panel.ui.commandNum--;
|
||||
}
|
||||
case KeyEvent.VK_DOWN -> {
|
||||
if(panel.ui.commandNum != 2) panel.ui.commandNum++;
|
||||
}
|
||||
case KeyEvent.VK_ENTER -> {
|
||||
switch (panel.ui.commandNum) {
|
||||
case 0:
|
||||
panel.gameState = GameState.PLAY;
|
||||
panel.playMusic(0);
|
||||
break;
|
||||
case 1:
|
||||
// add later
|
||||
break;
|
||||
case 2:
|
||||
System.exit(0);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
public void handlePlay(int code) {
|
||||
switch (code) {
|
||||
// CONTROLS
|
||||
case KeyEvent.VK_W, KeyEvent.VK_UP -> upPressed = true;
|
||||
case KeyEvent.VK_S, KeyEvent.VK_DOWN -> downPressed = true;
|
||||
case KeyEvent.VK_A, KeyEvent.VK_LEFT -> leftPressed = true;
|
||||
case KeyEvent.VK_D, KeyEvent.VK_RIGHT -> rightPressed = true;
|
||||
case KeyEvent.VK_SPACE -> spacePressed = true;
|
||||
|
||||
// DEBUG OPTIONS
|
||||
case KeyEvent.VK_T -> debug = !debug;
|
||||
|
||||
// GAME STATES
|
||||
case KeyEvent.VK_ESCAPE -> panel.gameState = GameState.PAUSE;
|
||||
case KeyEvent.VK_C -> panel.gameState = GameState.CHARACTER;
|
||||
}
|
||||
}
|
||||
public void handlePause(int code) {
|
||||
// EXIT STATE
|
||||
if(code == KeyEvent.VK_ESCAPE) panel.gameState = GameState.PLAY;
|
||||
}
|
||||
public void handleDialogue(int code) {
|
||||
// EXIT STATE
|
||||
if (code == KeyEvent.VK_SPACE) {
|
||||
panel.gameState = GameState.PLAY;
|
||||
}
|
||||
}
|
||||
public void handleCharacter(int code) {
|
||||
// EXIT STATE
|
||||
if(code == KeyEvent.VK_C) panel.gameState = GameState.PLAY;
|
||||
}
|
||||
|
||||
// KEY-LISTENER
|
||||
@Override
|
||||
public void keyTyped(KeyEvent e) {}
|
||||
|
||||
@Override
|
||||
public void keyPressed(KeyEvent e) {
|
||||
int code = e.getKeyCode();
|
||||
switch(panel.gameState) {
|
||||
case PLAY:
|
||||
switch (code) {
|
||||
// CONTROLS
|
||||
case KeyEvent.VK_W, KeyEvent.VK_UP -> upPressed = true;
|
||||
case KeyEvent.VK_S, KeyEvent.VK_DOWN -> downPressed = true;
|
||||
case KeyEvent.VK_A, KeyEvent.VK_LEFT -> leftPressed = true;
|
||||
case KeyEvent.VK_D, KeyEvent.VK_RIGHT -> rightPressed = true;
|
||||
case KeyEvent.VK_SPACE -> spacePressed = true;
|
||||
|
||||
// DEBUG OPTIONS
|
||||
case KeyEvent.VK_T -> checkDrawTime = !checkDrawTime;
|
||||
|
||||
// GAME STATES
|
||||
case KeyEvent.VK_ESCAPE -> panel.gameState = GameState.PAUSE;
|
||||
}
|
||||
handlePlay(code);
|
||||
break;
|
||||
case DIALOGUE:
|
||||
if (code == KeyEvent.VK_SPACE) {
|
||||
panel.gameState = GameState.PLAY;
|
||||
}
|
||||
handleDialogue(code);
|
||||
break;
|
||||
case TITLE:
|
||||
switch (code) {
|
||||
case KeyEvent.VK_UP -> {
|
||||
if(panel.ui.commandNum != 0) panel.ui.commandNum--;
|
||||
}
|
||||
case KeyEvent.VK_DOWN -> {
|
||||
if(panel.ui.commandNum != 2) panel.ui.commandNum++;
|
||||
}
|
||||
case KeyEvent.VK_ENTER -> {
|
||||
switch (panel.ui.commandNum) {
|
||||
case 0:
|
||||
panel.gameState = GameState.PLAY;
|
||||
panel.playMusic(0);
|
||||
break;
|
||||
case 1:
|
||||
// add later
|
||||
break;
|
||||
case 2:
|
||||
System.exit(0);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
handleTitle(code);
|
||||
break;
|
||||
case PAUSE:
|
||||
if(code == KeyEvent.VK_ESCAPE) panel.gameState = GameState.PLAY;
|
||||
handlePause(code);
|
||||
break;
|
||||
case CHARACTER:
|
||||
handleCharacter(code);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/// TODO: setup keybinds that will always work (like pausing the game)
|
||||
// public void alwaysOnKeys(int code) {
|
||||
// // GAME STATES
|
||||
// switch (code) {
|
||||
// case KeyEvent.VK_ESCAPE -> panel.gameState = GameState.PAUSE;
|
||||
// }
|
||||
//
|
||||
// }
|
||||
|
||||
@Override
|
||||
public void keyReleased(KeyEvent e) {
|
||||
int code = e.getKeyCode();
|
||||
|
||||
@@ -88,14 +88,11 @@ public class Player extends Entity {
|
||||
}
|
||||
}
|
||||
|
||||
System.out.println("cancel: "+attackCancel);
|
||||
if(keyH.spacePressed && !attackCancel) {
|
||||
System.out.println("entered");
|
||||
panel.playSE(7);
|
||||
attacking = true;
|
||||
spriteCounter = 0;
|
||||
}
|
||||
System.out.println("attacking: "+attacking);
|
||||
|
||||
attackCancel = false;
|
||||
panel.keyH.spacePressed = false;
|
||||
|
||||
@@ -10,7 +10,7 @@ public class ShieldWoodObj extends Entity {
|
||||
super(panel);
|
||||
name = "shield-wood";
|
||||
type = EntityType.ITEM;
|
||||
down1 = initEntitySprites("assets/objects/shield_wood");
|
||||
down1 = initEntitySprites("objects/shield_wood");
|
||||
defenseValue = 1;
|
||||
}
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@ public class SwordNormalObj extends Entity {
|
||||
|
||||
name = "sword-normal";
|
||||
type = EntityType.ITEM;
|
||||
down1 = initEntitySprites("assets/objects/sword_normal");
|
||||
down1 = initEntitySprites("objects/sword_normal");
|
||||
attackValue = 1;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user