Compare commits
9 Commits
2cda920e15
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
5dbf7fcf1f
|
|||
|
70eaa9514a
|
|||
|
befb117d85
|
|||
|
54a2ee3022
|
|||
|
ce3f590715
|
|||
|
39fc7d549a
|
|||
|
8902e28d31
|
|||
|
f15850b022
|
|||
|
46765031e4
|
@@ -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();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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;
|
||||||
|
|||||||
@@ -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,6 +8,7 @@ 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 {
|
||||||
|
|
||||||
@@ -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);
|
||||||
@@ -152,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();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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;
|
||||||
@@ -14,6 +16,7 @@ public class Config {
|
|||||||
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").mkdirs();
|
||||||
|
new File("gamedata/save").mkdirs();
|
||||||
new File("gamedata/config").createNewFile();
|
new File("gamedata/config").createNewFile();
|
||||||
}
|
}
|
||||||
|
|
||||||
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.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;
|
||||||
|
|
||||||
@@ -80,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
|
||||||
@@ -327,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;
|
||||||
|
|||||||
@@ -311,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;
|
||||||
@@ -346,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();
|
||||||
|
|||||||
@@ -75,6 +75,11 @@ public class Lighting {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
public void resetDay() {
|
||||||
|
dayState = DayState.DAY;
|
||||||
|
filterAlpha = 0f;
|
||||||
|
dayCount = 0;
|
||||||
|
}
|
||||||
|
|
||||||
// ...
|
// ...
|
||||||
public void setLightSource() {
|
public void setLightSource() {
|
||||||
|
|||||||
Reference in New Issue
Block a user