arranged large classes

This commit is contained in:
2025-11-29 23:08:20 +01:00
parent 0dde029719
commit b513370152
6 changed files with 84 additions and 86 deletions

View File

@@ -62,18 +62,12 @@ public class GamePanel extends JPanel implements Runnable {
this.setFocusable(true);
}
public void setupGame() {
assetSetter.setObject();
assetSetter.setNPC();
assetSetter.setMonster();
gameState = GameState.TITLE;
}
// GAME THREAD / CORE
public void startGameThread() {
gameThread = new Thread(this);
gameThread.start();
}
@Override
public void run() {
double drawInterval = (double) 1000000000 / FPS;
@@ -103,6 +97,7 @@ public class GamePanel extends JPanel implements Runnable {
}
}
// FRAME GENERATION
public void update() {
switch(gameState) {
case PLAY:
@@ -114,7 +109,6 @@ public class GamePanel extends JPanel implements Runnable {
break;
}
}
public void paintComponent(Graphics graphics) {
super.paintComponent(graphics);
Graphics2D graphics2d = (Graphics2D) graphics;
@@ -159,19 +153,26 @@ public class GamePanel extends JPanel implements Runnable {
graphics.dispose();
}
// MUSIC
public void playMusic(int i) {
music.setFile(i);
music.play();
music.loop();
}
public void stopMusic() {
music.stop();
}
public void playSE(int i) {
se.setFile(i);
se.play();
}
// SETTING THINGS UP
public void setupGame() {
assetSetter.setObject();
assetSetter.setNPC();
assetSetter.setMonster();
gameState = GameState.TITLE;
}
}

View File

@@ -52,6 +52,7 @@ public class UI {
}
}
// HUD
public void drawPlayerLife() {
int x = panel.tileSize / 2;
int y = panel.tileSize / 2;
@@ -78,13 +79,13 @@ public class UI {
}
}
// GAME STATES
public void drawPauseScreen() {
graphics2d.setFont(graphics2d.getFont().deriveFont(Font.PLAIN, 80));
String text = "PAUSED";
int y = panel.screenHeight / 2;
graphics2d.drawString(text, getCenteredX(text), y);
}
public void drawDialogueScreen() {
// WINDOW
int x = panel.tileSize*2;
@@ -102,7 +103,6 @@ public class UI {
y += 40;
}
}
public void drawTitleScreen() {
graphics2d.setColor(new Color(0, 0, 0));
graphics2d.fillRect(0, 0, panel.screenWidth, panel.screenHeight);
@@ -142,6 +142,7 @@ public class UI {
if(commandNum == 2) graphics2d.drawString(">", x-panel.tileSize, y);
}
// UTILITY
public void drawSubWindow(int x, int y, int width, int height) {
graphics2d.setColor(new Color(0,0,0,210));
graphics2d.fillRoundRect(x, y, width, height, 35, 35);
@@ -149,7 +150,6 @@ public class UI {
graphics2d.setStroke(new BasicStroke(5));
graphics2d.drawRoundRect(x+5, y+5, width-10, height-10, 25, 25);
}
public int getCenteredX(String text) {
return panel.screenWidth / 2 - (int) graphics2d.getFontMetrics().getStringBounds(text, graphics2d).getWidth() / 2;
}

View File

@@ -11,6 +11,7 @@ public class CollisionHandler {
this.panel = panel;
}
// WORLD COLLISION
public void checkTile(Entity entity) {
int entityLeftWorldX = entity.worldX + entity.solidArea.x;
int entityRightWorldX = entity.worldX + entity.solidArea.x + entity.solidArea.width;
@@ -51,7 +52,6 @@ public class CollisionHandler {
break;
}
}
public int checkObject(Entity entity, boolean player) {
int index = 999;
int c = -1;
@@ -112,7 +112,6 @@ public class CollisionHandler {
}
return index;
}
public boolean checkPlayer(Entity entity) {
boolean contactPlayer = false;
entity.solidArea.x += entity.worldX;
@@ -135,6 +134,7 @@ public class CollisionHandler {
return contactPlayer;
}
// UTILITY
private void parseSolidArea(Entity entity) {
switch (entity.direction) {
case UP -> entity.solidArea.y -= entity.speed;