Merge branch 'master' of github.com:jokerx3/prp
@@ -0,0 +1,28 @@
|
|||||||
|
package de.heatup.cfg;
|
||||||
|
|
||||||
|
import de.heatup.logging.Logger;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Bitte hier eure Magicnumbers eintragen
|
||||||
|
*/
|
||||||
|
public class Config {
|
||||||
|
/*
|
||||||
|
* de.heatup.mapengine.*
|
||||||
|
*/
|
||||||
|
public static final int triggerAreaAddition = 20;
|
||||||
|
public static final int mapMaxTilesWidth = 32;
|
||||||
|
public static final int mapMaxTilesHeight = 24;
|
||||||
|
public static int gamePanelWidth = 800;
|
||||||
|
public static int singleTilePixels = gamePanelWidth/mapMaxTilesWidth;
|
||||||
|
public static void setGamePanelWidth(int width) {
|
||||||
|
// Wir wollen hier keine Reste!
|
||||||
|
while (width % mapMaxTilesHeight != 0) {
|
||||||
|
width--;
|
||||||
|
}
|
||||||
|
gamePanelWidth = width;
|
||||||
|
updateSingleTilePixels();
|
||||||
|
}
|
||||||
|
private static void updateSingleTilePixels() {
|
||||||
|
singleTilePixels = gamePanelWidth/mapMaxTilesHeight;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -10,24 +10,22 @@ import java.util.HashMap;
|
|||||||
import java.util.Scanner;
|
import java.util.Scanner;
|
||||||
|
|
||||||
import javax.swing.JFileChooser;
|
import javax.swing.JFileChooser;
|
||||||
|
|
||||||
|
import de.heatup.cfg.Config;
|
||||||
import de.heatup.logging.Logger;
|
import de.heatup.logging.Logger;
|
||||||
import de.heatup.objects.*;
|
import de.heatup.objects.*;
|
||||||
|
|
||||||
public class MapEngine {
|
public class MapEngine {
|
||||||
/*
|
|
||||||
* MAGIC NUMBER SINGLE TILE WIDTH
|
private static final int singleTileWidth = Config.singleTilePixels;
|
||||||
*/
|
private final int mapHeight = Config.mapMaxTilesHeight;
|
||||||
private static final int singleTileWidth = 25;
|
private final int mapWidth = Config.mapMaxTilesWidth;
|
||||||
final int mapHeight = 24;
|
private final int gamePanelWidth = Config.gamePanelWidth;
|
||||||
final int mapWidth = 32;
|
|
||||||
HashMap<Character, ArrayList<Point>> allMapTiles = new HashMap<Character, ArrayList<Point>>();
|
HashMap<Character, ArrayList<Point>> allMapTiles = new HashMap<Character, ArrayList<Point>>();
|
||||||
ArrayList<Character> availableHardwareTileTypes = new ArrayList<Character>();
|
ArrayList<Character> availableHardwareTileTypes = new ArrayList<Character>();
|
||||||
char[][] tiles;
|
|
||||||
/*
|
|
||||||
* öffnet die map mit der gegebenen nummer aus den resourcen.
|
|
||||||
*/
|
|
||||||
public MapEngine(int mapNumber) {
|
public MapEngine(int mapNumber) {
|
||||||
tiles = new char[mapHeight][mapWidth];
|
|
||||||
Scanner input = null;
|
Scanner input = null;
|
||||||
try {
|
try {
|
||||||
input = new Scanner(new File("src/de/heatup/resources/maps/map"+mapNumber+".txt"));
|
input = new Scanner(new File("src/de/heatup/resources/maps/map"+mapNumber+".txt"));
|
||||||
@@ -38,11 +36,7 @@ public class MapEngine {
|
|||||||
}
|
}
|
||||||
this.createTiles(input);
|
this.createTiles(input);
|
||||||
}
|
}
|
||||||
/*
|
|
||||||
* öffnet einen file chooser um eine benutzer erstellte map zu öffnen
|
|
||||||
*/
|
|
||||||
public MapEngine() {
|
public MapEngine() {
|
||||||
tiles = new char[mapHeight][mapWidth];
|
|
||||||
Scanner input = null;
|
Scanner input = null;
|
||||||
try {
|
try {
|
||||||
JFileChooser chooser = new JFileChooser();
|
JFileChooser chooser = new JFileChooser();
|
||||||
@@ -62,11 +56,6 @@ public class MapEngine {
|
|||||||
while (input.hasNextLine() && lineCount <= mapHeight) {
|
while (input.hasNextLine() && lineCount <= mapHeight) {
|
||||||
String currentLine = input.nextLine();
|
String currentLine = input.nextLine();
|
||||||
for (int i = 0; i<mapWidth; i++) {
|
for (int i = 0; i<mapWidth; i++) {
|
||||||
tiles[lineCount][i] = currentLine.charAt(i); // ich glaube die zeile ist schon quasi-obsolet
|
|
||||||
|
|
||||||
/*
|
|
||||||
* setze die koordinaten (value) des tiles nach typ (key) in eine hashmap
|
|
||||||
*/
|
|
||||||
if (!allMapTiles.containsKey(currentLine.charAt(i))) {
|
if (!allMapTiles.containsKey(currentLine.charAt(i))) {
|
||||||
ArrayList<Point> newTileType = new ArrayList<Point>();
|
ArrayList<Point> newTileType = new ArrayList<Point>();
|
||||||
newTileType.add(new Point(x,y));
|
newTileType.add(new Point(x,y));
|
||||||
@@ -82,7 +71,7 @@ public class MapEngine {
|
|||||||
/*
|
/*
|
||||||
* setze x und y auf die koordinaten für das objekt im NÄCHSTEN durchlauf
|
* setze x und y auf die koordinaten für das objekt im NÄCHSTEN durchlauf
|
||||||
*/
|
*/
|
||||||
if (x+singleTileWidth >= 800) {
|
if (x+singleTileWidth >= gamePanelWidth) {
|
||||||
x = 0;
|
x = 0;
|
||||||
y += singleTileWidth;
|
y += singleTileWidth;
|
||||||
} else {
|
} else {
|
||||||
@@ -139,4 +128,16 @@ public class MapEngine {
|
|||||||
public ArrayList<StaticObject> getAllMapObjects() {
|
public ArrayList<StaticObject> getAllMapObjects() {
|
||||||
return MapObjectHandler.getAllMapObjects(this);
|
return MapObjectHandler.getAllMapObjects(this);
|
||||||
}
|
}
|
||||||
|
public ArrayList<StaticObject> getAllHardwareObjects() {
|
||||||
|
return MapObjectHandler.getAllHardwareObjects();
|
||||||
|
}
|
||||||
|
public ArrayList<StaticObject> getAllWallObjects() {
|
||||||
|
return MapObjectHandler.getAllWallObjects();
|
||||||
|
}
|
||||||
|
public ArrayList<StaticObject> getAllWayObjects() {
|
||||||
|
return MapObjectHandler.getAllWayObjects();
|
||||||
|
}
|
||||||
|
public ArrayList<StaticObject> getAllHardwareTriggerObjects() {
|
||||||
|
return MapObjectHandler.getAllHardwareTriggerObjects();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,17 +3,21 @@ package de.heatup.mapengine;
|
|||||||
import java.awt.Point;
|
import java.awt.Point;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
import de.heatup.cfg.Config;
|
||||||
import de.heatup.logging.Logger;
|
import de.heatup.logging.Logger;
|
||||||
import de.heatup.objects.StaticObject;
|
import de.heatup.objects.StaticObject;
|
||||||
|
|
||||||
public class MapObjectHandler {
|
public class MapObjectHandler {
|
||||||
|
|
||||||
/*
|
private static final int singleTileWidth = Config.singleTilePixels;
|
||||||
* MAGIC NUMBER SINGLE TILE WIDTH
|
private static final int triggerAreaAddition = Config.triggerAreaAddition;
|
||||||
*/
|
|
||||||
private static final int singleTileWidth = 25;
|
|
||||||
|
|
||||||
private static ArrayList<StaticObject> allMapObjects = new ArrayList<StaticObject>();
|
private static ArrayList<StaticObject> allMapObjects = new ArrayList<StaticObject>();
|
||||||
|
private static ArrayList<StaticObject> allWallObjects = new ArrayList<StaticObject>();
|
||||||
|
private static ArrayList<StaticObject> allWayObjects = new ArrayList<StaticObject>();
|
||||||
|
private static ArrayList<StaticObject> allHardwareObjects = new ArrayList<StaticObject>();
|
||||||
|
private static ArrayList<StaticObject> allHardwareTriggerObjects = new ArrayList<StaticObject>();
|
||||||
|
|
||||||
protected static ArrayList<StaticObject> getAllMapObjects(MapEngine me) {
|
protected static ArrayList<StaticObject> getAllMapObjects(MapEngine me) {
|
||||||
createAllMapObjectsArrayList(me);
|
createAllMapObjectsArrayList(me);
|
||||||
return allMapObjects;
|
return allMapObjects;
|
||||||
@@ -32,15 +36,19 @@ public class MapObjectHandler {
|
|||||||
int currentTilesTotalWidth = lastPoint.x-firstPoint.x+singleTileWidth;
|
int currentTilesTotalWidth = lastPoint.x-firstPoint.x+singleTileWidth;
|
||||||
int currentTilesTotalHeight = lastPoint.y-firstPoint.y+singleTileWidth;
|
int currentTilesTotalHeight = lastPoint.y-firstPoint.y+singleTileWidth;
|
||||||
|
|
||||||
|
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);
|
StaticObject newStaticObject = new StaticObject(currentType, firstPoint, currentTilesTotalWidth, currentTilesTotalHeight);
|
||||||
|
// Trigger Object
|
||||||
|
// StaticObject newTriggerObject = new StaticObject(currentType, firstPoint, currentTilesTotalWidth, currentTilesTotalHeight, true);
|
||||||
MapObjectHandler.allMapObjects.add(newStaticObject);
|
MapObjectHandler.allMapObjects.add(newStaticObject);
|
||||||
|
// MapObjectHandler.allMapObjects.add(newTriggerObject);
|
||||||
|
MapObjectHandler.allHardwareObjects.add(newStaticObject);
|
||||||
|
// MapObjectHandler.allHardwareTriggerObjects.add(newTriggerObject);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/*
|
|
||||||
* die ganze methode ist unglaublich schlechter und hässlicher programmierstil, aber das weiß ich und ändere ich noch.
|
|
||||||
*
|
|
||||||
* mfg daniel. :)
|
|
||||||
*/
|
|
||||||
protected static void addAllWallsAndWaysTiles(MapEngine me) {
|
protected static void addAllWallsAndWaysTiles(MapEngine me) {
|
||||||
ArrayList<Point> allCoordinatesOfWayTileType = me.getAllCoordinatesOfTileType('#');
|
ArrayList<Point> allCoordinatesOfWayTileType = me.getAllCoordinatesOfTileType('#');
|
||||||
ArrayList<Point> allCoordinatesOfWallTileType = me.getAllCoordinatesOfTileType('-');
|
ArrayList<Point> allCoordinatesOfWallTileType = me.getAllCoordinatesOfTileType('-');
|
||||||
@@ -49,15 +57,25 @@ public class MapObjectHandler {
|
|||||||
Point currentPoint = allCoordinatesOfWayTileType.get(i);
|
Point currentPoint = allCoordinatesOfWayTileType.get(i);
|
||||||
StaticObject newStaticObject = new StaticObject('#', currentPoint);
|
StaticObject newStaticObject = new StaticObject('#', currentPoint);
|
||||||
MapObjectHandler.allMapObjects.add(newStaticObject);
|
MapObjectHandler.allMapObjects.add(newStaticObject);
|
||||||
|
MapObjectHandler.allWayObjects.add(newStaticObject);
|
||||||
}
|
}
|
||||||
for (int i = 0; i < allCoordinatesOfWallTileType.size(); i++) {
|
for (int i = 0; i < allCoordinatesOfWallTileType.size(); i++) {
|
||||||
Point currentPoint = allCoordinatesOfWallTileType.get(i);
|
Point currentPoint = allCoordinatesOfWallTileType.get(i);
|
||||||
StaticObject newStaticObject = new StaticObject('-', currentPoint);
|
StaticObject newStaticObject = new StaticObject('-', currentPoint);
|
||||||
MapObjectHandler.allMapObjects.add(newStaticObject);
|
MapObjectHandler.allMapObjects.add(newStaticObject);
|
||||||
|
MapObjectHandler.allWallObjects.add(newStaticObject);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
protected static ArrayList<StaticObject> getAllHardwareObjects() {
|
||||||
|
return allHardwareObjects;
|
||||||
|
}
|
||||||
|
protected static ArrayList<StaticObject> getAllWallObjects() {
|
||||||
|
return allWallObjects;
|
||||||
|
}
|
||||||
|
protected static ArrayList<StaticObject> getAllWayObjects() {
|
||||||
|
return allWayObjects;
|
||||||
|
}
|
||||||
|
protected static ArrayList<StaticObject> getAllHardwareTriggerObjects() {
|
||||||
|
return allHardwareTriggerObjects;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
|
Before Width: | Height: | Size: 391 B After Width: | Height: | Size: 389 B |
|
Before Width: | Height: | Size: 2.9 KiB After Width: | Height: | Size: 2.7 KiB |
|
Before Width: | Height: | Size: 2.5 KiB After Width: | Height: | Size: 2.5 KiB |
|
Before Width: | Height: | Size: 374 B After Width: | Height: | Size: 371 B |
|
After Width: | Height: | Size: 391 B |
|
After Width: | Height: | Size: 2.9 KiB |
|
After Width: | Height: | Size: 2.5 KiB |
|
After Width: | Height: | Size: 374 B |
|
After Width: | Height: | Size: 1.0 KiB |
|
After Width: | Height: | Size: 1.1 KiB |