Compare commits
11 Commits
04c5192e0e
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
3102ce0e9b
|
|||
|
3e4fe8f2bf
|
|||
|
e0fc6b2803
|
|||
|
07549cf241
|
|||
|
f44e5478ab
|
|||
|
aadd01f8ec
|
|||
|
7bbbd8f72b
|
|||
|
6ef2391719
|
|||
|
b20f423348
|
|||
|
e5b86cd778
|
|||
|
8961dd0e1b
|
22
build.bat
Normal file
22
build.bat
Normal file
@@ -0,0 +1,22 @@
|
||||
@echo off
|
||||
echo [1/4] Clearing old files...
|
||||
rd /s /q "out/app"
|
||||
|
||||
echo [2/4] Building game...
|
||||
jpackage --type app-image ^
|
||||
--dest "out/app" ^
|
||||
--name "JGame2D" ^
|
||||
--input "out/artifacts/JGame2D_jar" ^
|
||||
--main-jar "JGame2D.jar" ^
|
||||
--main-class de.miaurizius.jgame2d.core.Boot
|
||||
|
||||
echo [3/4] Copy assets
|
||||
robocopy "assets" "out/app/JGame2D/assets" /e > nul
|
||||
|
||||
echo [4/4] Zipping...
|
||||
cd out\app
|
||||
tar -a -c -f ..\JGame2D.zip JGame2D
|
||||
|
||||
cd ../..
|
||||
|
||||
echo Done!
|
||||
32
build.sh
32
build.sh
@@ -1,10 +1,24 @@
|
||||
rm -rf out/app
|
||||
#!/bin/bash
|
||||
|
||||
jpackage \
|
||||
--input out/artifacts/JGame2D_jar/ \
|
||||
--main-jar JGame2D.jar \
|
||||
--main-class de.miaurizius.jgame2d.core.Boot \
|
||||
--name JGame2D \
|
||||
--type app-image \
|
||||
--add-modules ALL-MODULE-PATH \
|
||||
--dest out/app
|
||||
echo "[1/4] Clearing old files..."
|
||||
rm -rf "out/app"
|
||||
|
||||
echo "[2/4] Building game..."
|
||||
jpackage --type app-image \
|
||||
--dest "out/app" \
|
||||
--name "JGame2D" \
|
||||
--input "out/artifacts/JGame2D_jar" \
|
||||
--main-jar "JGame2D.jar" \
|
||||
--main-class de.miaurizius.jgame2d.core.Boot
|
||||
|
||||
echo "[3/4] Copy assets..."
|
||||
mkdir -p "out/app/JGame2D/assets"
|
||||
cp -r assets/* "out/app/JGame2D/assets/"
|
||||
|
||||
echo "[4/4] Zipping..."
|
||||
cd out/app
|
||||
zip -r ../JGame2D.zip JGame2D
|
||||
|
||||
cd ../..
|
||||
|
||||
echo "Done!"
|
||||
@@ -28,6 +28,10 @@ public class GamePanel extends JPanel implements Runnable {
|
||||
// SCREEN SETTINGS
|
||||
final int originalTileSize = 16; //16x16 tile
|
||||
final int scale = 3;
|
||||
/*
|
||||
final int originalTileSize = 48; //16x16 tile
|
||||
final int scale = 1;
|
||||
*/
|
||||
public final int tileSize = originalTileSize * scale; //48x48 tile
|
||||
public final int maxScreenCol = 20;
|
||||
public final int maxScreenRow = 12;
|
||||
@@ -78,6 +82,8 @@ public class GamePanel extends JPanel implements Runnable {
|
||||
|
||||
// GAME STATE
|
||||
public GameState gameState;
|
||||
public Map.Area currentArea;
|
||||
public Map.Area nextArea;
|
||||
|
||||
public GamePanel() throws IOException {
|
||||
this.setPreferredSize(new Dimension(screenWidth, screenHeight));
|
||||
@@ -205,13 +211,14 @@ public class GamePanel extends JPanel implements Runnable {
|
||||
|
||||
// DEBUG
|
||||
if(keyH.debug) {
|
||||
int start = 350;
|
||||
int start = 300;
|
||||
fg2.setColor(Color.white);
|
||||
fg2.drawString("Draw Time: " + passed, 10, start);
|
||||
fg2.drawString("FPS: " + fpsMeasure, 10, start+tileSize);
|
||||
fg2.drawString("Invincible: " + player.invincibleCount, 10, start+tileSize*2);
|
||||
fg2.drawString("X, Y: " + player.worldX+", "+player.worldY, 10, start+tileSize*3);
|
||||
fg2.drawString("Col, Row: " + (player.worldX+player.solidArea.x)/tileSize+", "+(player.worldY+player.solidArea.y)/tileSize, 10, start+tileSize*4);
|
||||
fg2.drawString("God Mode: " + keyH.godMode, 10, start+tileSize*5);
|
||||
Boot.logger.log(Level.FINE, "Draw Time: " + passed);
|
||||
}
|
||||
}
|
||||
@@ -252,6 +259,7 @@ public class GamePanel extends JPanel implements Runnable {
|
||||
assetSetter.setITiles();
|
||||
eManager.setup();
|
||||
gameState = GameState.TITLE;
|
||||
currentArea = Map.Area.OUTSIDE;
|
||||
|
||||
tempScreen = new BufferedImage(screenWidth, screenHeight, BufferedImage.TYPE_INT_RGB);
|
||||
fg2 = (Graphics2D) tempScreen.getGraphics();
|
||||
@@ -279,4 +287,16 @@ public class GamePanel extends JPanel implements Runnable {
|
||||
assetSetter.setITiles();
|
||||
eManager.lighting.resetDay();
|
||||
}
|
||||
public void changeArea() {
|
||||
if(nextArea != currentArea) {
|
||||
stopMusic();
|
||||
if(nextArea == Map.Area.OUTSIDE) playMusic(0);
|
||||
else if(nextArea == Map.Area.DUNGEON) playMusic(19);
|
||||
else if(nextArea == Map.Area.INDOOR) playMusic(18);
|
||||
}
|
||||
currentArea = nextArea;
|
||||
nextArea = null;
|
||||
assetSetter.setNPC();
|
||||
// assetSetter.setMonster();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,6 +28,8 @@ public class UI {
|
||||
public int npcSlotCol, npcSlotRow;
|
||||
private int transCount;
|
||||
private int sleepCount;
|
||||
private int charIndex;
|
||||
private String combinedText;
|
||||
|
||||
// SUB-STATES
|
||||
public TradeState tradeState = TradeState.SELECT;
|
||||
@@ -294,6 +296,29 @@ public class UI {
|
||||
x += panel.tileSize;
|
||||
y += panel.tileSize;
|
||||
|
||||
if(tradingNPC.dialogue[tradingNPC.dialogueSet][tradingNPC.dialogueIndex] != null) {
|
||||
currentDialogue = tradingNPC.dialogue[tradingNPC.dialogueSet][tradingNPC.dialogueIndex];
|
||||
char[] characters = tradingNPC.dialogue[tradingNPC.dialogueSet][tradingNPC.dialogueIndex].toCharArray();
|
||||
if(charIndex < characters.length) {
|
||||
String s = String.valueOf(characters[charIndex]);
|
||||
panel.playSE(17);
|
||||
combinedText = combinedText + s;
|
||||
currentDialogue = combinedText;
|
||||
charIndex++;
|
||||
}
|
||||
if(panel.keyH.spacePressed) {
|
||||
charIndex = 0;
|
||||
combinedText = "";
|
||||
if(panel.gameState == GameState.DIALOGUE) {
|
||||
tradingNPC.dialogueIndex++;
|
||||
panel.keyH.spacePressed = false;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
tradingNPC.dialogueIndex = 0;
|
||||
if(panel.gameState == GameState.DIALOGUE) panel.gameState = GameState.PLAY;
|
||||
}
|
||||
|
||||
for(String line : currentDialogue.split("\n")) {
|
||||
graphics2d.drawString(line, x, y);
|
||||
y += 40;
|
||||
@@ -389,6 +414,7 @@ public class UI {
|
||||
panel.player.worldY = panel.tileSize * panel.eventH.tempRow;
|
||||
panel.eventH.prevEventX = panel.player.worldX;
|
||||
panel.eventH.prevEventY = panel.player.worldY;
|
||||
panel.changeArea();
|
||||
}
|
||||
private void drawTradeScreen() {
|
||||
switch(tradeState) {
|
||||
@@ -419,6 +445,7 @@ public class UI {
|
||||
|
||||
// TRADING
|
||||
private void tradeSelect() {
|
||||
tradingNPC.dialogueSet = 0;
|
||||
drawDialogueScreen();
|
||||
|
||||
int x = panel.tileSize*15;
|
||||
@@ -449,9 +476,8 @@ public class UI {
|
||||
graphics2d.drawString(">", x-panel.tileSize/2, y);
|
||||
if(panel.keyH.spacePressed) {
|
||||
commandNum = 0;
|
||||
tradingNPC.startDialogue(tradingNPC,1);
|
||||
tradeState = TradeState.SELECT;
|
||||
panel.gameState = GameState.DIALOGUE;
|
||||
currentDialogue = "Come again, hehe!";
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -488,9 +514,7 @@ public class UI {
|
||||
if(!panel.keyH.spacePressed) return;
|
||||
if(tradingNPC.inventory.get(itemIndex).price > panel.player.coins) {
|
||||
tradeState = TradeState.SELECT;
|
||||
panel.gameState = GameState.DIALOGUE;
|
||||
currentDialogue = "You need more coins to buy that!";
|
||||
drawDialogueScreen();
|
||||
tradingNPC.startDialogue(tradingNPC,2);
|
||||
return;
|
||||
}
|
||||
if(panel.player.canObtainItem(tradingNPC.inventory.get(itemIndex))) {
|
||||
@@ -498,9 +522,7 @@ public class UI {
|
||||
return;
|
||||
}
|
||||
tradeState = TradeState.SELECT;
|
||||
panel.gameState = GameState.DIALOGUE;
|
||||
currentDialogue = "Your inventory is full!";
|
||||
drawDialogueScreen();
|
||||
tradingNPC.startDialogue(tradingNPC,3);
|
||||
}
|
||||
}
|
||||
private void tradeSell() {
|
||||
@@ -537,8 +559,7 @@ public class UI {
|
||||
if(panel.player.inventory.get(itemIndex) == panel.player.currentWeapon || panel.player.inventory.get(itemIndex) == panel.player.currentShield) {
|
||||
commandNum = 0;
|
||||
tradeState = TradeState.SELECT;
|
||||
panel.gameState = GameState.DIALOGUE;
|
||||
currentDialogue = "You cannot sell an equipped item!";
|
||||
tradingNPC.startDialogue(tradingNPC,4);
|
||||
return;
|
||||
}
|
||||
if(panel.player.inventory.get(itemIndex).amt <= 1) panel.player.inventory.remove(itemIndex);
|
||||
@@ -736,7 +757,6 @@ public class UI {
|
||||
if(commandNum == 1) {
|
||||
graphics2d.drawString(">", textX-25, textY);
|
||||
if(panel.keyH.spacePressed) optionState = OptionState.OVERVIEW;
|
||||
panel.resetGame(true);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -15,7 +15,8 @@ public enum EntityType {
|
||||
|
||||
public enum WeaponType {
|
||||
SWORD,
|
||||
AXE
|
||||
AXE,
|
||||
PICKAXE
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -2,15 +2,19 @@ package de.miaurizius.jgame2d.core.enums;
|
||||
|
||||
public enum Map {
|
||||
|
||||
OVERWORLD("worldmap", 0),
|
||||
HUT("indoor01", 1);
|
||||
OVERWORLD("worldmap", 0, Area.OUTSIDE),
|
||||
HUT("indoor01", 1, Area.INDOOR),
|
||||
DUNGEON_FIRST_FLOOR("dungeon01",2, Area.DUNGEON),
|
||||
DUNGEON_SECOND_FLOOR("dungeon02", 3, Area.DUNGEON);
|
||||
|
||||
private final String name;
|
||||
private final int index;
|
||||
private final Area area;
|
||||
|
||||
Map(String name, int index) {
|
||||
Map(String name, int index, Area area) {
|
||||
this.name = name;
|
||||
this.index = index;
|
||||
this.area = area;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
@@ -20,4 +24,15 @@ public enum Map {
|
||||
public int getIndex() {
|
||||
return index;
|
||||
}
|
||||
|
||||
public Area getArea() {
|
||||
return area;
|
||||
}
|
||||
|
||||
public enum Area {
|
||||
INDOOR,
|
||||
OUTSIDE,
|
||||
DUNGEON
|
||||
}
|
||||
|
||||
}
|
||||
@@ -3,13 +3,19 @@ package de.miaurizius.jgame2d.core.handlers;
|
||||
import de.miaurizius.jgame2d.core.GamePanel;
|
||||
import de.miaurizius.jgame2d.core.enums.Map;
|
||||
import de.miaurizius.jgame2d.entity.item.*;
|
||||
import de.miaurizius.jgame2d.entity.monster.BatMON;
|
||||
import de.miaurizius.jgame2d.entity.monster.OrcMON;
|
||||
import de.miaurizius.jgame2d.entity.monster.SkeletonLordMON;
|
||||
import de.miaurizius.jgame2d.entity.npc.BigRockNPC;
|
||||
import de.miaurizius.jgame2d.entity.npc.MerchantNPC;
|
||||
import de.miaurizius.jgame2d.entity.npc.OldManNPC;
|
||||
import de.miaurizius.jgame2d.entity.monster.GreenSlimeMON;
|
||||
import de.miaurizius.jgame2d.entity.obstacle.ChestObj;
|
||||
import de.miaurizius.jgame2d.entity.obstacle.DoorObj;
|
||||
import de.miaurizius.jgame2d.tile.interactive.DryTreeTI;
|
||||
import de.miaurizius.jgame2d.entity.obstacle.IronDoorObj;
|
||||
import de.miaurizius.jgame2d.tile.interactive.DestructibleWallIT;
|
||||
import de.miaurizius.jgame2d.tile.interactive.DryTreeIT;
|
||||
import de.miaurizius.jgame2d.tile.interactive.MetalPlateIT;
|
||||
|
||||
public class AssetSetter {
|
||||
|
||||
@@ -41,6 +47,36 @@ public class AssetSetter {
|
||||
panel.obj[Map.OVERWORLD.getIndex()][i].worldX = panel.tileSize*30;
|
||||
panel.obj[Map.OVERWORLD.getIndex()][i].worldY = panel.tileSize*29;
|
||||
i++;
|
||||
|
||||
i = 0;
|
||||
panel.obj[Map.DUNGEON_FIRST_FLOOR.getIndex()][i] = new ChestObj(panel);
|
||||
panel.obj[Map.DUNGEON_FIRST_FLOOR.getIndex()][i].setLoot(new PickaxeObj(panel));
|
||||
panel.obj[Map.DUNGEON_FIRST_FLOOR.getIndex()][i].worldX = panel.tileSize*40;
|
||||
panel.obj[Map.DUNGEON_FIRST_FLOOR.getIndex()][i].worldY = panel.tileSize*41;
|
||||
i++;
|
||||
|
||||
panel.obj[Map.DUNGEON_FIRST_FLOOR.getIndex()][i] = new ChestObj(panel);
|
||||
panel.obj[Map.DUNGEON_FIRST_FLOOR.getIndex()][i].setLoot(new PotionObj(panel));
|
||||
panel.obj[Map.DUNGEON_FIRST_FLOOR.getIndex()][i].worldX = panel.tileSize*13;
|
||||
panel.obj[Map.DUNGEON_FIRST_FLOOR.getIndex()][i].worldY = panel.tileSize*16;
|
||||
i++;
|
||||
|
||||
panel.obj[Map.DUNGEON_FIRST_FLOOR.getIndex()][i] = new ChestObj(panel);
|
||||
panel.obj[Map.DUNGEON_FIRST_FLOOR.getIndex()][i].setLoot(new PotionObj(panel));
|
||||
panel.obj[Map.DUNGEON_FIRST_FLOOR.getIndex()][i].worldX = panel.tileSize*26;
|
||||
panel.obj[Map.DUNGEON_FIRST_FLOOR.getIndex()][i].worldY = panel.tileSize*34;
|
||||
i++;
|
||||
|
||||
panel.obj[Map.DUNGEON_FIRST_FLOOR.getIndex()][i] = new ChestObj(panel);
|
||||
panel.obj[Map.DUNGEON_FIRST_FLOOR.getIndex()][i].setLoot(new PotionObj(panel));
|
||||
panel.obj[Map.DUNGEON_FIRST_FLOOR.getIndex()][i].worldX = panel.tileSize*27;
|
||||
panel.obj[Map.DUNGEON_FIRST_FLOOR.getIndex()][i].worldY = panel.tileSize*15;
|
||||
i++;
|
||||
|
||||
panel.obj[Map.DUNGEON_FIRST_FLOOR.getIndex()][i] = new IronDoorObj(panel);
|
||||
panel.obj[Map.DUNGEON_FIRST_FLOOR.getIndex()][i].worldX = panel.tileSize*18;
|
||||
panel.obj[Map.DUNGEON_FIRST_FLOOR.getIndex()][i].worldY = panel.tileSize*23;
|
||||
i++;
|
||||
}
|
||||
|
||||
public void setNPC() {
|
||||
@@ -51,6 +87,23 @@ public class AssetSetter {
|
||||
panel.npc[Map.HUT.getIndex()][0] = new MerchantNPC(panel);
|
||||
panel.npc[Map.HUT.getIndex()][0].worldX = panel.tileSize*12;
|
||||
panel.npc[Map.HUT.getIndex()][0].worldY = panel.tileSize*7;
|
||||
|
||||
|
||||
int i = 0;
|
||||
panel.npc[Map.DUNGEON_FIRST_FLOOR.getIndex()][i] = new BigRockNPC(panel);
|
||||
panel.npc[Map.DUNGEON_FIRST_FLOOR.getIndex()][i].worldX = panel.tileSize*20;
|
||||
panel.npc[Map.DUNGEON_FIRST_FLOOR.getIndex()][i].worldY = panel.tileSize*25;
|
||||
i++;
|
||||
|
||||
panel.npc[Map.DUNGEON_FIRST_FLOOR.getIndex()][i] = new BigRockNPC(panel);
|
||||
panel.npc[Map.DUNGEON_FIRST_FLOOR.getIndex()][i].worldX = panel.tileSize*11;
|
||||
panel.npc[Map.DUNGEON_FIRST_FLOOR.getIndex()][i].worldY = panel.tileSize*18;
|
||||
i++;
|
||||
|
||||
panel.npc[Map.DUNGEON_FIRST_FLOOR.getIndex()][i] = new BigRockNPC(panel);
|
||||
panel.npc[Map.DUNGEON_FIRST_FLOOR.getIndex()][i].worldX = panel.tileSize*23;
|
||||
panel.npc[Map.DUNGEON_FIRST_FLOOR.getIndex()][i].worldY = panel.tileSize*14;
|
||||
i++;
|
||||
}
|
||||
|
||||
public void setMonster() {
|
||||
@@ -83,42 +136,95 @@ public class AssetSetter {
|
||||
panel.monster[Map.OVERWORLD.getIndex()][i] = new OrcMON(panel);
|
||||
panel.monster[Map.OVERWORLD.getIndex()][i].worldX = panel.tileSize*12;
|
||||
panel.monster[Map.OVERWORLD.getIndex()][i].worldY = panel.tileSize*33;
|
||||
|
||||
i = 0;
|
||||
panel.monster[Map.DUNGEON_FIRST_FLOOR.getIndex()][i] = new BatMON(panel);
|
||||
panel.monster[Map.DUNGEON_FIRST_FLOOR.getIndex()][i].worldX = panel.tileSize*34;
|
||||
panel.monster[Map.DUNGEON_FIRST_FLOOR.getIndex()][i].worldY = panel.tileSize*39;
|
||||
|
||||
i++;
|
||||
panel.monster[Map.DUNGEON_FIRST_FLOOR.getIndex()][i] = new BatMON(panel);
|
||||
panel.monster[Map.DUNGEON_FIRST_FLOOR.getIndex()][i].worldX = panel.tileSize*36;
|
||||
panel.monster[Map.DUNGEON_FIRST_FLOOR.getIndex()][i].worldY = panel.tileSize*25;
|
||||
|
||||
i++;
|
||||
panel.monster[Map.DUNGEON_FIRST_FLOOR.getIndex()][i] = new BatMON(panel);
|
||||
panel.monster[Map.DUNGEON_FIRST_FLOOR.getIndex()][i].worldX = panel.tileSize*39;
|
||||
panel.monster[Map.DUNGEON_FIRST_FLOOR.getIndex()][i].worldY = panel.tileSize*26;
|
||||
|
||||
i++;
|
||||
panel.monster[Map.DUNGEON_FIRST_FLOOR.getIndex()][i] = new BatMON(panel);
|
||||
panel.monster[Map.DUNGEON_FIRST_FLOOR.getIndex()][i].worldX = panel.tileSize*28;
|
||||
panel.monster[Map.DUNGEON_FIRST_FLOOR.getIndex()][i].worldY = panel.tileSize*11;
|
||||
|
||||
i++;
|
||||
panel.monster[Map.DUNGEON_FIRST_FLOOR.getIndex()][i] = new BatMON(panel);
|
||||
panel.monster[Map.DUNGEON_FIRST_FLOOR.getIndex()][i].worldX = panel.tileSize*10;
|
||||
panel.monster[Map.DUNGEON_FIRST_FLOOR.getIndex()][i].worldY = panel.tileSize*19;
|
||||
|
||||
i = 0;
|
||||
panel.monster[Map.DUNGEON_SECOND_FLOOR.getIndex()][i] = new SkeletonLordMON(panel);
|
||||
panel.monster[Map.DUNGEON_SECOND_FLOOR.getIndex()][i].worldX = panel.tileSize*23;
|
||||
panel.monster[Map.DUNGEON_SECOND_FLOOR.getIndex()][i].worldY = panel.tileSize*16;
|
||||
}
|
||||
|
||||
public void setITiles() {
|
||||
int i = 0;
|
||||
panel.iTile[Map.OVERWORLD.getIndex()][i] = new DryTreeTI(panel,27,12);i++;
|
||||
panel.iTile[Map.OVERWORLD.getIndex()][i] = new DryTreeTI(panel,28,12);i++;
|
||||
panel.iTile[Map.OVERWORLD.getIndex()][i] = new DryTreeTI(panel,29,12);i++;
|
||||
panel.iTile[Map.OVERWORLD.getIndex()][i] = new DryTreeTI(panel,30,12);i++;
|
||||
panel.iTile[Map.OVERWORLD.getIndex()][i] = new DryTreeTI(panel,31,12);i++;
|
||||
panel.iTile[Map.OVERWORLD.getIndex()][i] = new DryTreeTI(panel,32,12);i++;
|
||||
panel.iTile[Map.OVERWORLD.getIndex()][i] = new DryTreeTI(panel,33,12);i++;
|
||||
panel.iTile[Map.OVERWORLD.getIndex()][i] = new DryTreeIT(panel,27,12);i++;
|
||||
panel.iTile[Map.OVERWORLD.getIndex()][i] = new DryTreeIT(panel,28,12);i++;
|
||||
panel.iTile[Map.OVERWORLD.getIndex()][i] = new DryTreeIT(panel,29,12);i++;
|
||||
panel.iTile[Map.OVERWORLD.getIndex()][i] = new DryTreeIT(panel,30,12);i++;
|
||||
panel.iTile[Map.OVERWORLD.getIndex()][i] = new DryTreeIT(panel,31,12);i++;
|
||||
panel.iTile[Map.OVERWORLD.getIndex()][i] = new DryTreeIT(panel,32,12);i++;
|
||||
panel.iTile[Map.OVERWORLD.getIndex()][i] = new DryTreeIT(panel,33,12);i++;
|
||||
|
||||
panel.iTile[Map.OVERWORLD.getIndex()][i] = new DryTreeTI(panel,30,21);i++;
|
||||
panel.iTile[Map.OVERWORLD.getIndex()][i] = new DryTreeIT(panel,30,21);i++;
|
||||
|
||||
panel.iTile[Map.OVERWORLD.getIndex()][i] = new DryTreeTI(panel,25,27);i++;
|
||||
panel.iTile[Map.OVERWORLD.getIndex()][i] = new DryTreeTI(panel,26,27);i++;
|
||||
panel.iTile[Map.OVERWORLD.getIndex()][i] = new DryTreeTI(panel,27,27);i++;
|
||||
panel.iTile[Map.OVERWORLD.getIndex()][i] = new DryTreeTI(panel,27,28);i++;
|
||||
panel.iTile[Map.OVERWORLD.getIndex()][i] = new DryTreeTI(panel,27,29);i++;
|
||||
panel.iTile[Map.OVERWORLD.getIndex()][i] = new DryTreeTI(panel,27,30);i++;
|
||||
panel.iTile[Map.OVERWORLD.getIndex()][i] = new DryTreeTI(panel,27,31);i++;
|
||||
panel.iTile[Map.OVERWORLD.getIndex()][i] = new DryTreeTI(panel,28,31);i++;
|
||||
panel.iTile[Map.OVERWORLD.getIndex()][i] = new DryTreeTI(panel,29,31);i++;
|
||||
panel.iTile[Map.OVERWORLD.getIndex()][i] = new DryTreeTI(panel,30,31);i++;
|
||||
panel.iTile[Map.OVERWORLD.getIndex()][i] = new DryTreeIT(panel,25,27);i++;
|
||||
panel.iTile[Map.OVERWORLD.getIndex()][i] = new DryTreeIT(panel,26,27);i++;
|
||||
panel.iTile[Map.OVERWORLD.getIndex()][i] = new DryTreeIT(panel,27,27);i++;
|
||||
panel.iTile[Map.OVERWORLD.getIndex()][i] = new DryTreeIT(panel,27,28);i++;
|
||||
panel.iTile[Map.OVERWORLD.getIndex()][i] = new DryTreeIT(panel,27,29);i++;
|
||||
panel.iTile[Map.OVERWORLD.getIndex()][i] = new DryTreeIT(panel,27,30);i++;
|
||||
panel.iTile[Map.OVERWORLD.getIndex()][i] = new DryTreeIT(panel,27,31);i++;
|
||||
panel.iTile[Map.OVERWORLD.getIndex()][i] = new DryTreeIT(panel,28,31);i++;
|
||||
panel.iTile[Map.OVERWORLD.getIndex()][i] = new DryTreeIT(panel,29,31);i++;
|
||||
panel.iTile[Map.OVERWORLD.getIndex()][i] = new DryTreeIT(panel,30,31);i++;
|
||||
|
||||
panel.iTile[Map.OVERWORLD.getIndex()][i] = new DryTreeTI(panel,18,40);i++;
|
||||
panel.iTile[Map.OVERWORLD.getIndex()][i] = new DryTreeTI(panel,17,40);i++;
|
||||
panel.iTile[Map.OVERWORLD.getIndex()][i] = new DryTreeTI(panel,16,40);i++;
|
||||
panel.iTile[Map.OVERWORLD.getIndex()][i] = new DryTreeTI(panel,15,40);i++;
|
||||
panel.iTile[Map.OVERWORLD.getIndex()][i] = new DryTreeTI(panel,14,40);i++;
|
||||
panel.iTile[Map.OVERWORLD.getIndex()][i] = new DryTreeTI(panel,13,40);i++;
|
||||
panel.iTile[Map.OVERWORLD.getIndex()][i] = new DryTreeTI(panel,13,41);i++;
|
||||
panel.iTile[Map.OVERWORLD.getIndex()][i] = new DryTreeTI(panel,12,41);i++;
|
||||
panel.iTile[Map.OVERWORLD.getIndex()][i] = new DryTreeTI(panel,11,41);i++;
|
||||
panel.iTile[Map.OVERWORLD.getIndex()][i] = new DryTreeTI(panel,10,41);i++;
|
||||
panel.iTile[Map.OVERWORLD.getIndex()][i] = new DryTreeTI(panel,10,40);i++;
|
||||
panel.iTile[Map.OVERWORLD.getIndex()][i] = new DryTreeIT(panel,18,40);i++;
|
||||
panel.iTile[Map.OVERWORLD.getIndex()][i] = new DryTreeIT(panel,17,40);i++;
|
||||
panel.iTile[Map.OVERWORLD.getIndex()][i] = new DryTreeIT(panel,16,40);i++;
|
||||
panel.iTile[Map.OVERWORLD.getIndex()][i] = new DryTreeIT(panel,15,40);i++;
|
||||
panel.iTile[Map.OVERWORLD.getIndex()][i] = new DryTreeIT(panel,14,40);i++;
|
||||
panel.iTile[Map.OVERWORLD.getIndex()][i] = new DryTreeIT(panel,13,40);i++;
|
||||
panel.iTile[Map.OVERWORLD.getIndex()][i] = new DryTreeIT(panel,13,41);i++;
|
||||
panel.iTile[Map.OVERWORLD.getIndex()][i] = new DryTreeIT(panel,12,41);i++;
|
||||
panel.iTile[Map.OVERWORLD.getIndex()][i] = new DryTreeIT(panel,11,41);i++;
|
||||
panel.iTile[Map.OVERWORLD.getIndex()][i] = new DryTreeIT(panel,10,41);i++;
|
||||
panel.iTile[Map.OVERWORLD.getIndex()][i] = new DryTreeIT(panel,10,40);i++;
|
||||
|
||||
i = 0;
|
||||
panel.iTile[Map.DUNGEON_FIRST_FLOOR.getIndex()][i] = new DestructibleWallIT(panel,18,30);i++;
|
||||
panel.iTile[Map.DUNGEON_FIRST_FLOOR.getIndex()][i] = new DestructibleWallIT(panel,17,31);i++;
|
||||
panel.iTile[Map.DUNGEON_FIRST_FLOOR.getIndex()][i] = new DestructibleWallIT(panel,17,32);i++;
|
||||
panel.iTile[Map.DUNGEON_FIRST_FLOOR.getIndex()][i] = new DestructibleWallIT(panel,17,34);i++;
|
||||
panel.iTile[Map.DUNGEON_FIRST_FLOOR.getIndex()][i] = new DestructibleWallIT(panel,18,34);i++;
|
||||
panel.iTile[Map.DUNGEON_FIRST_FLOOR.getIndex()][i] = new DestructibleWallIT(panel,18,33);i++;
|
||||
panel.iTile[Map.DUNGEON_FIRST_FLOOR.getIndex()][i] = new DestructibleWallIT(panel,10,22);i++;
|
||||
panel.iTile[Map.DUNGEON_FIRST_FLOOR.getIndex()][i] = new DestructibleWallIT(panel,10,24);i++;
|
||||
panel.iTile[Map.DUNGEON_FIRST_FLOOR.getIndex()][i] = new DestructibleWallIT(panel,38,18);i++;
|
||||
panel.iTile[Map.DUNGEON_FIRST_FLOOR.getIndex()][i] = new DestructibleWallIT(panel,38,19);i++;
|
||||
panel.iTile[Map.DUNGEON_FIRST_FLOOR.getIndex()][i] = new DestructibleWallIT(panel,38,20);i++;
|
||||
panel.iTile[Map.DUNGEON_FIRST_FLOOR.getIndex()][i] = new DestructibleWallIT(panel,38,21);i++;
|
||||
panel.iTile[Map.DUNGEON_FIRST_FLOOR.getIndex()][i] = new DestructibleWallIT(panel,18,13);i++;
|
||||
panel.iTile[Map.DUNGEON_FIRST_FLOOR.getIndex()][i] = new DestructibleWallIT(panel,18,14);i++;
|
||||
panel.iTile[Map.DUNGEON_FIRST_FLOOR.getIndex()][i] = new DestructibleWallIT(panel,22,28);i++;
|
||||
panel.iTile[Map.DUNGEON_FIRST_FLOOR.getIndex()][i] = new DestructibleWallIT(panel,30,28);i++;
|
||||
panel.iTile[Map.DUNGEON_FIRST_FLOOR.getIndex()][i] = new DestructibleWallIT(panel,32,28);i++;
|
||||
|
||||
panel.iTile[Map.DUNGEON_FIRST_FLOOR.getIndex()][i] = new MetalPlateIT(panel,20,22);i++;
|
||||
panel.iTile[Map.DUNGEON_FIRST_FLOOR.getIndex()][i] = new MetalPlateIT(panel,8,17);i++;
|
||||
panel.iTile[Map.DUNGEON_FIRST_FLOOR.getIndex()][i] = new MetalPlateIT(panel,39,31);i++;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -59,6 +59,10 @@ public class CollisionHandler {
|
||||
}
|
||||
public int checkObject(Entity entity, boolean player) {
|
||||
int index = 999;
|
||||
|
||||
Direction direction = entity.direction;
|
||||
if(entity.knockback) direction = entity.knockbackDirection;
|
||||
|
||||
int c = -1;
|
||||
|
||||
for(Entity obj : panel.obj[panel.currentMap.getIndex()]) {
|
||||
@@ -71,7 +75,7 @@ public class CollisionHandler {
|
||||
obj.solidArea.x += obj.worldX;
|
||||
obj.solidArea.y += obj.worldY;
|
||||
|
||||
parseSolidArea(entity);
|
||||
parseSolidArea(entity, direction);
|
||||
|
||||
if (entity.solidArea.intersects(obj.solidArea)) {
|
||||
if (obj.collision) entity.collisionOn = true;
|
||||
@@ -90,6 +94,10 @@ public class CollisionHandler {
|
||||
//NPC OR MONSTER COLLISION
|
||||
public int checkEntity(Entity entity, Entity[] target) {
|
||||
int index = 999;
|
||||
|
||||
Direction direction = entity.direction;
|
||||
if(entity.knockback) direction = entity.knockbackDirection;
|
||||
|
||||
int c = -1;
|
||||
|
||||
for(Entity e : target) {
|
||||
@@ -102,7 +110,7 @@ public class CollisionHandler {
|
||||
e.solidArea.x += e.worldX;
|
||||
e.solidArea.y += e.worldY;
|
||||
|
||||
parseSolidArea(entity);
|
||||
parseSolidArea(entity, direction);
|
||||
|
||||
if (entity.solidArea.intersects(e.solidArea) && e != entity) {
|
||||
entity.collisionOn = true;
|
||||
@@ -149,4 +157,13 @@ public class CollisionHandler {
|
||||
}
|
||||
}
|
||||
|
||||
private void parseSolidArea(Entity entity, Direction direction) {
|
||||
switch (direction) {
|
||||
case UP -> entity.solidArea.y -= entity.speed;
|
||||
case DOWN -> entity.solidArea.y += entity.speed;
|
||||
case LEFT -> entity.solidArea.x -= entity.speed;
|
||||
case RIGHT -> entity.solidArea.x += entity.speed;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -14,6 +14,7 @@ public class EventHandler {
|
||||
|
||||
GamePanel panel;
|
||||
EventRect[][][] eventRect;
|
||||
Entity eventMaster; //Like a "voice of god"
|
||||
public int prevEventX, prevEventY;
|
||||
boolean canTouchEvent = true;
|
||||
|
||||
@@ -23,6 +24,7 @@ public class EventHandler {
|
||||
|
||||
public EventHandler(GamePanel panel) {
|
||||
this.panel = panel;
|
||||
eventMaster = new Entity(panel);
|
||||
eventRect = new EventRect[Map.values().length][panel.maxWorldCol][panel.maxWorldRow];
|
||||
|
||||
int map = 0;
|
||||
@@ -46,8 +48,14 @@ public class EventHandler {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
setDialogue();
|
||||
}
|
||||
|
||||
public void setDialogue() {
|
||||
eventMaster.dialogue[0][0] = "You have fallen into a pit!";
|
||||
eventMaster.dialogue[1][0] = "You saved your progress!";
|
||||
}
|
||||
public void checkEvent() {
|
||||
// Check if the player char is more than 1 tile away from the last event
|
||||
int xDistance = Math.abs(panel.player.worldX - prevEventX); //return absolute number
|
||||
@@ -58,12 +66,20 @@ public class EventHandler {
|
||||
|
||||
// PIT/POOL TESTS
|
||||
if(hit(Map.OVERWORLD, 27,16, Direction.RIGHT)) damagePit();
|
||||
//if(hit(Map.OVERWORLD, 26,16, Direction.RIGHT)) changeMap(Map.DUNGEON_FIRST_FLOOR, 9, 41); //test
|
||||
else if(hit(Map.OVERWORLD, 23,12, null)) healingPool();
|
||||
else if(hit(Map.DUNGEON_SECOND_FLOOR, 27, 39, null)) healingPool();
|
||||
|
||||
// HUT
|
||||
else if(hit(Map.OVERWORLD, 10, 39, null)) changeMap(Map.HUT, 12, 13);
|
||||
else if(hit(Map.HUT, 12, 13, null)) changeMap(Map.OVERWORLD, 10, 39);
|
||||
|
||||
//DUNGEON
|
||||
else if(hit(Map.OVERWORLD, 12,9, null)) changeMap(Map.DUNGEON_FIRST_FLOOR, 9, 41); //enter
|
||||
else if(hit(Map.DUNGEON_FIRST_FLOOR, 9,41, null)) changeMap(Map.OVERWORLD, 12,9); //leave
|
||||
else if(hit(Map.DUNGEON_FIRST_FLOOR, 8,7, null)) changeMap(Map.DUNGEON_SECOND_FLOOR, 26, 41); //enter b2
|
||||
else if(hit(Map.DUNGEON_SECOND_FLOOR, 26, 41, null)) changeMap(Map.DUNGEON_FIRST_FLOOR, 8, 7); //enter b1
|
||||
|
||||
// ADVANCED SPEAKING
|
||||
else if(hit(Map.HUT, 12, 9, Direction.UP)) speak(panel.npc[Map.HUT.getIndex()][0]);
|
||||
}
|
||||
@@ -95,10 +111,9 @@ public class EventHandler {
|
||||
}
|
||||
|
||||
private void damagePit() {
|
||||
panel.gameState = GameState.DIALOGUE;
|
||||
panel.playSE(6);
|
||||
panel.ui.currentDialogue = "You have fallen into a pit!";
|
||||
panel.player.life -= 1;
|
||||
eventMaster.startDialogue(eventMaster,0);
|
||||
canTouchEvent = false;
|
||||
}
|
||||
private void healingPool() {
|
||||
@@ -106,7 +121,7 @@ public class EventHandler {
|
||||
panel.gameState = GameState.DIALOGUE;
|
||||
panel.player.attackCancel = true;
|
||||
panel.playSE(2);
|
||||
panel.ui.currentDialogue = "You saved your progress!";
|
||||
eventMaster.startDialogue(eventMaster,1);
|
||||
//panel.player.life = panel.player.maxLife;
|
||||
canTouchEvent = false;
|
||||
panel.assetSetter.setMonster();
|
||||
@@ -122,6 +137,7 @@ public class EventHandler {
|
||||
tempCol = col;
|
||||
tempRow = row;
|
||||
canTouchEvent = false;
|
||||
panel.nextArea = map.getArea();
|
||||
panel.playSE(13);
|
||||
}
|
||||
private void speak(Entity entity) {
|
||||
|
||||
@@ -15,6 +15,7 @@ public class KeyHandler implements KeyListener {
|
||||
public boolean upPressed, downPressed, leftPressed, rightPressed, spacePressed, shotKeyPressed, CTLKeyPressed;
|
||||
public GamePanel panel;
|
||||
public boolean debug;
|
||||
public boolean godMode;
|
||||
|
||||
public KeyHandler(GamePanel panel) {
|
||||
this.panel = panel;
|
||||
@@ -33,6 +34,7 @@ public class KeyHandler implements KeyListener {
|
||||
switch (panel.ui.commandNum) {
|
||||
case 0:
|
||||
panel.gameState = GameState.PLAY;
|
||||
panel.resetGame(true);
|
||||
panel.playMusic(0);
|
||||
break;
|
||||
case 1:
|
||||
@@ -69,6 +71,7 @@ public class KeyHandler implements KeyListener {
|
||||
|
||||
// DEBUG OPTIONS
|
||||
case KeyEvent.VK_T -> debug = !debug;
|
||||
case KeyEvent.VK_G -> godMode = !godMode;
|
||||
case KeyEvent.VK_R -> {for(Map m : Map.values()) panel.tileM.loadMap(m);}
|
||||
|
||||
// GAME STATES
|
||||
@@ -134,7 +137,7 @@ public class KeyHandler implements KeyListener {
|
||||
private void handleDialogue(int code) {
|
||||
// EXIT STATE
|
||||
if (code == KeyEvent.VK_SPACE) {
|
||||
panel.gameState = GameState.PLAY;
|
||||
spacePressed = true;
|
||||
}
|
||||
}
|
||||
private void handleCharacter(int code) {
|
||||
|
||||
@@ -37,6 +37,11 @@ public class Sound {
|
||||
load(14, "assets/sounds/sleep.wav");
|
||||
load(15, "assets/sounds/blocked.wav");
|
||||
load(16, "assets/sounds/parry.wav");
|
||||
load(17, "assets/sounds/speak.wav");
|
||||
load(18, "assets/sounds/Merchant.wav");
|
||||
load(19, "assets/sounds/Dungeon.wav");
|
||||
load(20, "assets/sounds/chipwall.wav");
|
||||
load(21, "assets/sounds/dooropen.wav");
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package de.miaurizius.jgame2d.data;
|
||||
|
||||
import de.miaurizius.jgame2d.core.enums.Map;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -19,6 +21,7 @@ public class DataStorage implements Serializable {
|
||||
int nextLevelExp;
|
||||
int coins;
|
||||
int worldX, worldY;
|
||||
Map currentMap;
|
||||
|
||||
// PLAYER INVENTORY
|
||||
List<String> itemNames = new ArrayList<>();
|
||||
|
||||
@@ -44,6 +44,7 @@ public class SaveLoad {
|
||||
ds.coins = panel.player.coins;
|
||||
ds.worldX = panel.player.worldX;
|
||||
ds.worldY = panel.player.worldY;
|
||||
ds.currentMap = panel.currentMap;
|
||||
|
||||
// PLAYER INVENTORY
|
||||
for(int i = 0; i < panel.player.inventory.size(); i++) {
|
||||
@@ -95,7 +96,7 @@ public class SaveLoad {
|
||||
panel.player.coins = ds.coins;
|
||||
panel.player.worldX = ds.worldX;
|
||||
panel.player.worldY = ds.worldY;
|
||||
|
||||
panel.currentMap = ds.currentMap;
|
||||
|
||||
// PLAYER INVENTORY
|
||||
panel.player.inventory.clear();
|
||||
@@ -118,8 +119,9 @@ public class SaveLoad {
|
||||
panel.obj[mapNum][i] = getObject(ds.mapObjectNames[mapNum][i]);
|
||||
panel.obj[mapNum][i].worldX = ds.mapObjectWorldX[mapNum][i];
|
||||
panel.obj[mapNum][i].worldY = ds.mapObjectWorldY[mapNum][i];
|
||||
if (ds.mapObjectLootNames[mapNum][i] != null) panel.obj[mapNum][i].loot = getObject(ds.mapObjectLootNames[mapNum][i]);
|
||||
if (ds.mapObjectLootNames[mapNum][i] != null) panel.obj[mapNum][i].setLoot(getObject(ds.mapObjectLootNames[mapNum][i]));
|
||||
panel.obj[mapNum][i].opened = ds.mapObjectOpened[mapNum][i];
|
||||
panel.obj[mapNum][i].setDialogue();
|
||||
if(panel.obj[mapNum][i].opened) panel.obj[mapNum][i].down1 = panel.obj[mapNum][i].image2;
|
||||
} else panel.obj[mapNum][i] = null;
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import de.miaurizius.jgame2d.core.enums.Direction;
|
||||
import de.miaurizius.jgame2d.core.GamePanel;
|
||||
import de.miaurizius.jgame2d.core.Utility;
|
||||
import de.miaurizius.jgame2d.core.enums.EntityType;
|
||||
import de.miaurizius.jgame2d.core.enums.GameState;
|
||||
import de.miaurizius.jgame2d.entity.particle.Particle;
|
||||
import de.miaurizius.jgame2d.entity.projectile.Projectile;
|
||||
|
||||
@@ -30,13 +31,15 @@ public class Entity {
|
||||
public Entity attacker;
|
||||
public int solidAreaDefaultX, solidAreaDefaultY;
|
||||
public boolean collision;
|
||||
protected String[] dialogue = new String[20];
|
||||
public String[][] dialogue = new String[20][20];
|
||||
public Entity linkedEntity;
|
||||
|
||||
// STATE
|
||||
public int worldX, worldY;
|
||||
public Direction direction = Direction.DOWN;
|
||||
public int spriteNum = 1;
|
||||
int dialogueIndex;
|
||||
public int dialogueSet;
|
||||
public int dialogueIndex;
|
||||
public boolean collisionOn;
|
||||
public boolean invincible;
|
||||
public boolean transparent;
|
||||
@@ -48,6 +51,7 @@ public class Entity {
|
||||
public boolean onPath;
|
||||
public boolean knockback;
|
||||
public boolean guarding;
|
||||
public boolean rage;
|
||||
public Direction knockbackDirection;
|
||||
|
||||
// COUNTER
|
||||
@@ -158,9 +162,9 @@ public class Entity {
|
||||
int screenX = worldX - panel.player.worldX + panel.player.screenX;
|
||||
int screenY = worldY - panel.player.worldY + panel.player.screenY;
|
||||
|
||||
if(worldX + panel.tileSize > panel.player.worldX - panel.player.screenX &&
|
||||
if(worldX + panel.tileSize*5 > panel.player.worldX - panel.player.screenX &&
|
||||
worldX - panel.tileSize < panel.player.worldX + panel.player.screenX &&
|
||||
worldY + panel.tileSize > panel.player.worldY - panel.player.screenY &&
|
||||
worldY + panel.tileSize*5 > panel.player.worldY - panel.player.screenY &&
|
||||
worldY - panel.tileSize < panel.player.worldY + panel.player.screenY
|
||||
) {
|
||||
|
||||
@@ -188,8 +192,8 @@ public class Entity {
|
||||
if(dying) dyingAnimation(graphics2d);
|
||||
if(type == EntityType.PLAYER || name.equals("orc")) { // only modify sprite render position for player because I dont know yet how monster attack sprite are gonna look
|
||||
if(attacking) graphics2d.drawImage(parseSpriteATK(),
|
||||
(direction == Direction.LEFT) ? screenX - panel.tileSize : screenX,
|
||||
(direction == Direction.UP) ? screenY - panel.tileSize : screenY, null);
|
||||
(direction == Direction.LEFT) ? screenX - left1.getWidth() : screenX,
|
||||
(direction == Direction.UP) ? screenY - up1.getHeight() : screenY, null);
|
||||
else if(guarding) graphics2d.drawImage(parseSpriteGRD(), screenX, screenY, null);
|
||||
else graphics2d.drawImage(parseSprite(), screenX, screenY, null);
|
||||
} else graphics2d.drawImage(parseSprite(), screenX, screenY, null);
|
||||
@@ -204,6 +208,20 @@ public class Entity {
|
||||
|
||||
// INTERACTION
|
||||
public void setAction() {}
|
||||
public void moveTowardPlayer(int interval) {
|
||||
actionLock++;
|
||||
if(actionLock > interval) {
|
||||
if(dX(panel.player) > dY(panel.player)) {
|
||||
if(panel.player.getCenterX() < getCenterX()) direction = Direction.LEFT;
|
||||
else direction = Direction.RIGHT;
|
||||
} else if(dX(panel.player) < dY(panel.player)) {
|
||||
if(panel.player.getCenterY() < getCenterY()) direction = Direction.UP;
|
||||
else direction = Direction.DOWN;
|
||||
}
|
||||
actionLock = 0;
|
||||
}
|
||||
}
|
||||
public void move(Direction direction) {}
|
||||
public void damageReaction() {}
|
||||
public void attacking() {
|
||||
if(panel.player.attackCancel && type == EntityType.PLAYER) return;
|
||||
@@ -267,10 +285,9 @@ public class Entity {
|
||||
panel.player.invincible = true;
|
||||
}
|
||||
public void speak() {
|
||||
if(dialogue[dialogueIndex] == null) dialogueIndex = 0;
|
||||
panel.ui.currentDialogue = dialogue[dialogueIndex];
|
||||
dialogueIndex++;
|
||||
|
||||
}
|
||||
public void facePlayer() {
|
||||
switch(panel.player.direction) {
|
||||
case UP -> direction = Direction.DOWN;
|
||||
case DOWN -> direction = Direction.UP;
|
||||
@@ -278,6 +295,11 @@ public class Entity {
|
||||
case RIGHT -> direction = Direction.LEFT;
|
||||
}
|
||||
}
|
||||
public void startDialogue(Entity entity, int setNum) {
|
||||
panel.gameState = GameState.DIALOGUE;
|
||||
panel.ui.tradingNPC = entity;
|
||||
dialogueSet = setNum;
|
||||
}
|
||||
public void dyingAnimation(Graphics2D graphics2d) {
|
||||
dyingCount++;
|
||||
int incr = 5;
|
||||
@@ -407,10 +429,16 @@ public class Entity {
|
||||
return (worldY + solidArea.y) / panel.tileSize;
|
||||
}
|
||||
public int dX(Entity target) {
|
||||
return Math.abs(worldX - target.worldX);
|
||||
return Math.abs(getCenterX() - target.getCenterX());
|
||||
}
|
||||
public int dY(Entity target) {
|
||||
return Math.abs(worldY - target.worldY);
|
||||
return Math.abs(getCenterY() - target.getCenterY());
|
||||
}
|
||||
public int getCenterX() {
|
||||
return worldX + left1.getWidth()/2;
|
||||
}
|
||||
public int getCenterY() {
|
||||
return worldY + up1.getHeight()/2;
|
||||
}
|
||||
public int dTile(Entity target) {
|
||||
//if(Objects.equals(name, "orc")) System.out.println("dX: " + dX(target) + " dY: " + dY(target));
|
||||
@@ -464,6 +492,7 @@ public class Entity {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
public void setDialogue() {}
|
||||
public void changeOpacity(Graphics2D graphics2d, float opacity) {
|
||||
graphics2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, opacity));
|
||||
}
|
||||
@@ -580,16 +609,16 @@ public class Entity {
|
||||
|
||||
switch(direction) {
|
||||
case UP -> {
|
||||
if(panel.player.worldY < worldY && yDist < straight && xDist < horizontal) targetInRange = true;
|
||||
if(panel.player.getCenterY() < getCenterY() && yDist < straight && xDist < horizontal) targetInRange = true;
|
||||
}
|
||||
case DOWN -> {
|
||||
if(panel.player.worldY > worldY && yDist < straight && xDist < horizontal) targetInRange = true;
|
||||
if(panel.player.getCenterY() > getCenterY() && yDist < straight && xDist < horizontal) targetInRange = true;
|
||||
}
|
||||
case LEFT -> {
|
||||
if(panel.player.worldX < worldX && xDist < straight && yDist < horizontal) targetInRange = true;
|
||||
if(panel.player.getCenterX() < getCenterX() && xDist < straight && yDist < horizontal) targetInRange = true;
|
||||
}
|
||||
case RIGHT -> {
|
||||
if(panel.player.worldX > worldX && xDist < straight && yDist < horizontal) targetInRange = true;
|
||||
if(panel.player.getCenterX() > getCenterX() && xDist < straight && yDist < horizontal) targetInRange = true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -601,9 +630,9 @@ public class Entity {
|
||||
shotAvailableCount = 0;
|
||||
}
|
||||
}
|
||||
public void setRandomDirection() {
|
||||
public void setRandomDirection(int interval) {
|
||||
actionLock++;
|
||||
if(actionLock == 120) { //lock action for x frames
|
||||
if(actionLock > interval) { //lock action for x frames
|
||||
Random rand = new Random();
|
||||
int i = rand.nextInt(100)+1; //Generate number between 1 and 100
|
||||
if(i <= 25) direction = Direction.UP;
|
||||
|
||||
@@ -4,14 +4,17 @@ import de.miaurizius.jgame2d.core.*;
|
||||
import de.miaurizius.jgame2d.core.enums.Direction;
|
||||
import de.miaurizius.jgame2d.core.enums.EntityType;
|
||||
import de.miaurizius.jgame2d.core.enums.GameState;
|
||||
import de.miaurizius.jgame2d.core.enums.Map;
|
||||
import de.miaurizius.jgame2d.core.handlers.KeyHandler;
|
||||
import de.miaurizius.jgame2d.entity.item.KeyObj;
|
||||
import de.miaurizius.jgame2d.entity.item.LanternObj;
|
||||
import de.miaurizius.jgame2d.entity.item.ShieldWoodObj;
|
||||
import de.miaurizius.jgame2d.entity.item.SwordNormalObj;
|
||||
import de.miaurizius.jgame2d.entity.projectile.FireballObj;
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
|
||||
public class Player extends Entity {
|
||||
|
||||
@@ -46,6 +49,7 @@ public class Player extends Entity {
|
||||
getPlayerImage();
|
||||
getPlayerAttackImage();
|
||||
getGuardImages();
|
||||
setDialogue();
|
||||
}
|
||||
|
||||
// DEFAULT
|
||||
@@ -175,6 +179,7 @@ public class Player extends Entity {
|
||||
if(!invincible) return;
|
||||
invincibleCounting();
|
||||
|
||||
if(keyH.godMode) return;
|
||||
if(life <= 0) {
|
||||
panel.gameState = GameState.GAMEOVER;
|
||||
invincibleCount = 0;
|
||||
@@ -255,15 +260,18 @@ public class Player extends Entity {
|
||||
panel.iTile[panel.currentMap.getIndex()][index].life--;
|
||||
panel.iTile[panel.currentMap.getIndex()][index].invincible = true;
|
||||
generateParticle(panel.iTile[panel.currentMap.getIndex()][index], panel.iTile[panel.currentMap.getIndex()][index]);
|
||||
panel.iTile[panel.currentMap.getIndex()][index].checkDrop();
|
||||
if(panel.iTile[panel.currentMap.getIndex()][index].life == 0) panel.iTile[panel.currentMap.getIndex()][index] = panel.iTile[panel.currentMap.getIndex()][index].getDestroyedForm();
|
||||
}
|
||||
|
||||
public void interactNPC(int index) {
|
||||
if(index == 999) return;
|
||||
//if(!panel.keyH.spacePressed) return; //Only uncomment if text should only appear if player hits space
|
||||
attackCancel = true;
|
||||
panel.gameState = GameState.DIALOGUE;
|
||||
panel.npc[panel.currentMap.getIndex()][index].speak();
|
||||
if(panel.keyH.spacePressed) {
|
||||
attackCancel = true;
|
||||
panel.npc[panel.currentMap.getIndex()][index].speak();
|
||||
return;
|
||||
}
|
||||
panel.npc[panel.currentMap.getIndex()][index].move(direction);
|
||||
}
|
||||
public void speak() {
|
||||
//This method only exists for character specific things later...
|
||||
@@ -281,9 +289,8 @@ public class Player extends Entity {
|
||||
attack = getAttack();
|
||||
defense = getDefense();
|
||||
panel.playSE(8);
|
||||
|
||||
panel.gameState = GameState.DIALOGUE;
|
||||
panel.ui.currentDialogue = "You are level " + level + " now!\nYou feel stronger!";
|
||||
setDialogue();
|
||||
startDialogue(this,0);
|
||||
}
|
||||
public void selectItem() {
|
||||
int itemIndex = panel.ui.getItemIndex(panel.ui.playerSlotCol, panel.ui.playerSlotRow);
|
||||
@@ -307,8 +314,15 @@ public class Player extends Entity {
|
||||
if(selectedItem.amt > 1) selectedItem.amt--; else inventory.remove(selectedItem);
|
||||
}
|
||||
public void setDefaultPositions() {
|
||||
panel.currentMap = Map.OVERWORLD;
|
||||
worldX = panel.tileSize * 23;
|
||||
worldY = panel.tileSize * 21;
|
||||
|
||||
// panel.currentMap = Map.DUNGEON_SECOND_FLOOR;
|
||||
// worldX = panel.tileSize * 26;
|
||||
// worldY = panel.tileSize * 40;
|
||||
// panel.player.inventory.add(new LanternObj(panel));
|
||||
|
||||
direction = Direction.DOWN;
|
||||
}
|
||||
public void restoreStatus() {
|
||||
@@ -363,6 +377,9 @@ public class Player extends Entity {
|
||||
inventory.add(currentShield);
|
||||
inventory.add(new KeyObj(panel));
|
||||
}
|
||||
public void setDialogue() {
|
||||
dialogue[0][0] = "You are level " + level + " now!\nYou feel stronger!";
|
||||
}
|
||||
public int getAttack() {
|
||||
attackArea = currentWeapon.attackArea;
|
||||
return attack = strength * currentWeapon.attackValue;
|
||||
@@ -414,6 +431,16 @@ public class Player extends Entity {
|
||||
attackRight1 = initEntitySprites("player/attack/boy_axe_right_1", panel.tileSize * 2, panel.tileSize);
|
||||
attackRight2 = initEntitySprites("player/attack/boy_axe_right_2", panel.tileSize * 2, panel.tileSize);
|
||||
break;
|
||||
case PICKAXE:
|
||||
attackUp1 = initEntitySprites("player/attack/boy_pick_up_1", panel.tileSize, panel.tileSize * 2);
|
||||
attackUp2 = initEntitySprites("player/attack/boy_pick_up_2", panel.tileSize, panel.tileSize * 2);
|
||||
attackDown1 = initEntitySprites("player/attack/boy_pick_down_1", panel.tileSize, panel.tileSize * 2);
|
||||
attackDown2 = initEntitySprites("player/attack/boy_pick_down_2", panel.tileSize, panel.tileSize * 2);
|
||||
attackLeft1 = initEntitySprites("player/attack/boy_pick_left_1", panel.tileSize * 2, panel.tileSize);
|
||||
attackLeft2 = initEntitySprites("player/attack/boy_pick_left_2", panel.tileSize * 2, panel.tileSize);
|
||||
attackRight1 = initEntitySprites("player/attack/boy_pick_right_1", panel.tileSize * 2, panel.tileSize);
|
||||
attackRight2 = initEntitySprites("player/attack/boy_pick_right_2", panel.tileSize * 2, panel.tileSize);
|
||||
break;
|
||||
}
|
||||
}
|
||||
public void getGuardImages() {
|
||||
@@ -432,17 +459,21 @@ public class Player extends Entity {
|
||||
}
|
||||
public boolean canObtainItem(Entity item) {
|
||||
int i = searchItemInInventory(item.name);
|
||||
if(item.stackable) {
|
||||
if(i != 999) {
|
||||
inventory.get(i).amt++;
|
||||
return true;
|
||||
try {
|
||||
if(item.stackable) {
|
||||
if(i != 999) {
|
||||
inventory.get(i).amt++;
|
||||
return true;
|
||||
} else if(inventory.size() != maxInvSize) {
|
||||
inventory.add((Entity) Class.forName(item.getClass().getName()).getDeclaredConstructor(GamePanel.class).newInstance(panel));
|
||||
return true;
|
||||
}
|
||||
} else if(inventory.size() != maxInvSize) {
|
||||
inventory.add(item);
|
||||
inventory.add((Entity) Class.forName(item.getClass().getName()).getDeclaredConstructor(GamePanel.class).newInstance(panel));
|
||||
return true;
|
||||
}
|
||||
} else if(inventory.size() != maxInvSize) {
|
||||
inventory.add(item);
|
||||
return true;
|
||||
} catch(ClassNotFoundException | NoSuchMethodException | InstantiationException | IllegalAccessException | InvocationTargetException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -17,19 +17,25 @@ public class KeyObj extends Entity {
|
||||
|
||||
price = 50;
|
||||
stackable = true;
|
||||
|
||||
setDialogue();
|
||||
}
|
||||
|
||||
public void setDialogue() {
|
||||
dialogue[0][0] = "What are you doing?\nThere is no door nearby.";
|
||||
dialogue[1][0] = "You used a " + name + "!\nThe door is now open.";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean use(Entity entity) {
|
||||
panel.gameState = GameState.DIALOGUE;
|
||||
int objIndex = getDetected(entity, panel.obj, "door");
|
||||
if(objIndex == 999) {
|
||||
panel.ui.currentDialogue = "What are you doing?\nThere is no door nearby.";
|
||||
startDialogue(this,0);
|
||||
return false;
|
||||
}
|
||||
panel.ui.currentDialogue = "You used a " + name + "!\nThe door is now open.";
|
||||
panel.playSE(3);
|
||||
panel.obj[panel.currentMap.getIndex()][objIndex] = null;
|
||||
startDialogue(this,1);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@ public class LanternObj extends Entity {
|
||||
down1 = initEntitySprites("objects/lantern");
|
||||
description = "[" + name + "]\nA lantern that lights up\nthe surrounding area.";
|
||||
price = 100;
|
||||
lightRadius = 250;
|
||||
lightRadius = 350;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
23
src/de/miaurizius/jgame2d/entity/item/PickaxeObj.java
Normal file
23
src/de/miaurizius/jgame2d/entity/item/PickaxeObj.java
Normal file
@@ -0,0 +1,23 @@
|
||||
package de.miaurizius.jgame2d.entity.item;
|
||||
|
||||
import de.miaurizius.jgame2d.core.GamePanel;
|
||||
import de.miaurizius.jgame2d.core.enums.EntityType;
|
||||
import de.miaurizius.jgame2d.entity.Entity;
|
||||
|
||||
public class PickaxeObj extends Entity {
|
||||
|
||||
public PickaxeObj(GamePanel panel) {
|
||||
super(panel);
|
||||
name = "Pickaxe";
|
||||
description = "[" + name + "]\nYou will dig it!";
|
||||
type = EntityType.WEAPON;
|
||||
weaponType = EntityType.WeaponType.PICKAXE;
|
||||
down1 = initEntitySprites("/objects/pickaxe");
|
||||
price = 75;
|
||||
knockbackVal = 10;
|
||||
|
||||
attackValue = 2;
|
||||
attackArea.width = 30;
|
||||
attackArea.height = 30;
|
||||
}
|
||||
}
|
||||
@@ -22,12 +22,16 @@ public class PotionObj extends Entity {
|
||||
|
||||
price = 50;
|
||||
stackable = true;
|
||||
|
||||
setDialogue();
|
||||
}
|
||||
|
||||
public void setDialogue() {
|
||||
dialogue[0][0] = "You drank a " + name + "!\nYour life has been recovered by " + value + ".";
|
||||
}
|
||||
|
||||
public boolean use(Entity entity) {
|
||||
panel.gameState = GameState.DIALOGUE;
|
||||
panel.ui.currentDialogue = "You drank a " + name + "!\n" +
|
||||
"Your life has been recovered by " + value + ".";
|
||||
startDialogue(this,0);
|
||||
entity.life += value;
|
||||
if(panel.player.life > panel.player.maxLife) panel.player.life = panel.player.maxLife;
|
||||
panel.playSE(2);
|
||||
|
||||
65
src/de/miaurizius/jgame2d/entity/monster/BatMON.java
Normal file
65
src/de/miaurizius/jgame2d/entity/monster/BatMON.java
Normal file
@@ -0,0 +1,65 @@
|
||||
package de.miaurizius.jgame2d.entity.monster;
|
||||
|
||||
import de.miaurizius.jgame2d.core.GamePanel;
|
||||
import de.miaurizius.jgame2d.core.enums.EntityType;
|
||||
import de.miaurizius.jgame2d.entity.Entity;
|
||||
import de.miaurizius.jgame2d.entity.item.CoinObj;
|
||||
import de.miaurizius.jgame2d.entity.item.HeartObj;
|
||||
import de.miaurizius.jgame2d.entity.item.PotionObj;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
public class BatMON extends Entity {
|
||||
|
||||
public BatMON(GamePanel panel) {
|
||||
super(panel);
|
||||
type = EntityType.MONSTER;
|
||||
name = "bat";
|
||||
defaultSpeed = 4;
|
||||
speed = defaultSpeed;
|
||||
maxLife = 4;
|
||||
life = maxLife;
|
||||
attack = 1;
|
||||
defense = 0;
|
||||
exp = 2;
|
||||
|
||||
knockbackVal = 5;
|
||||
|
||||
solidArea.x = 3;
|
||||
solidArea.y = 15;
|
||||
solidArea.width = 42;
|
||||
solidArea.height = 21;
|
||||
solidAreaDefaultX = solidArea.x;
|
||||
solidAreaDefaultY = solidArea.y;
|
||||
|
||||
getImage();
|
||||
}
|
||||
|
||||
// INTERACTION
|
||||
public void setAction() {
|
||||
setRandomDirection(10);
|
||||
}
|
||||
public void damageReaction() {
|
||||
actionLock = 0;
|
||||
//onPath = true;
|
||||
}
|
||||
public void checkDrop() {
|
||||
int i = new Random().nextInt(100)+1;
|
||||
if(i < 50) dropItem(new CoinObj(panel));
|
||||
if(i >= 50 && i < 75) dropItem(new HeartObj(panel));
|
||||
if(i >= 75 && i < 100) dropItem(new PotionObj(panel));
|
||||
}
|
||||
|
||||
// SETTING THINGS UP
|
||||
public void getImage() {
|
||||
up1 = initEntitySprites("monster/bat_down_1");
|
||||
up2 = initEntitySprites("monster/bat_down_2");
|
||||
down1 = initEntitySprites("monster/bat_down_1");
|
||||
down2 = initEntitySprites("monster/bat_down_2");
|
||||
left1 = initEntitySprites("monster/bat_down_1");
|
||||
left2 = initEntitySprites("monster/bat_down_2");
|
||||
right1 = initEntitySprites("monster/bat_down_1");
|
||||
right2 = initEntitySprites("monster/bat_down_2");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -45,7 +45,7 @@ public class GreenSlimeMON extends Entity {
|
||||
followPlayer();
|
||||
return;
|
||||
}
|
||||
setRandomDirection();
|
||||
setRandomDirection(120);
|
||||
checkShooting(200, 30);
|
||||
}
|
||||
public void damageReaction() {
|
||||
|
||||
@@ -41,7 +41,7 @@ public class OrcMON extends Entity {
|
||||
public void setAction() {
|
||||
if(!onPath) checkStartChasing(panel.player, 10 ,100); else followPlayer();
|
||||
checkStopChasing(panel.player, 15, 100);
|
||||
setRandomDirection();
|
||||
setRandomDirection(120);
|
||||
if(!attacking) checkAttack(50, panel.tileSize*4, panel.tileSize);
|
||||
}
|
||||
public void damageReaction() {
|
||||
|
||||
111
src/de/miaurizius/jgame2d/entity/monster/SkeletonLordMON.java
Normal file
111
src/de/miaurizius/jgame2d/entity/monster/SkeletonLordMON.java
Normal file
@@ -0,0 +1,111 @@
|
||||
package de.miaurizius.jgame2d.entity.monster;
|
||||
|
||||
import de.miaurizius.jgame2d.core.GamePanel;
|
||||
import de.miaurizius.jgame2d.core.enums.EntityType;
|
||||
import de.miaurizius.jgame2d.entity.Entity;
|
||||
import de.miaurizius.jgame2d.entity.item.CoinObj;
|
||||
import de.miaurizius.jgame2d.entity.item.HeartObj;
|
||||
import de.miaurizius.jgame2d.entity.item.PotionObj;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
public class SkeletonLordMON extends Entity {
|
||||
|
||||
private final int spriteScale = 5;
|
||||
|
||||
public SkeletonLordMON(GamePanel panel) {
|
||||
super(panel);
|
||||
type = EntityType.MONSTER;
|
||||
name = "Skeleton Lord";
|
||||
defaultSpeed = 1;
|
||||
speed = defaultSpeed;
|
||||
maxLife = 50;
|
||||
life = maxLife;
|
||||
attack = 10;
|
||||
defense = 2;
|
||||
exp = 50;
|
||||
knockbackVal = 5;
|
||||
|
||||
int size = panel.tileSize*spriteScale;
|
||||
solidArea.x = 48;
|
||||
solidArea.y = 48;
|
||||
solidArea.width = size-48*2;
|
||||
solidArea.height = size-48;
|
||||
solidAreaDefaultX = solidArea.x;
|
||||
solidAreaDefaultY = solidArea.y;
|
||||
|
||||
attackArea.width = 170;
|
||||
attackArea.height = 170;
|
||||
|
||||
getImage();
|
||||
getAttackImage();
|
||||
}
|
||||
|
||||
// INTERACTION
|
||||
public void setAction() {
|
||||
if(!rage && life < maxLife/2) {
|
||||
rage = true;
|
||||
getImage();
|
||||
getAttackImage();
|
||||
defaultSpeed++;
|
||||
speed = defaultSpeed;
|
||||
attack *= 2;
|
||||
}
|
||||
if(dTile(panel.player) < 10) moveTowardPlayer(60); else setRandomDirection(120);
|
||||
if(!attacking) checkAttack(60, panel.tileSize*7, panel.tileSize*5);
|
||||
}
|
||||
public void damageReaction() {
|
||||
actionLock = 0;
|
||||
}
|
||||
public void checkDrop() {
|
||||
int i = new Random().nextInt(100)+1;
|
||||
if(i < 50) dropItem(new CoinObj(panel));
|
||||
if(i >= 50 && i < 75) dropItem(new HeartObj(panel));
|
||||
if(i >= 75 && i < 100) dropItem(new PotionObj(panel));
|
||||
}
|
||||
|
||||
// SETTING THINGS UP
|
||||
public void getImage() {
|
||||
if(rage) {
|
||||
up1 = initEntitySprites("monster/skeletonlord_phase2_up_1", panel.tileSize * spriteScale, panel.tileSize * spriteScale);
|
||||
up2 = initEntitySprites("monster/skeletonlord_phase2_up_2", panel.tileSize * spriteScale, panel.tileSize * spriteScale);
|
||||
down1 = initEntitySprites("monster/skeletonlord_phase2_down_1", panel.tileSize * spriteScale, panel.tileSize * spriteScale);
|
||||
down2 = initEntitySprites("monster/skeletonlord_phase2_down_2", panel.tileSize * spriteScale, panel.tileSize * spriteScale);
|
||||
left1 = initEntitySprites("monster/skeletonlord_phase2_left_1", panel.tileSize * spriteScale, panel.tileSize * spriteScale);
|
||||
left2 = initEntitySprites("monster/skeletonlord_phase2_left_2", panel.tileSize * spriteScale, panel.tileSize * spriteScale);
|
||||
right1 = initEntitySprites("monster/skeletonlord_phase2_right_1", panel.tileSize * spriteScale, panel.tileSize * spriteScale);
|
||||
right2 = initEntitySprites("monster/skeletonlord_phase2_right_2", panel.tileSize * spriteScale, panel.tileSize * spriteScale);
|
||||
return;
|
||||
}
|
||||
up1 = initEntitySprites("monster/skeletonlord_up_1", panel.tileSize * spriteScale, panel.tileSize * spriteScale);
|
||||
up2 = initEntitySprites("monster/skeletonlord_up_2", panel.tileSize * spriteScale, panel.tileSize * spriteScale);
|
||||
down1 = initEntitySprites("monster/skeletonlord_down_1", panel.tileSize * spriteScale, panel.tileSize * spriteScale);
|
||||
down2 = initEntitySprites("monster/skeletonlord_down_2", panel.tileSize * spriteScale, panel.tileSize * spriteScale);
|
||||
left1 = initEntitySprites("monster/skeletonlord_left_1", panel.tileSize * spriteScale, panel.tileSize * spriteScale);
|
||||
left2 = initEntitySprites("monster/skeletonlord_left_2", panel.tileSize * spriteScale, panel.tileSize * spriteScale);
|
||||
right1 = initEntitySprites("monster/skeletonlord_right_1", panel.tileSize * spriteScale, panel.tileSize * spriteScale);
|
||||
right2 = initEntitySprites("monster/skeletonlord_right_2", panel.tileSize * spriteScale, panel.tileSize * spriteScale);
|
||||
}
|
||||
public void getAttackImage() {
|
||||
if(rage) {
|
||||
attackUp1 = initEntitySprites("monster/skeletonlord_phase2_attack_up_1", panel.tileSize * spriteScale, panel.tileSize * 2 * spriteScale);
|
||||
attackUp2 = initEntitySprites("monster/skeletonlord_phase2_attack_up_2", panel.tileSize * spriteScale, panel.tileSize * 2 * spriteScale);
|
||||
attackDown1 = initEntitySprites("monster/skeletonlord_phase2_attack_down_1", panel.tileSize * spriteScale, panel.tileSize * 2 * spriteScale);
|
||||
attackDown2 = initEntitySprites("monster/skeletonlord_phase2_attack_down_2", panel.tileSize * spriteScale, panel.tileSize * 2 * spriteScale);
|
||||
attackLeft1 = initEntitySprites("monster/skeletonlord_phase2_attack_left_1", panel.tileSize*2*spriteScale, panel.tileSize*spriteScale);
|
||||
attackLeft2 = initEntitySprites("monster/skeletonlord_phase2_attack_left_2", panel.tileSize*2*spriteScale, panel.tileSize*spriteScale);
|
||||
attackRight1 = initEntitySprites("monster/skeletonlord_phase2_attack_right_1", panel.tileSize*2*spriteScale, panel.tileSize*spriteScale);
|
||||
attackRight2 = initEntitySprites("monster/skeletonlord_phase2_attack_right_2", panel.tileSize*2*spriteScale, panel.tileSize*spriteScale);
|
||||
return;
|
||||
}
|
||||
attackUp1 = initEntitySprites("monster/skeletonlord_attack_up_1", panel.tileSize * spriteScale, panel.tileSize * 2 * spriteScale);
|
||||
attackUp2 = initEntitySprites("monster/skeletonlord_attack_up_2", panel.tileSize * spriteScale, panel.tileSize * 2 * spriteScale);
|
||||
attackDown1 = initEntitySprites("monster/skeletonlord_attack_down_1", panel.tileSize * spriteScale, panel.tileSize * 2 * spriteScale);
|
||||
attackDown2 = initEntitySprites("monster/skeletonlord_attack_down_2", panel.tileSize * spriteScale, panel.tileSize * 2 * spriteScale);
|
||||
attackLeft1 = initEntitySprites("monster/skeletonlord_attack_left_1", panel.tileSize*2*spriteScale, panel.tileSize*spriteScale);
|
||||
attackLeft2 = initEntitySprites("monster/skeletonlord_attack_left_2", panel.tileSize*2*spriteScale, panel.tileSize*spriteScale);
|
||||
attackRight1 = initEntitySprites("monster/skeletonlord_attack_right_1", panel.tileSize*2*spriteScale, panel.tileSize*spriteScale);
|
||||
attackRight2 = initEntitySprites("monster/skeletonlord_attack_right_2", panel.tileSize*2*spriteScale, panel.tileSize*spriteScale);
|
||||
}
|
||||
|
||||
}
|
||||
119
src/de/miaurizius/jgame2d/entity/npc/BigRockNPC.java
Normal file
119
src/de/miaurizius/jgame2d/entity/npc/BigRockNPC.java
Normal file
@@ -0,0 +1,119 @@
|
||||
package de.miaurizius.jgame2d.entity.npc;
|
||||
|
||||
import de.miaurizius.jgame2d.core.GamePanel;
|
||||
import de.miaurizius.jgame2d.core.enums.Direction;
|
||||
import de.miaurizius.jgame2d.core.enums.EntityType;
|
||||
import de.miaurizius.jgame2d.core.enums.Map;
|
||||
import de.miaurizius.jgame2d.entity.Entity;
|
||||
import de.miaurizius.jgame2d.entity.obstacle.IronDoorObj;
|
||||
import de.miaurizius.jgame2d.tile.interactive.InteractiveTile;
|
||||
import de.miaurizius.jgame2d.tile.interactive.MetalPlateIT;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Random;
|
||||
|
||||
public class BigRockNPC extends Entity {
|
||||
|
||||
public BigRockNPC(GamePanel panel) {
|
||||
super(panel);
|
||||
type = EntityType.NPC;
|
||||
name = "bigrock";
|
||||
|
||||
direction = Direction.DOWN;
|
||||
speed = 4;
|
||||
getImage();
|
||||
setDialogue();
|
||||
|
||||
dialogueSet = -1;
|
||||
|
||||
solidArea.x = 2;
|
||||
solidArea.y = 6;
|
||||
solidAreaDefaultX = solidArea.x;
|
||||
solidAreaDefaultY = solidArea.y;
|
||||
solidArea.width = 44;
|
||||
solidArea.height = 40;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void move(Direction direction) {
|
||||
this.direction = direction;
|
||||
checkCollision();
|
||||
if(collisionOn) return;
|
||||
switch (direction) {
|
||||
case UP -> worldY -= speed;
|
||||
case DOWN -> worldY += speed;
|
||||
case LEFT -> worldX -= speed;
|
||||
case RIGHT -> worldX += speed;
|
||||
}
|
||||
detectPlate();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void speak() {
|
||||
super.facePlayer();
|
||||
super.startDialogue(this,super.dialogueSet);
|
||||
dialogueSet++;
|
||||
if(dialogue[dialogueSet][0] == null) dialogueSet = 0;
|
||||
}
|
||||
|
||||
public void detectPlate() {
|
||||
ArrayList<InteractiveTile> plateList = new ArrayList<>();
|
||||
ArrayList<Entity> rockList = new ArrayList<>();
|
||||
|
||||
for(int i = 0; i < panel.iTile[Map.DUNGEON_FIRST_FLOOR.getIndex()].length; i++) {
|
||||
if(panel.iTile[panel.currentMap.getIndex()][i] != null && panel.iTile[panel.currentMap.getIndex()][i] instanceof MetalPlateIT) {
|
||||
plateList.add(panel.iTile[panel.currentMap.getIndex()][i]);
|
||||
}
|
||||
}
|
||||
|
||||
for(int i = 0; i < panel.npc[Map.DUNGEON_FIRST_FLOOR.getIndex()].length; i++) {
|
||||
if(panel.npc[panel.currentMap.getIndex()][i] != null && panel.npc[panel.currentMap.getIndex()][i] instanceof BigRockNPC) {
|
||||
rockList.add(panel.npc[panel.currentMap.getIndex()][i]);
|
||||
}
|
||||
}
|
||||
|
||||
int count = 0;
|
||||
|
||||
for (int i = 0; i < plateList.size(); i++) {
|
||||
int dx = Math.abs(worldX - plateList.get(i).worldX);
|
||||
int dy = Math.abs(worldY - plateList.get(i).worldY);
|
||||
if (Math.max(dx, dy) < 8 ) {
|
||||
if(linkedEntity == null) {
|
||||
linkedEntity = plateList.get(i);
|
||||
panel.playSE(3);
|
||||
}
|
||||
} else if(linkedEntity == plateList.get(i)) linkedEntity = null;
|
||||
}
|
||||
|
||||
for(Entity rock : rockList) if(rock.linkedEntity != null) count++;
|
||||
|
||||
if(count == rockList.size()) {
|
||||
for(int i = 0; i < panel.obj[Map.DUNGEON_FIRST_FLOOR.getIndex()].length; i++) {
|
||||
if(panel.obj[panel.currentMap.getIndex()][i] != null && panel.obj[panel.currentMap.getIndex()][i] instanceof IronDoorObj) {
|
||||
panel.obj[panel.currentMap.getIndex()][i] = null;
|
||||
panel.playSE(21);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// SETTING THINGS UP
|
||||
private void getImage() {
|
||||
up1 = initEntitySprites("npc/bigrock");
|
||||
up2 = initEntitySprites("npc/bigrock");
|
||||
down1 = initEntitySprites("npc/bigrock");
|
||||
down2 = initEntitySprites("npc/bigrock");
|
||||
left1 = initEntitySprites("npc/bigrock");
|
||||
left2 = initEntitySprites("npc/bigrock");
|
||||
right1 = initEntitySprites("npc/bigrock");
|
||||
right2 = initEntitySprites("npc/bigrock");
|
||||
}
|
||||
public void setDialogue() {
|
||||
dialogue[0][0] = "It's a giant rock.";
|
||||
}
|
||||
|
||||
}
|
||||
@@ -23,7 +23,7 @@ public class MerchantNPC extends Entity {
|
||||
|
||||
@Override
|
||||
public void speak() {
|
||||
super.speak();
|
||||
facePlayer();
|
||||
panel.gameState = GameState.TRADE;
|
||||
panel.ui.tradingNPC = this;
|
||||
}
|
||||
@@ -39,8 +39,12 @@ public class MerchantNPC extends Entity {
|
||||
right1 = initEntitySprites("npc/merchant_down_1");
|
||||
right2 = initEntitySprites("npc/merchant_down_2");
|
||||
}
|
||||
private void setDialogue() {
|
||||
dialogue[0] = "He he, so you found me. \nI have some good stuff. \nDo you want to trade?";
|
||||
public void setDialogue() {
|
||||
dialogue[0][0] = "He he, so you found me. \nI have some good stuff. \nDo you want to trade?";
|
||||
dialogue[1][0] = "Come again, hehe!";
|
||||
dialogue[2][0] = "You need more coins to buy that!";
|
||||
dialogue[3][0] = "Your inventory is full!";
|
||||
dialogue[4][0] = "You cannot sell an equipped item!";
|
||||
}
|
||||
private void setItems() {
|
||||
inventory.add(new PotionObj(panel));
|
||||
|
||||
@@ -20,6 +20,8 @@ public class OldManNPC extends Entity {
|
||||
getImage();
|
||||
setDialogue();
|
||||
|
||||
dialogueSet = -1;
|
||||
|
||||
solidArea.x = 8;
|
||||
solidArea.y = 16;
|
||||
solidAreaDefaultX = solidArea.x;
|
||||
@@ -48,8 +50,11 @@ public class OldManNPC extends Entity {
|
||||
}
|
||||
@Override
|
||||
public void speak() {
|
||||
super.speak();
|
||||
super.onPath = true;
|
||||
super.facePlayer();
|
||||
super.startDialogue(this,super.dialogueSet);
|
||||
dialogueSet++;
|
||||
if(dialogue[dialogueSet][0] == null) dialogueSet = 0;
|
||||
// super.onPath = true;
|
||||
}
|
||||
|
||||
// SETTING THINGS UP
|
||||
@@ -63,11 +68,18 @@ public class OldManNPC extends Entity {
|
||||
right1 = initEntitySprites("npc/oldman_right_1");
|
||||
right2 = initEntitySprites("npc/oldman_right_2");
|
||||
}
|
||||
private void setDialogue() {
|
||||
dialogue[0] = "Hello, lad.";
|
||||
dialogue[1] = "So you've come to this island to \nfind the treasure?";
|
||||
dialogue[2] = "I used to be a great wizard but now... \nI'm a bit too old for taking an \nadventure.";
|
||||
dialogue[3] = "Well, good luck on you.";
|
||||
dialogue[4] = "I heard drinking the water of the \nholy lake makes you feel fine again...";
|
||||
@Override
|
||||
public void setDialogue() {
|
||||
dialogue[0][0] = "Hello, lad.";
|
||||
dialogue[0][1] = "So you've come to this island to \nfind the treasure?";
|
||||
dialogue[0][2] = "I used to be a great wizard but now... \nI'm a bit too old for taking an \nadventure.";
|
||||
dialogue[0][3] = "Well, good luck on you.";
|
||||
dialogue[0][4] = "I heard drinking the water of the \nholy lake makes you feel fine again...";
|
||||
|
||||
dialogue[1][0] = "If you become tired, reset at the water.";
|
||||
dialogue[1][1] = "However, the monsters reappear if you rest.\nI don't know why but that's how it works.";
|
||||
dialogue[1][2] = "In any case, don't push yourself too hard.";
|
||||
|
||||
dialogue[2][0] = "I wonder how to open that door...";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,31 +28,33 @@ public class ChestObj extends Entity {
|
||||
solidAreaDefaultY = solidArea.y;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setDialogue() {
|
||||
dialogue[0][0] = "You open the chest and find a " + loot.name + "!\nBut your inventory is full...";
|
||||
dialogue[1][0] = "You open the chest and find a " + loot.name + "!\nYou obtain the " + loot.name + "!";
|
||||
dialogue[2][0] = "It's already empty...";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setLoot(Entity loot) {
|
||||
this.loot = loot;
|
||||
setDialogue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void interact() {
|
||||
panel.gameState = GameState.DIALOGUE;
|
||||
|
||||
if(this.opened) {
|
||||
panel.ui.currentDialogue = "It's already empty...";
|
||||
startDialogue(this,2);
|
||||
return;
|
||||
}
|
||||
panel.playSE(3);
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("You open the chest and find a ").append(loot.name).append("!");
|
||||
if(!panel.player.canObtainItem(loot)) {
|
||||
sb.append("\nBut your inventory is full...");
|
||||
panel.ui.currentDialogue = sb.toString();
|
||||
startDialogue(this,0);
|
||||
return;
|
||||
}
|
||||
sb.append("\nYou obtain the ").append(loot.name).append("!");
|
||||
down1 = image2;
|
||||
opened = true;
|
||||
panel.ui.currentDialogue = sb.toString();
|
||||
startDialogue(this,1);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -23,12 +23,17 @@ public class DoorObj extends Entity {
|
||||
solidArea.height = 32;
|
||||
solidAreaDefaultX = solidArea.x;
|
||||
solidAreaDefaultY = solidArea.y;
|
||||
|
||||
setDialogue();
|
||||
}
|
||||
|
||||
public void setDialogue() {
|
||||
dialogue[0][0] = "You need a key to open this.";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void interact() {
|
||||
panel.gameState = GameState.DIALOGUE;
|
||||
panel.ui.currentDialogue = "You need a key to open this.";
|
||||
startDialogue(this,0);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
36
src/de/miaurizius/jgame2d/entity/obstacle/IronDoorObj.java
Normal file
36
src/de/miaurizius/jgame2d/entity/obstacle/IronDoorObj.java
Normal file
@@ -0,0 +1,36 @@
|
||||
package de.miaurizius.jgame2d.entity.obstacle;
|
||||
|
||||
import de.miaurizius.jgame2d.core.GamePanel;
|
||||
import de.miaurizius.jgame2d.core.enums.EntityType;
|
||||
import de.miaurizius.jgame2d.entity.Entity;
|
||||
|
||||
public class IronDoorObj extends Entity {
|
||||
GamePanel panel;
|
||||
|
||||
public IronDoorObj(GamePanel panel) {
|
||||
super(panel);
|
||||
this.panel = panel;
|
||||
name = "door";
|
||||
type = EntityType.OBSTACLE;
|
||||
down1 = initEntitySprites("objects/door_iron");
|
||||
collision = true;
|
||||
|
||||
solidArea.x = 0;
|
||||
solidArea.y = 16;
|
||||
solidArea.width = 48;
|
||||
solidArea.height = 32;
|
||||
solidAreaDefaultX = solidArea.x;
|
||||
solidAreaDefaultY = solidArea.y;
|
||||
|
||||
setDialogue();
|
||||
}
|
||||
|
||||
public void setDialogue() {
|
||||
dialogue[0][0] = "It won't budge.";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void interact() {
|
||||
startDialogue(this,0);
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
package de.miaurizius.jgame2d.environment;
|
||||
|
||||
import de.miaurizius.jgame2d.core.GamePanel;
|
||||
import de.miaurizius.jgame2d.core.enums.Map;
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.image.BufferedImage;
|
||||
@@ -19,8 +20,8 @@ public class Lighting {
|
||||
}
|
||||
|
||||
public void draw(Graphics2D g2) {
|
||||
g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, filterAlpha));
|
||||
g2.drawImage(darknessFilter, 0, 0, null);
|
||||
if(panel.currentArea == Map.Area.OUTSIDE) g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, filterAlpha));
|
||||
if(panel.currentArea == Map.Area.OUTSIDE || panel.currentArea == Map.Area.DUNGEON) g2.drawImage(darknessFilter, 0, 0, null);
|
||||
g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1F));
|
||||
|
||||
// DEBUG
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
package de.miaurizius.jgame2d.tile.interactive;
|
||||
|
||||
import de.miaurizius.jgame2d.core.GamePanel;
|
||||
import de.miaurizius.jgame2d.core.enums.EntityType;
|
||||
import de.miaurizius.jgame2d.entity.Entity;
|
||||
|
||||
import java.awt.*;
|
||||
|
||||
public class DestructibleWallIT extends InteractiveTile {
|
||||
GamePanel panel;
|
||||
|
||||
public DestructibleWallIT(GamePanel panel, int col, int row) {
|
||||
super(panel, col, row);
|
||||
this.panel = panel;
|
||||
this.worldX = panel.tileSize * col;
|
||||
this.worldY = panel.tileSize * row;
|
||||
|
||||
down1 = initEntitySprites("/interactive_tiles/destructiblewall");
|
||||
destructible = true;
|
||||
life = 3;
|
||||
}
|
||||
|
||||
// PRE_CONFIGURED
|
||||
public void playSE() {
|
||||
panel.playSE(20);
|
||||
}
|
||||
|
||||
// GETTERS
|
||||
public boolean meetItemReq(Entity entity) {
|
||||
return entity.currentWeapon.weaponType == EntityType.WeaponType.PICKAXE;
|
||||
}
|
||||
public Color getParticleColor() {
|
||||
return new Color(65, 65,65);
|
||||
}
|
||||
public int getParticleSize() {
|
||||
return 6; //in pixels
|
||||
}
|
||||
public int getParticleSpeed() {
|
||||
return 1;
|
||||
}
|
||||
public int getParticleMaxLife() {
|
||||
return 20;
|
||||
}
|
||||
}
|
||||
@@ -6,11 +6,11 @@ import de.miaurizius.jgame2d.entity.Entity;
|
||||
|
||||
import java.awt.*;
|
||||
|
||||
public class DryTreeTI extends InteractiveTile{
|
||||
public class DryTreeIT extends InteractiveTile{
|
||||
|
||||
GamePanel panel;
|
||||
|
||||
public DryTreeTI(GamePanel panel, int col, int row) {
|
||||
public DryTreeIT(GamePanel panel, int col, int row) {
|
||||
super(panel, col, row);
|
||||
this.panel = panel;
|
||||
this.worldX = panel.tileSize * col;
|
||||
@@ -18,7 +18,7 @@ public class DryTreeTI extends InteractiveTile{
|
||||
|
||||
down1 = initEntitySprites("/interactive_tiles/drytree");
|
||||
destructible = true;
|
||||
life = 3;
|
||||
life = 2;
|
||||
}
|
||||
|
||||
// PRE_CONFIGURED
|
||||
26
src/de/miaurizius/jgame2d/tile/interactive/MetalPlateIT.java
Normal file
26
src/de/miaurizius/jgame2d/tile/interactive/MetalPlateIT.java
Normal file
@@ -0,0 +1,26 @@
|
||||
package de.miaurizius.jgame2d.tile.interactive;
|
||||
|
||||
import de.miaurizius.jgame2d.core.GamePanel;
|
||||
|
||||
public class MetalPlateIT extends InteractiveTile {
|
||||
|
||||
GamePanel panel;
|
||||
|
||||
public MetalPlateIT(GamePanel panel, int col, int row) {
|
||||
super(panel, col, row);
|
||||
this.panel = panel;
|
||||
this.name = "metal_plate";
|
||||
|
||||
this.worldX = panel.tileSize * col;
|
||||
this.worldY = panel.tileSize * row;
|
||||
|
||||
down1 = initEntitySprites("/interactive_tiles/metalplate");
|
||||
|
||||
solidArea.x = 0;
|
||||
solidArea.y = 0;
|
||||
solidArea.width = 0;
|
||||
solidArea.height = 0;
|
||||
solidAreaDefaultX = 0;
|
||||
solidAreaDefaultY = 0;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user