Walls can be drawn

master
GammelJAN 5 years ago
parent 72e091610b
commit 1eb3332cfb

@ -91,6 +91,8 @@ public class Controller extends ApplicationAdapter implements InputProcessor {
public void render () { public void render () {
Gdx.gl.glClearColor(1, 1, 1, 1); Gdx.gl.glClearColor(1, 1, 1, 1);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); 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); screen.render(batch,renderer,font);
@ -124,6 +126,20 @@ public class Controller extends ApplicationAdapter implements InputProcessor {
poly.draw(polygonSpriteBatch); poly.draw(polygonSpriteBatch);
polygonSpriteBatch.end(); 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(); renderer.end();
// DRAW MONSTER // DRAW MONSTER
@ -163,12 +179,14 @@ public class Controller extends ApplicationAdapter implements InputProcessor {
@Override @Override
public boolean touchDown(int screenX, int screenY, int pointer, int button) { public boolean touchDown(int screenX, int screenY, int pointer, int button) {
ManageButtonEvent(screen.touchDown(screenX,GAME_WORLD_HEIGHT-screenY)); ManageButtonEvent(screen.touchDown(screenX,GAME_WORLD_HEIGHT-screenY));
if(screen.getId() == 1) model.startWall(screenX, GAME_WORLD_HEIGHT - screenY);
return true; return true;
} }
@Override @Override
public boolean touchUp(int screenX, int screenY, int pointer, int button) { 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 @Override
@ -178,6 +196,8 @@ public class Controller extends ApplicationAdapter implements InputProcessor {
@Override @Override
public boolean mouseMoved(int screenX, int screenY) { public boolean mouseMoved(int screenX, int screenY) {
//if(screen.getId() == 1) model.adjustWall(screenX, GAME_WORLD_HEIGHT - screenY);
//return true;
return false; return false;
} }

@ -1,5 +1,7 @@
package com.trs.game.model; package com.trs.game.model;
import com.badlogic.gdx.math.Polygon;
import com.badlogic.gdx.math.Vector2;
import com.trs.game.StaticMath; import com.trs.game.StaticMath;
import java.util.ArrayList; import java.util.ArrayList;
@ -8,6 +10,9 @@ public class Model {
private Monster monster; private Monster monster;
private ArrayList<Wall> walls; private ArrayList<Wall> walls;
private ArrayList<Projectile> projectiles; private ArrayList<Projectile> projectiles;
private Polygon tempPolygon;
private Vector2 tempStart;
private boolean drawing = false;
public Model(){ public Model(){
monster = new Monster(250,150); 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<Wall> getWalls(){ public ArrayList<Wall> getWalls(){
return walls; return walls;
} }
@ -37,4 +67,8 @@ public class Model {
public ArrayList<Projectile> getProjectiles() { public ArrayList<Projectile> getProjectiles() {
return projectiles; return projectiles;
} }
public Polygon getTempPolygon() {
return tempPolygon;
}
} }

@ -75,7 +75,7 @@ public class Monster {
if(this.xPos == this.xPosTarget && this.yPos == this.yPosTarget){ if(this.xPos == this.xPosTarget && this.yPos == this.yPosTarget){
this.generateNewTarget(); this.generateNewTarget();
} }
if(Math.random() >= 0.9){ if(Math.random() >= 0.95){
this.generateNewTarget(); this.generateNewTarget();
} }
} }

@ -17,7 +17,7 @@ public class TempWall implements Wall {
@Override @Override
public Wall timerStep() { public Wall timerStep() {
return null; return this;
} }
public double getRotation() { public double getRotation() {

@ -46,7 +46,7 @@ public class EndScreen extends Screen {
return button.getId(); return button.getId();
} }
} }
return 0; return -1;
} }
@Override @Override

@ -46,7 +46,7 @@ public class GameScreen extends Screen {
return button.getId(); return button.getId();
} }
} }
return 0; return -1;
} }
@Override @Override

@ -46,7 +46,7 @@ public class MainMenuScreen extends Screen {
return button.getId(); return button.getId();
} }
} }
return 0; return -1;
} }
@Override @Override

Loading…
Cancel
Save