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
|
||||
public final int maxWorldCol = 50;
|
||||
public final int maxWorldRow = 50;
|
||||
public final String currentMap = "testmap2";
|
||||
|
||||
//FPS
|
||||
final int FPS = 60;
|
||||
@@ -146,10 +147,13 @@ public class GamePanel extends JPanel implements Runnable {
|
||||
|
||||
// DEBUG
|
||||
if(keyH.debug) {
|
||||
int start = 350;
|
||||
graphics2d.setColor(Color.white);
|
||||
graphics2d.drawString("Draw Time: " + passed, 10, 400);
|
||||
graphics2d.drawString("FPS: " + fpsMeasure, 10, 400+tileSize);
|
||||
graphics2d.drawString("Invincible: " + player.invincibleCount, 10, 400+tileSize*2);
|
||||
graphics2d.drawString("Draw Time: " + passed, 10, start);
|
||||
graphics2d.drawString("FPS: " + fpsMeasure, 10, start+tileSize);
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@ import de.miaurizius.jgame2d.entity.item.HeartObj;
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class UI {
|
||||
|
||||
@@ -13,6 +14,8 @@ public class UI {
|
||||
Graphics2D graphics2d;
|
||||
Font arial_40, arial_80B; //TODO: Custom font loader: https://www.youtube.com/watch?v=g-wrebFVP3E
|
||||
BufferedImage heart_full, heart_half, heart_blank;
|
||||
ArrayList<String> messages = new ArrayList<>();
|
||||
ArrayList<Integer> messageCounter = new ArrayList<>();
|
||||
public String currentDialogue;
|
||||
public int commandNum;
|
||||
|
||||
@@ -36,14 +39,12 @@ public class UI {
|
||||
if(panel.gameState == null) return;
|
||||
switch (panel.gameState) {
|
||||
case GameState.PLAY:
|
||||
drawPlayerLife();
|
||||
drawPlayScreen();
|
||||
break;
|
||||
case GameState.PAUSE:
|
||||
drawPlayerLife();
|
||||
drawPauseScreen();
|
||||
break;
|
||||
case GameState.DIALOGUE:
|
||||
drawPlayerLife();
|
||||
drawDialogueScreen();
|
||||
break;
|
||||
case TITLE:
|
||||
@@ -81,15 +82,38 @@ public class UI {
|
||||
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
|
||||
public void drawPauseScreen() {
|
||||
drawPlayerLife();
|
||||
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() {
|
||||
drawPlayerLife();
|
||||
// WINDOW
|
||||
int x = panel.tileSize*2;
|
||||
int y = panel.tileSize/2;
|
||||
@@ -191,6 +215,10 @@ public class UI {
|
||||
textY += panel.tileSize;
|
||||
graphics2d.drawImage(panel.player.currentShield.down1, tailX - panel.tileSize, textY-14, null);
|
||||
}
|
||||
public void drawPlayScreen() {
|
||||
drawPlayerLife();
|
||||
drawMessages();
|
||||
}
|
||||
|
||||
// UTILITY
|
||||
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) {
|
||||
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].worldX = 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() {
|
||||
panel.monster[0] = new GreenSlimeMON(panel);
|
||||
panel.monster[0].worldX = panel.tileSize*23;
|
||||
panel.monster[0].worldY = panel.tileSize*36;
|
||||
int i = 0;
|
||||
panel.monster[i] = new GreenSlimeMON(panel);
|
||||
panel.monster[i].worldX = panel.tileSize*23;
|
||||
panel.monster[i].worldY = panel.tileSize*36;
|
||||
|
||||
panel.monster[1] = new GreenSlimeMON(panel);
|
||||
panel.monster[1].worldX = panel.tileSize*23;
|
||||
panel.monster[1].worldY = panel.tileSize*37;
|
||||
i++;
|
||||
panel.monster[i] = new GreenSlimeMON(panel);
|
||||
panel.monster[i].worldX = panel.tileSize*23;
|
||||
panel.monster[i].worldY = panel.tileSize*37;
|
||||
|
||||
// panel.monster[0] = new GreenSlimeMON(panel);
|
||||
// panel.monster[0].worldX = panel.tileSize*11;
|
||||
// panel.monster[0].worldY = panel.tileSize*10;
|
||||
//
|
||||
// panel.monster[1] = new GreenSlimeMON(panel);
|
||||
// panel.monster[1].worldX = panel.tileSize*11;
|
||||
// panel.monster[1].worldY = panel.tileSize*11;
|
||||
i++;
|
||||
panel.monster[i] = new GreenSlimeMON(panel);
|
||||
panel.monster[i].worldX = panel.tileSize*24;
|
||||
panel.monster[i].worldY = panel.tileSize*37;
|
||||
|
||||
i++;
|
||||
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;
|
||||
panel.gameState = gameState;
|
||||
panel.player.attackCancel = true;
|
||||
System.out.println("attack cancel");
|
||||
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;
|
||||
canTouchEvent = false;
|
||||
panel.assetSetter.setMonster();
|
||||
}
|
||||
|
||||
static private class EventRect extends Rectangle {
|
||||
|
||||
@@ -52,6 +52,7 @@ public class KeyHandler implements KeyListener {
|
||||
|
||||
// DEBUG OPTIONS
|
||||
case KeyEvent.VK_T -> debug = !debug;
|
||||
case KeyEvent.VK_R -> panel.tileM.loadMap(panel.currentMap);
|
||||
|
||||
// GAME STATES
|
||||
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.Clip;
|
||||
import java.io.File;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.util.logging.Level;
|
||||
|
||||
@@ -25,6 +24,7 @@ public class Sound {
|
||||
load(5, "assets/sounds/hitmonster.wav");
|
||||
load(6, "assets/sounds/receivedamage.wav");
|
||||
load(7, "assets/sounds/blocked.wav");
|
||||
load(8, "assets/sounds/levelup.wav");
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
@@ -48,14 +48,6 @@ public class Sound {
|
||||
}
|
||||
}
|
||||
|
||||
public void play() {
|
||||
clip.start();
|
||||
}
|
||||
|
||||
public void loop() {
|
||||
clip.loop(Clip.LOOP_CONTINUOUSLY);
|
||||
}
|
||||
|
||||
public void stop() {
|
||||
clip.stop();
|
||||
}
|
||||
|
||||
@@ -82,7 +82,10 @@ public class Entity {
|
||||
if(this.type == EntityType.MONSTER && contactPlayer) {
|
||||
if(panel.player.invincible) return;
|
||||
panel.playSE(6);
|
||||
panel.player.life -= 1;
|
||||
|
||||
int damage = attack - panel.player.defense;
|
||||
panel.player.life -= Math.max(damage, 0);
|
||||
|
||||
panel.player.invincible = true;
|
||||
}
|
||||
|
||||
@@ -156,7 +159,7 @@ public class Entity {
|
||||
|
||||
// INTERACTION
|
||||
public void setAction() {}
|
||||
public void damageReaction() {};
|
||||
public void damageReaction() {}
|
||||
public void speak() {
|
||||
if(dialogue[dialogueIndex] == null) dialogueIndex = 0;
|
||||
panel.ui.currentDialogue = dialogue[dialogueIndex];
|
||||
|
||||
@@ -124,9 +124,15 @@ public class Player extends Entity {
|
||||
if(index == 999) return;
|
||||
if(invincible) return;
|
||||
if(panel.monster[index].dying || !panel.monster[index].alive) return;
|
||||
life -= 1;
|
||||
panel.playSE(6);
|
||||
invincible = true;
|
||||
|
||||
int damage = panel.monster[index].attack - defense;
|
||||
|
||||
if(damage > 0) {
|
||||
panel.playSE(6);
|
||||
life -= damage;
|
||||
invincible = true;
|
||||
}
|
||||
|
||||
}
|
||||
public void attacking() {
|
||||
if(attackCancel) return;
|
||||
@@ -166,11 +172,22 @@ public class Player extends Entity {
|
||||
public void damageMonster(int index) {
|
||||
if(index == 999) return;
|
||||
if(panel.monster[index].invincible) return;
|
||||
panel.monster[index].life -= 1;
|
||||
panel.playSE(5);
|
||||
panel.monster[index].invincible = true;
|
||||
|
||||
int damage = attack - panel.monster[index].defense;
|
||||
|
||||
if(damage > 0) {
|
||||
panel.playSE(5);
|
||||
panel.monster[index].life -= damage;
|
||||
panel.monster[index].invincible = true;
|
||||
}
|
||||
|
||||
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) {
|
||||
@@ -185,6 +202,22 @@ public class Player extends Entity {
|
||||
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
|
||||
public void setDefaultValues() {
|
||||
worldX = panel.tileSize * 23;
|
||||
@@ -210,7 +243,7 @@ public class Player extends Entity {
|
||||
return attack = strength * currentWeapon.attackValue;
|
||||
}
|
||||
public int getDefense() {
|
||||
return defense = dexterity * currentShield.attackValue;
|
||||
return defense = dexterity * currentShield.defenseValue;
|
||||
}
|
||||
public void getPlayerImage() {
|
||||
up1 = initEntitySprites("player/boy_up_1");
|
||||
|
||||
@@ -16,6 +16,9 @@ public class GreenSlimeMON extends Entity {
|
||||
speed = 1;
|
||||
maxLife = 4;
|
||||
life = maxLife;
|
||||
attack = 5;
|
||||
defense = 0;
|
||||
exp = 2;
|
||||
|
||||
solidArea.x = 3;
|
||||
solidArea.y = 18;
|
||||
|
||||
@@ -21,7 +21,7 @@ public class TileManager {
|
||||
tile = new Tile[50];
|
||||
mapTileNum = new int[panel.maxWorldCol][panel.maxWorldRow];
|
||||
getTileImage();
|
||||
loadMap("testmap2");
|
||||
loadMap(panel.currentMap);
|
||||
}
|
||||
|
||||
public void initializeTile(int i, String name, boolean col) {
|
||||
@@ -86,8 +86,6 @@ public class TileManager {
|
||||
initializeTile(40, "wall", true);
|
||||
initializeTile(41, "tree", true);
|
||||
|
||||
|
||||
BufferedImage scaledImage;
|
||||
for (Tile tile : tile) {
|
||||
if(tile == null) continue;
|
||||
tile.image = Utility.scaleImage(tile.image, panel.tileSize, panel.tileSize);
|
||||
|
||||
Reference in New Issue
Block a user