package sagittarius; 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; protected static Camera camera; // 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); } private void update(float deltaTime) { SagittariusGame.update(deltaTime); hud.update(); camera.position.set(WIDTH / 2, HEIGHT / 2, 0); camera.update(); } @Override public void render(float deltaTime) { update(deltaTime); clearScreen(); // ---------- batch ---------- batch.setProjectionMatrix(camera.combined); batch.begin(); // planets for (Planet planet : SagittariusGame.planetList) { planet.renderDebug(batch, font); } // moons for (Moon moon : SagittariusGame.moonList) { moon.renderDebug(batch, font); } // players for (Player player : SagittariusGame.playerList) { player.renderDebug(batch, font); } // arrows for (Arrow arrow : SagittariusGame.arrowList) { arrow.renderDebug(batch, font); } batch.end(); // ---------- shapeRenderer ---------- shapeRenderer.setProjectionMatrix(camera.combined); shapeRenderer.begin(ShapeRenderer.ShapeType.Line); // planets for (Planet planet : SagittariusGame.planetList) { planet.render(shapeRenderer); } // players for (Player player : SagittariusGame.playerList) { player.render(shapeRenderer); } // arrows for (Arrow arrow : SagittariusGame.arrowList) { arrow.render(shapeRenderer); } // moons for (Moon moon : SagittariusGame.moonList) { moon.render(shapeRenderer); } // float[] vertices = {100, 100, 200, 200, 1000, 500}; // shapeRenderer.polyline(vertices); shapeRenderer.end(); // HUD hud.render(); } @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(); } }