From ba29cdf4fe47aecead2b000723470b3d5fe22719 Mon Sep 17 00:00:00 2001 From: toksikk Date: Sun, 2 Nov 2014 03:17:03 +0100 Subject: [PATCH] =?UTF-8?q?Einf=C3=BChrung=20Config-Klasse.=20MapEngine=20?= =?UTF-8?q?Update.=20MapEngine=20auf=20Kollisionserkennungsmodul=20vorbere?= =?UTF-8?q?itet.=20Derzeit=20gehe=20ich=20davon=20aus,=20dass=20wir=20im?= =?UTF-8?q?=20StaticObject=20einen=20weiteren=20Constructor=20f=C3=BCr=20T?= =?UTF-8?q?rigger-Typ=20Objekte=20ben=C3=B6tigen.=20Sie=20m=C3=BCssen=20ei?= =?UTF-8?q?n=20weiteres=20Attribut=20entgegen=20nehmen,=20welches=20als=20?= =?UTF-8?q?Flag=20dient=20um=20Trigger=20zu=20Kennzeichnen.=20Der=20normal?= =?UTF-8?q?e=20Typ=20muss=20unver=C3=A4ndert=20bleiben,=20damit=20man=20we?= =?UTF-8?q?i=C3=9F=20zu=20welchem=20Hardware=20Objekt=20der=20Trigger=20ge?= =?UTF-8?q?h=C3=B6rt.=20Als=20Beispiel=20siehe=20Kommentare=20im=20MapObje?= =?UTF-8?q?ctHandler.=20Au=C3=9Ferdem=20w=C3=A4re=20es=20hinsichtlich=20de?= =?UTF-8?q?r=20Kollisionserkennung=20dem=20StaticObject=20noch=20Getter=20?= =?UTF-8?q?f=C3=BCr=20H=C3=B6he,=20Breite,=20Position,=20Typ,=20Trigger=20?= =?UTF-8?q?(Boolean-Methode=3F)=20zu=20verpassen.=20Die=20eigentliche=20Ko?= =?UTF-8?q?llisionserkennung=20zwischen=20zwei=20Objekten=20ist=20=C3=BCbr?= =?UTF-8?q?igens=20ein=20Zweizeiler,=20wenn=20man=20alle=20vier=20Koordina?= =?UTF-8?q?ten=20pro=20Objekt=20hat.=20Gibt=20einen=20Codeschnipsel=20im?= =?UTF-8?q?=20Internets=20:)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- HeatUp/src/de/heatup/cfg/Config.java | 14 ++++++ HeatUp/src/de/heatup/mapengine/MapEngine.java | 40 ++++++++--------- .../de/heatup/mapengine/MapObjectHandler.java | 44 +++++++++++++------ 3 files changed, 65 insertions(+), 33 deletions(-) create mode 100644 HeatUp/src/de/heatup/cfg/Config.java diff --git a/HeatUp/src/de/heatup/cfg/Config.java b/HeatUp/src/de/heatup/cfg/Config.java new file mode 100644 index 0000000..97e8a30 --- /dev/null +++ b/HeatUp/src/de/heatup/cfg/Config.java @@ -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; +} diff --git a/HeatUp/src/de/heatup/mapengine/MapEngine.java b/HeatUp/src/de/heatup/mapengine/MapEngine.java index ba58d13..71669d6 100644 --- a/HeatUp/src/de/heatup/mapengine/MapEngine.java +++ b/HeatUp/src/de/heatup/mapengine/MapEngine.java @@ -10,24 +10,21 @@ import java.util.HashMap; import java.util.Scanner; import javax.swing.JFileChooser; + +import de.heatup.cfg.Config; import de.heatup.logging.Logger; import de.heatup.objects.*; public class MapEngine { - /* - * MAGIC NUMBER SINGLE TILE WIDTH - */ - private static final int singleTileWidth = 25; - final int mapHeight = 24; - final int mapWidth = 32; + + private static final int singleTileWidth = Config.singleTilePixels; + private final int mapHeight = Config.mapMaxTilesHeight; + private final int mapWidth = Config.mapMaxTilesWidth; + HashMap> allMapTiles = new HashMap>(); ArrayList availableHardwareTileTypes = new ArrayList(); - char[][] tiles; - /* - * öffnet die map mit der gegebenen nummer aus den resourcen. - */ + public MapEngine(int mapNumber) { - tiles = new char[mapHeight][mapWidth]; Scanner input = null; try { input = new Scanner(new File("src/de/heatup/resources/maps/map"+mapNumber+".txt")); @@ -38,11 +35,7 @@ public class MapEngine { } this.createTiles(input); } - /* - * öffnet einen file chooser um eine benutzer erstellte map zu öffnen - */ public MapEngine() { - tiles = new char[mapHeight][mapWidth]; Scanner input = null; try { JFileChooser chooser = new JFileChooser(); @@ -62,11 +55,6 @@ public class MapEngine { while (input.hasNextLine() && lineCount <= mapHeight) { String currentLine = input.nextLine(); for (int i = 0; i newTileType = new ArrayList(); newTileType.add(new Point(x,y)); @@ -139,4 +127,16 @@ public class MapEngine { public ArrayList getAllMapObjects() { return MapObjectHandler.getAllMapObjects(this); } + public ArrayList getAllHardwareObjects() { + return MapObjectHandler.getAllHardwareObjects(); + } + public ArrayList getAllWallObjects() { + return MapObjectHandler.getAllWallObjects(); + } + public ArrayList getAllWayObjects() { + return MapObjectHandler.getAllWayObjects(); + } + public ArrayList getAllHardwareTriggerObjects() { + return MapObjectHandler.getAllHardwareTriggerObjects(); + } } diff --git a/HeatUp/src/de/heatup/mapengine/MapObjectHandler.java b/HeatUp/src/de/heatup/mapengine/MapObjectHandler.java index 69ce574..8e858e1 100644 --- a/HeatUp/src/de/heatup/mapengine/MapObjectHandler.java +++ b/HeatUp/src/de/heatup/mapengine/MapObjectHandler.java @@ -3,17 +3,21 @@ package de.heatup.mapengine; import java.awt.Point; import java.util.ArrayList; +import de.heatup.cfg.Config; import de.heatup.logging.Logger; import de.heatup.objects.StaticObject; public class MapObjectHandler { - /* - * MAGIC NUMBER SINGLE TILE WIDTH - */ - private static final int singleTileWidth = 25; + private static final int singleTileWidth = Config.singleTilePixels; + private static final int triggerAreaAddition = Config.triggerAreaAddition; private static ArrayList allMapObjects = new ArrayList(); + private static ArrayList allWallObjects = new ArrayList(); + private static ArrayList allWayObjects = new ArrayList(); + private static ArrayList allHardwareObjects = new ArrayList(); + private static ArrayList allHardwareTriggerObjects = new ArrayList(); + protected static ArrayList getAllMapObjects(MapEngine me) { createAllMapObjectsArrayList(me); return allMapObjects; @@ -32,15 +36,19 @@ public class MapObjectHandler { int currentTilesTotalWidth = lastPoint.x-firstPoint.x+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); + // Trigger Object + // StaticObject newTriggerObject = new StaticObject(currentType, firstPoint, currentTilesTotalWidth, currentTilesTotalHeight, true); 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) { ArrayList allCoordinatesOfWayTileType = me.getAllCoordinatesOfTileType('#'); ArrayList allCoordinatesOfWallTileType = me.getAllCoordinatesOfTileType('-'); @@ -49,15 +57,25 @@ public class MapObjectHandler { Point currentPoint = allCoordinatesOfWayTileType.get(i); StaticObject newStaticObject = new StaticObject('#', currentPoint); MapObjectHandler.allMapObjects.add(newStaticObject); + MapObjectHandler.allWayObjects.add(newStaticObject); } for (int i = 0; i < allCoordinatesOfWallTileType.size(); i++) { Point currentPoint = allCoordinatesOfWallTileType.get(i); StaticObject newStaticObject = new StaticObject('-', currentPoint); MapObjectHandler.allMapObjects.add(newStaticObject); + MapObjectHandler.allWallObjects.add(newStaticObject); } - - - - + } + protected static ArrayList getAllHardwareObjects() { + return allHardwareObjects; + } + protected static ArrayList getAllWallObjects() { + return allWallObjects; + } + protected static ArrayList getAllWayObjects() { + return allWayObjects; + } + protected static ArrayList getAllHardwareTriggerObjects() { + return allHardwareTriggerObjects; } }