2021-04-06 20:08:14 +00:00
|
|
|
package sagittarius;
|
2021-04-05 16:45:57 +00:00
|
|
|
|
|
|
|
import com.badlogic.gdx.Gdx;
|
|
|
|
import com.badlogic.gdx.ScreenAdapter;
|
|
|
|
import com.badlogic.gdx.graphics.Camera;
|
|
|
|
import com.badlogic.gdx.graphics.Color;
|
|
|
|
import com.badlogic.gdx.graphics.GL20;
|
|
|
|
import com.badlogic.gdx.graphics.OrthographicCamera;
|
|
|
|
import com.badlogic.gdx.graphics.g2d.BitmapFont;
|
|
|
|
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
|
|
|
|
import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
|
|
|
|
import com.badlogic.gdx.utils.viewport.FitViewport;
|
|
|
|
import com.badlogic.gdx.utils.viewport.Viewport;
|
|
|
|
|
|
|
|
class GameScreen extends ScreenAdapter {
|
|
|
|
|
|
|
|
// ---------- ATTRIBUTES ----------
|
|
|
|
|
|
|
|
// screen size
|
|
|
|
static final int WIDTH = 1920;
|
|
|
|
static final int HEIGHT = 1080;
|
|
|
|
|
|
|
|
// drawing stuff
|
|
|
|
private SpriteBatch batch;
|
|
|
|
private ShapeRenderer shapeRenderer;
|
|
|
|
private BitmapFont font;
|
|
|
|
|
|
|
|
// camera stuff
|
|
|
|
private Viewport viewport;
|
2021-04-06 20:59:10 +00:00
|
|
|
protected static Camera camera;
|
2021-04-05 16:45:57 +00:00
|
|
|
|
|
|
|
// TODO: categorize better ?
|
|
|
|
private HUD hud = new HUD();
|
|
|
|
|
|
|
|
// ---------- METHODS ----------
|
|
|
|
|
|
|
|
private void clearScreen() {
|
|
|
|
Gdx.gl.glClearColor(Color.BLACK.r, Color.BLACK.g, Color.BLACK.b, Color.BLACK.a);
|
|
|
|
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
|
|
|
|
}
|
|
|
|
|
2021-04-05 21:14:56 +00:00
|
|
|
private void update(float deltaTime) {
|
|
|
|
SagittariusGame.update(deltaTime);
|
2021-04-05 16:45:57 +00:00
|
|
|
hud.update();
|
2021-04-05 17:01:25 +00:00
|
|
|
camera.position.set(WIDTH / 2, HEIGHT / 2, 0);
|
2021-04-05 16:45:57 +00:00
|
|
|
camera.update();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2021-04-05 21:14:56 +00:00
|
|
|
public void render(float deltaTime) {
|
2021-04-05 16:45:57 +00:00
|
|
|
|
2021-04-05 21:14:56 +00:00
|
|
|
update(deltaTime);
|
2021-04-05 16:45:57 +00:00
|
|
|
|
|
|
|
clearScreen();
|
|
|
|
|
2021-04-05 17:01:25 +00:00
|
|
|
// ---------- batch ----------
|
2021-04-05 16:45:57 +00:00
|
|
|
batch.setProjectionMatrix(camera.combined);
|
|
|
|
batch.begin();
|
2021-04-05 18:42:51 +00:00
|
|
|
|
|
|
|
// planets
|
|
|
|
for (Planet planet : SagittariusGame.planetList) {
|
|
|
|
planet.renderDebug(batch, font);
|
|
|
|
}
|
2021-04-06 20:59:10 +00:00
|
|
|
|
|
|
|
// moons
|
|
|
|
for (Moon moon : SagittariusGame.moonList) {
|
|
|
|
moon.renderDebug(batch, font);
|
|
|
|
}
|
2021-04-05 18:42:51 +00:00
|
|
|
|
|
|
|
// players
|
|
|
|
for (Player player : SagittariusGame.playerList) {
|
|
|
|
player.renderDebug(batch, font);
|
|
|
|
}
|
|
|
|
|
2021-04-05 21:14:56 +00:00
|
|
|
// arrows
|
|
|
|
for (Arrow arrow : SagittariusGame.arrowList) {
|
|
|
|
arrow.renderDebug(batch, font);
|
|
|
|
}
|
|
|
|
|
2021-04-05 16:45:57 +00:00
|
|
|
batch.end();
|
|
|
|
|
2021-04-05 17:01:25 +00:00
|
|
|
// ---------- shapeRenderer ----------
|
2021-04-05 16:45:57 +00:00
|
|
|
shapeRenderer.setProjectionMatrix(camera.combined);
|
|
|
|
shapeRenderer.begin(ShapeRenderer.ShapeType.Line);
|
|
|
|
|
2021-04-05 17:01:25 +00:00
|
|
|
// planets
|
|
|
|
for (Planet planet : SagittariusGame.planetList) {
|
|
|
|
planet.render(shapeRenderer);
|
|
|
|
}
|
2021-04-05 16:45:57 +00:00
|
|
|
|
2021-04-05 18:42:51 +00:00
|
|
|
// players
|
|
|
|
for (Player player : SagittariusGame.playerList) {
|
|
|
|
player.render(shapeRenderer);
|
|
|
|
}
|
|
|
|
|
2021-04-05 21:14:56 +00:00
|
|
|
// arrows
|
|
|
|
for (Arrow arrow : SagittariusGame.arrowList) {
|
|
|
|
arrow.render(shapeRenderer);
|
|
|
|
}
|
|
|
|
|
2021-04-06 20:59:10 +00:00
|
|
|
// moons
|
|
|
|
for (Moon moon : SagittariusGame.moonList) {
|
|
|
|
moon.render(shapeRenderer);
|
|
|
|
}
|
|
|
|
|
2021-04-06 10:58:27 +00:00
|
|
|
// float[] vertices = {100, 100, 200, 200, 1000, 500};
|
|
|
|
// shapeRenderer.polyline(vertices);
|
|
|
|
|
2021-04-05 16:45:57 +00:00
|
|
|
shapeRenderer.end();
|
|
|
|
|
2021-04-05 17:01:25 +00:00
|
|
|
// HUD
|
|
|
|
hud.render();
|
|
|
|
|
2021-04-05 16:45:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void show() {
|
|
|
|
camera = new OrthographicCamera(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
|
|
|
|
camera.position.set(WIDTH / 2, HEIGHT / 2, 0);
|
|
|
|
camera.update();
|
|
|
|
|
|
|
|
viewport = new FitViewport(WIDTH, HEIGHT, camera);
|
|
|
|
|
|
|
|
shapeRenderer = new ShapeRenderer();
|
|
|
|
batch = new SpriteBatch();
|
|
|
|
font = new BitmapFont();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void resize(int width, int height) {
|
|
|
|
viewport.update(width, height);
|
|
|
|
camera.update();
|
|
|
|
batch.setProjectionMatrix(camera.combined);
|
|
|
|
shapeRenderer.setProjectionMatrix(camera.combined);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void dispose() {
|
|
|
|
batch.dispose();
|
|
|
|
font.dispose();
|
|
|
|
shapeRenderer.dispose();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|