Skip to content

Commit 3d423d1

Browse files
committed
New objects, entities, new maps. Lore changes
1 parent 3294849 commit 3d423d1

40 files changed

+544
-209
lines changed

config.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
fullscreen=Off
22
music_volume=1
3-
se_volume=2
3+
se_volume=1

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@
77

88
public class DataInitializer implements Serializable {
99
//Player Coord
10-
int playerX;
11-
int playerY;
10+
public int playerX;
11+
public int playerY;
12+
public int currentMap;
1213
//Player stats
1314
int level;
1415
int maxHp;

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

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
package com.khomsi.game.data;
22

3+
import com.khomsi.game.entity.Entity;
34
import com.khomsi.game.main.GameManager;
45

56
import java.io.*;
67

78
public class SaveLoad {
89
GameManager gameManager;
910
// Path to save.dat file to check the statement
10-
private static final String FILE_PATH = "save.dat";
11+
public static final String FILE_PATH = "save.dat";
1112
public final File file = new File(FILE_PATH);
1213
public final boolean hasFile = file.exists();
1314

@@ -21,6 +22,7 @@ public SaveLoad(GameManager gameManager) {
2122
public void save() {
2223
try (ObjectOutputStream os = new ObjectOutputStream(new FileOutputStream(FILE_PATH))) {
2324
DataInitializer initializer = new DataInitializer();
25+
initializer.currentMap = gameManager.currentMap;
2426
initializer.playerX = gameManager.player.worldX;
2527
initializer.playerY = gameManager.player.worldY;
2628

@@ -86,8 +88,7 @@ public boolean load() {
8688
try (ObjectInputStream is = new ObjectInputStream(new FileInputStream(FILE_PATH))) {
8789
//Read object from file
8890
DataInitializer initializer = (DataInitializer) is.readObject();
89-
gameManager.player.worldX = initializer.playerX;
90-
gameManager.player.worldY = initializer.playerY;
91+
getPlayerCoordinates(initializer);
9192

9293
gameManager.player.level = initializer.level;
9394
gameManager.player.maxHp = initializer.maxHp;
@@ -111,8 +112,11 @@ public boolean load() {
111112
//Player inventory
112113
gameManager.player.inventory.clear();
113114
for (int i = 0; i < initializer.itemNames.size(); i++) {
114-
gameManager.player.inventory.add(gameManager.entityGenerator.getObject(initializer.itemNames.get(i)));
115-
gameManager.player.inventory.get(i).amount = initializer.itemAmounts.get(i);
115+
Entity item = gameManager.entityGenerator.getObject(initializer.itemNames.get(i));
116+
if (item != null) {
117+
item.amount = initializer.itemAmounts.get(i);
118+
gameManager.player.inventory.add(item);
119+
}
116120
}
117121
//Player equipment
118122
gameManager.player.currentWeapon = gameManager.player.inventory.get(initializer.currentWeaponSlot);
@@ -150,6 +154,12 @@ public boolean load() {
150154
return true;
151155
}
152156

157+
public void getPlayerCoordinates(DataInitializer initializer) {
158+
gameManager.currentMap = initializer.currentMap;
159+
gameManager.player.worldX = initializer.playerX;
160+
gameManager.player.worldY = initializer.playerY;
161+
}
162+
153163
public void loadTitleData() {
154164
if (!hasFile) {
155165
// Set to default values or fallback values

src/main/java/com/khomsi/game/entity/Entity.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ public class Entity extends Tools {
5959
public boolean opened = false;
6060
public boolean bossSleep = false;
6161
public boolean drawing = true;
62+
public boolean hasSpoken = false;
6263
public Entity loot;
6364

6465

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package com.khomsi.game.entity.npc.beach;
2+
3+
public enum Color {
4+
RED, YELLOW, BLUE
5+
}

src/main/java/com/khomsi/game/entity/npc/beach/CrabEntity.java renamed to src/main/java/com/khomsi/game/entity/npc/beach/NpcCrabs.java

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,14 @@
66
import java.awt.*;
77
import java.util.Random;
88

9-
public class CrabEntity extends Entity {
9+
public class NpcCrabs extends Entity {
10+
private final Random random = new Random();
11+
private final String[] directions = {"up", "down", "left", "right"};
1012

11-
public CrabEntity(GameManager gameManager) {
13+
public NpcCrabs(GameManager gameManager, Color color) {
1214
super(gameManager);
13-
direction = "up";
15+
direction = getRandomDirection();
1416
speed = 1;
15-
1617
solidArea = new Rectangle();
1718
solidArea.x = 8;
1819
solidArea.y = 16;
@@ -24,14 +25,22 @@ public CrabEntity(GameManager gameManager) {
2425
solidArea.height = 32;
2526
dialogueSet = -1;
2627
setDialog();
28+
getImage(color);
2729
}
2830

2931
@Override
3032
public void update() {
3133
super.update();
3234
}
3335

34-
public void getImage(String basePath) {
36+
public void getImage(Color color) {
37+
String basePath = "/npc/beach/crab/";
38+
switch (color) {
39+
case RED -> basePath += "red/crab_red_";
40+
case YELLOW -> basePath += "yellow/crab_yellow_";
41+
case BLUE -> basePath += "blue/crab_blue_";
42+
default -> throw new IllegalArgumentException("Invalid color: " + color);
43+
}
3544
// Loop from 0 to 15 to set up the images
3645
for (int i = 0; i < 16; i++) {
3746
String filename = basePath + String.format("%02d", i);
@@ -65,26 +74,22 @@ private void setDialog() {
6574
dialogues[1][0] = "(Don't touch me, little human!)";
6675
}
6776

68-
//set npc movement
77+
//Set random npc movement
6978
public void setAction() {
7079
lockCounter++;
7180
if (lockCounter == 120) {
72-
Random random = new Random();
7381
int i = random.nextInt(100) + 1;
7482
if (i <= 30) {
75-
direction = "up";
76-
}
77-
if (i <= 30) {
78-
direction = "up";
83+
direction = directions[0];
7984
}
8085
if (i > 30 && i <= 50) {
81-
direction = "down";
86+
direction = directions[1];
8287
}
8388
if (i > 50 && i <= 75) {
84-
direction = "left";
89+
direction = directions[2];
8590
}
8691
if (i > 75) {
87-
direction = "right";
92+
direction = directions[3];
8893
}
8994
lockCounter = 0;
9095
}
@@ -100,4 +105,8 @@ public void speak() {
100105
dialogueSet = 0;
101106
}
102107
}
108+
109+
private String getRandomDirection() {
110+
return directions[random.nextInt(directions.length)];
111+
}
103112
}

src/main/java/com/khomsi/game/entity/npc/beach/crab/NpcCrabBlue.java

Lines changed: 0 additions & 12 deletions
This file was deleted.

src/main/java/com/khomsi/game/entity/npc/beach/crab/NpcCrabRed.java

Lines changed: 0 additions & 12 deletions
This file was deleted.

src/main/java/com/khomsi/game/entity/npc/beach/crab/NpcCrabYellow.java

Lines changed: 0 additions & 12 deletions
This file was deleted.
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
package com.khomsi.game.entity.npc.dungeon;
2+
3+
import com.khomsi.game.entity.Entity;
4+
import com.khomsi.game.main.GameManager;
5+
6+
import java.awt.*;
7+
8+
public class NpcTutorialMan extends Entity {
9+
10+
public NpcTutorialMan(GameManager gameManager) {
11+
super(gameManager);
12+
direction = "down";
13+
speed = 1;
14+
15+
solidArea = new Rectangle();
16+
solidArea.x = 8;
17+
solidArea.y = 16;
18+
19+
solidAreaDefaultX = solidArea.x;
20+
solidAreaDefaultY = solidArea.y;
21+
//boundaries of npc
22+
solidArea.width = 31;
23+
solidArea.height = 32;
24+
dialogueSet = -1;
25+
26+
getImage();
27+
setDialog();
28+
}
29+
30+
@Override
31+
public void update() {
32+
if (onPath)
33+
super.update();
34+
else {
35+
direction = "down";
36+
spriteNum = 0;
37+
}
38+
}
39+
40+
public void getImage() {
41+
down = setup("/npc/tutorial/old_man/npc_old_man_00");
42+
down1 = setup("/npc/tutorial/old_man/npc_old_man_01");
43+
down2 = setup("/npc/tutorial/old_man/npc_old_man_02");
44+
down3 = setup("/npc/tutorial/old_man/npc_old_man_03");
45+
46+
right = setup("/npc/tutorial/old_man/npc_old_man_04");
47+
right1 = setup("/npc/tutorial/old_man/npc_old_man_05");
48+
right2 = setup("/npc/tutorial/old_man/npc_old_man_06");
49+
right3 = setup("/npc/tutorial/old_man/npc_old_man_07");
50+
51+
up = setup("/npc/tutorial/old_man/npc_old_man_08");
52+
up1 = setup("/npc/tutorial/old_man/npc_old_man_09");
53+
up2 = setup("/npc/tutorial/old_man/npc_old_man_10");
54+
up3 = setup("/npc/tutorial/old_man/npc_old_man_11");
55+
56+
left = setup("/npc/tutorial/old_man/npc_old_man_12");
57+
left1 = setup("/npc/tutorial/old_man/npc_old_man_13");
58+
left2 = setup("/npc/tutorial/old_man/npc_old_man_14");
59+
left3 = setup("/npc/tutorial/old_man/npc_old_man_15");
60+
61+
}
62+
63+
private void setDialog() {
64+
dialogues[0][0] = "So you are finally here?";
65+
dialogues[0][1] = "Happy to see you again.\nYou probably don't remember me...";
66+
dialogues[0][2] = "But I remember you.";
67+
dialogues[0][3] = "But don't bother your head with this now.";
68+
dialogues[0][4] = "Grab this sword and go outside\nYou will need to find your shield now!";
69+
dialogues[1][0] = "Are you still here?\n There's nothing to do here, go outside!";
70+
}
71+
72+
//set npc movement
73+
public void setAction() {
74+
if (onPath) {
75+
int goalCol = 60;
76+
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;
79+
searchPath(goalCol, goalRow, true);
80+
}
81+
}
82+
83+
//Maybe add special stuff, different custom text for this character
84+
public void speak() {
85+
facePlayer();
86+
startDialogue(this, dialogueSet);
87+
dialogueSet++;
88+
if (dialogues[dialogueSet][0] == null) {
89+
dialogueSet--;
90+
}
91+
if (!hasSpoken) {
92+
hasSpoken = true;
93+
onPath = true;
94+
}
95+
}
96+
}

0 commit comments

Comments
 (0)