Compare commits
16 Commits
c4b1d029aa
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
5dbf7fcf1f
|
|||
|
70eaa9514a
|
|||
|
befb117d85
|
|||
|
54a2ee3022
|
|||
|
ce3f590715
|
|||
|
39fc7d549a
|
|||
|
8902e28d31
|
|||
|
f15850b022
|
|||
|
46765031e4
|
|||
|
2cda920e15
|
|||
|
93467760db
|
|||
|
6be9927752
|
|||
|
1343b18753
|
|||
|
e0986d4708
|
|||
|
d018ed3e6e
|
|||
|
133afa9c06
|
@@ -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 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 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 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
|
||||
|
||||
BIN
assets/player/guarding/boy_guard_down.png
Normal file
BIN
assets/player/guarding/boy_guard_down.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 6.3 KiB |
BIN
assets/player/guarding/boy_guard_left.png
Normal file
BIN
assets/player/guarding/boy_guard_left.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 6.3 KiB |
BIN
assets/player/guarding/boy_guard_right.png
Normal file
BIN
assets/player/guarding/boy_guard_right.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 6.3 KiB |
BIN
assets/player/guarding/boy_guard_up.png
Normal file
BIN
assets/player/guarding/boy_guard_up.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 6.1 KiB |
@@ -19,7 +19,7 @@ public class Boot {
|
||||
}
|
||||
}
|
||||
|
||||
static void main() {
|
||||
public static void main(String[] args) {
|
||||
generateWindow();
|
||||
|
||||
gamePanel.setupGame();
|
||||
|
||||
@@ -4,6 +4,8 @@ import de.miaurizius.jgame2d.aStar.PathFinder;
|
||||
import de.miaurizius.jgame2d.core.enums.GameState;
|
||||
import de.miaurizius.jgame2d.core.enums.Map;
|
||||
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.Player;
|
||||
import de.miaurizius.jgame2d.environment.EnvironmentManager;
|
||||
@@ -61,6 +63,7 @@ public class GamePanel extends JPanel implements Runnable {
|
||||
public PathFinder pFinder = new PathFinder(this);
|
||||
public EnvironmentManager eManager = new EnvironmentManager(this);
|
||||
public MiniMap mapMan = new MiniMap(this);
|
||||
public SaveLoad saveLoad = new SaveLoad(this);
|
||||
Thread gameThread;
|
||||
|
||||
// ENTITY AND OBJECT
|
||||
@@ -263,18 +266,16 @@ public class GamePanel extends JPanel implements Runnable {
|
||||
fScreenWidth = Boot.window.getWidth();
|
||||
fScreenHeight = Boot.window.getHeight();
|
||||
}
|
||||
public void retry() {
|
||||
public void resetGame(boolean restart) {
|
||||
player.setDefaultPositions();
|
||||
player.restoreLife();
|
||||
player.restoreStatus();
|
||||
assetSetter.setNPC();
|
||||
assetSetter.setMonster();
|
||||
}
|
||||
public void restart() {
|
||||
|
||||
if(!restart) return;
|
||||
player.setDefaultValues();
|
||||
assetSetter.setObject();
|
||||
assetSetter.setNPC();
|
||||
assetSetter.setMonster();
|
||||
assetSetter.setITiles();
|
||||
eManager.lighting.resetDay();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -736,6 +736,7 @@ public class UI {
|
||||
if(commandNum == 1) {
|
||||
graphics2d.drawString(">", textX-25, textY);
|
||||
if(panel.keyH.spacePressed) optionState = OptionState.OVERVIEW;
|
||||
panel.resetGame(true);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -5,6 +5,14 @@ public enum Direction {
|
||||
UP,
|
||||
DOWN,
|
||||
LEFT,
|
||||
RIGHT
|
||||
RIGHT;
|
||||
|
||||
public Direction getOpposite() {
|
||||
return switch (this) {
|
||||
case UP -> DOWN;
|
||||
case DOWN -> UP;
|
||||
case LEFT -> RIGHT;
|
||||
case RIGHT -> LEFT;
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -3,7 +3,7 @@ package de.miaurizius.jgame2d.core.enums;
|
||||
public enum Map {
|
||||
|
||||
OVERWORLD("worldmap", 0),
|
||||
HUT("worldmap", 1);
|
||||
HUT("indoor01", 1);
|
||||
|
||||
private final String name;
|
||||
private final int index;
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package de.miaurizius.jgame2d.core.handlers;
|
||||
|
||||
import de.miaurizius.jgame2d.core.Boot;
|
||||
import de.miaurizius.jgame2d.core.GamePanel;
|
||||
import de.miaurizius.jgame2d.core.enums.Direction;
|
||||
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 java.awt.*;
|
||||
import java.util.logging.Level;
|
||||
|
||||
public class EventHandler {
|
||||
|
||||
@@ -104,10 +106,15 @@ public class EventHandler {
|
||||
panel.gameState = GameState.DIALOGUE;
|
||||
panel.player.attackCancel = true;
|
||||
panel.playSE(2);
|
||||
panel.ui.currentDialogue = "You drank the holy water.\nYour life has been recovered!\nBut all monsters respawned... \nGood luck!";
|
||||
panel.player.life = panel.player.maxLife;
|
||||
panel.ui.currentDialogue = "You saved your progress!";
|
||||
//panel.player.life = panel.player.maxLife;
|
||||
canTouchEvent = false;
|
||||
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) {
|
||||
panel.gameState = GameState.TRANSITION;
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package de.miaurizius.jgame2d.core.handlers;
|
||||
|
||||
import de.miaurizius.jgame2d.core.Boot;
|
||||
import de.miaurizius.jgame2d.core.GamePanel;
|
||||
import de.miaurizius.jgame2d.core.UI;
|
||||
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.KeyListener;
|
||||
import java.util.logging.Level;
|
||||
|
||||
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 boolean debug;
|
||||
|
||||
@@ -34,7 +36,15 @@ public class KeyHandler implements KeyListener {
|
||||
panel.playMusic(0);
|
||||
break;
|
||||
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;
|
||||
case 2:
|
||||
System.exit(0);
|
||||
@@ -50,6 +60,7 @@ public class KeyHandler implements KeyListener {
|
||||
case KeyEvent.VK_S, KeyEvent.VK_DOWN -> downPressed = true;
|
||||
case KeyEvent.VK_A, KeyEvent.VK_LEFT -> leftPressed = 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_F -> shotKeyPressed = true;
|
||||
|
||||
@@ -151,12 +162,12 @@ public class KeyHandler implements KeyListener {
|
||||
if(panel.ui.commandNum == 0) {
|
||||
panel.gameState = GameState.PLAY;
|
||||
panel.playMusic(0);
|
||||
panel.retry();
|
||||
panel.resetGame(false);
|
||||
}
|
||||
if(panel.ui.commandNum == 1) {
|
||||
panel.gameState = GameState.TITLE;
|
||||
panel.ui.commandNum = 0;
|
||||
panel.restart();
|
||||
panel.resetGame(true);
|
||||
panel.stopMusic();
|
||||
}
|
||||
}
|
||||
@@ -276,6 +287,7 @@ public class KeyHandler implements KeyListener {
|
||||
case KeyEvent.VK_S, KeyEvent.VK_DOWN -> downPressed = false;
|
||||
case KeyEvent.VK_A, KeyEvent.VK_LEFT -> leftPressed = false;
|
||||
case KeyEvent.VK_D, KeyEvent.VK_RIGHT -> rightPressed = false;
|
||||
case KeyEvent.VK_CONTROL -> CTLKeyPressed = false;
|
||||
case KeyEvent.VK_F -> shotKeyPressed = false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,6 +35,8 @@ public class Sound {
|
||||
load(12, "assets/sounds/gameover.wav");
|
||||
load(13, "assets/sounds/stairs.wav");
|
||||
load(14, "assets/sounds/sleep.wav");
|
||||
load(15, "assets/sounds/blocked.wav");
|
||||
load(16, "assets/sounds/parry.wav");
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
|
||||
@@ -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.util.HashMap;
|
||||
@@ -10,9 +12,12 @@ public class Config {
|
||||
private final GamePanel panel;
|
||||
private final HashMap<String, String> settings = new HashMap<>();
|
||||
|
||||
public Config(GamePanel panel) {
|
||||
public Config(GamePanel panel) throws IOException {
|
||||
this.panel = panel;
|
||||
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
|
||||
28
src/de/miaurizius/jgame2d/data/DataStorage.java
Normal file
28
src/de/miaurizius/jgame2d/data/DataStorage.java
Normal 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<>();
|
||||
|
||||
|
||||
}
|
||||
82
src/de/miaurizius/jgame2d/data/SaveLoad.java
Normal file
82
src/de/miaurizius/jgame2d/data/SaveLoad.java
Normal 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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -14,7 +14,7 @@ import java.awt.image.BufferedImage;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Objects;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
import java.util.logging.Level;
|
||||
|
||||
@@ -23,6 +23,7 @@ public class Entity {
|
||||
protected GamePanel panel;
|
||||
public BufferedImage up1, up2, down1, down2, left1, left2, right1, right2;
|
||||
public BufferedImage attackUp1, attackUp2, attackDown1, attackDown2, attackLeft1, attackLeft2, attackRight1, attackRight2;
|
||||
public BufferedImage guardUp, guardDown, guardLeft, guardRight;
|
||||
public BufferedImage image, image2, image3;
|
||||
public Rectangle solidArea = new Rectangle(0, 0, 48, 48);
|
||||
public Rectangle attackArea = new Rectangle(0, 0, 0, 0);
|
||||
@@ -38,6 +39,7 @@ public class Entity {
|
||||
int dialogueIndex;
|
||||
public boolean collisionOn;
|
||||
public boolean invincible;
|
||||
public boolean transparent;
|
||||
public boolean attacking;
|
||||
public boolean alive = true;
|
||||
public boolean dying;
|
||||
@@ -45,6 +47,7 @@ public class Entity {
|
||||
public boolean consumable;
|
||||
public boolean onPath;
|
||||
public boolean knockback;
|
||||
public boolean guarding;
|
||||
public Direction knockbackDirection;
|
||||
|
||||
// COUNTER
|
||||
@@ -77,7 +80,7 @@ public class Entity {
|
||||
public Entity currentShield;
|
||||
public Entity currentLight;
|
||||
public Projectile projectile;
|
||||
public ArrayList<Entity> inventory = new ArrayList<>();
|
||||
public List<Entity> inventory = new ArrayList<>();
|
||||
public final int maxInvSize = 20;
|
||||
|
||||
// ITEM ATTRIBUTES
|
||||
@@ -105,6 +108,7 @@ public class Entity {
|
||||
knockbackCount = 0;
|
||||
knockback = false;
|
||||
speed = defaultSpeed;
|
||||
invincibleCounting();
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -116,7 +120,10 @@ public class Entity {
|
||||
}
|
||||
|
||||
knockbackCount++;
|
||||
if(knockbackCount != 10) return;
|
||||
if(knockbackCount != 10) {
|
||||
invincibleCounting();
|
||||
return;
|
||||
}
|
||||
|
||||
knockback = false;
|
||||
knockbackCount = 0;
|
||||
@@ -143,14 +150,7 @@ public class Entity {
|
||||
spriteCount = 0;
|
||||
}
|
||||
}
|
||||
|
||||
// INVINCIBLE COUNTER
|
||||
if(!invincible) return;
|
||||
invincibleCount++;
|
||||
if(invincibleCount > 40) {
|
||||
invincible = false;
|
||||
invincibleCount = 0;
|
||||
}
|
||||
invincibleCounting();
|
||||
}
|
||||
public void draw(Graphics2D graphics2d) {
|
||||
int screenX = worldX - panel.player.worldX + panel.player.screenX;
|
||||
@@ -181,16 +181,16 @@ public class Entity {
|
||||
if(invincible) {
|
||||
hpBarOn = true;
|
||||
hpBarCount = 0;
|
||||
changeOpacity(graphics2d, 0.4f);
|
||||
if(transparent) changeOpacity(graphics2d, 0.4f);
|
||||
}
|
||||
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);
|
||||
else if(guarding) graphics2d.drawImage(parseSpriteGRD(), screenX, screenY, null);
|
||||
else graphics2d.drawImage(parseSprite(), screenX, screenY, null);
|
||||
} else graphics2d.drawImage(parseSprite(), screenX, screenY, null);
|
||||
|
||||
changeOpacity(graphics2d, 1f);
|
||||
}
|
||||
|
||||
@@ -247,11 +247,21 @@ public class Entity {
|
||||
}
|
||||
public void damagePlayer(int attack) {
|
||||
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;
|
||||
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;
|
||||
}
|
||||
public void speak() {
|
||||
@@ -317,10 +327,10 @@ public class Entity {
|
||||
int nextWorldY = user.getTopY();
|
||||
|
||||
switch(user.direction) {
|
||||
case UP -> nextWorldY = user.getTopY()-1;
|
||||
case DOWN -> nextWorldY = user.getBottomY()+1;
|
||||
case LEFT -> nextWorldX = user.getLeftX()-1;
|
||||
case RIGHT -> nextWorldX = user.getRightX()+1;
|
||||
case UP -> nextWorldY = user.getTopY()-panel.player.speed;
|
||||
case DOWN -> nextWorldY = user.getBottomY()+panel.player.speed;
|
||||
case LEFT -> nextWorldX = user.getLeftX()-panel.player.speed;
|
||||
case RIGHT -> nextWorldX = user.getRightX()+panel.player.speed;
|
||||
}
|
||||
int col = nextWorldX / panel.tileSize;
|
||||
int row = nextWorldY / panel.tileSize;
|
||||
@@ -427,6 +437,14 @@ public class Entity {
|
||||
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) {
|
||||
try {
|
||||
return Utility.scaleImage(ImageIO.read(new FileInputStream("assets/" + name + ".png")), panel.tileSize, panel.tileSize);
|
||||
@@ -592,5 +610,13 @@ public class Entity {
|
||||
actionLock = 0;
|
||||
}
|
||||
}
|
||||
public void invincibleCounting() {
|
||||
if(!invincible) return;
|
||||
invincibleCount++;
|
||||
if(invincibleCount > 40) {
|
||||
invincible = false;
|
||||
invincibleCount = 0;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@ public class Player extends Entity {
|
||||
KeyHandler keyH;
|
||||
public final int screenX;
|
||||
public final int screenY;
|
||||
private int standCount;
|
||||
|
||||
// STATE
|
||||
public boolean attackCancel;
|
||||
@@ -44,16 +45,60 @@ public class Player extends Entity {
|
||||
setDefaultValues();
|
||||
getPlayerImage();
|
||||
getPlayerAttackImage();
|
||||
getGuardImages();
|
||||
}
|
||||
|
||||
// DEFAULT
|
||||
public void update() {
|
||||
if(life > maxLife) life = maxLife;
|
||||
|
||||
if(attacking) {
|
||||
attacking();
|
||||
if(knockback) {
|
||||
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;
|
||||
}
|
||||
|
||||
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
|
||||
if(keyH.upPressed || keyH.downPressed || keyH.leftPressed || keyH.rightPressed || keyH.spacePressed) {
|
||||
if(!keyH.spacePressed) {
|
||||
@@ -102,6 +147,7 @@ public class Player extends Entity {
|
||||
|
||||
attackCancel = false;
|
||||
panel.keyH.spacePressed = false;
|
||||
guarding = false;
|
||||
|
||||
spriteCount++;
|
||||
if(spriteCount > 12) {
|
||||
@@ -110,6 +156,13 @@ public class Player extends Entity {
|
||||
else spriteNum = 0;
|
||||
spriteCount = 0;
|
||||
}
|
||||
} else {
|
||||
standCount++;
|
||||
if(standCount == 20) {
|
||||
spriteNum = 1;
|
||||
standCount = 0;
|
||||
}
|
||||
guarding = false;
|
||||
}
|
||||
|
||||
if(panel.keyH.shotKeyPressed && !projectile.alive) {
|
||||
@@ -120,14 +173,11 @@ public class Player extends Entity {
|
||||
|
||||
// INVINCIBLE COUNTER
|
||||
if(!invincible) return;
|
||||
invincibleCount++;
|
||||
if(invincibleCount > 60) {
|
||||
invincible = false;
|
||||
invincibleCount = 0;
|
||||
}
|
||||
invincibleCounting();
|
||||
|
||||
if(life <= 0) {
|
||||
panel.gameState = GameState.GAMEOVER;
|
||||
invincibleCount = 0;
|
||||
panel.ui.commandNum = -1;
|
||||
panel.stopMusic();
|
||||
panel.playSE(12);
|
||||
@@ -169,11 +219,10 @@ public class Player extends Entity {
|
||||
|
||||
int damage = panel.monster[panel.currentMap.getIndex()][index].attack - defense;
|
||||
|
||||
if(damage > 0) {
|
||||
panel.playSE(6);
|
||||
life -= damage;
|
||||
life -= Math.max(damage, 0);
|
||||
if(damage != 0) panel.player.transparent = true;
|
||||
invincible = true;
|
||||
}
|
||||
|
||||
}
|
||||
public void damageMonster(int index, Entity attacker, int attack, int knockbackVal) {
|
||||
@@ -186,6 +235,7 @@ public class Player extends Entity {
|
||||
panel.playSE(5);
|
||||
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].transparent = true;
|
||||
panel.monster[panel.currentMap.getIndex()][index].invincible = true;
|
||||
}
|
||||
|
||||
@@ -261,9 +311,14 @@ public class Player extends Entity {
|
||||
worldY = panel.tileSize * 21;
|
||||
direction = Direction.DOWN;
|
||||
}
|
||||
public void restoreLife() {
|
||||
public void restoreStatus() {
|
||||
life = maxLife;
|
||||
invincible = false;
|
||||
transparent = false;
|
||||
attacking = false;
|
||||
guarding = false;
|
||||
knockback = false;
|
||||
lightUpdated = true;
|
||||
}
|
||||
public void getSleepingImage(BufferedImage image) {
|
||||
down1 = image;
|
||||
@@ -296,6 +351,7 @@ public class Player extends Entity {
|
||||
coins = 500;
|
||||
currentWeapon = new SwordNormalObj(panel);
|
||||
currentShield = new ShieldWoodObj(panel);
|
||||
currentLight = null;
|
||||
projectile = new FireballObj(panel);
|
||||
attack = getAttack();
|
||||
defense = getDefense();
|
||||
@@ -347,6 +403,12 @@ public class Player extends Entity {
|
||||
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) {
|
||||
for(int i = 0; i < inventory.size(); i++) {
|
||||
if(inventory.get(i).name.equals(itemName)) {
|
||||
@@ -371,5 +433,14 @@ public class Player extends Entity {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@Override
|
||||
public void invincibleCounting() {
|
||||
if(!invincible) return;
|
||||
invincibleCount++;
|
||||
if(invincibleCount > 60) {
|
||||
invincible = false;
|
||||
invincibleCount = 0;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -25,6 +25,8 @@ public class GreenSlimeMON extends Entity {
|
||||
exp = 2;
|
||||
projectile = new RockObj(panel);
|
||||
|
||||
knockbackVal = 5;
|
||||
|
||||
solidArea.x = 3;
|
||||
solidArea.y = 18;
|
||||
solidArea.width = 42;
|
||||
|
||||
@@ -42,7 +42,7 @@ public class OrcMON extends Entity {
|
||||
if(!onPath) checkStartChasing(panel.player, 10 ,100); else followPlayer();
|
||||
checkStopChasing(panel.player, 15, 100);
|
||||
setRandomDirection();
|
||||
if(!attacking) checkAttack(30, panel.tileSize*4, panel.tileSize);
|
||||
if(!attacking) checkAttack(50, panel.tileSize*4, panel.tileSize);
|
||||
}
|
||||
public void damageReaction() {
|
||||
actionLock = 0;
|
||||
|
||||
@@ -75,6 +75,11 @@ public class Lighting {
|
||||
}
|
||||
}
|
||||
}
|
||||
public void resetDay() {
|
||||
dayState = DayState.DAY;
|
||||
filterAlpha = 0f;
|
||||
dayCount = 0;
|
||||
}
|
||||
|
||||
// ...
|
||||
public void setLightSource() {
|
||||
|
||||
Reference in New Issue
Block a user