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().playMusic();
|
||||||
window.getMusicManager().fadeIn(10);
|
window.getMusicManager().fadeIn(10);
|
||||||
}
|
}
|
||||||
|
else if (data[1].equals("<loadnextchapter>")) window.loadNextChapter();
|
||||||
else if (data[1].equals("<end>")) {
|
else if (data[1].equals("<end>")) {
|
||||||
timer.stop();
|
timer.stop();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -40,18 +40,18 @@ public class Game extends JFrame {
|
|||||||
battle = new WindowOfBattle(this);
|
battle = new WindowOfBattle(this);
|
||||||
|
|
||||||
//tohle spustí na začátku menu
|
//tohle spustí na začátku menu
|
||||||
// add(menu);
|
add(menu);
|
||||||
|
|
||||||
//tohle spustí na začátku hru
|
//tohle spustí na začátku hru
|
||||||
// add(freeMove);
|
// add(freeMove);
|
||||||
// freeMove.start(true);
|
// freeMove.start(true);
|
||||||
|
|
||||||
//tohle spustí na začátku bitvu
|
//tohle spustí na začátku bitvu
|
||||||
add(battle);
|
// add(battle);
|
||||||
battle.startBattle();
|
// battle.startBattle();
|
||||||
|
|
||||||
//Tohle spustí na začátku tileset overview
|
//Tohle spustí na začátku tileset overview
|
||||||
// tilesetOverview = new TilesetOverview();
|
// new TilesetOverview();
|
||||||
|
|
||||||
setDefaultCloseOperation(EXIT_ON_CLOSE);
|
setDefaultCloseOperation(EXIT_ON_CLOSE);
|
||||||
setUndecorated(true);
|
setUndecorated(true);
|
||||||
|
|||||||
@ -25,7 +25,7 @@ public class ImageCell {
|
|||||||
try {
|
try {
|
||||||
mapBackground = new int[WindowOfFreeMove.CANVAS_WIDTH][WindowOfFreeMove.CANVAS_HEIGHT];
|
mapBackground = new int[WindowOfFreeMove.CANVAS_WIDTH][WindowOfFreeMove.CANVAS_HEIGHT];
|
||||||
mapForeground = 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);
|
Scanner scanner = new Scanner(mapFile);
|
||||||
int j = 0;
|
int j = 0;
|
||||||
while (scanner.hasNextLine()) {
|
while (scanner.hasNextLine()) {
|
||||||
@ -91,7 +91,7 @@ public class ImageCell {
|
|||||||
|
|
||||||
public void imageObjectset(String file) {
|
public void imageObjectset(String file) {
|
||||||
try {
|
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);
|
Scanner scanner = new Scanner(objectFile);
|
||||||
int j = 0;
|
int j = 0;
|
||||||
while (scanner.hasNextLine()) {
|
while (scanner.hasNextLine()) {
|
||||||
|
|||||||
@ -29,6 +29,8 @@ public class Map {
|
|||||||
|
|
||||||
private static Scanner scanner;
|
private static Scanner scanner;
|
||||||
|
|
||||||
|
private static String mapWithSpawn = "";
|
||||||
|
|
||||||
public Map(TypeOfCell[][] mapArray) {
|
public Map(TypeOfCell[][] mapArray) {
|
||||||
idExit = -1;
|
idExit = -1;
|
||||||
moveToCells = new LinkedList<>();
|
moveToCells = new LinkedList<>();
|
||||||
@ -56,7 +58,7 @@ public class Map {
|
|||||||
|
|
||||||
public static Map loadMapFromFile(String name, WindowOfFreeMove window) {
|
public static Map loadMapFromFile(String name, WindowOfFreeMove window) {
|
||||||
try {
|
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);
|
scanner = new Scanner(file);
|
||||||
String firstLine = scanner.nextLine();
|
String firstLine = scanner.nextLine();
|
||||||
String[] size = firstLine.split(" ");
|
String[] size = firstLine.split(" ");
|
||||||
@ -117,6 +119,7 @@ public class Map {
|
|||||||
} else if (line[x].equals("SPAWN")) {
|
} else if (line[x].equals("SPAWN")) {
|
||||||
map.setIdExit(0);
|
map.setIdExit(0);
|
||||||
map.setSpawnPoint(x, y);
|
map.setSpawnPoint(x, y);
|
||||||
|
mapWithSpawn = map.getName();
|
||||||
} else if (line[x].contains("DOOR") && !line[x].contains("DOORTO")) {
|
} else if (line[x].contains("DOOR") && !line[x].contains("DOORTO")) {
|
||||||
String[] door = line[x].split(",");
|
String[] door = line[x].split(",");
|
||||||
if (door.length == 2)
|
if (door.length == 2)
|
||||||
@ -136,7 +139,7 @@ public class Map {
|
|||||||
|
|
||||||
public void linkMaps(Map map, WindowOfFreeMove window) {
|
public void linkMaps(Map map, WindowOfFreeMove window) {
|
||||||
try {
|
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);
|
scanner = new Scanner(dialogFile);
|
||||||
String firstLine = scanner.nextLine();
|
String firstLine = scanner.nextLine();
|
||||||
String[] size = firstLine.split(" ");
|
String[] size = firstLine.split(" ");
|
||||||
@ -221,6 +224,8 @@ public class Map {
|
|||||||
return idExit;
|
return idExit;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static String getMapWithSpawn() { return mapWithSpawn; }
|
||||||
|
|
||||||
public LinkedList<Block> getBlocks() {
|
public LinkedList<Block> getBlocks() {
|
||||||
return block;
|
return block;
|
||||||
}
|
}
|
||||||
@ -239,9 +244,7 @@ public class Map {
|
|||||||
|
|
||||||
public LinkedList<ChestCell> getChestCells() { return chestCells; }
|
public LinkedList<ChestCell> getChestCells() { return chestCells; }
|
||||||
|
|
||||||
public void setIdExit(int id) {
|
public void setIdExit(int id) { this.idExit = id; }
|
||||||
this.idExit = id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setSpawnPoint(int x, int y) {
|
public void setSpawnPoint(int x, int y) {
|
||||||
mapArray[x][y] = TypeOfCell.SPAWNPOINT;
|
mapArray[x][y] = TypeOfCell.SPAWNPOINT;
|
||||||
|
|||||||
@ -72,13 +72,15 @@ public class LoadManager {
|
|||||||
Scanner scanner = new Scanner(mapsFile);
|
Scanner scanner = new Scanner(mapsFile);
|
||||||
|
|
||||||
while (scanner.hasNextLine()) {
|
while (scanner.hasNextLine()) {
|
||||||
String mapName = scanner.nextLine();
|
String[] mapName = scanner.nextLine().split(" ");
|
||||||
Map map = Map.loadMapFromFile(mapName, window);
|
if (mapName[0].equals("<" + WindowOfFreeMove.CHAPTER + ">")) {
|
||||||
if (mapName.equals("tutorial")) map.getPerson().setImagePerson("tutorialpers", rec);
|
Map map = Map.loadMapFromFile(mapName[1], window);
|
||||||
|
if (mapName[1].equals("tutorial")) map.getPerson().setImagePerson("tutorialpers", rec);
|
||||||
else map.getPerson().setImagePerson("main", rec);
|
else map.getPerson().setImagePerson("main", rec);
|
||||||
map.setName(mapName);
|
map.setName(mapName[1]);
|
||||||
mapLinkedList.add(map);
|
mapLinkedList.add(map);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
scanner.close();
|
scanner.close();
|
||||||
for (Map map : mapLinkedList) {
|
for (Map map : mapLinkedList) {
|
||||||
map.linkMaps(map, window);
|
map.linkMaps(map, window);
|
||||||
@ -93,13 +95,15 @@ public class LoadManager {
|
|||||||
File npcsFile = new File("src/main/resources/save/newGame/npcs.txt");
|
File npcsFile = new File("src/main/resources/save/newGame/npcs.txt");
|
||||||
Scanner scanner = new Scanner(npcsFile);
|
Scanner scanner = new Scanner(npcsFile);
|
||||||
while (scanner.hasNextLine()) {
|
while (scanner.hasNextLine()) {
|
||||||
String name = scanner.nextLine();
|
String[] npcName = scanner.nextLine().split(" ");
|
||||||
File npcFile = new File("src/main/resources/characters/" + name + ".txt");
|
if (npcName[0].equals("<" + WindowOfFreeMove.CHAPTER + ">")) {
|
||||||
|
File npcFile = new File("src/main/resources/characters/" + npcName[1] + ".txt");
|
||||||
Scanner sc = new Scanner(npcFile);
|
Scanner sc = new Scanner(npcFile);
|
||||||
String[] position = sc.nextLine().split(" ");
|
String[] position = sc.nextLine().split(" ");
|
||||||
Npc npc = new Npc(Integer.parseInt(position[0]), Integer.parseInt(position[1]), name, Map.findMapByName(position[2], window), mapManager);
|
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);
|
Map.findMapByName(position[2], window).setNpcs(npc);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
} catch (FileNotFoundException e) {
|
} catch (FileNotFoundException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,5 +1,7 @@
|
|||||||
package ruscz.game.gameOfProd.Sounds;
|
package ruscz.game.gameOfProd.Sounds;
|
||||||
|
|
||||||
|
import ruscz.game.gameOfProd.Windows.WindowOfFreeMove;
|
||||||
|
|
||||||
import javax.sound.sampled.*;
|
import javax.sound.sampled.*;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileNotFoundException;
|
import java.io.FileNotFoundException;
|
||||||
@ -19,7 +21,7 @@ public class SoundManager {
|
|||||||
|
|
||||||
public void loadSoundMap(String file) {
|
public void loadSoundMap(String file) {
|
||||||
try {
|
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);
|
Scanner scanner = new Scanner(mapFile);
|
||||||
soundMap = new HashMap<>();
|
soundMap = new HashMap<>();
|
||||||
while (scanner.hasNextLine()) {
|
while (scanner.hasNextLine()) {
|
||||||
|
|||||||
@ -35,6 +35,8 @@ public class WindowOfFreeMove extends JLayeredPane {
|
|||||||
|
|
||||||
private static final int KEY_ESCAPE = 27;
|
private static final int KEY_ESCAPE = 27;
|
||||||
|
|
||||||
|
public static int CHAPTER = 0;
|
||||||
|
|
||||||
private JFrame game;
|
private JFrame game;
|
||||||
private Canvas canvas;
|
private Canvas canvas;
|
||||||
private DialogBar dialogBar;
|
private DialogBar dialogBar;
|
||||||
@ -164,8 +166,8 @@ public class WindowOfFreeMove extends JLayeredPane {
|
|||||||
if (newGame) {
|
if (newGame) {
|
||||||
mapManager.getLoadManager().clearSave();
|
mapManager.getLoadManager().clearSave();
|
||||||
mapManager.getLoadManager().loadNewGame();
|
mapManager.getLoadManager().loadNewGame();
|
||||||
Map openspace = Map.findMapByName("tutorial", this);
|
Map firstMap = Map.findMapByName(Map.getMapWithSpawn(), this);
|
||||||
setMapManager(openspace);
|
setMapManager(firstMap);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
mapManager.getLoadManager().loadSavedGame();
|
mapManager.getLoadManager().loadSavedGame();
|
||||||
@ -187,6 +189,18 @@ public class WindowOfFreeMove extends JLayeredPane {
|
|||||||
timer.start();
|
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 {
|
public class Canvas extends JPanel {
|
||||||
@Override
|
@Override
|
||||||
public void paint(Graphics g) {
|
public void paint(Graphics g) {
|
||||||
|
|||||||
@ -1,3 +1,4 @@
|
|||||||
<1> <text> test
|
<1> <text> test
|
||||||
<3> <text> null
|
<3> <text> null
|
||||||
|
<3> <loadnextchapter>
|
||||||
<3> <end>
|
<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
|
<0> tutorial
|
||||||
openspace
|
<0> openspace
|
||||||
office
|
<0> office
|
||||||
boss
|
<0> boss
|
||||||
treasure
|
<0> treasure
|
||||||
|
<1> glade
|
||||||
@ -1,8 +1,8 @@
|
|||||||
boy1
|
<0> boy1
|
||||||
boy2
|
<0> boy2
|
||||||
boy3
|
<0> boy3
|
||||||
boy4
|
<0> boy4
|
||||||
boy5
|
<0> boy5
|
||||||
girl1
|
<0> girl1
|
||||||
girl2
|
<0> girl2
|
||||||
boss
|
<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