Compare commits

..

16 Commits

21 changed files with 304 additions and 54 deletions

View File

@@ -23,7 +23,7 @@
18 18 18 18 18 18 18 24 16 16 1 16 16 1 14 5 5 5 5 5 5 5 6 3 4 5 5 5 5 15 16 16 16 14 5 6 3 7 2 23 18 18 19 18 18 18 18 18 18 18 18 18 18 18 18 18 18 24 16 16 1 16 16 1 14 5 5 5 5 5 5 5 6 3 4 5 5 5 5 15 16 16 16 14 5 6 3 7 2 23 18 18 19 18 18 18 18 18 18 18
18 18 18 18 18 18 18 30 22 16 1 16 16 1 16 16 16 16 16 16 16 1 8 3 7 1 16 16 16 16 16 16 16 16 16 8 3 7 1 23 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 30 22 16 1 16 16 1 16 16 16 16 16 16 16 1 8 3 7 1 16 16 16 16 16 16 16 16 16 8 3 7 1 23 18 18 18 18 18 18 18 18 18 18
18 18 18 18 18 18 18 18 24 16 1 16 16 1 16 16 16 16 16 16 16 16 8 3 7 16 16 16 16 16 16 16 16 16 16 8 3 7 1 23 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 24 16 1 16 16 1 16 16 16 16 16 16 16 16 8 3 7 16 16 16 16 16 16 16 16 16 16 8 3 7 1 23 18 18 18 18 18 18 18 18 18 18
18 18 18 18 18 18 18 18 27 16 1 16 16 1 1 16 16 16 16 16 16 16 8 3 7 16 16 16 16 16 16 16 16 16 16 8 3 7 1 23 18 18 18 18 18 18 19 18 18 18 18 18 18 18 18 18 18 28 27 16 1 16 16 1 1 16 16 16 16 16 16 16 8 3 7 16 16 16 16 16 16 16 16 16 16 8 3 7 1 23 18 18 18 18 18 18 19 18 18 18
18 18 18 19 18 18 18 24 16 16 1 16 16 16 1 16 16 16 16 16 16 16 8 3 7 16 16 16 16 16 16 16 16 16 16 8 3 7 1 23 18 18 18 18 18 18 18 18 18 18 18 18 18 19 18 18 18 24 16 16 1 16 16 16 1 16 16 16 16 16 16 16 8 3 7 16 16 16 16 16 16 16 16 16 16 8 3 7 1 23 18 18 18 18 18 18 18 18 18 18
18 18 18 18 18 18 18 24 16 16 1 16 16 16 1 16 16 16 16 16 16 16 8 3 7 1 1 1 16 16 16 16 16 16 16 8 3 7 1 23 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 24 16 16 1 16 16 16 1 16 16 16 16 16 16 16 8 3 7 1 1 1 16 16 16 16 16 16 16 8 3 7 1 23 18 18 18 18 18 18 18 18 18 18
18 18 18 18 18 18 18 24 16 16 1 16 16 16 1 16 16 16 16 16 16 16 8 3 7 16 16 1 16 16 16 16 16 16 16 8 3 7 1 23 18 18 19 18 18 18 18 18 18 18 18 18 18 18 18 18 18 24 16 16 1 16 16 16 1 16 16 16 16 16 16 16 8 3 7 16 16 1 16 16 16 16 16 16 16 8 3 7 1 23 18 18 19 18 18 18 18 18 18 18

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.1 KiB

View File

@@ -19,7 +19,7 @@ public class Boot {
} }
} }
static void main() { public static void main(String[] args) {
generateWindow(); generateWindow();
gamePanel.setupGame(); gamePanel.setupGame();

View File

@@ -4,6 +4,8 @@ import de.miaurizius.jgame2d.aStar.PathFinder;
import de.miaurizius.jgame2d.core.enums.GameState; import de.miaurizius.jgame2d.core.enums.GameState;
import de.miaurizius.jgame2d.core.enums.Map; import de.miaurizius.jgame2d.core.enums.Map;
import de.miaurizius.jgame2d.core.handlers.*; import de.miaurizius.jgame2d.core.handlers.*;
import de.miaurizius.jgame2d.data.Config;
import de.miaurizius.jgame2d.data.SaveLoad;
import de.miaurizius.jgame2d.entity.Entity; import de.miaurizius.jgame2d.entity.Entity;
import de.miaurizius.jgame2d.entity.Player; import de.miaurizius.jgame2d.entity.Player;
import de.miaurizius.jgame2d.environment.EnvironmentManager; import de.miaurizius.jgame2d.environment.EnvironmentManager;
@@ -61,6 +63,7 @@ public class GamePanel extends JPanel implements Runnable {
public PathFinder pFinder = new PathFinder(this); public PathFinder pFinder = new PathFinder(this);
public EnvironmentManager eManager = new EnvironmentManager(this); public EnvironmentManager eManager = new EnvironmentManager(this);
public MiniMap mapMan = new MiniMap(this); public MiniMap mapMan = new MiniMap(this);
public SaveLoad saveLoad = new SaveLoad(this);
Thread gameThread; Thread gameThread;
// ENTITY AND OBJECT // ENTITY AND OBJECT
@@ -263,18 +266,16 @@ public class GamePanel extends JPanel implements Runnable {
fScreenWidth = Boot.window.getWidth(); fScreenWidth = Boot.window.getWidth();
fScreenHeight = Boot.window.getHeight(); fScreenHeight = Boot.window.getHeight();
} }
public void retry() { public void resetGame(boolean restart) {
player.setDefaultPositions(); player.setDefaultPositions();
player.restoreLife(); player.restoreStatus();
assetSetter.setNPC(); assetSetter.setNPC();
assetSetter.setMonster(); assetSetter.setMonster();
}
public void restart() { if(!restart) return;
player.setDefaultValues(); player.setDefaultValues();
assetSetter.setObject(); assetSetter.setObject();
assetSetter.setNPC();
assetSetter.setMonster();
assetSetter.setITiles(); assetSetter.setITiles();
eManager.lighting.resetDay();
} }
} }

View File

@@ -736,6 +736,7 @@ public class UI {
if(commandNum == 1) { if(commandNum == 1) {
graphics2d.drawString(">", textX-25, textY); graphics2d.drawString(">", textX-25, textY);
if(panel.keyH.spacePressed) optionState = OptionState.OVERVIEW; if(panel.keyH.spacePressed) optionState = OptionState.OVERVIEW;
panel.resetGame(true);
} }
} }

View File

@@ -5,6 +5,14 @@ public enum Direction {
UP, UP,
DOWN, DOWN,
LEFT, LEFT,
RIGHT RIGHT;
public Direction getOpposite() {
return switch (this) {
case UP -> DOWN;
case DOWN -> UP;
case LEFT -> RIGHT;
case RIGHT -> LEFT;
};
}
} }

View File

@@ -3,7 +3,7 @@ package de.miaurizius.jgame2d.core.enums;
public enum Map { public enum Map {
OVERWORLD("worldmap", 0), OVERWORLD("worldmap", 0),
HUT("worldmap", 1); HUT("indoor01", 1);
private final String name; private final String name;
private final int index; private final int index;

View File

@@ -1,5 +1,6 @@
package de.miaurizius.jgame2d.core.handlers; package de.miaurizius.jgame2d.core.handlers;
import de.miaurizius.jgame2d.core.Boot;
import de.miaurizius.jgame2d.core.GamePanel; import de.miaurizius.jgame2d.core.GamePanel;
import de.miaurizius.jgame2d.core.enums.Direction; import de.miaurizius.jgame2d.core.enums.Direction;
import de.miaurizius.jgame2d.core.enums.GameState; import de.miaurizius.jgame2d.core.enums.GameState;
@@ -7,6 +8,7 @@ import de.miaurizius.jgame2d.core.enums.Map;
import de.miaurizius.jgame2d.entity.Entity; import de.miaurizius.jgame2d.entity.Entity;
import java.awt.*; import java.awt.*;
import java.util.logging.Level;
public class EventHandler { public class EventHandler {
@@ -104,10 +106,15 @@ public class EventHandler {
panel.gameState = GameState.DIALOGUE; panel.gameState = GameState.DIALOGUE;
panel.player.attackCancel = true; panel.player.attackCancel = true;
panel.playSE(2); panel.playSE(2);
panel.ui.currentDialogue = "You drank the holy water.\nYour life has been recovered!\nBut all monsters respawned... \nGood luck!"; panel.ui.currentDialogue = "You saved your progress!";
panel.player.life = panel.player.maxLife; //panel.player.life = panel.player.maxLife;
canTouchEvent = false; canTouchEvent = false;
panel.assetSetter.setMonster(); panel.assetSetter.setMonster();
try {
panel.saveLoad.save();
} catch (Exception e) {
Boot.logger.log(Level.SEVERE, "Saving game failed!", e);
}
} }
private void changeMap(Map map, int col, int row) { private void changeMap(Map map, int col, int row) {
panel.gameState = GameState.TRANSITION; panel.gameState = GameState.TRANSITION;

View File

@@ -1,5 +1,6 @@
package de.miaurizius.jgame2d.core.handlers; package de.miaurizius.jgame2d.core.handlers;
import de.miaurizius.jgame2d.core.Boot;
import de.miaurizius.jgame2d.core.GamePanel; import de.miaurizius.jgame2d.core.GamePanel;
import de.miaurizius.jgame2d.core.UI; import de.miaurizius.jgame2d.core.UI;
import de.miaurizius.jgame2d.core.enums.GameState; import de.miaurizius.jgame2d.core.enums.GameState;
@@ -7,10 +8,11 @@ import de.miaurizius.jgame2d.core.enums.Map;
import java.awt.event.KeyEvent; import java.awt.event.KeyEvent;
import java.awt.event.KeyListener; import java.awt.event.KeyListener;
import java.util.logging.Level;
public class KeyHandler implements KeyListener { public class KeyHandler implements KeyListener {
public boolean upPressed, downPressed, leftPressed, rightPressed, spacePressed, shotKeyPressed; public boolean upPressed, downPressed, leftPressed, rightPressed, spacePressed, shotKeyPressed, CTLKeyPressed;
public GamePanel panel; public GamePanel panel;
public boolean debug; public boolean debug;
@@ -34,7 +36,15 @@ public class KeyHandler implements KeyListener {
panel.playMusic(0); panel.playMusic(0);
break; break;
case 1: case 1:
// add later System.out.printf("Loading config...%n");
try {
panel.config.load();
panel.saveLoad.load();
panel.gameState = GameState.PLAY;
panel.playMusic(0);
} catch (Exception e) {
Boot.logger.log(Level.SEVERE, "Failed to load config", e);
}
break; break;
case 2: case 2:
System.exit(0); System.exit(0);
@@ -50,6 +60,7 @@ public class KeyHandler implements KeyListener {
case KeyEvent.VK_S, KeyEvent.VK_DOWN -> downPressed = true; case KeyEvent.VK_S, KeyEvent.VK_DOWN -> downPressed = true;
case KeyEvent.VK_A, KeyEvent.VK_LEFT -> leftPressed = true; case KeyEvent.VK_A, KeyEvent.VK_LEFT -> leftPressed = true;
case KeyEvent.VK_D, KeyEvent.VK_RIGHT -> rightPressed = true; case KeyEvent.VK_D, KeyEvent.VK_RIGHT -> rightPressed = true;
case KeyEvent.VK_CONTROL -> CTLKeyPressed = true;
case KeyEvent.VK_SPACE -> spacePressed = true; case KeyEvent.VK_SPACE -> spacePressed = true;
//case KeyEvent.VK_F -> shotKeyPressed = true; //case KeyEvent.VK_F -> shotKeyPressed = true;
@@ -151,12 +162,12 @@ public class KeyHandler implements KeyListener {
if(panel.ui.commandNum == 0) { if(panel.ui.commandNum == 0) {
panel.gameState = GameState.PLAY; panel.gameState = GameState.PLAY;
panel.playMusic(0); panel.playMusic(0);
panel.retry(); panel.resetGame(false);
} }
if(panel.ui.commandNum == 1) { if(panel.ui.commandNum == 1) {
panel.gameState = GameState.TITLE; panel.gameState = GameState.TITLE;
panel.ui.commandNum = 0; panel.ui.commandNum = 0;
panel.restart(); panel.resetGame(true);
panel.stopMusic(); panel.stopMusic();
} }
} }
@@ -276,6 +287,7 @@ public class KeyHandler implements KeyListener {
case KeyEvent.VK_S, KeyEvent.VK_DOWN -> downPressed = false; case KeyEvent.VK_S, KeyEvent.VK_DOWN -> downPressed = false;
case KeyEvent.VK_A, KeyEvent.VK_LEFT -> leftPressed = false; case KeyEvent.VK_A, KeyEvent.VK_LEFT -> leftPressed = false;
case KeyEvent.VK_D, KeyEvent.VK_RIGHT -> rightPressed = false; case KeyEvent.VK_D, KeyEvent.VK_RIGHT -> rightPressed = false;
case KeyEvent.VK_CONTROL -> CTLKeyPressed = false;
case KeyEvent.VK_F -> shotKeyPressed = false; case KeyEvent.VK_F -> shotKeyPressed = false;
} }
} }

View File

@@ -35,6 +35,8 @@ public class Sound {
load(12, "assets/sounds/gameover.wav"); load(12, "assets/sounds/gameover.wav");
load(13, "assets/sounds/stairs.wav"); load(13, "assets/sounds/stairs.wav");
load(14, "assets/sounds/sleep.wav"); load(14, "assets/sounds/sleep.wav");
load(15, "assets/sounds/blocked.wav");
load(16, "assets/sounds/parry.wav");
} }
@Deprecated @Deprecated

View File

@@ -1,4 +1,6 @@
package de.miaurizius.jgame2d.core; package de.miaurizius.jgame2d.data;
import de.miaurizius.jgame2d.core.GamePanel;
import java.io.*; import java.io.*;
import java.util.HashMap; import java.util.HashMap;
@@ -10,9 +12,12 @@ public class Config {
private final GamePanel panel; private final GamePanel panel;
private final HashMap<String, String> settings = new HashMap<>(); private final HashMap<String, String> settings = new HashMap<>();
public Config(GamePanel panel) { public Config(GamePanel panel) throws IOException {
this.panel = panel; this.panel = panel;
for (Setting option : Setting.values()) settings.put(option.name, null); for (Setting option : Setting.values()) settings.put(option.name, null);
new File("gamedata").mkdirs();
new File("gamedata/save").mkdirs();
new File("gamedata/config").createNewFile();
} }
// GENERAL // GENERAL

View File

@@ -0,0 +1,28 @@
package de.miaurizius.jgame2d.data;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
public class DataStorage implements Serializable {
// PLAYER STATS
int level;
int maxLife;
int life;
int maxMana;
int strength;
int dexterity;
int attack;
int defense;
int exp;
int nextLevelExp;
int coins;
int worldX, worldY;
// PLAYER INVENTORY
List<String> itemNames = new ArrayList<>();
List<Integer> itemAmounts = new ArrayList<>();
}

View File

@@ -0,0 +1,82 @@
package de.miaurizius.jgame2d.data;
import de.miaurizius.jgame2d.core.GamePanel;
import de.miaurizius.jgame2d.entity.Entity;
import java.io.*;
import java.lang.reflect.InvocationTargetException;
public class SaveLoad {
GamePanel panel;
public SaveLoad(GamePanel panel) {
this.panel = panel;
}
public Entity getObject(String itemName) {
Entity obj;
try {
obj = (Entity) Class.forName(itemName).getDeclaredConstructor().newInstance(panel);
} catch (ClassNotFoundException | NoSuchMethodException | InstantiationException | IllegalAccessException |
InvocationTargetException e) {
throw new RuntimeException(e);
}
return obj;
}
public void save() throws IOException {
ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream("gamedata/save/savegame.dat"));
DataStorage ds = new DataStorage();
// PLAYER STATS
ds.level = panel.player.level;
ds.maxLife = panel.player.maxLife;
ds.life = panel.player.life;
ds.maxMana = panel.player.maxMana;
ds.strength = panel.player.strength;
ds.dexterity = panel.player.dexterity;
ds.attack = panel.player.attack;
ds.defense = panel.player.defense;
ds.exp = panel.player.exp;
ds.nextLevelExp = panel.player.nextLevelExp;
ds.coins = panel.player.coins;
ds.worldX = panel.player.worldX;
ds.worldY = panel.player.worldY;
// PLAYER INVENTORY
for(int i = 0; i < panel.player.inventory.size(); i++) {
ds.itemNames.add(panel.player.inventory.get(i).getClass().getName());
ds.itemAmounts.add(panel.player.inventory.get(i).amt);
}
// WRITE
oos.writeObject(ds);
}
public void load() throws ClassNotFoundException, IOException {
ObjectInputStream ois = new ObjectInputStream(new FileInputStream("gamedata/save/savegame.dat"));
DataStorage ds = (DataStorage) ois.readObject();
panel.player.level = ds.level;
panel.player.maxLife = ds.maxLife;
panel.player.life = ds.life;
panel.player.maxMana = ds.maxMana;
panel.player.strength = ds.strength;
panel.player.dexterity = ds.dexterity;
panel.player.attack = ds.attack;
panel.player.defense = ds.defense;
panel.player.exp = ds.exp;
panel.player.nextLevelExp = ds.nextLevelExp;
panel.player.coins = ds.coins;
panel.player.worldX = ds.worldX;
panel.player.worldY = ds.worldY;
for(int i = 0; i < ds.itemNames.size(); i++) {
Entity obj = getObject(ds.itemNames.get(i));
obj.amt = ds.itemAmounts.get(i);
panel.player.inventory.add(obj);
}
}
}

View File

@@ -14,7 +14,7 @@ import java.awt.image.BufferedImage;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Objects; import java.util.List;
import java.util.Random; import java.util.Random;
import java.util.logging.Level; import java.util.logging.Level;
@@ -23,6 +23,7 @@ public class Entity {
protected GamePanel panel; protected GamePanel panel;
public BufferedImage up1, up2, down1, down2, left1, left2, right1, right2; public BufferedImage up1, up2, down1, down2, left1, left2, right1, right2;
public BufferedImage attackUp1, attackUp2, attackDown1, attackDown2, attackLeft1, attackLeft2, attackRight1, attackRight2; public BufferedImage attackUp1, attackUp2, attackDown1, attackDown2, attackLeft1, attackLeft2, attackRight1, attackRight2;
public BufferedImage guardUp, guardDown, guardLeft, guardRight;
public BufferedImage image, image2, image3; public BufferedImage image, image2, image3;
public Rectangle solidArea = new Rectangle(0, 0, 48, 48); public Rectangle solidArea = new Rectangle(0, 0, 48, 48);
public Rectangle attackArea = new Rectangle(0, 0, 0, 0); public Rectangle attackArea = new Rectangle(0, 0, 0, 0);
@@ -38,6 +39,7 @@ public class Entity {
int dialogueIndex; int dialogueIndex;
public boolean collisionOn; public boolean collisionOn;
public boolean invincible; public boolean invincible;
public boolean transparent;
public boolean attacking; public boolean attacking;
public boolean alive = true; public boolean alive = true;
public boolean dying; public boolean dying;
@@ -45,6 +47,7 @@ public class Entity {
public boolean consumable; public boolean consumable;
public boolean onPath; public boolean onPath;
public boolean knockback; public boolean knockback;
public boolean guarding;
public Direction knockbackDirection; public Direction knockbackDirection;
// COUNTER // COUNTER
@@ -77,7 +80,7 @@ public class Entity {
public Entity currentShield; public Entity currentShield;
public Entity currentLight; public Entity currentLight;
public Projectile projectile; public Projectile projectile;
public ArrayList<Entity> inventory = new ArrayList<>(); public List<Entity> inventory = new ArrayList<>();
public final int maxInvSize = 20; public final int maxInvSize = 20;
// ITEM ATTRIBUTES // ITEM ATTRIBUTES
@@ -105,6 +108,7 @@ public class Entity {
knockbackCount = 0; knockbackCount = 0;
knockback = false; knockback = false;
speed = defaultSpeed; speed = defaultSpeed;
invincibleCounting();
return; return;
} }
@@ -116,7 +120,10 @@ public class Entity {
} }
knockbackCount++; knockbackCount++;
if(knockbackCount != 10) return; if(knockbackCount != 10) {
invincibleCounting();
return;
}
knockback = false; knockback = false;
knockbackCount = 0; knockbackCount = 0;
@@ -143,14 +150,7 @@ public class Entity {
spriteCount = 0; spriteCount = 0;
} }
} }
invincibleCounting();
// INVINCIBLE COUNTER
if(!invincible) return;
invincibleCount++;
if(invincibleCount > 40) {
invincible = false;
invincibleCount = 0;
}
} }
public void draw(Graphics2D graphics2d) { public void draw(Graphics2D graphics2d) {
int screenX = worldX - panel.player.worldX + panel.player.screenX; int screenX = worldX - panel.player.worldX + panel.player.screenX;
@@ -181,16 +181,16 @@ public class Entity {
if(invincible) { if(invincible) {
hpBarOn = true; hpBarOn = true;
hpBarCount = 0; hpBarCount = 0;
changeOpacity(graphics2d, 0.4f); if(transparent) changeOpacity(graphics2d, 0.4f);
} }
if(dying) dyingAnimation(graphics2d); 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(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(), if(attacking) graphics2d.drawImage(parseSpriteATK(),
(direction == Direction.LEFT) ? screenX - panel.tileSize : screenX, (direction == Direction.LEFT) ? screenX - panel.tileSize : screenX,
(direction == Direction.UP) ? screenY - panel.tileSize : screenY, null); (direction == Direction.UP) ? screenY - panel.tileSize : 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);
} else graphics2d.drawImage(parseSprite(), screenX, screenY, null); } else graphics2d.drawImage(parseSprite(), screenX, screenY, null);
changeOpacity(graphics2d, 1f); changeOpacity(graphics2d, 1f);
} }
@@ -247,11 +247,21 @@ public class Entity {
} }
public void damagePlayer(int attack) { public void damagePlayer(int attack) {
if(panel.player.invincible) return; if(panel.player.invincible) return;
panel.playSE(6);
boolean block = panel.player.guarding && panel.player.direction == this.direction.getOpposite();
int damage = attack - panel.player.defense; int damage = attack - panel.player.defense;
panel.player.life -= Math.max(damage, 0);
if(block) {
panel.playSE(15);
damage = 0;
} else panel.playSE(6);
panel.player.life -= Math.max(damage, (block ? 0 : 1));
if(damage != 0) {
setKnockback(panel.player, this, knockbackVal);
panel.player.transparent = true;
}
panel.player.invincible = true; panel.player.invincible = true;
} }
public void speak() { public void speak() {
@@ -317,10 +327,10 @@ public class Entity {
int nextWorldY = user.getTopY(); int nextWorldY = user.getTopY();
switch(user.direction) { switch(user.direction) {
case UP -> nextWorldY = user.getTopY()-1; case UP -> nextWorldY = user.getTopY()-panel.player.speed;
case DOWN -> nextWorldY = user.getBottomY()+1; case DOWN -> nextWorldY = user.getBottomY()+panel.player.speed;
case LEFT -> nextWorldX = user.getLeftX()-1; case LEFT -> nextWorldX = user.getLeftX()-panel.player.speed;
case RIGHT -> nextWorldX = user.getRightX()+1; case RIGHT -> nextWorldX = user.getRightX()+panel.player.speed;
} }
int col = nextWorldX / panel.tileSize; int col = nextWorldX / panel.tileSize;
int row = nextWorldY / panel.tileSize; int row = nextWorldY / panel.tileSize;
@@ -427,6 +437,14 @@ public class Entity {
case RIGHT -> (spriteNum == 1) ? attackRight1 : attackRight2; case RIGHT -> (spriteNum == 1) ? attackRight1 : attackRight2;
}; };
} }
BufferedImage parseSpriteGRD() {
return switch (direction) {
case UP -> guardUp;
case DOWN -> guardDown;
case LEFT -> guardLeft;
case RIGHT -> guardRight;
};
}
public BufferedImage initEntitySprites(String name) { public BufferedImage initEntitySprites(String name) {
try { try {
return Utility.scaleImage(ImageIO.read(new FileInputStream("assets/" + name + ".png")), panel.tileSize, panel.tileSize); return Utility.scaleImage(ImageIO.read(new FileInputStream("assets/" + name + ".png")), panel.tileSize, panel.tileSize);
@@ -592,5 +610,13 @@ public class Entity {
actionLock = 0; actionLock = 0;
} }
} }
public void invincibleCounting() {
if(!invincible) return;
invincibleCount++;
if(invincibleCount > 40) {
invincible = false;
invincibleCount = 0;
}
}
} }

View File

@@ -18,6 +18,7 @@ public class Player extends Entity {
KeyHandler keyH; KeyHandler keyH;
public final int screenX; public final int screenX;
public final int screenY; public final int screenY;
private int standCount;
// STATE // STATE
public boolean attackCancel; public boolean attackCancel;
@@ -44,16 +45,60 @@ public class Player extends Entity {
setDefaultValues(); setDefaultValues();
getPlayerImage(); getPlayerImage();
getPlayerAttackImage(); getPlayerAttackImage();
getGuardImages();
} }
// DEFAULT // DEFAULT
public void update() { public void update() {
if(life > maxLife) life = maxLife; if(life > maxLife) life = maxLife;
if(attacking) { if(knockback) {
attacking(); collisionOn = false;
panel.collisionH.checkTile(this);
panel.collisionH.checkObject(this, false);
panel.collisionH.checkEntity(this, panel.npc[panel.currentMap.getIndex()]);
// panel.collisionH.checkEntity(this, panel.monster[panel.currentMap.getIndex()]);
panel.collisionH.checkEntity(this, panel.iTile[panel.currentMap.getIndex()]);
if(collisionOn) {
knockbackCount = 0;
knockback = false;
speed = defaultSpeed;
invincibleCounting();
return; return;
} }
switch(knockbackDirection) {
case UP -> worldY -= speed;
case DOWN -> worldY += speed;
case LEFT -> worldX -= speed;
case RIGHT -> worldX += speed;
}
knockbackCount++;
if(knockbackCount != 10) {
invincibleCounting();
return;
}
knockback = false;
knockbackCount = 0;
speed = defaultSpeed;
invincibleCounting();
return;
} else if(attacking) {
attacking();
invincibleCounting();
return;
}
// BLOCKING
if(keyH.CTLKeyPressed) {
guarding = true;
transparent = false;
invincibleCounting();
return;
}
// MOVEMENT // MOVEMENT
if(keyH.upPressed || keyH.downPressed || keyH.leftPressed || keyH.rightPressed || keyH.spacePressed) { if(keyH.upPressed || keyH.downPressed || keyH.leftPressed || keyH.rightPressed || keyH.spacePressed) {
if(!keyH.spacePressed) { if(!keyH.spacePressed) {
@@ -89,7 +134,7 @@ public class Player extends Entity {
switch (direction) { switch (direction) {
case UP -> worldY -= speed; case UP -> worldY -= speed;
case DOWN -> worldY += speed; case DOWN -> worldY += speed;
case LEFT ->worldX -= speed; case LEFT -> worldX -= speed;
case RIGHT -> worldX += speed; case RIGHT -> worldX += speed;
} }
} }
@@ -102,6 +147,7 @@ public class Player extends Entity {
attackCancel = false; attackCancel = false;
panel.keyH.spacePressed = false; panel.keyH.spacePressed = false;
guarding = false;
spriteCount++; spriteCount++;
if(spriteCount > 12) { if(spriteCount > 12) {
@@ -110,6 +156,13 @@ public class Player extends Entity {
else spriteNum = 0; else spriteNum = 0;
spriteCount = 0; spriteCount = 0;
} }
} else {
standCount++;
if(standCount == 20) {
spriteNum = 1;
standCount = 0;
}
guarding = false;
} }
if(panel.keyH.shotKeyPressed && !projectile.alive) { if(panel.keyH.shotKeyPressed && !projectile.alive) {
@@ -120,14 +173,11 @@ public class Player extends Entity {
// INVINCIBLE COUNTER // INVINCIBLE COUNTER
if(!invincible) return; if(!invincible) return;
invincibleCount++; invincibleCounting();
if(invincibleCount > 60) {
invincible = false;
invincibleCount = 0;
}
if(life <= 0) { if(life <= 0) {
panel.gameState = GameState.GAMEOVER; panel.gameState = GameState.GAMEOVER;
invincibleCount = 0;
panel.ui.commandNum = -1; panel.ui.commandNum = -1;
panel.stopMusic(); panel.stopMusic();
panel.playSE(12); panel.playSE(12);
@@ -169,11 +219,10 @@ public class Player extends Entity {
int damage = panel.monster[panel.currentMap.getIndex()][index].attack - defense; int damage = panel.monster[panel.currentMap.getIndex()][index].attack - defense;
if(damage > 0) {
panel.playSE(6); panel.playSE(6);
life -= damage; life -= Math.max(damage, 0);
if(damage != 0) panel.player.transparent = true;
invincible = true; invincible = true;
}
} }
public void damageMonster(int index, Entity attacker, int attack, int knockbackVal) { public void damageMonster(int index, Entity attacker, int attack, int knockbackVal) {
@@ -186,6 +235,7 @@ public class Player extends Entity {
panel.playSE(5); panel.playSE(5);
if(knockbackVal > 0) setKnockback(panel.monster[panel.currentMap.getIndex()][index], attacker, knockbackVal); if(knockbackVal > 0) setKnockback(panel.monster[panel.currentMap.getIndex()][index], attacker, knockbackVal);
panel.monster[panel.currentMap.getIndex()][index].life -= damage; panel.monster[panel.currentMap.getIndex()][index].life -= damage;
panel.monster[panel.currentMap.getIndex()][index].transparent = true;
panel.monster[panel.currentMap.getIndex()][index].invincible = true; panel.monster[panel.currentMap.getIndex()][index].invincible = true;
} }
@@ -261,9 +311,14 @@ public class Player extends Entity {
worldY = panel.tileSize * 21; worldY = panel.tileSize * 21;
direction = Direction.DOWN; direction = Direction.DOWN;
} }
public void restoreLife() { public void restoreStatus() {
life = maxLife; life = maxLife;
invincible = false; invincible = false;
transparent = false;
attacking = false;
guarding = false;
knockback = false;
lightUpdated = true;
} }
public void getSleepingImage(BufferedImage image) { public void getSleepingImage(BufferedImage image) {
down1 = image; down1 = image;
@@ -296,6 +351,7 @@ public class Player extends Entity {
coins = 500; coins = 500;
currentWeapon = new SwordNormalObj(panel); currentWeapon = new SwordNormalObj(panel);
currentShield = new ShieldWoodObj(panel); currentShield = new ShieldWoodObj(panel);
currentLight = null;
projectile = new FireballObj(panel); projectile = new FireballObj(panel);
attack = getAttack(); attack = getAttack();
defense = getDefense(); defense = getDefense();
@@ -347,6 +403,12 @@ public class Player extends Entity {
break; break;
} }
} }
public void getGuardImages() {
guardUp = initEntitySprites("player/guarding/boy_guard_up");
guardDown = initEntitySprites("player/guarding/boy_guard_down");
guardLeft = initEntitySprites("player/guarding/boy_guard_left");
guardRight = initEntitySprites("player/guarding/boy_guard_right");
}
public int searchItemInInventory(String itemName) { public int searchItemInInventory(String itemName) {
for(int i = 0; i < inventory.size(); i++) { for(int i = 0; i < inventory.size(); i++) {
if(inventory.get(i).name.equals(itemName)) { if(inventory.get(i).name.equals(itemName)) {
@@ -371,5 +433,14 @@ public class Player extends Entity {
} }
return false; return false;
} }
@Override
public void invincibleCounting() {
if(!invincible) return;
invincibleCount++;
if(invincibleCount > 60) {
invincible = false;
invincibleCount = 0;
}
}
} }

View File

@@ -25,6 +25,8 @@ public class GreenSlimeMON extends Entity {
exp = 2; exp = 2;
projectile = new RockObj(panel); projectile = new RockObj(panel);
knockbackVal = 5;
solidArea.x = 3; solidArea.x = 3;
solidArea.y = 18; solidArea.y = 18;
solidArea.width = 42; solidArea.width = 42;

View File

@@ -42,7 +42,7 @@ public class OrcMON extends Entity {
if(!onPath) checkStartChasing(panel.player, 10 ,100); else followPlayer(); if(!onPath) checkStartChasing(panel.player, 10 ,100); else followPlayer();
checkStopChasing(panel.player, 15, 100); checkStopChasing(panel.player, 15, 100);
setRandomDirection(); setRandomDirection();
if(!attacking) checkAttack(30, panel.tileSize*4, panel.tileSize); if(!attacking) checkAttack(50, panel.tileSize*4, panel.tileSize);
} }
public void damageReaction() { public void damageReaction() {
actionLock = 0; actionLock = 0;

View File

@@ -75,6 +75,11 @@ public class Lighting {
} }
} }
} }
public void resetDay() {
dayState = DayState.DAY;
filterAlpha = 0f;
dayCount = 0;
}
// ... // ...
public void setLightSource() { public void setLightSource() {