walls disappear and despawn

master
GammelJAN 5 years ago
parent e8b9ad73fc
commit df1d27d282

@ -34,6 +34,8 @@ public class Controller extends ApplicationAdapter implements InputProcessor {
final int GAME_WORLD_WIDTH = 1600;
final int GAME_WORLD_HEIGHT = 900;
final int WALL_LIFETIME = 75;
SpriteBatch batch;
ShapeRenderer renderer;
PolygonSpriteBatch polygonSpriteBatch;
@ -77,10 +79,7 @@ public class Controller extends ApplicationAdapter implements InputProcessor {
//
//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);
@ -90,6 +89,7 @@ public class Controller extends ApplicationAdapter implements InputProcessor {
@Override
public void render () {
Gdx.gl.glClearColor(1, 1, 1, 1);
//Gdx.gl.glClearColor(0, 0, 0, 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());
@ -100,56 +100,35 @@ public class Controller extends ApplicationAdapter implements InputProcessor {
if(screen.getId() == 1){
// DRAW WALLS
for(Wall wall : model.getWalls()){
PolygonSprite poly;
PolygonRegion polyReg = new PolygonRegion(new TextureRegion(textureSolid),
wall.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();
if(wall.getLifetime() == -1){
drawPolygon(wall.getPolygon(),Color.BLACK);
}
else{
//float Value = ((float)(((float)wall.getLifetime() / (float)WALL_LIFETIME) * 255f))/255f);
float Value = 1f-(((float)wall.getLifetime()) / ((float)WALL_LIFETIME));
System.out.println(Value);
Color color = new Color(Value,Value,Value,1);
drawPolygon(wall.getPolygon(),color);
}
}
// DRAW PROJECTILES
renderer.begin(ShapeRenderer.ShapeType.Filled);
for(Projectile projectile : model.getProjectiles()){
PolygonSprite poly;
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();
drawPolygon(projectile.getPolygon(), Color.BLACK);
}
// 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();
drawPolygon(model.getTempPolygon(),Color.BLACK);
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();
// write left Length
batch.begin();
font.setColor(Color.BLACK);
@ -233,4 +212,21 @@ public class Controller extends ApplicationAdapter implements InputProcessor {
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;
public class Model {
final int WALL_LIFETIME = 75;
private Monster monster;
private ArrayList<Wall> walls;
private ArrayList<Projectile> projectiles;
@ -16,7 +19,7 @@ public class Model {
private boolean drawing = false;
private int currentLength;
private int leftWallLength = 2500;
private int leftWallLength = 5000;
public Model(){
monster = new Monster(250,150);
@ -33,6 +36,13 @@ public class Model {
for(Projectile projectile : projectiles){
projectile.move(walls);
}
for(int i = 0; i < walls.size(); i++){
walls.get(i).timerStep();
if(walls.get(i).getLifetime() == 0){
walls.remove(i);
i--;
}
}
}
public void startWall(int x, int y){
@ -73,7 +83,7 @@ public class Model {
if(possible){
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;

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

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

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

Loading…
Cancel
Save