diff --git a/core/src/com/trs/game/Controller.java b/core/src/com/trs/game/Controller.java index 0b9ee75..42beb34 100644 --- a/core/src/com/trs/game/Controller.java +++ b/core/src/com/trs/game/Controller.java @@ -91,6 +91,8 @@ public class Controller extends ApplicationAdapter implements InputProcessor { public void render () { Gdx.gl.glClearColor(1, 1, 1, 1); Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); + // WORKAROUND, BECAUSE MOUSEMOVED NOT WORKING WHILE TOUCHDOWN + if(screen.getId() == 1) model.adjustWall(Gdx.input.getX(), GAME_WORLD_HEIGHT - Gdx.input.getY()); screen.render(batch,renderer,font); @@ -124,6 +126,20 @@ public class Controller extends ApplicationAdapter implements InputProcessor { poly.draw(polygonSpriteBatch); polygonSpriteBatch.end(); } + // TEMP POLYGON + if(model.getTempPolygon() != null){ + PolygonSprite poly2; + PolygonRegion polyReg = new PolygonRegion(new TextureRegion(textureSolid), + model.getTempPolygon().getVertices(), new short[]{ + 0, 1, 2, // Two triangles using vertex indices. + 0, 2, 3 // Take care of the counter-clockwise direction. + }); + poly2 = new PolygonSprite(polyReg); + polygonSpriteBatch.begin(); + poly2.draw(polygonSpriteBatch); + polygonSpriteBatch.end(); + } + // renderer.end(); // DRAW MONSTER @@ -163,12 +179,14 @@ public class Controller extends ApplicationAdapter implements InputProcessor { @Override public boolean touchDown(int screenX, int screenY, int pointer, int button) { ManageButtonEvent(screen.touchDown(screenX,GAME_WORLD_HEIGHT-screenY)); + if(screen.getId() == 1) model.startWall(screenX, GAME_WORLD_HEIGHT - screenY); return true; } @Override public boolean touchUp(int screenX, int screenY, int pointer, int button) { - return false; + if(screen.getId() == 1) model.finishWall(screenX, GAME_WORLD_HEIGHT - screenY); + return true; } @Override @@ -178,6 +196,8 @@ public class Controller extends ApplicationAdapter implements InputProcessor { @Override public boolean mouseMoved(int screenX, int screenY) { + //if(screen.getId() == 1) model.adjustWall(screenX, GAME_WORLD_HEIGHT - screenY); + //return true; return false; } diff --git a/core/src/com/trs/game/model/Model.java b/core/src/com/trs/game/model/Model.java index 21c2ff5..2a8f2cd 100644 --- a/core/src/com/trs/game/model/Model.java +++ b/core/src/com/trs/game/model/Model.java @@ -1,5 +1,7 @@ package com.trs.game.model; +import com.badlogic.gdx.math.Polygon; +import com.badlogic.gdx.math.Vector2; import com.trs.game.StaticMath; import java.util.ArrayList; @@ -8,6 +10,9 @@ public class Model { private Monster monster; private ArrayList walls; private ArrayList projectiles; + private Polygon tempPolygon; + private Vector2 tempStart; + private boolean drawing = false; public Model(){ monster = new Monster(250,150); @@ -26,6 +31,31 @@ public class Model { } } + public void startWall(int x, int y){ + if(!drawing){ + tempPolygon = StaticMath.createPolygon(x,y,0,10,5); + tempStart = new Vector2(x,y); + drawing = true; + } + } + public void adjustWall(int x, int y){ + if(drawing){ + 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)); + } + } + public void finishWall(int x, int y){ + if(Vector2.dst(tempStart.x,tempStart.y,x,y) > 50) { + 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)); + } + tempPolygon = null; + tempStart = null; + drawing = false; + } + + public ArrayList getWalls(){ return walls; } @@ -37,4 +67,8 @@ public class Model { public ArrayList getProjectiles() { return projectiles; } + + public Polygon getTempPolygon() { + return tempPolygon; + } } diff --git a/core/src/com/trs/game/model/Monster.java b/core/src/com/trs/game/model/Monster.java index 933d803..e5d561c 100644 --- a/core/src/com/trs/game/model/Monster.java +++ b/core/src/com/trs/game/model/Monster.java @@ -75,7 +75,7 @@ public class Monster { if(this.xPos == this.xPosTarget && this.yPos == this.yPosTarget){ this.generateNewTarget(); } - if(Math.random() >= 0.9){ + if(Math.random() >= 0.95){ this.generateNewTarget(); } } diff --git a/core/src/com/trs/game/model/TempWall.java b/core/src/com/trs/game/model/TempWall.java index 7d7fbaa..1f41459 100644 --- a/core/src/com/trs/game/model/TempWall.java +++ b/core/src/com/trs/game/model/TempWall.java @@ -17,7 +17,7 @@ public class TempWall implements Wall { @Override public Wall timerStep() { - return null; + return this; } public double getRotation() { diff --git a/core/src/com/trs/game/view/Screens/EndScreen.java b/core/src/com/trs/game/view/Screens/EndScreen.java index 773df1b..83bfecb 100644 --- a/core/src/com/trs/game/view/Screens/EndScreen.java +++ b/core/src/com/trs/game/view/Screens/EndScreen.java @@ -46,7 +46,7 @@ public class EndScreen extends Screen { return button.getId(); } } - return 0; + return -1; } @Override diff --git a/core/src/com/trs/game/view/Screens/GameScreen.java b/core/src/com/trs/game/view/Screens/GameScreen.java index 710ae5b..1854d76 100644 --- a/core/src/com/trs/game/view/Screens/GameScreen.java +++ b/core/src/com/trs/game/view/Screens/GameScreen.java @@ -46,7 +46,7 @@ public class GameScreen extends Screen { return button.getId(); } } - return 0; + return -1; } @Override diff --git a/core/src/com/trs/game/view/Screens/MainMenuScreen.java b/core/src/com/trs/game/view/Screens/MainMenuScreen.java index 6a8b0b9..d0401be 100644 --- a/core/src/com/trs/game/view/Screens/MainMenuScreen.java +++ b/core/src/com/trs/game/view/Screens/MainMenuScreen.java @@ -46,7 +46,7 @@ public class MainMenuScreen extends Screen { return button.getId(); } } - return 0; + return -1; } @Override