This commit is contained in:
musilto9 2020-06-07 15:27:09 +02:00
parent 6c7f9cdef2
commit 2328494c4f
10 changed files with 100 additions and 35 deletions

View File

@ -1,6 +1,9 @@
package ruscz.game.gameOfProd.Battle; package ruscz.game.gameOfProd.Battle;
import ruscz.game.gameOfProd.Cells.InteractionCell;
import ruscz.game.gameOfProd.Dialog.Dialog;
import ruscz.game.gameOfProd.Windows.WindowOfBattle; import ruscz.game.gameOfProd.Windows.WindowOfBattle;
import ruscz.game.gameOfProd.Windows.WindowOfFreeMove;
import javax.swing.*; import javax.swing.*;
import java.awt.*; import java.awt.*;
@ -96,11 +99,27 @@ public class Battle {
} }
private void endBattle(boolean b) { private void endBattle(boolean b) {
//TODO Return to Map
timer.stop(); timer.stop();
timerStopped = true; timerStopped = true;
if (b) windowOfBattle.writeToOutput("Win!"); windowOfBattle.setVisible(false);
else windowOfBattle.writeToOutput("Lose!"); WindowOfFreeMove windowOfFreeMove = windowOfBattle.getGame().getFreeMove();
windowOfBattle.getMenuOfActions().getAttack().removeActionListener(windowOfBattle.getMenuOfActions().getAttack().getActionListeners()[0]);
windowOfBattle.getMenuOfActions().getConsole().removeActionListener(windowOfBattle.getMenuOfActions().getConsole().getActionListeners()[0]);
windowOfBattle.getMenuOfActions().getEscape().removeActionListener(windowOfBattle.getMenuOfActions().getEscape().getActionListeners()[0]);
windowOfBattle.getMenuOfActions().getInventory().removeActionListener(windowOfBattle.getMenuOfActions().getInventory().getActionListeners()[0]);
InteractionCell ic;
if (b) ic = new InteractionCell(-1, -1, windowOfBattle.getWinCutscene(),
new Dialog(windowOfFreeMove.getDialogBar()), windowOfFreeMove.getMapManager().getActualMap(), windowOfFreeMove, true);
else ic = new InteractionCell(-1, -1, windowOfBattle.getLoseCutscene(),
new Dialog(windowOfFreeMove.getDialogBar()), windowOfFreeMove.getMapManager().getActualMap(), windowOfFreeMove, true);
ic.startEvent();
windowOfFreeMove.getForegroundPanel().setColorForeground(0, 0, 0, 255);
windowOfFreeMove.setVisible(true);
windowOfFreeMove.requestFocus();
windowOfBattle.getGame().remove(windowOfBattle);
windowOfBattle.getMusicManager().stopMusic();
// SaveManager saveManager = game.getFreeMove().getMapManager().getSaveManager();
// saveManager.saveGame();
} }
private void returnControlToPlayer(){ private void returnControlToPlayer(){

View File

@ -338,7 +338,7 @@ public class InteractionCell extends Cell {
Npc npc = new Npc(Integer.parseInt(position[0]), Integer.parseInt(position[1]), data[3], Map.findMapByName(position[2], window), window.getMapManager()); Npc npc = new Npc(Integer.parseInt(position[0]), Integer.parseInt(position[1]), data[3], Map.findMapByName(position[2], window), window.getMapManager());
Map.findMapByName(position[2], window).setNpcs(npc); Map.findMapByName(position[2], window).setNpcs(npc);
} }
else if (data[2].contains("move")) { else if (data[2].contains("move") && !data[2].equals("remove")) {
Npc npc = window.getMapManager().getActualMap().findNpcByName(data[3]); Npc npc = window.getMapManager().getActualMap().findNpcByName(data[3]);
if (data[2].equals("movetoplayer")) { if (data[2].equals("movetoplayer")) {
npc.move(window.getMapManager().getActualMap().getPerson().getX(), window.getMapManager().getActualMap().getPerson().getY()); npc.move(window.getMapManager().getActualMap().getPerson().getX(), window.getMapManager().getActualMap().getPerson().getY());
@ -347,6 +347,10 @@ public class InteractionCell extends Cell {
npc.move(Integer.parseInt(data[4]), Integer.parseInt(data[5])); npc.move(Integer.parseInt(data[4]), Integer.parseInt(data[5]));
} }
} }
else if (data[2].equals("remove")) {
Npc npc = window.getMapManager().getActualMap().findNpcByName(data[3]);
window.getMapManager().getActualMap().getNpcs().remove(npc);
}
} }
else if (data[1].equals("<removenpcs>")) window.getMapManager().getActualMap().getNpcs().clear(); else if (data[1].equals("<removenpcs>")) window.getMapManager().getActualMap().getNpcs().clear();
else if (data[1].equals("<loadnextchapter>")) window.loadNextChapter(); else if (data[1].equals("<loadnextchapter>")) window.loadNextChapter();

View File

@ -24,24 +24,23 @@ public class MusicManager {
AudioInputStream audioIn; AudioInputStream audioIn;
try { try {
audioIn = AudioSystem.getAudioInputStream(new File("src/main/resources/music/" + musicName)); audioIn = AudioSystem.getAudioInputStream(new File("src/main/resources/music/" + musicName));
clip = AudioSystem.getClip(); clip = AudioSystem.getClip();
if (clip != null) { if (clip != null) {
clip.open(audioIn); clip.open(audioIn);
} }
if (clip != null) { if (clip != null) {
gainControl = gainControl = (FloatControl) clip.getControl(FloatControl.Type.MASTER_GAIN);
(FloatControl) clip.getControl(FloatControl.Type.MASTER_GAIN); gainControl.setValue(volume);
gainControl.setValue(volume); clip.loop(1000);
clip.loop(1000); clip.start();
clip.start(); }
}
} catch (LineUnavailableException | IOException | UnsupportedAudioFileException e) { } catch (LineUnavailableException | IOException | UnsupportedAudioFileException e) {
e.printStackTrace(); e.printStackTrace();
} }
} }
public void stopMusic() { public void stopMusic() {
timerOut.stop(); if (timerOut != null) timerOut.stop();
clip.stop(); clip.stop();
volume = -40.0f; volume = -40.0f;
} }

View File

@ -67,6 +67,10 @@ public class WindowOfBattle extends JPanel {
private MusicManager musicManager; private MusicManager musicManager;
private String winCutscene;
private String loseCutscene;
private String name;
public Battle getBattle() { public Battle getBattle() {
return battle; return battle;
} }
@ -108,15 +112,16 @@ public class WindowOfBattle extends JPanel {
} }
} }
}); });
setCursor(Cursor.getDefaultCursor());
} }
public void startBattle(String name) { public void startBattle(String name) {
// SaveManager saveManager = game.getFreeMove().getMapManager().getSaveManager();
// saveManager.saveGame();
LinkedList<Hero> heroes = new LinkedList<>(); LinkedList<Hero> heroes = new LinkedList<>();
LinkedList<Enemy> enemies = new LinkedList<>(); LinkedList<Enemy> enemies = new LinkedList<>();
this.name = name;
try { try {
File battleFile = new File("src/main/resources/battles/" + name + ".txt"); File battleFile = new File("src/main/resources/battles/" + name + ".txt");
Scanner scanner = new Scanner(battleFile); Scanner scanner = new Scanner(battleFile);
@ -141,12 +146,17 @@ public class WindowOfBattle extends JPanel {
if (data[1].equals("flicker")) canvas.flicker(Integer.parseInt(data[2])); if (data[1].equals("flicker")) canvas.flicker(Integer.parseInt(data[2]));
else canvas.addImage(data[1]); else canvas.addImage(data[1]);
} }
else if (data[0].equals("<wincutscene>")) {
winCutscene = data[1];
}
else if (data[0].equals("<losecutscene>")) {
loseCutscene = data[1];
}
} }
} catch (FileNotFoundException e) { } catch (FileNotFoundException e) {
e.printStackTrace(); e.printStackTrace();
} }
MusicManager musicManager = new MusicManager("Fight_Music.wav", -15.0f);
battle = new Battle(heroes, enemies, this); battle = new Battle(heroes, enemies, this);
isReadyToPaint = true; isReadyToPaint = true;
@ -186,6 +196,23 @@ public class WindowOfBattle extends JPanel {
return game; return game;
} }
public MusicManager getMusicManager() {
return musicManager;
}
public String getWinCutscene() {
return winCutscene;
}
public String getLoseCutscene() {
return loseCutscene;
}
@Override
public String getName() {
return name;
}
class Canvas extends JPanel { class Canvas extends JPanel {
private LinkedList<BufferedImage> images; private LinkedList<BufferedImage> images;
private BufferedImage image; private BufferedImage image;

View File

@ -1,6 +1,8 @@
<hero> 100 10 Mark 1 10 1 main-battle <hero> 100 10 Mark 1 10 1 main-battle
<enemy> 100 10 Karen 10 1 monster-battle hover <enemy> 1 1 Karen 1 1 monster-battle hover
<music> Fight_Music.wav -10.0f <music> Fight_Music.wav -10.0f
<image> battle1 <image> battle1
<image> battle2 <image> battle2
<image> flicker 500 <image> flicker 500
<wincutscene> cutscene-storageroombattle-win
<losecutscene> cutscene-storageroombattle-lose

View File

@ -0,0 +1,10 @@
<1> <npc> remove monster
<1> <music> start
<1> <doorlock> 6 1 false
<1> <foreground> fade 255 0 1
<3> <foreground> null
<3> <text> image main-face.png
<3> <text> Huh,-what-a-weird-encounter.
<5> <text> null
<5> <personmove> true
<5> <end>

View File

@ -0,0 +1,10 @@
<1> <npc> remove monster
<1> <music> start
<1> <doorlock> 6 1 false
<1> <foreground> fade 255 0 1
<3> <foreground> null
<3> <text> image main-face.png
<3> <text> Huh,-what-a-weird-encounter.
<5> <text> null
<5> <personmove> true
<5> <end>

View File

@ -14,7 +14,7 @@
<trigger> <trigger>
<x>6</x> <x>6</x>
<y>4</y> <y>4</y>
<active>false</active> <active>true</active>
</trigger> </trigger>
<trigger> <trigger>
<x>14</x> <x>14</x>
@ -24,7 +24,7 @@
<chest> <chest>
<x>1</x> <x>1</x>
<y>2</y> <y>2</y>
<active>false</active> <active>true</active>
</chest> </chest>
<chest> <chest>
<x>15</x> <x>15</x>
@ -74,7 +74,7 @@
<trigger> <trigger>
<x>6</x> <x>6</x>
<y>2</y> <y>2</y>
<active>true</active> <active>false</active>
</trigger> </trigger>
</events> </events>
</map> </map>

View File

@ -1,6 +0,0 @@
<item>
<name>cup-o'-coffee</name>
<multiplicity>1</multiplicity>
<image>295</image>
<action>heal</action>
</item>

View File

@ -1,6 +1,6 @@
<location> <location>
<map>storageroom</map> <map>office</map>
<x>6</x> <x>2</x>
<y>2</y> <y>11</y>
<direction>0</direction> <direction>2</direction>
</location> </location>