mirror of
https://github.com/jokerx3/HeatUp
synced 2026-07-27 10:19:46 +02:00
Merge branch 'master' of github.com:jokerx3/prp
This commit is contained in:
@@ -20,7 +20,7 @@ public class MapEngine {
|
|||||||
final int mapHeight = 24;
|
final int mapHeight = 24;
|
||||||
final int mapWidth = 32;
|
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> availableTileTypes = new ArrayList<Character>();
|
ArrayList<Character> availableHardwareTileTypes = new ArrayList<Character>();
|
||||||
char[][] tiles;
|
char[][] tiles;
|
||||||
/*
|
/*
|
||||||
* öffnet die map mit der gegebenen nummer aus den resourcen.
|
* öffnet die map mit der gegebenen nummer aus den resourcen.
|
||||||
@@ -70,7 +70,11 @@ public class MapEngine {
|
|||||||
ArrayList<Point> newTileType = new ArrayList<Point>();
|
ArrayList<Point> newTileType = new ArrayList<Point>();
|
||||||
newTileType.add(new Point(x,y));
|
newTileType.add(new Point(x,y));
|
||||||
allMapTiles.put(currentLine.charAt(i), newTileType);
|
allMapTiles.put(currentLine.charAt(i), newTileType);
|
||||||
availableTileTypes.add(currentLine.charAt(i));
|
for (char j = '0'; j <= '9'; j++) {
|
||||||
|
if (j==currentLine.charAt(i)) {
|
||||||
|
availableHardwareTileTypes.add(currentLine.charAt(i));
|
||||||
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
allMapTiles.get(currentLine.charAt(i)).add(new Point(x,y));
|
allMapTiles.get(currentLine.charAt(i)).add(new Point(x,y));
|
||||||
}
|
}
|
||||||
@@ -90,7 +94,7 @@ public class MapEngine {
|
|||||||
/*
|
/*
|
||||||
* wird wahrscheinlich anders umgesetzt. methode ist für testzwecke enthalten.
|
* wird wahrscheinlich anders umgesetzt. methode ist für testzwecke enthalten.
|
||||||
*/
|
*/
|
||||||
public void addAllGameTilesToGamePanel(JPanel gamePanel) throws IOException {
|
protected void addAllGameTilesToGamePanel(JPanel gamePanel) throws IOException {
|
||||||
int x = 0;
|
int x = 0;
|
||||||
int y = 0;
|
int y = 0;
|
||||||
for (int i = 0; i<mapHeight; i++) {
|
for (int i = 0; i<mapHeight; i++) {
|
||||||
@@ -119,10 +123,19 @@ public class MapEngine {
|
|||||||
private HashMap<Character, ArrayList<Point>> getAllMapTiles() {
|
private HashMap<Character, ArrayList<Point>> getAllMapTiles() {
|
||||||
return allMapTiles;
|
return allMapTiles;
|
||||||
}
|
}
|
||||||
public ArrayList<Character> getAvailableTileTypes() {
|
protected ArrayList<Character> getAvailableHardwareTileTypes() {
|
||||||
return availableTileTypes;
|
return availableHardwareTileTypes;
|
||||||
}
|
}
|
||||||
public ArrayList<Point> getCoordinatesOfTileType(char c) {
|
protected ArrayList<Point> getAllCoordinatesOfTileType(char c) {
|
||||||
return getAllMapTiles().get(c);
|
return getAllMapTiles().get(c);
|
||||||
}
|
}
|
||||||
|
protected Point getFirstTilesCoordinatesOfTileType(char c) {
|
||||||
|
return getAllMapTiles().get(c).get(0);
|
||||||
|
}
|
||||||
|
protected Point getLastTilesCoordinatesOfTileType(char c) {
|
||||||
|
return getAllMapTiles().get(c).get(getAllMapTiles().get(c).size()-1);
|
||||||
|
}
|
||||||
|
public ArrayList<StaticObject> getAllMapObjects() {
|
||||||
|
return MapObjectHandler.getAllMapObjects(this);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,51 @@
|
|||||||
|
package de.heatup.mapengine;
|
||||||
|
|
||||||
|
import java.awt.Point;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
import de.heatup.objects.StaticObject;
|
||||||
|
|
||||||
|
public class MapObjectHandler {
|
||||||
|
|
||||||
|
/*
|
||||||
|
* MAGIC NUMBER SINGLE TILE WIDTH
|
||||||
|
*/
|
||||||
|
private static final int singleTileWidth = 25;
|
||||||
|
|
||||||
|
private static ArrayList<StaticObject> allMapObjects = new ArrayList<StaticObject>();
|
||||||
|
protected static ArrayList<StaticObject> getAllMapObjects(MapEngine me) {
|
||||||
|
createAllMapObjectsArrayList(me);
|
||||||
|
return allMapObjects;
|
||||||
|
}
|
||||||
|
protected static void createAllMapObjectsArrayList(MapEngine me) {
|
||||||
|
addAllWallsAndWaysTiles(me);
|
||||||
|
addAllHardwareTiles(me);
|
||||||
|
}
|
||||||
|
protected static void addAllHardwareTiles(MapEngine me) {
|
||||||
|
for (int i = 0; i<me.getAvailableHardwareTileTypes().size(); i++) {
|
||||||
|
char currentType = me.getAvailableHardwareTileTypes().get(i); // current type
|
||||||
|
ArrayList<Point> allPointsOfCurrentType = me.getAllCoordinatesOfTileType(currentType);
|
||||||
|
Point firstPoint = allPointsOfCurrentType.get(0);
|
||||||
|
Point lastPoint = allPointsOfCurrentType.get(allPointsOfCurrentType.size()-1);
|
||||||
|
|
||||||
|
int currentTilesTotalWidth = lastPoint.x-firstPoint.x+singleTileWidth;
|
||||||
|
int currentTilesTotalHeight = lastPoint.y-firstPoint.y+singleTileWidth;
|
||||||
|
|
||||||
|
StaticObject newStaticObject = new StaticObject(currentType, firstPoint, currentTilesTotalWidth, currentTilesTotalHeight);
|
||||||
|
MapObjectHandler.allMapObjects.add(newStaticObject);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
protected static void addAllWallsAndWaysTiles(MapEngine me) {
|
||||||
|
for (int i = 0; i<me.getAvailableHardwareTileTypes().size(); i++) {
|
||||||
|
char currentType = me.getAvailableHardwareTileTypes().get(i);
|
||||||
|
if (currentType == '#' || currentType == '-') {
|
||||||
|
ArrayList<Point> allPointsOfCurrentType = me.getAllCoordinatesOfTileType(currentType);
|
||||||
|
for (int j = 0; j<allPointsOfCurrentType.size(); j++) {
|
||||||
|
Point currentPoint = allPointsOfCurrentType.get(j);
|
||||||
|
StaticObject newStaticObject = new StaticObject(currentType, currentPoint);
|
||||||
|
MapObjectHandler.allMapObjects.add(newStaticObject);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user