Skip to content

Instantly share code, notes, and snippets.

@isXander
Created January 19, 2021 16:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save isXander/f1cc5b82aafcb1727253dfb7af0ff241 to your computer and use it in GitHub Desktop.
Save isXander/f1cc5b82aafcb1727253dfb7af0ff241 to your computer and use it in GitHub Desktop.
package com.britishpenguin.astrowarrior.screens;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Screen;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.math.MathUtils;
import com.britishpenguin.astrowarrior.AstroWarrior;
import com.britishpenguin.astrowarrior.entity.Entity;
import com.britishpenguin.astrowarrior.entity.enemy.SpaceshipEnemy;
import java.util.ArrayList;
public class PlayScreen implements Screen {
private OrthographicCamera camera;
private SpriteBatch batch;
private final AstroWarrior game;
public PlayScreen(AstroWarrior game) {
this.game = game;
camera = new OrthographicCamera(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
//camera.update();
batch = game.batch;
}
@Override
public void show() {
}
@Override
public void render(float delta) {
camera.translate(Gdx.graphics.getWidth() / 2f, Gdx.graphics.getHeight() / 2f, 0);
camera.update();
batch.setProjectionMatrix(camera.combined);
Gdx.gl.glClearColor(0, 0, 0, 1);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
batch.begin();
for (Entity entity : new ArrayList<>(game.renderedSprites)) {
if (entity.isBeingDamaged()) {
entity.setColor(0.6f, 0.6f, 0.6f, 1f);
}
entity.update(Gdx.graphics.getDeltaTime(), batch);
entity.draw(batch);
entity.setColor(1, 1, 1, 1);
}
game.fontRenderer.draw(batch, "Health: " + game.player.getCurrentHealth() + " | Mana: " + game.player.getCurrentMana() + " | Difficulty: " + game.difficulty, 10, Gdx.graphics.getHeight() - 10);
batch.end();
if (game.gameSettings.keySpawnEnemy.isPressed()) {
game.renderedSprites.add(new SpaceshipEnemy(game, MathUtils.random(0, Gdx.graphics.getWidth()), MathUtils.random(0, Gdx.graphics.getHeight()), MathUtils.random(0f, 360f)));
}
if (game.renderedSprites.stream().filter(e -> e instanceof SpaceshipEnemy).count() < 1) {
game.nextWave();
}
try {
Thread.sleep(1000);
} catch (Exception e) {}
}
@Override
public void resize(int width, int height) {
camera.viewportWidth = width;
camera.viewportHeight = height;
camera.update();
}
@Override
public void pause() {
}
@Override
public void resume() {
}
@Override
public void hide() {
}
@Override
public void dispose() {
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment