merge complete

master
Jonathan Hager 5 years ago
commit 9cbcce610c

@ -34,6 +34,8 @@ public class Controller extends ApplicationAdapter implements InputProcessor {
final int GAME_WORLD_WIDTH = 1600; final int GAME_WORLD_WIDTH = 1600;
final int GAME_WORLD_HEIGHT = 900; final int GAME_WORLD_HEIGHT = 900;
final int WALL_LIFETIME = 75;
SpriteBatch batch; SpriteBatch batch;
ShapeRenderer renderer; ShapeRenderer renderer;
PolygonSpriteBatch polygonSpriteBatch; PolygonSpriteBatch polygonSpriteBatch;
@ -77,10 +79,7 @@ public class Controller extends ApplicationAdapter implements InputProcessor {
// //
//POLYGON STUFF //POLYGON STUFF
pix = new Pixmap(1, 1, Pixmap.Format.RGBA8888);
pix.setColor(Color.BLACK); // DE is red, AD is green and BE is blue.
pix.fill();
textureSolid = new Texture(pix);
screen = new MainMenuScreen(GAME_WORLD_WIDTH,GAME_WORLD_HEIGHT); screen = new MainMenuScreen(GAME_WORLD_WIDTH,GAME_WORLD_HEIGHT);
@ -90,6 +89,7 @@ public class Controller extends ApplicationAdapter implements InputProcessor {
@Override @Override
public void render () { public void render () {
Gdx.gl.glClearColor(1, 1, 1, 1); Gdx.gl.glClearColor(1, 1, 1, 1);
//Gdx.gl.glClearColor(0, 0, 0, 1);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
// WORKAROUND, BECAUSE MOUSEMOVED NOT WORKING WHILE TOUCHDOWN // WORKAROUND, BECAUSE MOUSEMOVED NOT WORKING WHILE TOUCHDOWN
if(screen.getId() == 1) model.adjustWall(Gdx.input.getX(), GAME_WORLD_HEIGHT - Gdx.input.getY()); if(screen.getId() == 1) model.adjustWall(Gdx.input.getX(), GAME_WORLD_HEIGHT - Gdx.input.getY());
@ -100,56 +100,35 @@ public class Controller extends ApplicationAdapter implements InputProcessor {
if(screen.getId() == 1){ if(screen.getId() == 1){
// DRAW WALLS // DRAW WALLS
for(Wall wall : model.getWalls()){ for(Wall wall : model.getWalls()){
PolygonSprite poly; if(wall.getLifetime() == -1){
PolygonRegion polyReg = new PolygonRegion(new TextureRegion(textureSolid), drawPolygon(wall.getPolygon(),Color.BLACK);
wall.getPolygon().getVertices(), new short[] { }
0, 1, 2, // Two triangles using vertex indices. else{
0, 2, 3 // Take care of the counter-clockwise direction. //float Value = ((float)(((float)wall.getLifetime() / (float)WALL_LIFETIME) * 255f))/255f);
}); float Value = 1f-(((float)wall.getLifetime()) / ((float)WALL_LIFETIME));
poly = new PolygonSprite(polyReg); System.out.println(Value);
polygonSpriteBatch.begin(); Color color = new Color(Value,Value,Value,1);
poly.draw(polygonSpriteBatch); drawPolygon(wall.getPolygon(),color);
polygonSpriteBatch.end(); }
} }
// DRAW PROJECTILES // DRAW PROJECTILES
renderer.begin(ShapeRenderer.ShapeType.Filled); renderer.begin(ShapeRenderer.ShapeType.Filled);
for(Projectile projectile : model.getProjectiles()){ for(Projectile projectile : model.getProjectiles()){
PolygonSprite poly; drawPolygon(projectile.getPolygon(), Color.BLACK);
PolygonRegion polyReg = new PolygonRegion(new TextureRegion(textureSolid),
projectile.getPolygon().getVertices(), new short[] {
0, 1, 2, // Two triangles using vertex indices.
0, 2, 3 // Take care of the counter-clockwise direction.
});
poly = new PolygonSprite(polyReg);
polygonSpriteBatch.begin();
poly.draw(polygonSpriteBatch);
polygonSpriteBatch.end();
} }
// TEMP POLYGON // TEMP POLYGON
if(model.getTempPolygon() != null){ if(model.getTempPolygon() != null){
PolygonSprite poly2; drawPolygon(model.getTempPolygon(),Color.BLACK);
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();
batch.begin();
font.setColor(Color.GRAY);
if(model.getCurrentLength()!=0)font.draw(batch, ""+model.getCurrentLength(), Gdx.input.getX()+10, GAME_WORLD_HEIGHT - Gdx.input.getY()+10);
batch.end();
renderer.begin(ShapeRenderer.ShapeType.Filled); // LENGTH
batch.begin();
font.setColor(Color.GRAY);
if(model.getCurrentLength()!=0)font.draw(batch, ""+model.getCurrentLength(), Gdx.input.getX()+10, GAME_WORLD_HEIGHT - Gdx.input.getY()+10);
batch.end();
} }
// //
renderer.end(); renderer.end();
// write left Length // write left Length
batch.begin(); batch.begin();
font.setColor(Color.BLACK); font.setColor(Color.BLACK);
@ -233,4 +212,21 @@ public class Controller extends ApplicationAdapter implements InputProcessor {
break; break;
} }
} }
public void drawPolygon(Polygon polygon, Color color){
pix = new Pixmap(1, 1, Pixmap.Format.RGBA8888);
pix.setColor(color); // DE is red, AD is green and BE is blue.
pix.fill();
textureSolid = new Texture(pix);
PolygonSprite poly;
PolygonRegion polyReg = new PolygonRegion(new TextureRegion(textureSolid),
polygon.getVertices(), new short[] {
0, 1, 2, // Two triangles using vertex indices.
0, 2, 3 // Take care of the counter-clockwise direction.
});
poly = new PolygonSprite(polyReg);
polygonSpriteBatch.begin();
poly.draw(polygonSpriteBatch);
polygonSpriteBatch.end();
}
} }

@ -8,6 +8,9 @@ import com.trs.game.StaticMath;
import java.util.ArrayList; import java.util.ArrayList;
public class Model { public class Model {
final int WALL_LIFETIME = 75;
private Monster monster; private Monster monster;
private ArrayList<Wall> walls; private ArrayList<Wall> walls;
private ArrayList<Projectile> projectiles; private ArrayList<Projectile> projectiles;
@ -18,7 +21,7 @@ public class Model {
private int difficulty; private int difficulty;
private int leftWallLength = 2500; private int leftWallLength = 5000;
public Model(){ public Model(){
difficulty = 0; difficulty = 0;
@ -31,20 +34,26 @@ public class Model {
projectiles.add(new Projectile(270, 500, 270, 0)); projectiles.add(new Projectile(270, 500, 270, 0));
} }
public void timerStep(){ public void timerStep() {
monster.move(walls, projectiles); monster.move(walls, projectiles);
for(int i = projectiles.size() - 1; i >= 0; i--){ for(int i = projectiles.size() - 1; i >= 0; i--){
Projectile projectile = projectiles.get(i); Projectile projectile = projectiles.get(i);
projectile.move(walls); projectile.move(walls);
if(projectile.getxPos() < -110 || projectile.getxPos() > 1710 || projectile.getyPos() < -110 || projectile.getyPos() > 1010){ if(projectile.getxPos() < -110 || projectile.getxPos() > 1710 || projectile.getyPos() < -110 || projectile.getyPos() > 1010){
projectiles.remove(i); projectiles.remove(i);
} }
} }
for (int i = 0; i < walls.size(); i++) {
walls.get(i).timerStep();
if (walls.get(i).getLifetime() == 0) {
walls.remove(i);
i--;
}
if(monster.getIsDead()){ if (monster.getIsDead()) {
// TODO: Tod implementieren // TODO: Tod implementieren
}
} }
// Generation of new projectiles // Generation of new projectiles
@ -92,7 +101,7 @@ public class Model {
if(possible){ if(possible){
leftWallLength -= Vector2.dst(tempStart.x,tempStart.y,x,y); leftWallLength -= Vector2.dst(tempStart.x,tempStart.y,x,y);
walls.add(new TempWall(angle-Math.PI, tempPolygon, 500)); walls.add(new TempWall(angle-Math.PI, tempPolygon, WALL_LIFETIME));
} }
} }
tempPolygon = null; tempPolygon = null;

@ -31,6 +31,11 @@ public class PermWall implements Wall {
return collisionPolygons; return collisionPolygons;
} }
@Override
public int getLifetime() {
return -1;
}
public void setRotation(double rotation) { public void setRotation(double rotation) {
this.rotation = rotation; this.rotation = rotation;
} }

@ -20,6 +20,7 @@ public class TempWall implements Wall {
@Override @Override
public Wall timerStep() { public Wall timerStep() {
lifetime--;
return this; return this;
} }

@ -7,4 +7,5 @@ public interface Wall {
public Polygon getPolygon(); public Polygon getPolygon();
public double getRotation(); public double getRotation();
public Polygon[] getCollisionPolygons(); public Polygon[] getCollisionPolygons();
public int getLifetime();
} }

Loading…
Cancel
Save