mirror of
https://github.com/jokerx3/HeatUp
synced 2026-07-27 11:49:44 +02:00
Einführung Config-Klasse. MapEngine Update.
MapEngine auf Kollisionserkennungsmodul vorbereitet. Derzeit gehe ich davon aus, dass wir im StaticObject einen weiteren Constructor für Trigger-Typ Objekte benötigen. Sie müssen ein weiteres Attribut entgegen nehmen, welches als Flag dient um Trigger zu Kennzeichnen. Der normale Typ muss unverändert bleiben, damit man weiß zu welchem Hardware Objekt der Trigger gehört. Als Beispiel siehe Kommentare im MapObjectHandler. Außerdem wäre es hinsichtlich der Kollisionserkennung dem StaticObject noch Getter für Höhe, Breite, Position, Typ, Trigger (Boolean-Methode?) zu verpassen. Die eigentliche Kollisionserkennung zwischen zwei Objekten ist übrigens ein Zweizeiler, wenn man alle vier Koordinaten pro Objekt hat. Gibt einen Codeschnipsel im Internets :)
This commit is contained in:
@@ -0,0 +1,14 @@
|
|||||||
|
package de.heatup.cfg;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Bitte hier eure Magicnumbers eintragen
|
||||||
|
*/
|
||||||
|
public class Config {
|
||||||
|
/*
|
||||||
|
* Map related magic numbers
|
||||||
|
*/
|
||||||
|
public static final int singleTilePixels = 25;
|
||||||
|
public static final int triggerAreaAddition = 20;
|
||||||
|
public static final int mapMaxTilesWidth = 32;
|
||||||
|
public static final int mapMaxTilesHeight = 24;
|
||||||
|
}
|
||||||
@@ -10,24 +10,21 @@ 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;
|
|
||||||
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 +35,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 +55,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));
|
||||||
@@ -139,4 +127,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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user