parent
5ce7ed0208
commit
ee6c8738a2
@ -1,5 +1,17 @@
|
||||
package com.trs.main;
|
||||
|
||||
public class Door {
|
||||
import com.badlogic.gdx.math.Rectangle;
|
||||
|
||||
public class Door{
|
||||
int id;
|
||||
int destinationMap;
|
||||
int destinationDoor;
|
||||
Rectangle rect;
|
||||
|
||||
public Door(int id, int destinationMap, int destinationDoor, Rectangle rect) {
|
||||
this.id = id;
|
||||
this.destinationMap = destinationMap;
|
||||
this.destinationDoor = destinationDoor;
|
||||
this.rect = rect;
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,5 +1,41 @@
|
||||
package com.trs.main;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import com.badlogic.gdx.graphics.OrthographicCamera;
|
||||
import com.badlogic.gdx.maps.MapObject;
|
||||
import com.badlogic.gdx.maps.MapProperties;
|
||||
import com.badlogic.gdx.maps.objects.RectangleMapObject;
|
||||
import com.badlogic.gdx.maps.tiled.TiledMap;
|
||||
import com.badlogic.gdx.maps.tiled.TmxMapLoader;
|
||||
import com.badlogic.gdx.maps.tiled.renderers.OrthogonalTiledMapRenderer;
|
||||
import com.badlogic.gdx.math.Rectangle;
|
||||
import com.badlogic.gdx.scenes.scene2d.Stage;
|
||||
import com.badlogic.gdx.utils.viewport.FitViewport;
|
||||
|
||||
public class MapContainer {
|
||||
Stage stage;
|
||||
OrthographicCamera camera;
|
||||
TmxMapLoader tmx;
|
||||
TiledMap map;
|
||||
OrthogonalTiledMapRenderer tmr;
|
||||
ArrayList<Door> doors = new ArrayList<>();
|
||||
|
||||
public MapContainer(float CAMERA_WIDTH, float CAMERA_HEIGHT, TiledMap map) {
|
||||
camera = new OrthographicCamera();
|
||||
camera.setToOrtho(false, CAMERA_WIDTH, CAMERA_HEIGHT);
|
||||
camera.update();
|
||||
this.map = map;
|
||||
stage = new Stage(new FitViewport(CAMERA_WIDTH, CAMERA_HEIGHT, camera));
|
||||
|
||||
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"));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -0,0 +1,52 @@
|
||||
package com.trs.main;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author jonathan
|
||||
*/
|
||||
public class StaticMath {
|
||||
|
||||
public static float calculateAngle(float xPos1, float yPos1, float xPos2, float yPos2){
|
||||
float deltaX = xPos2 - xPos1;
|
||||
float deltaY = yPos2 - yPos1;
|
||||
|
||||
double alpha;
|
||||
if(deltaY == 0){
|
||||
if(deltaX < 0){
|
||||
alpha = Math.PI;
|
||||
}
|
||||
else{
|
||||
alpha = 0;
|
||||
}
|
||||
}
|
||||
else if(deltaX == 0 && deltaY >= 0){
|
||||
alpha = Math.PI / 2;
|
||||
}
|
||||
else if(deltaX == 0 && deltaY < 0){
|
||||
alpha = Math.PI / -2;
|
||||
}
|
||||
else{
|
||||
alpha = Math.abs(Math.atan(deltaY / deltaX));
|
||||
|
||||
if(deltaX < 0 && deltaY < 0){
|
||||
alpha = Math.PI + alpha;
|
||||
}
|
||||
else if(deltaX < 0 && deltaY > 0){
|
||||
alpha = Math.PI - alpha;
|
||||
}
|
||||
else if(deltaX > 0 && deltaY < 0){
|
||||
alpha = 2*Math.PI - alpha;
|
||||
}
|
||||
}
|
||||
|
||||
return (float) alpha;
|
||||
}
|
||||
|
||||
public static double calculateDistance(int xPos1, int yPos1, int xPos2, int yPos2, double angle){
|
||||
float deltaX = xPos2 - xPos1;
|
||||
float deltaY = yPos2 - yPos1;
|
||||
|
||||
double distance = Math.abs((deltaY / Math.sin(angle)));
|
||||
return distance;
|
||||
}
|
||||
}
|
||||
Loading…
Reference in new issue