Compare commits
13 Commits
e0986d4708
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
5dbf7fcf1f
|
|||
|
70eaa9514a
|
|||
|
befb117d85
|
|||
|
54a2ee3022
|
|||
|
ce3f590715
|
|||
|
39fc7d549a
|
|||
|
8902e28d31
|
|||
|
f15850b022
|
|||
|
46765031e4
|
|||
|
2cda920e15
|
|||
|
93467760db
|
|||
|
6be9927752
|
|||
|
1343b18753
|
@@ -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
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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,6 +8,7 @@ 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 {
|
||||
|
||||
@@ -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);
|
||||
@@ -152,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();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -80,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
|
||||
@@ -108,6 +108,7 @@ public class Entity {
|
||||
knockbackCount = 0;
|
||||
knockback = false;
|
||||
speed = defaultSpeed;
|
||||
invincibleCounting();
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -119,7 +120,10 @@ public class Entity {
|
||||
}
|
||||
|
||||
knockbackCount++;
|
||||
if(knockbackCount != 10) return;
|
||||
if(knockbackCount != 10) {
|
||||
invincibleCounting();
|
||||
return;
|
||||
}
|
||||
|
||||
knockback = false;
|
||||
knockbackCount = 0;
|
||||
@@ -146,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;
|
||||
@@ -262,7 +259,7 @@ public class Entity {
|
||||
panel.player.life -= Math.max(damage, (block ? 0 : 1));
|
||||
|
||||
if(damage != 0) {
|
||||
//setKnockback(panel.player, this, knockbackVal);
|
||||
setKnockback(panel.player, this, knockbackVal);
|
||||
panel.player.transparent = true;
|
||||
}
|
||||
panel.player.invincible = true;
|
||||
@@ -330,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;
|
||||
@@ -613,5 +610,13 @@ public class Entity {
|
||||
actionLock = 0;
|
||||
}
|
||||
}
|
||||
public void invincibleCounting() {
|
||||
if(!invincible) return;
|
||||
invincibleCount++;
|
||||
if(invincibleCount > 40) {
|
||||
invincible = false;
|
||||
invincibleCount = 0;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -52,15 +52,50 @@ public class Player extends Entity {
|
||||
public void update() {
|
||||
if(life > maxLife) life = maxLife;
|
||||
|
||||
// ATTACKING
|
||||
if(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;
|
||||
}
|
||||
|
||||
@@ -138,15 +173,11 @@ public class Player extends Entity {
|
||||
|
||||
// INVINCIBLE COUNTER
|
||||
if(!invincible) return;
|
||||
invincibleCount++;
|
||||
if(invincibleCount > 60) {
|
||||
invincible = false;
|
||||
transparent = false;
|
||||
invincibleCount = 0;
|
||||
}
|
||||
invincibleCounting();
|
||||
|
||||
if(life <= 0) {
|
||||
panel.gameState = GameState.GAMEOVER;
|
||||
invincibleCount = 0;
|
||||
panel.ui.commandNum = -1;
|
||||
panel.stopMusic();
|
||||
panel.playSE(12);
|
||||
@@ -204,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;
|
||||
}
|
||||
|
||||
@@ -279,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;
|
||||
@@ -314,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();
|
||||
@@ -395,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;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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