diff --git a/core/src/com/trs/game/Controller.java b/core/src/com/trs/game/Controller.java index 42beb34..6034cc8 100644 --- a/core/src/com/trs/game/Controller.java +++ b/core/src/com/trs/game/Controller.java @@ -142,6 +142,11 @@ public class Controller extends ApplicationAdapter implements InputProcessor { // renderer.end(); + // write left Length + batch.begin(); + font.setColor(Color.BLACK); + font.draw(batch, ""+model.getLeftWallLength(), 1500f,800f); + batch.end(); // DRAW MONSTER //model.getMonster().drawMonster(renderer,polygonSpriteBatch); } diff --git a/core/src/com/trs/game/model/Model.java b/core/src/com/trs/game/model/Model.java index 2a8f2cd..884bebd 100644 --- a/core/src/com/trs/game/model/Model.java +++ b/core/src/com/trs/game/model/Model.java @@ -1,5 +1,6 @@ package com.trs.game.model; +import com.badlogic.gdx.math.Intersector; import com.badlogic.gdx.math.Polygon; import com.badlogic.gdx.math.Vector2; import com.trs.game.StaticMath; @@ -14,6 +15,8 @@ public class Model { private Vector2 tempStart; private boolean drawing = false; + private int leftWallLength = 2500; + public Model(){ monster = new Monster(250,150); walls = new ArrayList<>(); @@ -45,10 +48,25 @@ public class Model { } } public void finishWall(int x, int y){ - if(Vector2.dst(tempStart.x,tempStart.y,x,y) > 50) { + if(Vector2.dst(tempStart.x,tempStart.y,x,y) > 150) { double angle = StaticMath.calculateAngle(x,y,(int)tempStart.x,(int)tempStart.y); tempPolygon = StaticMath.createPolygon((int)tempStart.x, (int)tempStart.y, Math.toDegrees(angle-Math.PI),10,Vector2.dst(tempStart.x,tempStart.y,x,y)); - walls.add(new TempWall(Math.toDegrees(angle-Math.PI), tempPolygon, 500)); + + boolean possible = true; + if(Vector2.dst(tempStart.x,tempStart.y,x,y) > leftWallLength) + possible = false; + if(possible) + for(Wall wall : walls){ + if(Intersector.overlapConvexPolygons(tempPolygon, wall.getPolygon())){ + possible = false; + break; + } + } + + if(possible){ + leftWallLength -= Vector2.dst(tempStart.x,tempStart.y,x,y); + walls.add(new TempWall(Math.toDegrees(angle-Math.PI), tempPolygon, 500)); + } } tempPolygon = null; tempStart = null; @@ -71,4 +89,8 @@ public class Model { public Polygon getTempPolygon() { return tempPolygon; } + + public int getLeftWallLength() { + return leftWallLength; + } }