Skip to content

Commit 175ad14

Browse files
committed
New features, map refactor and bug fixes.
1 parent e045ed5 commit 175ad14

File tree

13 files changed

+242
-115
lines changed

13 files changed

+242
-115
lines changed

src/main/java/com/khomsi/game/data/DataInitializer.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import java.io.Serializable;
44
import java.time.Duration;
5-
import java.time.Instant;
65
import java.util.ArrayList;
76

87
public class DataInitializer implements Serializable {

src/main/java/com/khomsi/game/data/SaveLoad.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
package com.khomsi.game.data;
22

33
import com.khomsi.game.entity.Entity;
4+
import com.khomsi.game.entity.npc.dungeon.NpcTutorialMan;
45
import com.khomsi.game.main.GameManager;
56

67
import java.io.*;
78

89
public class SaveLoad {
9-
GameManager gameManager;
10+
private GameManager gameManager;
11+
1012
// Path to save.dat file to check the statement
1113
public static final String FILE_PATH = "save.dat";
1214
public final File file = new File(FILE_PATH);
@@ -30,6 +32,7 @@ public void save() {
3032
initializer.maxHp = gameManager.player.maxHp;
3133
initializer.hp = gameManager.player.hp;
3234
initializer.maxMana = gameManager.player.maxMana;
35+
//FIXME if player press shift while saving, he will gain the speed higher that he supposed to.
3336
initializer.speed = gameManager.player.speed;
3437
initializer.mana = gameManager.player.mana;
3538
initializer.strength = gameManager.player.strength;

src/main/java/com/khomsi/game/entity/npc/dungeon/NpcTutorialMan.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,18 +69,20 @@ private void setDialog() {
6969
dialogues[1][0] = "Are you still here?\n There's nothing to do here, go outside!";
7070
}
7171

72+
//TODO the npc doesn't save the position on which he moved after loading the game + the text appears again.
73+
// Somehow needs to be fixed or just not to move the npc
74+
75+
//TODO maybe it's better to remove the npc when player speaks to him by moving him to exit and use flag to indicate
76+
// in NpcPlacement with that flag that the player had already spoken to him (and store the flag in SaveLoad class)
7277
//set npc movement
7378
public void setAction() {
7479
if (onPath) {
7580
int goalCol = 60;
7681
int goalRow = 73;
77-
// int goalCol = (gameManager.player.worldX + gameManager.player.solidArea.x) / GameManager.TILE_SIZE;
78-
// int goalRow = (gameManager.player.worldY + gameManager.player.solidArea.y) / GameManager.TILE_SIZE;
7982
searchPath(goalCol, goalRow, true);
8083
}
8184
}
8285

83-
//Maybe add special stuff, different custom text for this character
8486
public void speak() {
8587
facePlayer();
8688
startDialogue(this, dialogueSet);

src/main/java/com/khomsi/game/entity/player/Player.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,13 @@ public void setDefaultValues() {
8787

8888
public void setDefaultPosition() {
8989
//player position of player
90-
gameManager.currentMap = 0;
90+
/* gameManager.currentMap = 0;
9191
worldX = GameManager.TILE_SIZE * 29;
9292
worldY = GameManager.TILE_SIZE * 92;
93+
direction = "down";*/
94+
gameManager.currentMap = 0;
95+
worldX = GameManager.TILE_SIZE * 15;
96+
worldY = GameManager.TILE_SIZE * 27;
9397
direction = "down";
9498
}
9599

src/main/java/com/khomsi/game/enviroment/Lightning.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,9 @@ public void setLightSource() {
2828
darknessFilter = new BufferedImage(GameManager.SCREEN_WIDTH,
2929
GameManager.SCREEN_HEIGHT, BufferedImage.TYPE_INT_ARGB);
3030
Graphics2D g2d = (Graphics2D) darknessFilter.getGraphics();
31+
3132
if (gameManager.player.currentLight == null) {
32-
g2d.setColor(new Color(0, 0, 0.1F, 0.98F));
33+
g2d.setColor(new Color(0, 0, 0.1F, 0.94F));
3334
} else {
3435
//Get the center x and y of the light circle
3536
int centerX = gameManager.player.screenX + (GameManager.TILE_SIZE) / 2;
@@ -125,7 +126,14 @@ public void draw(Graphics2D g2d) {
125126
g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, filterAlfa));
126127
}
127128

128-
if (gameManager.currentArea == GameManager.OUTSIDE || gameManager.currentArea == GameManager.DUNGEON
129+
if (gameManager.currentArea == GameManager.OUTSIDE
130+
/* || gameManager.currentArea == GameManager.DUNGEON
131+
|| gameManager.currentArea == GameManager.BOSS_DUNGEON*/
132+
|| gameManager.currentArea == GameManager.FOREST) {
133+
g2d.drawImage(darknessFilter, 0, 0, null);
134+
}
135+
136+
if (gameManager.currentArea == GameManager.DUNGEON
129137
|| gameManager.currentArea == GameManager.BOSS_DUNGEON) {
130138
g2d.drawImage(darknessFilter, 0, 0, null);
131139
}

src/main/java/com/khomsi/game/main/GameManager.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,6 @@ public class GameManager extends JPanel implements Runnable {
112112
public static final int CUTSCENE_STATE = 13;
113113
public static final int DYING_STATE = 14;
114114

115-
116115
//Area
117116
public int currentArea;
118117
public int nextArea;
@@ -121,6 +120,7 @@ public class GameManager extends JPanel implements Runnable {
121120
public static final int DUNGEON = 13;
122121
public static final int BOSS_DUNGEON = 14;
123122
public static final int LIGHT_DUNGEON = 15;
123+
public static final int FOREST = 16;
124124
//Until player doesn't press shift, he doesn't run
125125
public boolean playerRun = false;
126126
public boolean fullScreenOn = false;
@@ -512,7 +512,7 @@ public void changeArea() {
512512
}
513513
if (nextArea == LIGHT_DUNGEON) {
514514
playMusic(20);
515-
placeObjects.trapsOnDungeonMap1();
515+
placeObjects.setTrapsOnDungeonMap1();
516516
}
517517
if (nextArea == DUNGEON) {
518518
playMusic(20);

src/main/java/com/khomsi/game/main/logic/EventHandler.java

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ public class EventHandler {
1616
public int tempMap;
1717
public int tempCol;
1818
public int tempRow;
19+
private boolean inForest = false; // Flag to track the player location
1920

2021
public EventHandler(GameManager gameManager) {
2122
this.gameManager = gameManager;
@@ -79,6 +80,16 @@ else if (interact(0, 35, 84, "any")) {
7980
changeLocation(2, 47, 71, GameManager.INDOOR);
8081
gameManager.playSE(28);
8182
}
83+
84+
//Enter the forest
85+
if (interact(0, 15, 24, "any") && inForest) {
86+
changeLocation(0, 15, 24, GameManager.OUTSIDE);
87+
inForest = false; // restore the flag after the exit of forest
88+
} else if (interact(0, 15, 23, "any") && !inForest) {
89+
changeLocation(0, 15, 23, GameManager.FOREST, GameManager.TRANSITION_STATE);
90+
inForest = true; // install the flag that we're in forest
91+
}
92+
8293
}
8394
case 1 -> { // Dungeon
8495
//back to main map from Dungeon
@@ -226,7 +237,11 @@ private void speak(Entity entity) {
226237
}
227238

228239
private void changeLocation(int map, int col, int row, int area) {
229-
gameManager.gameState = GameManager.TRANSITION_STATE;
240+
changeLocation(map, col, row, area, GameManager.TRANSITION_STATE);
241+
}
242+
243+
private void changeLocation(int map, int col, int row, int area, int gameState) {
244+
gameManager.gameState = gameState;
230245
gameManager.nextArea = area;
231246
tempMap = map;
232247
tempCol = col;

src/main/java/com/khomsi/game/main/tools/ui/UI.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ public void draw(Graphics2D graphics2D) {
9494
if (gameManager.gameState == GameManager.GAME_OVER_STATE) {
9595
drawGameOverScreen();
9696
}
97-
//Transition Over state
97+
//Transition state
9898
if (gameManager.gameState == GameManager.TRANSITION_STATE) {
9999
drawTransitionScreen();
100100
}
@@ -321,6 +321,7 @@ private void drawTransitionScreen() {
321321
}
322322
}
323323

324+
324325
void drawSleepScreen() {
325326
counter++;
326327
if (counter < 120) {

src/main/java/com/khomsi/game/objects/editor/PlaceObjects.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
public class PlaceObjects {
77
private final GameManager gameManager;
88
public static final int MAP_MAIN = 0;
9-
public static final int MAP_HOUSE_BEACH = 2;
109
public static final int MAP_DUNGEON = 1;
10+
public static final int MAP_HOUSE_BEACH = 2;
1111

1212
public PlaceObjects(GameManager gameManager) {
1313
this.gameManager = gameManager;
@@ -42,7 +42,7 @@ public void setMobs() {
4242
mobPlacement.setMobsOnDungeonMap1();
4343
}
4444

45-
public void trapsOnDungeonMap1() {
45+
public void setTrapsOnDungeonMap1() {
4646
DungeonTrapsPlacement trapsPlacement = new DungeonTrapsPlacement(gameManager);
4747
trapsPlacement.trapsOnDungeonMap1();
4848
}

src/main/java/com/khomsi/game/objects/editor/placement/ObjectPlacement.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,6 @@ public void placeObjectsOnMapHouseBeach1() {
4444
gameManager.object[mapNum][index].worldY = GameManager.TILE_SIZE * 72;
4545
index++;
4646

47-
gameManager.object[mapNum][index] = new WindowObject(gameManager);
48-
gameManager.object[mapNum][index].worldX = GameManager.TILE_SIZE * 45;
49-
gameManager.object[mapNum][index].worldY = GameManager.TILE_SIZE * 72;
50-
index++;
51-
5247
gameManager.object[mapNum][index] = new PictureObject(gameManager);
5348
gameManager.object[mapNum][index].worldX = GameManager.TILE_SIZE * 50;
5449
gameManager.object[mapNum][index].worldY = GameManager.TILE_SIZE * 66;

0 commit comments

Comments
 (0)