T-T it just doesn't work, it just doesn't work T-T

This commit is contained in:
musilto9 2020-04-09 20:37:41 +02:00
parent 397e3dab7c
commit f4b1d33403
21 changed files with 283 additions and 47 deletions

View File

@ -2,10 +2,12 @@ import ruscz.game.gameOfProd.Windows.WindowOfFreeMove;
import ruscz.game.gameOfProd.Windows.WindowOfMenu; import ruscz.game.gameOfProd.Windows.WindowOfMenu;
import javax.swing.*; import javax.swing.*;
import java.awt.*;
import java.awt.event.KeyAdapter; import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent; import java.awt.event.KeyEvent;
import java.awt.event.KeyListener; import java.awt.event.KeyListener;
import java.awt.event.WindowEvent; import java.awt.event.WindowEvent;
import java.awt.image.BufferedImage;
public class Game extends JFrame { public class Game extends JFrame {
private static final int WINDOW_WIDTH = 13; private static final int WINDOW_WIDTH = 13;
@ -23,10 +25,10 @@ public class Game extends JFrame {
freeMove = new WindowOfFreeMove(this); freeMove = new WindowOfFreeMove(this);
menu = new WindowOfMenu(this, freeMove); menu = new WindowOfMenu(this, freeMove);
//tohle spustí na začátku menu, ale nejsem schopen přinutit to menu, aby se vzdalo Listeneru a mohl ho využít Game //tohle spustí na začátku menu
add(menu); add(menu);
//tohle spustí na začátku hru, vše funguje tak, jak má //tohle spustí na začátku hru
// add(freeMove); // add(freeMove);
// freeMove.start(true); // freeMove.start(true);
@ -36,9 +38,19 @@ public class Game extends JFrame {
setLocationRelativeTo(null); setLocationRelativeTo(null);
setResizable(false); setResizable(false);
setVisible(true); setVisible(true);
setLayout(new BorderLayout());
getContentPane().setBackground(Color.BLACK);
setExtendedState(game().MAXIMIZED_BOTH);
centerContent();
} }
public Game game() {return this;} public Game game() {return this;}
public void centerContent() {
getContentPane().getComponent(0).setLocation((Toolkit.getDefaultToolkit().getScreenSize().width - (WINDOW_WIDTH * CELL_SIZE)) / 2, (Toolkit.getDefaultToolkit().getScreenSize().height - (WINDOW_HEIGHT * CELL_SIZE)) / 2);
getContentPane().getComponent(0).setSize(WINDOW_WIDTH * CELL_SIZE, WINDOW_HEIGHT * CELL_SIZE);
}
} }

View File

@ -117,6 +117,6 @@ public class MapManager {
canvas.setPreferredSize(new Dimension( canvas.setPreferredSize(new Dimension(
CELL_SIZE * size[0], CELL_SIZE * size[0],
CELL_SIZE * size[1])); CELL_SIZE * size[1]));
canvas.setBounds(0, 0, CELL_SIZE * size[0], CELL_SIZE * size[1]); canvas.setSize(CELL_SIZE * size[0], CELL_SIZE * size[1]);
} }
} }

View File

@ -33,7 +33,6 @@ public class WindowOfFreeMove extends JLayeredPane {
public static final int KEY_DOWN = 40; public static final int KEY_DOWN = 40;
public static final int KEY_EVENT = 69; public static final int KEY_EVENT = 69;
private static final int KEY_FULLSCREEN = 115;
private static final int KEY_ESCAPE = 27; private static final int KEY_ESCAPE = 27;
private JFrame game; private JFrame game;
@ -46,6 +45,8 @@ public class WindowOfFreeMove extends JLayeredPane {
private LinkedList<Map> mapLinkedList; private LinkedList<Map> mapLinkedList;
public WindowOfFreeMove windowOfFreeMove() { return this;}
public MapManager getMapManager() { public MapManager getMapManager() {
return mapManager; return mapManager;
} }
@ -81,24 +82,21 @@ public class WindowOfFreeMove extends JLayeredPane {
public Camera getCamera() { return camera; } public Camera getCamera() { return camera; }
public WindowOfFreeMove(JFrame game) { public WindowOfFreeMove(JFrame game) {
this.game = game; this.game = game;
isReadyToPaint = false; isReadyToPaint = false;
canPersonMove = true; canPersonMove = true;
JPanel background = new JPanel();
background.setBounds(-WINDOW_WIDTH/2, -WINDOW_HEIGHT/2, (CANVAS_WIDTH + WINDOW_WIDTH)*CELL_SIZE, (CANVAS_HEIGHT + WINDOW_HEIGHT)*CELL_SIZE);
background.setBackground(Color.BLACK);
canvas = new Canvas(); canvas = new Canvas();
camera = new Camera(this, canvas); camera = new Camera(this, canvas);
canvas.setBackground(Color.BLACK); canvas.setBackground(Color.BLACK);
canvas.setPreferredSize(new Dimension( canvas.setPreferredSize(new Dimension(
CELL_SIZE * CANVAS_WIDTH, CELL_SIZE * CANVAS_WIDTH,
CELL_SIZE * CANVAS_HEIGHT)); CELL_SIZE * CANVAS_HEIGHT));
canvas.setBounds(0, 0, CELL_SIZE * CANVAS_HEIGHT, CELL_SIZE * CANVAS_WIDTH); canvas.setSize(CELL_SIZE * CANVAS_HEIGHT, CELL_SIZE * CANVAS_WIDTH);
dialogBar = new DialogBar(); dialogBar = new DialogBar();
dialogBar.setBounds(0, WindowOfFreeMove.CELL_SIZE * WindowOfFreeMove.WINDOW_HEIGHT * 3 / 4, WindowOfFreeMove.CELL_SIZE * WindowOfFreeMove.WINDOW_WIDTH, WindowOfFreeMove.CELL_SIZE * WindowOfFreeMove.WINDOW_HEIGHT / 4); dialogBar.setBounds(0, CELL_SIZE * WINDOW_HEIGHT * 3/4, CELL_SIZE * WINDOW_WIDTH, CELL_SIZE * WINDOW_HEIGHT / 4);
dialogBar.setOpaque(false); dialogBar.setOpaque(false);
dialogBar.setVisible(false); dialogBar.setVisible(false);
dialogBar.setLayout(null); dialogBar.setLayout(null);
@ -111,7 +109,6 @@ public class WindowOfFreeMove extends JLayeredPane {
add(dialogBar, JLayeredPane.MODAL_LAYER); add(dialogBar, JLayeredPane.MODAL_LAYER);
add(canvas, JLayeredPane.PALETTE_LAYER); add(canvas, JLayeredPane.PALETTE_LAYER);
add(background, JLayeredPane.DEFAULT_LAYER);
addKeyListener(new KeyAdapter() { addKeyListener(new KeyAdapter() {
@Override @Override
@ -121,12 +118,6 @@ public class WindowOfFreeMove extends JLayeredPane {
game.dispatchEvent(new WindowEvent(game, WindowEvent.WINDOW_CLOSING)); game.dispatchEvent(new WindowEvent(game, WindowEvent.WINDOW_CLOSING));
return; return;
} }
if (e.getKeyCode() == KEY_FULLSCREEN){
if (game.getExtendedState() == game.MAXIMIZED_BOTH)
game.setExtendedState(game.NORMAL);
else
game.setExtendedState(game.MAXIMIZED_BOTH);
}
else { else {
if (canPersonMove) { if (canPersonMove) {
nextMove = e.getKeyCode(); nextMove = e.getKeyCode();
@ -151,10 +142,10 @@ public class WindowOfFreeMove extends JLayeredPane {
inputTimer.stop(); inputTimer.stop();
} }
}); });
} }
public void start(boolean newGame) { public void start(boolean newGame) {
mapLinkedList = new LinkedList<>(); mapLinkedList = new LinkedList<>();
mapManager = new MapManager(mapLinkedList, canvas, this); mapManager = new MapManager(mapLinkedList, canvas, this);
@ -183,6 +174,12 @@ public class WindowOfFreeMove extends JLayeredPane {
musicManager = new MusicManager("Town1.wav"); musicManager = new MusicManager("Town1.wav");
// musicManager.playMusic(); // musicManager.playMusic();
Timer center = new Timer(1, actionEvent -> {
centerContent();
});
center.start();
Timer timer = new Timer(10, actionEvent -> { Timer timer = new Timer(10, actionEvent -> {
mapManager.getActualMap().getPerson().move(); mapManager.getActualMap().getPerson().move();
camera.moveCamera(); camera.moveCamera();
@ -243,4 +240,8 @@ public class WindowOfFreeMove extends JLayeredPane {
CANVAS_HEIGHT = size[1]; CANVAS_HEIGHT = size[1];
} }
public void centerContent() {
game.getContentPane().getComponent(0).setLocation((Toolkit.getDefaultToolkit().getScreenSize().width - (WINDOW_WIDTH * CELL_SIZE)) / 2, (Toolkit.getDefaultToolkit().getScreenSize().height - (WINDOW_HEIGHT * CELL_SIZE)) / 2);
game.getContentPane().getComponent(0).setSize(WINDOW_WIDTH * CELL_SIZE, WINDOW_HEIGHT * CELL_SIZE);
}
} }

View File

@ -3,6 +3,7 @@ package ruscz.game.gameOfProd.Windows;
import javax.swing.*; import javax.swing.*;
import java.awt.*; import java.awt.*;
import java.awt.event.*; import java.awt.event.*;
import java.awt.image.BufferedImage;
public class WindowOfMenu extends JLayeredPane { public class WindowOfMenu extends JLayeredPane {
public static final int WINDOW_WIDTH = 13; public static final int WINDOW_WIDTH = 13;
@ -22,10 +23,6 @@ public class WindowOfMenu extends JLayeredPane {
this.game = game; this.game = game;
this.freeMove = freeMove; this.freeMove = freeMove;
JPanel background = new JPanel();
background.setBounds(0, 0, WINDOW_WIDTH*CELL_SIZE, WINDOW_HEIGHT*CELL_SIZE);
background.setBackground(Color.BLACK);
startNewGame = new JButton("START NEW GAME"); startNewGame = new JButton("START NEW GAME");
//startNewGame.setFocusable(false); //startNewGame.setFocusable(false);
startNewGame.setBounds((WINDOW_WIDTH*CELL_SIZE - 200) / 2,(WINDOW_HEIGHT*CELL_SIZE - 30) / 2 -70,200,30); startNewGame.setBounds((WINDOW_WIDTH*CELL_SIZE - 200) / 2,(WINDOW_HEIGHT*CELL_SIZE - 30) / 2 -70,200,30);
@ -49,7 +46,6 @@ public class WindowOfMenu extends JLayeredPane {
}); });
exitGame = new JButton("EXIT GAME"); exitGame = new JButton("EXIT GAME");
//exitGame.setFocusable(false);
exitGame.setBounds((WINDOW_WIDTH*CELL_SIZE - 200) / 2,(WINDOW_HEIGHT*CELL_SIZE - 30) / 2 + 70,200,30); exitGame.setBounds((WINDOW_WIDTH*CELL_SIZE - 200) / 2,(WINDOW_HEIGHT*CELL_SIZE - 30) / 2 + 70,200,30);
exitGame.setActionCommand("exitGame"); exitGame.setActionCommand("exitGame");
exitGame.addActionListener(actionEvent -> game.dispatchEvent(new WindowEvent(game, WindowEvent.WINDOW_CLOSING))); exitGame.addActionListener(actionEvent -> game.dispatchEvent(new WindowEvent(game, WindowEvent.WINDOW_CLOSING)));
@ -57,24 +53,6 @@ public class WindowOfMenu extends JLayeredPane {
add(startNewGame); add(startNewGame);
add(loadSavedGame); add(loadSavedGame);
add(exitGame); add(exitGame);
add(background);
addKeyListener(new KeyAdapter() {
@Override
public void keyPressed(KeyEvent e) {
if (e.getKeyCode() == KEY_ESCAPE){
game.dispatchEvent(new WindowEvent(game, WindowEvent.WINDOW_CLOSING));
return;
}
if (e.getKeyCode() == KEY_FULLSCREEN){
if (game.getExtendedState() == game.MAXIMIZED_BOTH)
game.setExtendedState(game.NORMAL);
else
game.setExtendedState(game.MAXIMIZED_BOTH);
}
}
});
} }
private void cleanUp() { private void cleanUp() {
@ -86,6 +64,10 @@ public class WindowOfMenu extends JLayeredPane {
game.remove(this); game.remove(this);
menu().revalidate(); menu().revalidate();
menu().repaint(); menu().repaint();
freeMove.setCursor(freeMove.getToolkit().createCustomCursor(
new BufferedImage( 1, 1, BufferedImage.TYPE_INT_ARGB ),
new Point(),
null ) );
} }
public WindowOfMenu menu() { return this; } public WindowOfMenu menu() { return this; }

View File

@ -10,4 +10,4 @@ BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK EMPTY EMPTY EMPTY BLOCK BL
BLOCK block EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY BLOCK BLOCK block EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY BLOCK
BLOCK EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY block BLOCK EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY block
BLOCK EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY BLOCK BLOCK EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY BLOCK
BLOCK BLOCK DOOR,locked,false BLOCK BLOCK BLOCK BLOCK DOOR,locked,false BLOCK BLOCK BLOCK BLOCK DOOR,locked,false BLOCK BLOCK BLOCK BLOCK block BLOCK BLOCK BLOCK BLOCK DOOR,locked,false BLOCK BLOCK BLOCK BLOCK DOOR,locked,false BLOCK BLOCK BLOCK BLOCK DOOR,locked,false BLOCK BLOCK BLOCK BLOCK DOOR,locked,false BLOCK BLOCK

View File

@ -0,0 +1,70 @@
<map>
<mapName>m1</mapName>
<events>
</events>
</map>
<map>
<mapName>m2</mapName>
<events>
<event>
<x>7</x>
<y>2</y>
<active>true</active>
</event>
</events>
</map>
<map>
<mapName>m3</mapName>
<events>
<event>
<x>2</x>
<y>5</y>
<active>true</active>
</event>
</events>
</map>
<map>
<mapName>m4</mapName>
<events>
<event>
<x>3</x>
<y>3</y>
<active>true</active>
</event>
</events>
</map>
<map>
<mapName>m5</mapName>
<events>
</events>
</map>
<map>
<mapName>m6</mapName>
<events>
<event>
<x>11</x>
<y>11</y>
<active>true</active>
</event>
</events>
</map>
<map>
<mapName>openspace</mapName>
<events>
</events>
</map>
<map>
<mapName>office</mapName>
<events>
</events>
</map>
<map>
<mapName>boss</mapName>
<events>
<event>
<x>4</x>
<y>18</y>
<active>true</active>
</event>
</events>
</map>

View File

@ -0,0 +1,70 @@
<map>
<mapName>m1</mapName>
<events>
</events>
</map>
<map>
<mapName>m2</mapName>
<events>
<event>
<x>7</x>
<y>2</y>
<active>true</active>
</event>
</events>
</map>
<map>
<mapName>m3</mapName>
<events>
<event>
<x>2</x>
<y>5</y>
<active>true</active>
</event>
</events>
</map>
<map>
<mapName>m4</mapName>
<events>
<event>
<x>3</x>
<y>3</y>
<active>true</active>
</event>
</events>
</map>
<map>
<mapName>m5</mapName>
<events>
</events>
</map>
<map>
<mapName>m6</mapName>
<events>
<event>
<x>11</x>
<y>11</y>
<active>true</active>
</event>
</events>
</map>
<map>
<mapName>openspace</mapName>
<events>
</events>
</map>
<map>
<mapName>office</mapName>
<events>
</events>
</map>
<map>
<mapName>boss</mapName>
<events>
<event>
<x>4</x>
<y>18</y>
<active>true</active>
</event>
</events>
</map>

View File

@ -0,0 +1,70 @@
<map>
<mapName>m1</mapName>
<events>
</events>
</map>
<map>
<mapName>m2</mapName>
<events>
<event>
<x>7</x>
<y>2</y>
<active>true</active>
</event>
</events>
</map>
<map>
<mapName>m3</mapName>
<events>
<event>
<x>2</x>
<y>5</y>
<active>true</active>
</event>
</events>
</map>
<map>
<mapName>m4</mapName>
<events>
<event>
<x>3</x>
<y>3</y>
<active>true</active>
</event>
</events>
</map>
<map>
<mapName>m5</mapName>
<events>
</events>
</map>
<map>
<mapName>m6</mapName>
<events>
<event>
<x>11</x>
<y>11</y>
<active>true</active>
</event>
</events>
</map>
<map>
<mapName>openspace</mapName>
<events>
</events>
</map>
<map>
<mapName>office</mapName>
<events>
</events>
</map>
<map>
<mapName>boss</mapName>
<events>
<event>
<x>4</x>
<y>18</y>
<active>true</active>
</event>
</events>
</map>

View File

@ -64,7 +64,7 @@
<event> <event>
<x>4</x> <x>4</x>
<y>18</y> <y>18</y>
<active>false</active> <active>true</active>
</event> </event>
</events> </events>
</map> </map>

View File

@ -0,0 +1 @@
TODO: Inventory

View File

@ -0,0 +1 @@
TODO: Inventory

View File

@ -0,0 +1 @@
TODO: Inventory

View File

@ -0,0 +1,5 @@
<location>
<map>m1</map>
<x>1</x>
<y>7</y>
</location>

View File

@ -0,0 +1,5 @@
<location>
<map>m1</map>
<x>1</x>
<y>7</y>
</location>

View File

@ -0,0 +1,5 @@
<location>
<map>m1</map>
<x>1</x>
<y>7</y>
</location>

View File

@ -0,0 +1,5 @@
<location>
<map>m1</map>
<x>1</x>
<y>7</y>
</location>

View File

@ -0,0 +1,5 @@
<location>
<map>m1</map>
<x>1</x>
<y>7</y>
</location>

View File

@ -1,5 +1,5 @@
<location> <location>
<map>office</map> <map>m1</map>
<x>4</x> <x>8</x>
<y>1</y> <y>4</y>
</location> </location>

View File

@ -0,0 +1 @@
TODO: Village

View File

@ -0,0 +1 @@
TODO: Village

View File

@ -0,0 +1 @@
TODO: Village