diff --git a/core/assets/map2.tmx b/core/assets/map2.tmx
index d435e26..53a6f22 100644
--- a/core/assets/map2.tmx
+++ b/core/assets/map2.tmx
@@ -241,7 +241,8 @@
diff --git a/core/src/com/trs/main/Door.java b/core/src/com/trs/main/Door.java
index ae65c3e..51b178c 100644
--- a/core/src/com/trs/main/Door.java
+++ b/core/src/com/trs/main/Door.java
@@ -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;
+ }
}
diff --git a/core/src/com/trs/main/MapContainer.java b/core/src/com/trs/main/MapContainer.java
index bae9426..da67300 100644
--- a/core/src/com/trs/main/MapContainer.java
+++ b/core/src/com/trs/main/MapContainer.java
@@ -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 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"));
+ }
+ }
}
diff --git a/core/src/com/trs/main/MovingNpc.java b/core/src/com/trs/main/MovingNpc.java
index 05bddb1..89e3462 100644
--- a/core/src/com/trs/main/MovingNpc.java
+++ b/core/src/com/trs/main/MovingNpc.java
@@ -39,7 +39,7 @@ public class MovingNpc extends Actor{
animatedSprite.setRow(0);
collisionRect = new Rectangle(xPos + 16, yPos, 32, 48);
this.area = area;
- speed = 2.5f;
+ speed = 1f;
setBounds(xPos, yPos, animatedSprite.getSprite().getWidth(), animatedSprite.getSprite().getHeight());
}
@@ -47,17 +47,32 @@ public class MovingNpc extends Actor{
protected void positionChanged() {
animatedSprite.setSpritePosition((int)getX(), (int)getY());
collisionRect = new Rectangle(getX() + 16, getY(), 32, 48);
- super.positionChanged(); //To change body of generated methods, choose Tools | Templates.
+ super.positionChanged();
}
@Override
public void act(float delta) {
- if(POI == null || Math.random() < 0.05f){
- POI = new Vector2(area.getX()+(float)Math.random() * (float)area.getWidth(), area.getY()+(float)Math.random()*(float)area.getHeight());
+ if(POI == null || Math.random() < 0.01f){
+ POI = new Vector2(area.getX() + ((float) Math.random() * (float) area.getWidth()), area.getY() + ((float) Math.random() * (float) area.getHeight()));
}
Vector2 movement = new Vector2(speed,0);
- movement.setAngleRad((float)Math.atan((double)(POI.y-getY())/(double)(POI.x-getX())));
+ //movement.setAngleRad((float)Math.atan((double)(POI.y-getY())/(double)(POI.x-getX())));
+ movement.setAngleRad(StaticMath.calculateAngle(getX(), getY(), POI.x, POI.y));
+
+ if(movement.angleDeg() < 135 && movement.angleDeg() >= 45) {
+ facing = 0;
+ }
+ else if(movement.angleDeg() >= 135 && movement.angleDeg() < 225) {
+ facing = 1;
+ }
+ else if(movement.angleDeg() >= 225 && movement.angleDeg() < 315) {
+ facing = 2;
+ }
+ else {
+ facing = 3;
+ }
+
System.out.println(movement.angleDeg());
System.out.println(POI.x + " " + POI.y);
System.out.println();
diff --git a/core/src/com/trs/main/StaticMath.java b/core/src/com/trs/main/StaticMath.java
new file mode 100644
index 0000000..55f791f
--- /dev/null
+++ b/core/src/com/trs/main/StaticMath.java
@@ -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;
+ }
+}
diff --git a/core/src/com/trs/main/view/screens/GameScreen.java b/core/src/com/trs/main/view/screens/GameScreen.java
index 7daf8a2..fc500ab 100644
--- a/core/src/com/trs/main/view/screens/GameScreen.java
+++ b/core/src/com/trs/main/view/screens/GameScreen.java
@@ -22,6 +22,7 @@ import com.badlogic.gdx.scenes.scene2d.Actor;
import com.badlogic.gdx.scenes.scene2d.Group;
import com.trs.main.Main;
import com.trs.main.MapCollisionObject;
+import com.trs.main.MapContainer;
import com.trs.main.MovingNpc;
import com.trs.main.Player;
import com.trs.main.Textbox;
@@ -48,6 +49,7 @@ public class GameScreen extends AbstractScreen{
maploader = new TmxMapLoader();
map = maploader.load("map2.tmx");
+ MapContainer test = new MapContainer(CAMERA_WIDTH, CAMERA_HEIGHT, map);
renderer = new OrthogonalTiledMapRenderer(map);
renderer.setView((OrthographicCamera)stage.getCamera());
stage.getCamera().update();