added map-loading by chapters
This commit is contained in:
parent
f587f1a7ab
commit
a4c49e1439
@ -256,6 +256,7 @@ public class InteractionCell extends Cell {
|
||||
window.getMusicManager().playMusic();
|
||||
window.getMusicManager().fadeIn(10);
|
||||
}
|
||||
else if (data[1].equals("<loadnextchapter>")) window.loadNextChapter();
|
||||
else if (data[1].equals("<end>")) {
|
||||
timer.stop();
|
||||
}
|
||||
|
||||
@ -40,18 +40,18 @@ public class Game extends JFrame {
|
||||
battle = new WindowOfBattle(this);
|
||||
|
||||
//tohle spustí na začátku menu
|
||||
// add(menu);
|
||||
add(menu);
|
||||
|
||||
//tohle spustí na začátku hru
|
||||
// add(freeMove);
|
||||
// freeMove.start(true);
|
||||
|
||||
//tohle spustí na začátku bitvu
|
||||
add(battle);
|
||||
battle.startBattle();
|
||||
// add(battle);
|
||||
// battle.startBattle();
|
||||
|
||||
//Tohle spustí na začátku tileset overview
|
||||
// tilesetOverview = new TilesetOverview();
|
||||
// new TilesetOverview();
|
||||
|
||||
setDefaultCloseOperation(EXIT_ON_CLOSE);
|
||||
setUndecorated(true);
|
||||
|
||||
@ -25,7 +25,7 @@ public class ImageCell {
|
||||
try {
|
||||
mapBackground = new int[WindowOfFreeMove.CANVAS_WIDTH][WindowOfFreeMove.CANVAS_HEIGHT];
|
||||
mapForeground = new int[WindowOfFreeMove.CANVAS_WIDTH][WindowOfFreeMove.CANVAS_HEIGHT];
|
||||
File mapFile = new File("src/main/resources/maps/" + name + "-tileset.txt");
|
||||
File mapFile = new File("src/main/resources/maps/" + WindowOfFreeMove.CHAPTER + "/" + name + "-tileset.txt");
|
||||
Scanner scanner = new Scanner(mapFile);
|
||||
int j = 0;
|
||||
while (scanner.hasNextLine()) {
|
||||
@ -91,7 +91,7 @@ public class ImageCell {
|
||||
|
||||
public void imageObjectset(String file) {
|
||||
try {
|
||||
File objectFile = new File("src/main/resources/maps/" + file + "-objectset.txt");
|
||||
File objectFile = new File("src/main/resources/maps/" + WindowOfFreeMove.CHAPTER + "/" + file + "-objectset.txt");
|
||||
Scanner scanner = new Scanner(objectFile);
|
||||
int j = 0;
|
||||
while (scanner.hasNextLine()) {
|
||||
|
||||
@ -29,6 +29,8 @@ public class Map {
|
||||
|
||||
private static Scanner scanner;
|
||||
|
||||
private static String mapWithSpawn = "";
|
||||
|
||||
public Map(TypeOfCell[][] mapArray) {
|
||||
idExit = -1;
|
||||
moveToCells = new LinkedList<>();
|
||||
@ -56,7 +58,7 @@ public class Map {
|
||||
|
||||
public static Map loadMapFromFile(String name, WindowOfFreeMove window) {
|
||||
try {
|
||||
File file = new File("src/main/resources/maps/" + name + ".txt");
|
||||
File file = new File("src/main/resources/maps/" + WindowOfFreeMove.CHAPTER + "/" + name + ".txt");
|
||||
scanner = new Scanner(file);
|
||||
String firstLine = scanner.nextLine();
|
||||
String[] size = firstLine.split(" ");
|
||||
@ -117,6 +119,7 @@ public class Map {
|
||||
} else if (line[x].equals("SPAWN")) {
|
||||
map.setIdExit(0);
|
||||
map.setSpawnPoint(x, y);
|
||||
mapWithSpawn = map.getName();
|
||||
} else if (line[x].contains("DOOR") && !line[x].contains("DOORTO")) {
|
||||
String[] door = line[x].split(",");
|
||||
if (door.length == 2)
|
||||
@ -136,7 +139,7 @@ public class Map {
|
||||
|
||||
public void linkMaps(Map map, WindowOfFreeMove window) {
|
||||
try {
|
||||
File dialogFile = new File("src/main/resources/maps/" + map.getName() + ".txt");
|
||||
File dialogFile = new File("src/main/resources/maps/" + WindowOfFreeMove.CHAPTER + "/" + map.getName() + ".txt");
|
||||
scanner = new Scanner(dialogFile);
|
||||
String firstLine = scanner.nextLine();
|
||||
String[] size = firstLine.split(" ");
|
||||
@ -221,6 +224,8 @@ public class Map {
|
||||
return idExit;
|
||||
}
|
||||
|
||||
public static String getMapWithSpawn() { return mapWithSpawn; }
|
||||
|
||||
public LinkedList<Block> getBlocks() {
|
||||
return block;
|
||||
}
|
||||
@ -239,9 +244,7 @@ public class Map {
|
||||
|
||||
public LinkedList<ChestCell> getChestCells() { return chestCells; }
|
||||
|
||||
public void setIdExit(int id) {
|
||||
this.idExit = id;
|
||||
}
|
||||
public void setIdExit(int id) { this.idExit = id; }
|
||||
|
||||
public void setSpawnPoint(int x, int y) {
|
||||
mapArray[x][y] = TypeOfCell.SPAWNPOINT;
|
||||
|
||||
@ -72,12 +72,14 @@ public class LoadManager {
|
||||
Scanner scanner = new Scanner(mapsFile);
|
||||
|
||||
while (scanner.hasNextLine()) {
|
||||
String mapName = scanner.nextLine();
|
||||
Map map = Map.loadMapFromFile(mapName, window);
|
||||
if (mapName.equals("tutorial")) map.getPerson().setImagePerson("tutorialpers", rec);
|
||||
else map.getPerson().setImagePerson("main", rec);
|
||||
map.setName(mapName);
|
||||
mapLinkedList.add(map);
|
||||
String[] mapName = scanner.nextLine().split(" ");
|
||||
if (mapName[0].equals("<" + WindowOfFreeMove.CHAPTER + ">")) {
|
||||
Map map = Map.loadMapFromFile(mapName[1], window);
|
||||
if (mapName[1].equals("tutorial")) map.getPerson().setImagePerson("tutorialpers", rec);
|
||||
else map.getPerson().setImagePerson("main", rec);
|
||||
map.setName(mapName[1]);
|
||||
mapLinkedList.add(map);
|
||||
}
|
||||
}
|
||||
scanner.close();
|
||||
for (Map map : mapLinkedList) {
|
||||
@ -93,12 +95,14 @@ public class LoadManager {
|
||||
File npcsFile = new File("src/main/resources/save/newGame/npcs.txt");
|
||||
Scanner scanner = new Scanner(npcsFile);
|
||||
while (scanner.hasNextLine()) {
|
||||
String name = scanner.nextLine();
|
||||
File npcFile = new File("src/main/resources/characters/" + name + ".txt");
|
||||
Scanner sc = new Scanner(npcFile);
|
||||
String[] position = sc.nextLine().split(" ");
|
||||
Npc npc = new Npc(Integer.parseInt(position[0]), Integer.parseInt(position[1]), name, Map.findMapByName(position[2], window), mapManager);
|
||||
Map.findMapByName(position[2], window).setNpcs(npc);
|
||||
String[] npcName = scanner.nextLine().split(" ");
|
||||
if (npcName[0].equals("<" + WindowOfFreeMove.CHAPTER + ">")) {
|
||||
File npcFile = new File("src/main/resources/characters/" + npcName[1] + ".txt");
|
||||
Scanner sc = new Scanner(npcFile);
|
||||
String[] position = sc.nextLine().split(" ");
|
||||
Npc npc = new Npc(Integer.parseInt(position[0]), Integer.parseInt(position[1]), npcName[1], Map.findMapByName(position[2], window), mapManager);
|
||||
Map.findMapByName(position[2], window).setNpcs(npc);
|
||||
}
|
||||
}
|
||||
} catch (FileNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
|
||||
@ -1,5 +1,7 @@
|
||||
package ruscz.game.gameOfProd.Sounds;
|
||||
|
||||
import ruscz.game.gameOfProd.Windows.WindowOfFreeMove;
|
||||
|
||||
import javax.sound.sampled.*;
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
@ -19,7 +21,7 @@ public class SoundManager {
|
||||
|
||||
public void loadSoundMap(String file) {
|
||||
try {
|
||||
File mapFile = new File("src/main/resources/maps/" + file + "-tileset.txt");
|
||||
File mapFile = new File("src/main/resources/maps/" + WindowOfFreeMove.CHAPTER + "/" + file + "-tileset.txt");
|
||||
Scanner scanner = new Scanner(mapFile);
|
||||
soundMap = new HashMap<>();
|
||||
while (scanner.hasNextLine()) {
|
||||
|
||||
@ -35,6 +35,8 @@ public class WindowOfFreeMove extends JLayeredPane {
|
||||
|
||||
private static final int KEY_ESCAPE = 27;
|
||||
|
||||
public static int CHAPTER = 0;
|
||||
|
||||
private JFrame game;
|
||||
private Canvas canvas;
|
||||
private DialogBar dialogBar;
|
||||
@ -164,8 +166,8 @@ public class WindowOfFreeMove extends JLayeredPane {
|
||||
if (newGame) {
|
||||
mapManager.getLoadManager().clearSave();
|
||||
mapManager.getLoadManager().loadNewGame();
|
||||
Map openspace = Map.findMapByName("tutorial", this);
|
||||
setMapManager(openspace);
|
||||
Map firstMap = Map.findMapByName(Map.getMapWithSpawn(), this);
|
||||
setMapManager(firstMap);
|
||||
}
|
||||
else {
|
||||
mapManager.getLoadManager().loadSavedGame();
|
||||
@ -187,6 +189,18 @@ public class WindowOfFreeMove extends JLayeredPane {
|
||||
timer.start();
|
||||
}
|
||||
|
||||
public void loadNextChapter() {
|
||||
CHAPTER++;
|
||||
isReadyToPaint = false;
|
||||
mapLinkedList = new LinkedList<>();
|
||||
mapManager = new MapManager(mapLinkedList, canvas, this);
|
||||
mapManager.getLoadManager().loadNewGame();
|
||||
Map map = Map.findMapByName(Map.getMapWithSpawn(), this);
|
||||
setMapManager(map);
|
||||
mapManager.createMap();
|
||||
isReadyToPaint = true;
|
||||
}
|
||||
|
||||
public class Canvas extends JPanel {
|
||||
@Override
|
||||
public void paint(Graphics g) {
|
||||
|
||||
@ -1,3 +1,4 @@
|
||||
<1> <text> test
|
||||
<3> <text> null
|
||||
<3> <loadnextchapter>
|
||||
<3> <end>
|
||||
13
src/main/resources/maps/1/glade-objectset.txt
Normal file
13
src/main/resources/maps/1/glade-objectset.txt
Normal file
@ -0,0 +1,13 @@
|
||||
0 0 0 0 0 0 0 0 0 0 0 0 0
|
||||
0 205 221 0 0 0 0 310 0 0 0 0 0
|
||||
0 206 222 0 0 0 0 0 0 0 0 0 0
|
||||
0 0 0 0 0 0 0 0 0 0 0 0 0
|
||||
0 0 0 0 0 0 0 0 0 0 0 0 0
|
||||
0 0 0 0 0 0 0 0 0 0 0 0 0
|
||||
0 0 0 0 0 0 0 0 0 0 0 0 0
|
||||
0 0 0 0 0 0 0 0 0 0 0 0 0
|
||||
0 0 0 0 0 0 0 0 0 0 0 0 0
|
||||
0 0 0 0 0 0 0 0 0 0 0 0 0
|
||||
0 0 0 0 0 0 0 0 0 0 0 0 0
|
||||
0 293 0 0 0 0 0 0 0 0 0 0 0
|
||||
0 0 0 0 0 0 0 0 0 0 0 0 0
|
||||
19
src/main/resources/maps/1/glade-tileset.txt
Normal file
19
src/main/resources/maps/1/glade-tileset.txt
Normal file
@ -0,0 +1,19 @@
|
||||
<tileset> A2_Ground.png 512 384 32 192
|
||||
<tileset> D_OutDoor.png 512 512 32 256
|
||||
<cellmap> BLOCK 120
|
||||
<cellmap> MOVETO 277
|
||||
<cellmap> EVENT 334
|
||||
<cellmap> TRIGGER 147
|
||||
1 1 1 1 1 1 1 1 1 1 1 1 1
|
||||
1 1 27 1 1 1 1 1 1 1 1 1 1
|
||||
1 1 1 1 1 1 1 1 1 27 1 1 1
|
||||
1 1 1 1 1 1 1 1 1 1 1 1 1
|
||||
1 1 1 1 1 1 1 1 1 1 27 1 1
|
||||
1 1 1 1 1 1 1 1 1 1 1 1 1
|
||||
1 1 27 1 1 1 1 1 1 1 1 1 1
|
||||
1 1 1 1 1 1 1 1 27 1 1 1 1
|
||||
1 1 1 1 1 1 1 1 1 1 1 1 1
|
||||
1 1 1 1 27 1 1 1 1 1 1 1 1
|
||||
1 1 1 1 1 1 1 1 1 1 1 1 1
|
||||
1 1 1 1 1 1 1 1 1 1 27 1 1
|
||||
1 1 1 1 1 1 1 1 1 1 1 1 1
|
||||
14
src/main/resources/maps/1/glade.txt
Normal file
14
src/main/resources/maps/1/glade.txt
Normal file
@ -0,0 +1,14 @@
|
||||
13 13
|
||||
block block block block block block block block block block block block block
|
||||
block EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY block
|
||||
block EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY block
|
||||
block EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY block
|
||||
block EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY block
|
||||
block EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY block
|
||||
block EMPTY EMPTY EMPTY EMPTY EMPTY SPAWN EMPTY EMPTY EMPTY EMPTY EMPTY block
|
||||
block EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY block
|
||||
block EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY block
|
||||
block EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY block
|
||||
block EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY block
|
||||
block EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY block
|
||||
block block block block block block block block block block block block block
|
||||
@ -1,5 +1,6 @@
|
||||
tutorial
|
||||
openspace
|
||||
office
|
||||
boss
|
||||
treasure
|
||||
<0> tutorial
|
||||
<0> openspace
|
||||
<0> office
|
||||
<0> boss
|
||||
<0> treasure
|
||||
<1> glade
|
||||
@ -1,8 +1,8 @@
|
||||
boy1
|
||||
boy2
|
||||
boy3
|
||||
boy4
|
||||
boy5
|
||||
girl1
|
||||
girl2
|
||||
boss
|
||||
<0> boy1
|
||||
<0> boy2
|
||||
<0> boy3
|
||||
<0> boy4
|
||||
<0> boy5
|
||||
<0> girl1
|
||||
<0> girl2
|
||||
<0> boss
|
||||
BIN
src/main/resources/tilesets/trees.png
Normal file
BIN
src/main/resources/tilesets/trees.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 107 KiB |
Loading…
x
Reference in New Issue
Block a user