Compare commits
5 Commits
587a852ffb
...
c82bad796e
| Author | SHA1 | Date | |
|---|---|---|---|
|
c82bad796e
|
|||
|
0a7d12aec6
|
|||
|
ed871fc5d4
|
|||
|
435dbc7c0e
|
|||
|
138db014ba
|
@@ -27,6 +27,7 @@ public class GamePanel extends JPanel implements Runnable {
|
|||||||
// WORLD SETTINGS
|
// WORLD SETTINGS
|
||||||
public final int maxWorldCol = 50;
|
public final int maxWorldCol = 50;
|
||||||
public final int maxWorldRow = 50;
|
public final int maxWorldRow = 50;
|
||||||
|
public final String currentMap = "testmap2";
|
||||||
|
|
||||||
//FPS
|
//FPS
|
||||||
final int FPS = 60;
|
final int FPS = 60;
|
||||||
@@ -146,10 +147,13 @@ public class GamePanel extends JPanel implements Runnable {
|
|||||||
|
|
||||||
// DEBUG
|
// DEBUG
|
||||||
if(keyH.debug) {
|
if(keyH.debug) {
|
||||||
|
int start = 350;
|
||||||
graphics2d.setColor(Color.white);
|
graphics2d.setColor(Color.white);
|
||||||
graphics2d.drawString("Draw Time: " + passed, 10, 400);
|
graphics2d.drawString("Draw Time: " + passed, 10, start);
|
||||||
graphics2d.drawString("FPS: " + fpsMeasure, 10, 400+tileSize);
|
graphics2d.drawString("FPS: " + fpsMeasure, 10, start+tileSize);
|
||||||
graphics2d.drawString("Invincible: " + player.invincibleCount, 10, 400+tileSize*2);
|
graphics2d.drawString("Invincible: " + player.invincibleCount, 10, start+tileSize*2);
|
||||||
|
graphics2d.drawString("X, Y: " + player.worldX+", "+player.worldY, 10, start+tileSize*3);
|
||||||
|
graphics2d.drawString("Col, Row: " + (player.worldX+player.solidArea.x)/tileSize+", "+(player.worldY+player.solidArea.y)/tileSize, 10, start+tileSize*4);
|
||||||
Boot.logger.log(Level.FINE, "Draw Time: " + passed);
|
Boot.logger.log(Level.FINE, "Draw Time: " + passed);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import de.miaurizius.jgame2d.entity.item.HeartObj;
|
|||||||
|
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
import java.awt.image.BufferedImage;
|
import java.awt.image.BufferedImage;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
public class UI {
|
public class UI {
|
||||||
|
|
||||||
@@ -13,6 +14,8 @@ public class UI {
|
|||||||
Graphics2D graphics2d;
|
Graphics2D graphics2d;
|
||||||
Font arial_40, arial_80B; //TODO: Custom font loader: https://www.youtube.com/watch?v=g-wrebFVP3E
|
Font arial_40, arial_80B; //TODO: Custom font loader: https://www.youtube.com/watch?v=g-wrebFVP3E
|
||||||
BufferedImage heart_full, heart_half, heart_blank;
|
BufferedImage heart_full, heart_half, heart_blank;
|
||||||
|
ArrayList<String> messages = new ArrayList<>();
|
||||||
|
ArrayList<Integer> messageCounter = new ArrayList<>();
|
||||||
public String currentDialogue;
|
public String currentDialogue;
|
||||||
public int commandNum;
|
public int commandNum;
|
||||||
|
|
||||||
@@ -36,14 +39,12 @@ public class UI {
|
|||||||
if(panel.gameState == null) return;
|
if(panel.gameState == null) return;
|
||||||
switch (panel.gameState) {
|
switch (panel.gameState) {
|
||||||
case GameState.PLAY:
|
case GameState.PLAY:
|
||||||
drawPlayerLife();
|
drawPlayScreen();
|
||||||
break;
|
break;
|
||||||
case GameState.PAUSE:
|
case GameState.PAUSE:
|
||||||
drawPlayerLife();
|
|
||||||
drawPauseScreen();
|
drawPauseScreen();
|
||||||
break;
|
break;
|
||||||
case GameState.DIALOGUE:
|
case GameState.DIALOGUE:
|
||||||
drawPlayerLife();
|
|
||||||
drawDialogueScreen();
|
drawDialogueScreen();
|
||||||
break;
|
break;
|
||||||
case TITLE:
|
case TITLE:
|
||||||
@@ -81,15 +82,38 @@ public class UI {
|
|||||||
x += panel.tileSize;
|
x += panel.tileSize;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
public void drawMessages() {
|
||||||
|
int messageX = panel.tileSize;
|
||||||
|
int messageY = panel.tileSize*4;
|
||||||
|
graphics2d.setFont(graphics2d.getFont().deriveFont(Font.BOLD, 32F));
|
||||||
|
|
||||||
|
for(int i = 0; i < messages.size(); i++) {
|
||||||
|
if(messages.get(i) == null) return;
|
||||||
|
|
||||||
|
graphics2d.setColor(Color.black);
|
||||||
|
graphics2d.drawString(messages.get(i), messageX+2, messageY+2);
|
||||||
|
graphics2d.setColor(Color.white);
|
||||||
|
graphics2d.drawString(messages.get(i), messageX, messageY);
|
||||||
|
|
||||||
|
messageCounter.set(i, messageCounter.get(i) + 1);
|
||||||
|
messageY += 50;
|
||||||
|
if(messageCounter.get(i) > 180) {
|
||||||
|
messages.remove(i);
|
||||||
|
messageCounter.remove(i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// GAME STATES
|
// GAME STATES
|
||||||
public void drawPauseScreen() {
|
public void drawPauseScreen() {
|
||||||
|
drawPlayerLife();
|
||||||
graphics2d.setFont(graphics2d.getFont().deriveFont(Font.PLAIN, 80));
|
graphics2d.setFont(graphics2d.getFont().deriveFont(Font.PLAIN, 80));
|
||||||
String text = "PAUSED";
|
String text = "PAUSED";
|
||||||
int y = panel.screenHeight / 2;
|
int y = panel.screenHeight / 2;
|
||||||
graphics2d.drawString(text, getCenteredX(text), y);
|
graphics2d.drawString(text, getCenteredX(text), y);
|
||||||
}
|
}
|
||||||
public void drawDialogueScreen() {
|
public void drawDialogueScreen() {
|
||||||
|
drawPlayerLife();
|
||||||
// WINDOW
|
// WINDOW
|
||||||
int x = panel.tileSize*2;
|
int x = panel.tileSize*2;
|
||||||
int y = panel.tileSize/2;
|
int y = panel.tileSize/2;
|
||||||
@@ -191,6 +215,10 @@ public class UI {
|
|||||||
textY += panel.tileSize;
|
textY += panel.tileSize;
|
||||||
graphics2d.drawImage(panel.player.currentShield.down1, tailX - panel.tileSize, textY-14, null);
|
graphics2d.drawImage(panel.player.currentShield.down1, tailX - panel.tileSize, textY-14, null);
|
||||||
}
|
}
|
||||||
|
public void drawPlayScreen() {
|
||||||
|
drawPlayerLife();
|
||||||
|
drawMessages();
|
||||||
|
}
|
||||||
|
|
||||||
// UTILITY
|
// UTILITY
|
||||||
public void drawSubWindow(int x, int y, int width, int height) {
|
public void drawSubWindow(int x, int y, int width, int height) {
|
||||||
@@ -206,5 +234,9 @@ public class UI {
|
|||||||
public int getAlignedToRightX(String text, int tailX) {
|
public int getAlignedToRightX(String text, int tailX) {
|
||||||
return tailX - (int) graphics2d.getFontMetrics().getStringBounds(text, graphics2d).getWidth() / 2;
|
return tailX - (int) graphics2d.getFontMetrics().getStringBounds(text, graphics2d).getWidth() / 2;
|
||||||
}
|
}
|
||||||
|
public void addMessage(String text) {
|
||||||
|
messages.add(text);
|
||||||
|
messageCounter.add(0);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,28 +20,33 @@ public class AssetSetter {
|
|||||||
panel.npc[0] = new OldManNPC(panel);
|
panel.npc[0] = new OldManNPC(panel);
|
||||||
panel.npc[0].worldX = panel.tileSize*21;
|
panel.npc[0].worldX = panel.tileSize*21;
|
||||||
panel.npc[0].worldY = panel.tileSize*21;
|
panel.npc[0].worldY = panel.tileSize*21;
|
||||||
|
|
||||||
// panel.npc[0] = new OldManNPC(panel);
|
|
||||||
// panel.npc[0].worldX = panel.tileSize*9;
|
|
||||||
// panel.npc[0].worldY = panel.tileSize*10;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setMonster() {
|
public void setMonster() {
|
||||||
panel.monster[0] = new GreenSlimeMON(panel);
|
int i = 0;
|
||||||
panel.monster[0].worldX = panel.tileSize*23;
|
panel.monster[i] = new GreenSlimeMON(panel);
|
||||||
panel.monster[0].worldY = panel.tileSize*36;
|
panel.monster[i].worldX = panel.tileSize*23;
|
||||||
|
panel.monster[i].worldY = panel.tileSize*36;
|
||||||
|
|
||||||
panel.monster[1] = new GreenSlimeMON(panel);
|
i++;
|
||||||
panel.monster[1].worldX = panel.tileSize*23;
|
panel.monster[i] = new GreenSlimeMON(panel);
|
||||||
panel.monster[1].worldY = panel.tileSize*37;
|
panel.monster[i].worldX = panel.tileSize*23;
|
||||||
|
panel.monster[i].worldY = panel.tileSize*37;
|
||||||
|
|
||||||
// panel.monster[0] = new GreenSlimeMON(panel);
|
i++;
|
||||||
// panel.monster[0].worldX = panel.tileSize*11;
|
panel.monster[i] = new GreenSlimeMON(panel);
|
||||||
// panel.monster[0].worldY = panel.tileSize*10;
|
panel.monster[i].worldX = panel.tileSize*24;
|
||||||
//
|
panel.monster[i].worldY = panel.tileSize*37;
|
||||||
// panel.monster[1] = new GreenSlimeMON(panel);
|
|
||||||
// panel.monster[1].worldX = panel.tileSize*11;
|
i++;
|
||||||
// panel.monster[1].worldY = panel.tileSize*11;
|
panel.monster[i] = new GreenSlimeMON(panel);
|
||||||
|
panel.monster[i].worldX = panel.tileSize*34;
|
||||||
|
panel.monster[i].worldY = panel.tileSize*42;
|
||||||
|
|
||||||
|
i++;
|
||||||
|
panel.monster[i] = new GreenSlimeMON(panel);
|
||||||
|
panel.monster[i].worldX = panel.tileSize*38;
|
||||||
|
panel.monster[i].worldY = panel.tileSize*42;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -84,11 +84,11 @@ public class EventHandler {
|
|||||||
if(!panel.keyH.spacePressed) return;
|
if(!panel.keyH.spacePressed) return;
|
||||||
panel.gameState = gameState;
|
panel.gameState = gameState;
|
||||||
panel.player.attackCancel = true;
|
panel.player.attackCancel = true;
|
||||||
System.out.println("attack cancel");
|
|
||||||
panel.playSE(2);
|
panel.playSE(2);
|
||||||
panel.ui.currentDialogue = "You drank the holy water.\nYour life has been recovered!";
|
panel.ui.currentDialogue = "You drank the holy water.\nYour life has been recovered!\nBut all monsters respawned... \nGood luck!";
|
||||||
panel.player.life = panel.player.maxLife;
|
panel.player.life = panel.player.maxLife;
|
||||||
canTouchEvent = false;
|
canTouchEvent = false;
|
||||||
|
panel.assetSetter.setMonster();
|
||||||
}
|
}
|
||||||
|
|
||||||
static private class EventRect extends Rectangle {
|
static private class EventRect extends Rectangle {
|
||||||
|
|||||||
@@ -52,6 +52,7 @@ public class KeyHandler implements KeyListener {
|
|||||||
|
|
||||||
// DEBUG OPTIONS
|
// DEBUG OPTIONS
|
||||||
case KeyEvent.VK_T -> debug = !debug;
|
case KeyEvent.VK_T -> debug = !debug;
|
||||||
|
case KeyEvent.VK_R -> panel.tileM.loadMap(panel.currentMap);
|
||||||
|
|
||||||
// GAME STATES
|
// GAME STATES
|
||||||
case KeyEvent.VK_ESCAPE -> panel.gameState = GameState.PAUSE;
|
case KeyEvent.VK_ESCAPE -> panel.gameState = GameState.PAUSE;
|
||||||
|
|||||||
@@ -6,7 +6,6 @@ import javax.sound.sampled.AudioInputStream;
|
|||||||
import javax.sound.sampled.AudioSystem;
|
import javax.sound.sampled.AudioSystem;
|
||||||
import javax.sound.sampled.Clip;
|
import javax.sound.sampled.Clip;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.net.MalformedURLException;
|
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
|
|
||||||
@@ -25,6 +24,7 @@ public class Sound {
|
|||||||
load(5, "assets/sounds/hitmonster.wav");
|
load(5, "assets/sounds/hitmonster.wav");
|
||||||
load(6, "assets/sounds/receivedamage.wav");
|
load(6, "assets/sounds/receivedamage.wav");
|
||||||
load(7, "assets/sounds/blocked.wav");
|
load(7, "assets/sounds/blocked.wav");
|
||||||
|
load(8, "assets/sounds/levelup.wav");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Deprecated
|
@Deprecated
|
||||||
@@ -48,14 +48,6 @@ public class Sound {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void play() {
|
|
||||||
clip.start();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void loop() {
|
|
||||||
clip.loop(Clip.LOOP_CONTINUOUSLY);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void stop() {
|
public void stop() {
|
||||||
clip.stop();
|
clip.stop();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -82,7 +82,10 @@ public class Entity {
|
|||||||
if(this.type == EntityType.MONSTER && contactPlayer) {
|
if(this.type == EntityType.MONSTER && contactPlayer) {
|
||||||
if(panel.player.invincible) return;
|
if(panel.player.invincible) return;
|
||||||
panel.playSE(6);
|
panel.playSE(6);
|
||||||
panel.player.life -= 1;
|
|
||||||
|
int damage = attack - panel.player.defense;
|
||||||
|
panel.player.life -= Math.max(damage, 0);
|
||||||
|
|
||||||
panel.player.invincible = true;
|
panel.player.invincible = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -156,7 +159,7 @@ public class Entity {
|
|||||||
|
|
||||||
// INTERACTION
|
// INTERACTION
|
||||||
public void setAction() {}
|
public void setAction() {}
|
||||||
public void damageReaction() {};
|
public void damageReaction() {}
|
||||||
public void speak() {
|
public void speak() {
|
||||||
if(dialogue[dialogueIndex] == null) dialogueIndex = 0;
|
if(dialogue[dialogueIndex] == null) dialogueIndex = 0;
|
||||||
panel.ui.currentDialogue = dialogue[dialogueIndex];
|
panel.ui.currentDialogue = dialogue[dialogueIndex];
|
||||||
|
|||||||
@@ -124,10 +124,16 @@ public class Player extends Entity {
|
|||||||
if(index == 999) return;
|
if(index == 999) return;
|
||||||
if(invincible) return;
|
if(invincible) return;
|
||||||
if(panel.monster[index].dying || !panel.monster[index].alive) return;
|
if(panel.monster[index].dying || !panel.monster[index].alive) return;
|
||||||
life -= 1;
|
|
||||||
|
int damage = panel.monster[index].attack - defense;
|
||||||
|
|
||||||
|
if(damage > 0) {
|
||||||
panel.playSE(6);
|
panel.playSE(6);
|
||||||
|
life -= damage;
|
||||||
invincible = true;
|
invincible = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
public void attacking() {
|
public void attacking() {
|
||||||
if(attackCancel) return;
|
if(attackCancel) return;
|
||||||
spriteCounter++;
|
spriteCounter++;
|
||||||
@@ -166,11 +172,22 @@ public class Player extends Entity {
|
|||||||
public void damageMonster(int index) {
|
public void damageMonster(int index) {
|
||||||
if(index == 999) return;
|
if(index == 999) return;
|
||||||
if(panel.monster[index].invincible) return;
|
if(panel.monster[index].invincible) return;
|
||||||
panel.monster[index].life -= 1;
|
|
||||||
|
int damage = attack - panel.monster[index].defense;
|
||||||
|
|
||||||
|
if(damage > 0) {
|
||||||
panel.playSE(5);
|
panel.playSE(5);
|
||||||
|
panel.monster[index].life -= damage;
|
||||||
panel.monster[index].invincible = true;
|
panel.monster[index].invincible = true;
|
||||||
|
}
|
||||||
|
|
||||||
panel.monster[index].damageReaction();
|
panel.monster[index].damageReaction();
|
||||||
if(panel.monster[index].life <= 0) panel.monster[index].dying = true;
|
if(panel.monster[index].life <= 0) {
|
||||||
|
panel.monster[index].dying = true;
|
||||||
|
panel.ui.addMessage("Gained +" + panel.monster[index].exp + " XP!");
|
||||||
|
exp += panel.monster[index].exp;
|
||||||
|
checkLevelUp();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void interactNPC(int index) {
|
public void interactNPC(int index) {
|
||||||
@@ -185,6 +202,22 @@ public class Player extends Entity {
|
|||||||
super.speak();
|
super.speak();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// BACKGROUND CHECKS
|
||||||
|
public void checkLevelUp() {
|
||||||
|
if(exp < nextLevelExp) return;
|
||||||
|
level++;
|
||||||
|
nextLevelExp = nextLevelExp*2;
|
||||||
|
maxLife += 2;
|
||||||
|
strength++;
|
||||||
|
dexterity++;
|
||||||
|
attack = getAttack();
|
||||||
|
defense = getDefense();
|
||||||
|
panel.playSE(8);
|
||||||
|
|
||||||
|
panel.gameState = GameState.DIALOGUE;
|
||||||
|
panel.ui.currentDialogue = "You are level " + level + " now!\nYou feel stronger!";
|
||||||
|
}
|
||||||
|
|
||||||
// SETTING THINGS UP
|
// SETTING THINGS UP
|
||||||
public void setDefaultValues() {
|
public void setDefaultValues() {
|
||||||
worldX = panel.tileSize * 23;
|
worldX = panel.tileSize * 23;
|
||||||
@@ -210,7 +243,7 @@ public class Player extends Entity {
|
|||||||
return attack = strength * currentWeapon.attackValue;
|
return attack = strength * currentWeapon.attackValue;
|
||||||
}
|
}
|
||||||
public int getDefense() {
|
public int getDefense() {
|
||||||
return defense = dexterity * currentShield.attackValue;
|
return defense = dexterity * currentShield.defenseValue;
|
||||||
}
|
}
|
||||||
public void getPlayerImage() {
|
public void getPlayerImage() {
|
||||||
up1 = initEntitySprites("player/boy_up_1");
|
up1 = initEntitySprites("player/boy_up_1");
|
||||||
|
|||||||
@@ -16,6 +16,9 @@ public class GreenSlimeMON extends Entity {
|
|||||||
speed = 1;
|
speed = 1;
|
||||||
maxLife = 4;
|
maxLife = 4;
|
||||||
life = maxLife;
|
life = maxLife;
|
||||||
|
attack = 5;
|
||||||
|
defense = 0;
|
||||||
|
exp = 2;
|
||||||
|
|
||||||
solidArea.x = 3;
|
solidArea.x = 3;
|
||||||
solidArea.y = 18;
|
solidArea.y = 18;
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ public class TileManager {
|
|||||||
tile = new Tile[50];
|
tile = new Tile[50];
|
||||||
mapTileNum = new int[panel.maxWorldCol][panel.maxWorldRow];
|
mapTileNum = new int[panel.maxWorldCol][panel.maxWorldRow];
|
||||||
getTileImage();
|
getTileImage();
|
||||||
loadMap("testmap2");
|
loadMap(panel.currentMap);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void initializeTile(int i, String name, boolean col) {
|
public void initializeTile(int i, String name, boolean col) {
|
||||||
@@ -86,8 +86,6 @@ public class TileManager {
|
|||||||
initializeTile(40, "wall", true);
|
initializeTile(40, "wall", true);
|
||||||
initializeTile(41, "tree", true);
|
initializeTile(41, "tree", true);
|
||||||
|
|
||||||
|
|
||||||
BufferedImage scaledImage;
|
|
||||||
for (Tile tile : tile) {
|
for (Tile tile : tile) {
|
||||||
if(tile == null) continue;
|
if(tile == null) continue;
|
||||||
tile.image = Utility.scaleImage(tile.image, panel.tileSize, panel.tileSize);
|
tile.image = Utility.scaleImage(tile.image, panel.tileSize, panel.tileSize);
|
||||||
|
|||||||
Reference in New Issue
Block a user