mirror of
https://github.com/jokerx3/HeatUp
synced 2026-07-27 08:49:44 +02:00
Merge branch 'master' of github.com:jokerx3/prp
Conflicts: HeatUp/src/de/heatup/resources/maps/map1.txt
This commit is contained in:
+2
-1
@@ -11,4 +11,5 @@ local.properties
|
||||
.settings/
|
||||
.loadpath
|
||||
.classpath
|
||||
.project
|
||||
.project
|
||||
.recommenders
|
||||
+2
-2
@@ -1,8 +1,8 @@
|
||||
package de.heatup.audio;
|
||||
|
||||
public class BackgroundSound {
|
||||
public class Main {
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
new WavePlayer("<filetpath>").start();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,99 @@
|
||||
package de.heatup.audio;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import javax.sound.sampled.AudioFormat;
|
||||
import javax.sound.sampled.AudioInputStream;
|
||||
import javax.sound.sampled.AudioSystem;
|
||||
import javax.sound.sampled.DataLine;
|
||||
import javax.sound.sampled.FloatControl;
|
||||
import javax.sound.sampled.LineUnavailableException;
|
||||
import javax.sound.sampled.SourceDataLine;
|
||||
import javax.sound.sampled.UnsupportedAudioFileException;
|
||||
|
||||
public class WavePlayer extends Thread {
|
||||
|
||||
private String filename;
|
||||
|
||||
private Position curPosition;
|
||||
|
||||
private final int EXTERNAL_BUFFER_SIZE = 524288; // 128Kb
|
||||
|
||||
enum Position {
|
||||
LEFT, RIGHT, NORMAL
|
||||
};
|
||||
|
||||
public WavePlayer(String wavfile) {
|
||||
filename = wavfile;
|
||||
curPosition = Position.NORMAL;
|
||||
}
|
||||
|
||||
public WavePlayer(String wavfile, Position p) {
|
||||
filename = wavfile;
|
||||
curPosition = p;
|
||||
}
|
||||
|
||||
public void run() {
|
||||
|
||||
File soundFile = new File(filename);
|
||||
if (!soundFile.exists()) {
|
||||
System.err.println("Wave file not found: " + filename);
|
||||
return;
|
||||
}
|
||||
|
||||
AudioInputStream audioInputStream = null;
|
||||
try {
|
||||
audioInputStream = AudioSystem.getAudioInputStream(soundFile);
|
||||
} catch (UnsupportedAudioFileException e1) {
|
||||
e1.printStackTrace();
|
||||
return;
|
||||
} catch (IOException e1) {
|
||||
e1.printStackTrace();
|
||||
return;
|
||||
}
|
||||
|
||||
AudioFormat format = audioInputStream.getFormat();
|
||||
SourceDataLine auline = null;
|
||||
DataLine.Info info = new DataLine.Info(SourceDataLine.class, format);
|
||||
|
||||
try {
|
||||
auline = (SourceDataLine) AudioSystem.getLine(info);
|
||||
auline.open(format);
|
||||
} catch (LineUnavailableException e) {
|
||||
e.printStackTrace();
|
||||
return;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return;
|
||||
}
|
||||
|
||||
if (auline.isControlSupported(FloatControl.Type.PAN)) {
|
||||
FloatControl pan = (FloatControl) auline
|
||||
.getControl(FloatControl.Type.PAN);
|
||||
if (curPosition == Position.RIGHT)
|
||||
pan.setValue(1.0f);
|
||||
else if (curPosition == Position.LEFT)
|
||||
pan.setValue(-1.0f);
|
||||
}
|
||||
|
||||
auline.start();
|
||||
int nBytesRead = 0;
|
||||
byte[] abData = new byte[EXTERNAL_BUFFER_SIZE];
|
||||
|
||||
try {
|
||||
while (nBytesRead != -1) {
|
||||
nBytesRead = audioInputStream.read(abData, 0, abData.length);
|
||||
if (nBytesRead >= 0)
|
||||
auline.write(abData, 0, nBytesRead);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
return;
|
||||
} finally {
|
||||
auline.drain();
|
||||
auline.close();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,19 +1,26 @@
|
||||
package de.heatup.cfg;
|
||||
|
||||
import de.heatup.logging.Logger;
|
||||
|
||||
/*
|
||||
* Bitte hier eure Magicnumbers eintragen
|
||||
*/
|
||||
public class Config {
|
||||
/*
|
||||
* Attribute
|
||||
* de.heatup.mapengine.*
|
||||
*/
|
||||
public static final int triggerAreaAddition = 20;
|
||||
public static final int triggerAreaAddition = 20; // wird nicht gebraucht, wenn MapGrid verwendet wird
|
||||
public static final int mapMaxTilesWidth = 32;
|
||||
public static final int mapMaxTilesHeight = 24;
|
||||
public static int gamePanelWidth = 800;
|
||||
public static int singleTilePixels = gamePanelWidth/mapMaxTilesWidth;
|
||||
/*
|
||||
* Attribute
|
||||
* de.heatup.ein.anderes.package.*
|
||||
*/
|
||||
/*
|
||||
* Methoden
|
||||
* de.heatup.mapengine.*
|
||||
*/
|
||||
public static void setGamePanelWidth(int width) {
|
||||
// Wir wollen hier keine Reste!
|
||||
while (width % mapMaxTilesWidth != 0) {
|
||||
@@ -25,4 +32,8 @@ public class Config {
|
||||
private static void updateSingleTilePixels() {
|
||||
singleTilePixels = gamePanelWidth/mapMaxTilesWidth;
|
||||
}
|
||||
/*
|
||||
* Methoden
|
||||
* de.heatup.ein.anderes.package.*
|
||||
*/
|
||||
}
|
||||
|
||||
@@ -14,12 +14,22 @@ import javax.swing.JFileChooser;
|
||||
import de.heatup.cfg.Config;
|
||||
import de.heatup.logging.Logger;
|
||||
import de.heatup.objects.*;
|
||||
|
||||
/**
|
||||
* Diese Klasse soll als primäre Schnittstelle zu anderen Spielmodulen dienen.
|
||||
* Sie generiert die Map als StaticObjects um diese dann auf ein Spielfeld zu malen.
|
||||
* Außerdem erstellt sie eine MapGrid, welches zur Kollisionserkennung und Positionierung
|
||||
* von Entitäten dient.
|
||||
* @author daniel
|
||||
*
|
||||
*/
|
||||
public class MapEngine {
|
||||
|
||||
private static final int singleTileWidth = Config.singleTilePixels;
|
||||
|
||||
private final int mapHeight = Config.mapMaxTilesHeight;
|
||||
|
||||
private final int mapWidth = Config.mapMaxTilesWidth;
|
||||
|
||||
private final int gamePanelWidth = Config.gamePanelWidth;
|
||||
|
||||
HashMap<Character, ArrayList<Point>> allMapTiles = new HashMap<Character, ArrayList<Point>>();
|
||||
@@ -36,6 +46,7 @@ public class MapEngine {
|
||||
}
|
||||
this.createTiles(input);
|
||||
}
|
||||
|
||||
public MapEngine() {
|
||||
Scanner input = null;
|
||||
try {
|
||||
@@ -49,6 +60,11 @@ public class MapEngine {
|
||||
}
|
||||
this.createTiles(input);
|
||||
}
|
||||
/**
|
||||
* Erstellt aus einem gegebenen Scanner, welche eine Datei einliest,
|
||||
* eine Map, welche dann zu einem Spielfeld hinzugefügt werden kann.
|
||||
* @param input Ein Scanner der auf eine Map-Datei zeigt.
|
||||
*/
|
||||
private void createTiles(Scanner input) {
|
||||
int lineCount = 0;
|
||||
int x = 0;
|
||||
@@ -120,9 +136,6 @@ public class MapEngine {
|
||||
} else {
|
||||
allMapTiles.get(currentLine.charAt(i)).add(new Point(x,y));
|
||||
}
|
||||
/*
|
||||
* setze x und y auf die koordinaten für das objekt im NÄCHSTEN durchlauf
|
||||
*/
|
||||
if (x+singleTileWidth >= gamePanelWidth) {
|
||||
x = 0;
|
||||
y += singleTileWidth;
|
||||
@@ -133,68 +146,70 @@ public class MapEngine {
|
||||
lineCount++;
|
||||
}
|
||||
}
|
||||
/*
|
||||
* wird wahrscheinlich anders umgesetzt. methode ist für testzwecke enthalten.
|
||||
*/
|
||||
// protected void addAllGameTilesToGamePanel(JPanel gamePanel) throws IOException {
|
||||
// int x = 0;
|
||||
// int y = 0;
|
||||
// for (int i = 0; i<mapHeight; i++) {
|
||||
// for (int j = 0; j < mapWidth; j++) {
|
||||
// Objekt newGameTile = new Objekt(getTiles()[i][j]);
|
||||
// newGameTile.setPosition(x, y);
|
||||
// if (x+25 >= 800) {
|
||||
// x = 0;
|
||||
// y += 25;
|
||||
// } else {
|
||||
// x += 25;
|
||||
// }
|
||||
// gamePanel.add(newGameTile.getLabel());
|
||||
//
|
||||
// }
|
||||
//
|
||||
// }
|
||||
// gamePanel.repaint();
|
||||
// }
|
||||
// /*
|
||||
// * get all tiles in a 2 dimensional char array
|
||||
// */
|
||||
// private char[][] getTiles() {
|
||||
// return tiles;
|
||||
// }
|
||||
|
||||
private HashMap<Character, ArrayList<Point>> getAllMapTiles() {
|
||||
return allMapTiles;
|
||||
}
|
||||
|
||||
protected ArrayList<Character> getAvailableHardwareTileTypes() {
|
||||
return availableHardwareTileTypes;
|
||||
}
|
||||
|
||||
protected ArrayList<Point> getAllCoordinatesOfTileType(char c) {
|
||||
return getAllMapTiles().get(c);
|
||||
}
|
||||
/*
|
||||
* obsolet bisher.
|
||||
*/
|
||||
protected Point getFirstTilesCoordinatesOfTileType(char c) {
|
||||
return getAllMapTiles().get(c).get(0);
|
||||
}
|
||||
/*
|
||||
* obsolet bisher.
|
||||
*/
|
||||
protected Point getLastTilesCoordinatesOfTileType(char c) {
|
||||
return getAllMapTiles().get(c).get(getAllMapTiles().get(c).size()-1);
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @return Gibt alle MapObjekte als ArrayList<StaticObject> zurück.
|
||||
*/
|
||||
public ArrayList<StaticObject> getAllMapObjects() {
|
||||
return MapObjectHandler.getAllMapObjects(this);
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @return Gibt alle HardwareObjekte auf einer Map als ArrayList<StaticObject> zurück.
|
||||
*/
|
||||
public ArrayList<StaticObject> getAllHardwareObjects() {
|
||||
return MapObjectHandler.getAllHardwareObjects();
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @return Gibt alle WallObjekte auf einer Map als ArrayList<StaticObject> zurück.
|
||||
*/
|
||||
public ArrayList<StaticObject> getAllWallObjects() {
|
||||
return MapObjectHandler.getAllWallObjects();
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @return Gibt alle WayObjekte auf einer Map als ArrayList<StaticObject> zurück.
|
||||
*/
|
||||
public ArrayList<StaticObject> getAllWayObjects() {
|
||||
return MapObjectHandler.getAllWayObjects();
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @return Gibt alle HardwareTriggerObjekte auf einer Map als ArrayList<StaticObject> zurück.
|
||||
*/
|
||||
public ArrayList<StaticObject> getAllHardwareTriggerObjects() {
|
||||
return MapObjectHandler.getAllHardwareTriggerObjects();
|
||||
}
|
||||
|
||||
private boolean checkIfPath(char c) {
|
||||
return (c=='#');
|
||||
}
|
||||
|
||||
private boolean checkIfHardware(char c) {
|
||||
for (char j = '0'; j <= '9'; j++) {
|
||||
if (j==c) {
|
||||
@@ -203,4 +218,25 @@ public class MapEngine {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
/**
|
||||
* Schreibt eine mit Trigger konvertierte Map-Datei in die Konsole
|
||||
*/
|
||||
public void printMapGridWithTriggers() {
|
||||
for (int i = 0; i < 24; i++) {
|
||||
for (int j = 0; j < 32; j++) {
|
||||
if (!MapGrid.getGridCell(j, i).isPath() && !MapGrid.getGridCell(j, i).isTrigger()) {
|
||||
System.out.print("-");
|
||||
} else {
|
||||
if (MapGrid.getGridCell(j, i).isTrigger()) {
|
||||
System.out.print(MapGrid.getGridCell(j, i).getCorrespondingHardwareToTrigger()+"");
|
||||
}
|
||||
if (MapGrid.getGridCell(j, i).isPath() && !MapGrid.getGridCell(j, i).isTrigger()) {
|
||||
System.out.print("#");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
System.out.println();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,34 +3,40 @@ package de.heatup.mapengine;
|
||||
import de.heatup.cfg.Config;
|
||||
|
||||
public class MapGrid {
|
||||
private static GridCell[][] allGridCells = new GridCell[Config.mapMaxTilesWidth][Config.mapMaxTilesHeight];
|
||||
private static GridCell dummyCell = new GridCell(); // wird zurückgegeben, falls der MapGrid index ausserhalb unserer allGridCells dimension zeigt.
|
||||
|
||||
private static MapGridCell[][] allGridCells = new MapGridCell[Config.mapMaxTilesWidth][Config.mapMaxTilesHeight];
|
||||
|
||||
private static MapGridCell dummyCell = new MapGridCell(); // wird zurückgegeben, falls der MapGrid index ausserhalb unserer allGridCells dimension zeigt.
|
||||
|
||||
protected static void addGrid(int x, int y, boolean isPath) {
|
||||
if (!(x < 0 || x > Config.mapMaxTilesWidth || y < 0 || y > Config.mapMaxTilesHeight)) {
|
||||
GridCell newCell = new GridCell();
|
||||
MapGridCell newCell = new MapGridCell();
|
||||
newCell.setPath(isPath);
|
||||
allGridCells[x][y] = newCell;
|
||||
}
|
||||
}
|
||||
|
||||
protected static void addGrid(int x, int y, boolean isPath, boolean isTrigger, char correspondingHardwareToTrigger) {
|
||||
if (!(x < 0 || x > Config.mapMaxTilesWidth || y < 0 || y > Config.mapMaxTilesHeight)) {
|
||||
GridCell newCell = new GridCell();
|
||||
MapGridCell newCell = new MapGridCell();
|
||||
newCell.setPath(isPath);
|
||||
newCell.setTrigger(isTrigger);
|
||||
newCell.setCorrespondingHardwareToTrigger(correspondingHardwareToTrigger);
|
||||
allGridCells[x][y] = newCell;
|
||||
}
|
||||
}
|
||||
|
||||
protected static void addGrid(int x, int y, boolean isTrigger, char correspondingHardwareToTrigger) {
|
||||
if (!(x < 0 || x > Config.mapMaxTilesWidth || y < 0 || y > Config.mapMaxTilesHeight)) {
|
||||
GridCell newCell = new GridCell();
|
||||
MapGridCell newCell = new MapGridCell();
|
||||
newCell.setTrigger(isTrigger);
|
||||
newCell.setCorrespondingHardwareToTrigger(correspondingHardwareToTrigger);
|
||||
allGridCells[x][y] = newCell;
|
||||
}
|
||||
}
|
||||
public static GridCell getGridCell(int x, int y) {
|
||||
if (!(x < 0 || x > Config.mapMaxTilesWidth || y < 0 || y > Config.mapMaxTilesHeight)) {
|
||||
|
||||
public static MapGridCell getGridCell(int x, int y) {
|
||||
if (!(x < 0 || x > Config.mapMaxTilesWidth-1 || y < 0 || y > Config.mapMaxTilesHeight-1)) {
|
||||
return allGridCells[x][y];
|
||||
}
|
||||
return dummyCell;
|
||||
|
||||
+11
-2
@@ -1,24 +1,33 @@
|
||||
package de.heatup.mapengine;
|
||||
|
||||
public class GridCell {
|
||||
public class MapGridCell {
|
||||
|
||||
private boolean isPath = false;
|
||||
|
||||
private boolean isTrigger = false;
|
||||
|
||||
private char correspondingHardwareToTrigger;
|
||||
|
||||
public char getCorrespondingHardwareToTrigger() {
|
||||
return correspondingHardwareToTrigger;
|
||||
}
|
||||
public void setCorrespondingHardwareToTrigger(char correspondingHardwareToTrigger) {
|
||||
|
||||
protected void setCorrespondingHardwareToTrigger(char correspondingHardwareToTrigger) {
|
||||
this.correspondingHardwareToTrigger = correspondingHardwareToTrigger;
|
||||
}
|
||||
|
||||
public boolean isPath() {
|
||||
return isPath;
|
||||
}
|
||||
|
||||
protected void setPath(boolean isPath) {
|
||||
this.isPath = isPath;
|
||||
}
|
||||
|
||||
public boolean isTrigger() {
|
||||
return isTrigger;
|
||||
}
|
||||
|
||||
protected void setTrigger(boolean isTrigger) {
|
||||
this.isTrigger = isTrigger;
|
||||
}
|
||||
@@ -9,7 +9,7 @@ import de.heatup.objects.StaticObject;
|
||||
public class MapObjectHandler {
|
||||
|
||||
private static final int singleTileWidth = Config.singleTilePixels;
|
||||
private static final int triggerAreaAddition = Config.triggerAreaAddition;
|
||||
//private static final int triggerAreaAddition = Config.triggerAreaAddition;
|
||||
|
||||
private static ArrayList<StaticObject> allMapObjects = new ArrayList<StaticObject>();
|
||||
private static ArrayList<StaticObject> allWallObjects = new ArrayList<StaticObject>();
|
||||
@@ -35,12 +35,14 @@ public class MapObjectHandler {
|
||||
int currentTilesTotalWidth = lastPoint.x-firstPoint.x+singleTileWidth;
|
||||
int currentTilesTotalHeight = lastPoint.y-firstPoint.y+singleTileWidth;
|
||||
|
||||
/* obsolet
|
||||
int currentTriggerTilesTotalWidth = lastPoint.x-firstPoint.x+singleTileWidth+triggerAreaAddition;
|
||||
int currentTriggerTilesTotalHeight = lastPoint.y-firstPoint.y+singleTileWidth+triggerAreaAddition;
|
||||
Point currentTriggerTilesFirstPoint = new Point(firstPoint.x-(triggerAreaAddition/2),firstPoint.y-(triggerAreaAddition/2));
|
||||
*/
|
||||
|
||||
StaticObject newStaticObject = new StaticObject(currentType, firstPoint, currentTilesTotalWidth, currentTilesTotalHeight);
|
||||
// Trigger Object - auskommentieren sobald implementiert.
|
||||
// Trigger Object - obsolet
|
||||
// StaticObject newTriggerObject = new StaticObject(currentType, firstPoint, currentTilesTotalWidth, currentTilesTotalHeight, true);
|
||||
MapObjectHandler.allMapObjects.add(newStaticObject);
|
||||
// MapObjectHandler.allMapObjects.add(newTriggerObject);
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
package de.heatup.mapengine;
|
||||
|
||||
import java.awt.Point;
|
||||
import java.util.Random;
|
||||
|
||||
import de.heatup.cfg.Config;
|
||||
|
||||
public class SpawnAssistant {
|
||||
public static Point getPathLocationOnGrid() {
|
||||
Point spawnPoint = null;
|
||||
Random rand = new Random();
|
||||
boolean foundLocation = false;
|
||||
while (!foundLocation) {
|
||||
int x = rand.nextInt(Config.mapMaxTilesWidth);
|
||||
int y = rand.nextInt(Config.mapMaxTilesHeight);
|
||||
if (MapGrid.getGridCell(x, y).isPath()) {
|
||||
spawnPoint = new Point(x,y);
|
||||
foundLocation = true;
|
||||
}
|
||||
}
|
||||
return spawnPoint;
|
||||
}
|
||||
}
|
||||
Binary file not shown.
@@ -1,6 +1,12 @@
|
||||
<<<<<<< HEAD
|
||||
################################
|
||||
#1111111111#----------#222222--#
|
||||
#1111111111#----------#222222--#
|
||||
=======
|
||||
###1111#########################
|
||||
#--1111----#----------#222222--#
|
||||
#--1111----#----------#222222--#
|
||||
>>>>>>> 40455906b6b13240c134820d521b57ed3cefb128
|
||||
#######################222222###
|
||||
#---------#----------#########-#
|
||||
###############-######---------#
|
||||
@@ -19,6 +25,6 @@
|
||||
-666#---#-###---####-####--#-##-
|
||||
-666#---#---#-###777-#--##----#-
|
||||
-666#####---###-#777-#---#######
|
||||
----#-------#---##########88888#
|
||||
---##########------#------88888#
|
||||
------------####################
|
||||
----#-------#---##########888888
|
||||
---##########------#------888888
|
||||
------------####################
|
||||
|
||||
@@ -0,0 +1,195 @@
|
||||
package de.heatup.testing;
|
||||
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.GridLayout;
|
||||
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JPanel;
|
||||
|
||||
import de.heatup.mapengine.MapEngine;
|
||||
import de.heatup.objects.DynamicObject;
|
||||
import de.heatup.objects.StaticObject;
|
||||
import de.heatup.objects.logic;
|
||||
import de.heatup.ui.GameInterface;
|
||||
import de.heatup.ui.KeyBindings;
|
||||
|
||||
public class GameLoopD extends JFrame implements Runnable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
|
||||
private boolean running = false;
|
||||
|
||||
private Thread thread;
|
||||
|
||||
private static JPanel outerPanel;
|
||||
private static JPanel statusPanel;
|
||||
private static JPanel gamePanel;
|
||||
private static JPanel actionPanel;
|
||||
|
||||
DynamicObject dynO3;
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
/*
|
||||
* hier drin bauen wir unser ui zusammen.
|
||||
*/
|
||||
|
||||
GameLoopD frame = new GameLoopD();
|
||||
|
||||
|
||||
frame.setTitle("HeatUP!");
|
||||
frame.setDefaultCloseOperation(EXIT_ON_CLOSE);
|
||||
|
||||
|
||||
outerPanel = new JPanel();
|
||||
outerPanel.setLayout(new BorderLayout());
|
||||
outerPanel.setVisible(true);
|
||||
|
||||
statusPanel = new JPanel();
|
||||
statusPanel.setLayout(new GridLayout(1,4));
|
||||
statusPanel.setPreferredSize(new Dimension(800,80));
|
||||
|
||||
gamePanel = new JPanel();
|
||||
gamePanel.setLayout(null);
|
||||
gamePanel.setPreferredSize(new Dimension(800,600));
|
||||
gamePanel.setVisible(true);
|
||||
|
||||
actionPanel = new JPanel();
|
||||
actionPanel.setLayout(new GridLayout(1,1));
|
||||
actionPanel.setPreferredSize(new Dimension(800,80));
|
||||
|
||||
|
||||
outerPanel.add(statusPanel,BorderLayout.NORTH);
|
||||
outerPanel.add(gamePanel,BorderLayout.CENTER);
|
||||
outerPanel.add(actionPanel,BorderLayout.SOUTH);
|
||||
|
||||
frame.add(outerPanel);
|
||||
frame.pack();
|
||||
frame.setVisible(true);
|
||||
|
||||
/*
|
||||
* zeug aus dem alten gameloop
|
||||
*/
|
||||
DynamicObject dynO1 = new DynamicObject();
|
||||
gamePanel.add(dynO1);
|
||||
DynamicObject dynO2 = new DynamicObject();
|
||||
gamePanel.add(dynO2);
|
||||
DynamicObject dynO3 = new DynamicObject();
|
||||
gamePanel.add(dynO3);
|
||||
DynamicObject dynO4 = new DynamicObject();
|
||||
gamePanel.add(dynO4);
|
||||
|
||||
Player player01 = new Player();
|
||||
Query.setPlayer(player01);
|
||||
gamePanel.add(player01);
|
||||
player01.setBounds(25, 25, 200, 200);
|
||||
|
||||
|
||||
// Keybindings as object so we can load different bindings depending on number of players.
|
||||
// KeyBindings kb = new KeyBindings();
|
||||
gamePanel.setFocusable(true);
|
||||
// kb.setKeyBindings();
|
||||
|
||||
|
||||
//dynO3.setRescale(1.5,3.5);
|
||||
|
||||
// Config.setGamePanelWidth(900);
|
||||
MapEngine me = new MapEngine(1);
|
||||
for (StaticObject currentStaticObject : me.getAllMapObjects()) {
|
||||
gamePanel.add(currentStaticObject);
|
||||
}
|
||||
|
||||
gamePanel.setVisible(true);
|
||||
|
||||
//GameInterface.getGamePanel().repaint();
|
||||
//GameInterface.getGamePanel().setComponentZOrder(dynO1, 1);
|
||||
//GameInterface.getGamePanel().add(dynO1);
|
||||
//logic.startMovement(dynO1);
|
||||
//logic.startMovement(dynO2);
|
||||
|
||||
logic.startMovement(dynO3);
|
||||
|
||||
//logic.startMovement(dynO4);
|
||||
|
||||
|
||||
/*
|
||||
* ende
|
||||
*/
|
||||
|
||||
|
||||
frame.repaint();
|
||||
frame.start();
|
||||
}
|
||||
|
||||
private synchronized void start() {
|
||||
if (running) {
|
||||
return;
|
||||
}
|
||||
|
||||
running = true;
|
||||
thread = new Thread(this);
|
||||
thread.start();
|
||||
|
||||
}
|
||||
|
||||
private synchronized void stop() {
|
||||
if (!running) {
|
||||
return;
|
||||
}
|
||||
|
||||
running = false;
|
||||
try {
|
||||
thread.join();
|
||||
} catch (InterruptedException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
System.exit(1);
|
||||
|
||||
}
|
||||
|
||||
public void run() {
|
||||
|
||||
long lastTime = System.nanoTime();
|
||||
final double fps = 60.0;
|
||||
double ns = 1000000000 / fps;
|
||||
double delta = 0;
|
||||
int updates = 0;
|
||||
int frames = 0;
|
||||
long timer = System.currentTimeMillis();
|
||||
|
||||
while (running) {
|
||||
|
||||
long now = System.nanoTime();
|
||||
delta += (lastTime - now) / ns;
|
||||
lastTime = now;
|
||||
if (delta >= 1) {
|
||||
tick();
|
||||
updates++;
|
||||
delta--;
|
||||
}
|
||||
render();
|
||||
frames++;
|
||||
|
||||
if (System.currentTimeMillis() - timer > 1000) {
|
||||
timer += 1000;
|
||||
System.out.println(updates +" Ticks, fps " + frames);
|
||||
updates = 0;
|
||||
frames = 0;
|
||||
}
|
||||
}
|
||||
|
||||
stop();
|
||||
}
|
||||
// alles was geupdatet werden muss hier rein
|
||||
private void tick() {
|
||||
|
||||
}
|
||||
// alles was animiert wird hier rein (paints)
|
||||
private void render() {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user