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/IOSLauncher.app
/ios/IOSLauncher.app.dSYM
/.nb-gradle/

@ -39,6 +39,9 @@
<objectgroup id="4" name="tuerebene">
<object id="9" x="32" y="32" width="64" height="64">
<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"/>
</properties>
</object>

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

@ -3,13 +3,15 @@ package com.trs.main;
import com.badlogic.gdx.math.Rectangle;
public class Door{
int id;
int destinationMap;
int destinationDoor;
public int id;
public int exit;
public int destinationMap;
public int destinationDoor;
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.exit = exit;
this.destinationMap = destinationMap;
this.destinationDoor = destinationDoor;
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.objects.TiledMapTileMapObject;
import com.badlogic.gdx.maps.tiled.renderers.OrthogonalTiledMapRenderer;
import com.badlogic.gdx.math.Intersector;
import com.badlogic.gdx.math.Rectangle;
import com.badlogic.gdx.scenes.scene2d.Actor;
import com.badlogic.gdx.scenes.scene2d.Stage;
@ -18,16 +19,16 @@ import com.badlogic.gdx.utils.viewport.FitViewport;
public class MapContainer {
Stage stage;
OrthographicCamera camera;
TmxMapLoader maploader;
TiledMap map;
OrthogonalTiledMapRenderer renderer;
ArrayList<Door> doors = new ArrayList<>();
TiledMap map;
OrthogonalTiledMapRenderer renderer;
Door[] doors;
public Door collidingDoor;
// 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
camera = new OrthographicCamera();
camera.setToOrtho(false, CAMERA_WIDTH, CAMERA_HEIGHT);
@ -55,14 +56,24 @@ public class MapContainer {
}
// adding the door links
ArrayList<Door> tempDoors = new ArrayList<>();
for(MapObject object : map.getLayers().get(3).getObjects().getByType(RectangleMapObject.class)){
Rectangle rect = ((RectangleMapObject) object).getRectangle();
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));
//System.out.println("ID: " + props.get("y"));
int id = props.get("id", Integer.class);
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){
@ -82,6 +93,15 @@ public class MapContainer {
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
*/
if(movementX == 0 && movementY == 0){
System.out.println(collidingWithMapCollisionObject());
}
else if(movementX == 0 && movementY != 0){
setY(getY()+movementY);

@ -40,13 +40,12 @@ public class GameScreen extends AbstractScreen{
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"));
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){
this.map = new MapContainer(Main.CAMERA_WIDTH, Main.CAMERA_HEIGHT, this.map.getPlayer(), map);
public void loadNewMap(int map, int doorId){
String filename = "map" + map + ".tmx";
this.map = new MapContainer(Main.CAMERA_WIDTH, Main.CAMERA_HEIGHT, this.map.getPlayer(), filename, doorId);
}
@Override
@ -56,12 +55,17 @@ public class GameScreen extends AbstractScreen{
@Override
public void render(float f) {
map.render(f);
/*
if(Gdx.input.isKeyJustPressed(Input.Keys.NUM_1)){
loadNewMap("map.tmx");
}
if(Gdx.input.isKeyJustPressed(Input.Keys.NUM_2)){
loadNewMap("map2.tmx");
}
*/
if(map.collidingDoor != null) {
loadNewMap(map.collidingDoor.destinationMap, map.collidingDoor.destinationDoor);
}
}
@Override

Loading…
Cancel
Save