added notifications and added leveling system
This commit is contained in:
@@ -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 {
|
||||||
|
|||||||
@@ -25,6 +25,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
|
||||||
|
|||||||
@@ -125,12 +125,14 @@ public class Player extends Entity {
|
|||||||
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;
|
||||||
|
|
||||||
panel.playSE(6);
|
|
||||||
|
|
||||||
int damage = panel.monster[index].attack - defense;
|
int damage = panel.monster[index].attack - defense;
|
||||||
life -= Math.max(damage, 0);
|
|
||||||
|
|
||||||
invincible = true;
|
if(damage > 0) {
|
||||||
|
panel.playSE(6);
|
||||||
|
life -= damage;
|
||||||
|
invincible = true;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
public void attacking() {
|
public void attacking() {
|
||||||
if(attackCancel) return;
|
if(attackCancel) return;
|
||||||
@@ -170,14 +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.playSE(5);
|
|
||||||
|
|
||||||
int damage = attack - panel.monster[index].defense;
|
int damage = attack - panel.monster[index].defense;
|
||||||
panel.monster[index].life -= Math.max(damage, 0);
|
|
||||||
|
|
||||||
panel.monster[index].invincible = true;
|
if(damage > 0) {
|
||||||
|
panel.playSE(5);
|
||||||
|
panel.monster[index].life -= damage;
|
||||||
|
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) {
|
||||||
@@ -192,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;
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ public class GreenSlimeMON extends Entity {
|
|||||||
life = maxLife;
|
life = maxLife;
|
||||||
attack = 5;
|
attack = 5;
|
||||||
defense = 0;
|
defense = 0;
|
||||||
|
exp = 2;
|
||||||
|
|
||||||
solidArea.x = 3;
|
solidArea.x = 3;
|
||||||
solidArea.y = 18;
|
solidArea.y = 18;
|
||||||
|
|||||||
Reference in New Issue
Block a user