Map loading added

master
Jonathan Hager 5 years ago
parent a34723c5e9
commit 58aa3990d7

1
.gitignore vendored

@ -113,3 +113,4 @@ Thumbs.db
/ios/xcode/native/ /ios/xcode/native/
/ios/IOSLauncher.app /ios/IOSLauncher.app
/ios/IOSLauncher.app.dSYM /ios/IOSLauncher.app.dSYM
/.nb-gradle/

@ -39,6 +39,9 @@
<objectgroup id="4" name="tuerebene"> <objectgroup id="4" name="tuerebene">
<object id="9" x="32" y="32" width="64" height="64"> <object id="9" x="32" y="32" width="64" height="64">
<properties> <properties>
<property name="destinationDoor" type="int" value="0"/>
<property name="destinationMap" type="int" value="2"/>
<property name="exit" type="int" value="3"/>
<property name="id" type="int" value="0"/> <property name="id" type="int" value="0"/>
</properties> </properties>
</object> </object>

@ -241,8 +241,10 @@
<objectgroup id="4" name="tuerebene"> <objectgroup id="4" name="tuerebene">
<object id="40" x="192" y="2720" width="64" height="64"> <object id="40" x="192" y="2720" width="64" height="64">
<properties> <properties>
<property name="ID" type="int" value="1337"/> <property name="destinationDoor" type="int" value="0"/>
<property name="test" value="Hallo"/> <property name="destinationMap" type="int" value="1"/>
<property name="exit" type="int" value="1"/>
<property name="id" type="int" value="0"/>
</properties> </properties>
</object> </object>
</objectgroup> </objectgroup>

@ -3,13 +3,15 @@ package com.trs.main;
import com.badlogic.gdx.math.Rectangle; import com.badlogic.gdx.math.Rectangle;
public class Door{ public class Door{
int id; public int id;
int destinationMap; public int exit;
int destinationDoor; public int destinationMap;
public int destinationDoor;
Rectangle rect; Rectangle rect;
public Door(int id, int destinationMap, int destinationDoor, Rectangle rect) { public Door(int id, int exit, int destinationMap, int destinationDoor, Rectangle rect) {
this.id = id; this.id = id;
this.exit = exit;
this.destinationMap = destinationMap; this.destinationMap = destinationMap;
this.destinationDoor = destinationDoor; this.destinationDoor = destinationDoor;
this.rect = rect; this.rect = rect;

@ -11,6 +11,7 @@ import com.badlogic.gdx.maps.tiled.TiledMap;
import com.badlogic.gdx.maps.tiled.TmxMapLoader; import com.badlogic.gdx.maps.tiled.TmxMapLoader;
import com.badlogic.gdx.maps.tiled.objects.TiledMapTileMapObject; import com.badlogic.gdx.maps.tiled.objects.TiledMapTileMapObject;
import com.badlogic.gdx.maps.tiled.renderers.OrthogonalTiledMapRenderer; import com.badlogic.gdx.maps.tiled.renderers.OrthogonalTiledMapRenderer;
import com.badlogic.gdx.math.Intersector;
import com.badlogic.gdx.math.Rectangle; import com.badlogic.gdx.math.Rectangle;
import com.badlogic.gdx.scenes.scene2d.Actor; import com.badlogic.gdx.scenes.scene2d.Actor;
import com.badlogic.gdx.scenes.scene2d.Stage; import com.badlogic.gdx.scenes.scene2d.Stage;
@ -18,16 +19,16 @@ import com.badlogic.gdx.utils.viewport.FitViewport;
public class MapContainer { public class MapContainer {
Stage stage; Stage stage;
OrthographicCamera camera; OrthographicCamera camera;
TmxMapLoader maploader; TmxMapLoader maploader;
TiledMap map; TiledMap map;
OrthogonalTiledMapRenderer renderer; OrthogonalTiledMapRenderer renderer;
ArrayList<Door> doors = new ArrayList<>(); Door[] doors;
public Door collidingDoor;
// TODO: Value which shows from which door the player is coming? // TODO: Value which shows from which door the player is coming?
public MapContainer(float CAMERA_WIDTH, float CAMERA_HEIGHT, Player p, String mapString) { public MapContainer(float CAMERA_WIDTH, float CAMERA_HEIGHT, Player p, String mapString, int inDoor) {
// CREATION OF STAGE // CREATION OF STAGE
camera = new OrthographicCamera(); camera = new OrthographicCamera();
camera.setToOrtho(false, CAMERA_WIDTH, CAMERA_HEIGHT); camera.setToOrtho(false, CAMERA_WIDTH, CAMERA_HEIGHT);
@ -55,14 +56,24 @@ public class MapContainer {
} }
// adding the door links // adding the door links
ArrayList<Door> tempDoors = new ArrayList<>();
for(MapObject object : map.getLayers().get(3).getObjects().getByType(RectangleMapObject.class)){ for(MapObject object : map.getLayers().get(3).getObjects().getByType(RectangleMapObject.class)){
Rectangle rect = ((RectangleMapObject) object).getRectangle(); Rectangle rect = ((RectangleMapObject) object).getRectangle();
MapProperties props = object.getProperties(); MapProperties props = object.getProperties();
//Door door = new Door(props.get("id"), props.get("destinationMap"), props.get("destinationDoor"), rect);
//System.out.println("ID: " + props.get("ID", Integer.class)); int id = props.get("id", Integer.class);
//System.out.println("ID: " + props.get("y")); int exit = props.get("exit", Integer.class);
int destinationMap = props.get("destinationMap", Integer.class);
int destinationDoor = props.get("destinationDoor", Integer.class);
Door door = new Door(id, exit, destinationMap, destinationDoor, rect);
tempDoors.add(door);
} }
doors = new Door[tempDoors.size()];
for(int i = 0; i < doors.length; i++) {
doors[i] = tempDoors.get(i);
}
} }
public void render(float f){ public void render(float f){
@ -82,6 +93,15 @@ public class MapContainer {
t.getSelectedAsw(); // DO STUFF NICENICE t.getSelectedAsw(); // DO STUFF NICENICE
} }
} }
if(a instanceof Player) {
Rectangle rect = ((Player) a).collisionRect;
for(Door d : doors) {
if(Intersector.overlaps(rect, d.rect)) {
collidingDoor = d;
}
}
}
} }
} }

@ -92,7 +92,7 @@ public class Player extends Actor{
* 3: no movement available * 3: no movement available
*/ */
if(movementX == 0 && movementY == 0){ if(movementX == 0 && movementY == 0){
System.out.println(collidingWithMapCollisionObject());
} }
else if(movementX == 0 && movementY != 0){ else if(movementX == 0 && movementY != 0){
setY(getY()+movementY); setY(getY()+movementY);

@ -40,13 +40,12 @@ public class GameScreen extends AbstractScreen{
super(game, CAMERA_WIDTH, CAMERA_HEIGHT); super(game, CAMERA_WIDTH, CAMERA_HEIGHT);
//setTextbox(new Textbox("How are you doing my friend How are you doing my friend How are you doing my friend How are you doing my friend", "good", "bad")); //setTextbox(new Textbox("How are you doing my friend How are you doing my friend How are you doing my friend How are you doing my friend", "good", "bad"));
map = new MapContainer(CAMERA_WIDTH, CAMERA_HEIGHT, new Player(200, 200), "map2.tmx"); map = new MapContainer(CAMERA_WIDTH, CAMERA_HEIGHT, new Player(200, 200), "map2.tmx", 0);
} }
public void loadNewMap(String map){ public void loadNewMap(int map, int doorId){
this.map = new MapContainer(Main.CAMERA_WIDTH, Main.CAMERA_HEIGHT, this.map.getPlayer(), map); String filename = "map" + map + ".tmx";
this.map = new MapContainer(Main.CAMERA_WIDTH, Main.CAMERA_HEIGHT, this.map.getPlayer(), filename, doorId);
} }
@Override @Override
@ -56,12 +55,17 @@ public class GameScreen extends AbstractScreen{
@Override @Override
public void render(float f) { public void render(float f) {
map.render(f); map.render(f);
/*
if(Gdx.input.isKeyJustPressed(Input.Keys.NUM_1)){ if(Gdx.input.isKeyJustPressed(Input.Keys.NUM_1)){
loadNewMap("map.tmx"); loadNewMap("map.tmx");
} }
if(Gdx.input.isKeyJustPressed(Input.Keys.NUM_2)){ if(Gdx.input.isKeyJustPressed(Input.Keys.NUM_2)){
loadNewMap("map2.tmx"); loadNewMap("map2.tmx");
} }
*/
if(map.collidingDoor != null) {
loadNewMap(map.collidingDoor.destinationMap, map.collidingDoor.destinationDoor);
}
} }
@Override @Override

Loading…
Cancel
Save