159 lines
4.1 KiB
Java
Executable File
159 lines
4.1 KiB
Java
Executable File
package zero1hd.polyjet.screens;
|
|
|
|
import com.badlogic.gdx.Gdx;
|
|
import com.badlogic.gdx.InputMultiplexer;
|
|
import com.badlogic.gdx.ScreenAdapter;
|
|
import com.badlogic.gdx.graphics.GL20;
|
|
import com.badlogic.gdx.graphics.Texture;
|
|
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
|
|
import com.badlogic.gdx.graphics.glutils.ShaderProgram;
|
|
import com.badlogic.gdx.scenes.scene2d.Actor;
|
|
import com.badlogic.gdx.scenes.scene2d.ui.ImageButton;
|
|
import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener;
|
|
|
|
import zero1hd.polyjet.Main;
|
|
import zero1hd.polyjet.audio.AudioData;
|
|
import zero1hd.polyjet.audio.map.GamePlayMap;
|
|
import zero1hd.polyjet.ui.stages.GameHUD;
|
|
import zero1hd.polyjet.ui.stages.GamePlayArea;
|
|
|
|
public class GameScreen extends ScreenAdapter {
|
|
private GamePlayArea gameArea;
|
|
private GameHUD gameHUD;
|
|
|
|
public InputMultiplexer inputs;
|
|
|
|
public Main core;
|
|
|
|
private AudioData music;
|
|
|
|
SpriteBatch bgBatch;
|
|
private ShaderProgram bgShader;
|
|
private Texture background;
|
|
|
|
public GameScreen(Main polyJet, GamePlayMap gpm) {
|
|
core = polyJet;
|
|
|
|
// Overlay stuff
|
|
ImageButton pause = new ImageButton(core.getDefaultSkin().getDrawable("pause"),
|
|
core.getDefaultSkin().getDrawable("pause-down"));
|
|
pause.setPosition(Gdx.graphics.getWidth() - pause.getWidth() - 25,
|
|
Gdx.graphics.getHeight() - pause.getHeight() - 25);
|
|
pause.addListener(new ChangeListener() {
|
|
@Override
|
|
public void changed(ChangeEvent event, Actor actor) {
|
|
pause();
|
|
}
|
|
});
|
|
|
|
music = gpm.getMusicData();
|
|
|
|
gameArea = new GamePlayArea(polyJet.getAssetManager(), core.getPrefs());
|
|
gameArea.setAudioMap(gpm);
|
|
gameHUD = new GameHUD(polyJet.getDefaultSkin(), gpm.getMusicData().getPlaybackMusic(), gameArea.getMaxHealth());
|
|
|
|
inputs = new InputMultiplexer();
|
|
inputs.addProcessor(gameHUD);
|
|
inputs.addProcessor(gameArea);
|
|
|
|
background = core.getAssetManager().get("star_bg.png");
|
|
}
|
|
|
|
@Override
|
|
public void show() {
|
|
Gdx.input.setInputProcessor(inputs);
|
|
gameArea.loadShaders(core.getPrefs());
|
|
|
|
if (!gameHUD.isPaused()) {
|
|
music.getPlaybackMusic().play();
|
|
}
|
|
|
|
if (core.getPrefs().getBoolean("bg shader")) {
|
|
Gdx.app.debug("Shader", "using background shader");
|
|
|
|
bgShader = new ShaderProgram(Gdx.files.internal("shaders/bg.vsh"), Gdx.files.internal("shaders/bg.fsh"));
|
|
|
|
if (!bgShader.isCompiled()) {
|
|
System.err.println(bgShader.getLog());
|
|
System.exit(0);
|
|
}
|
|
if (bgShader.getLog().length()!=0) {
|
|
System.out.println(bgShader.getLog());
|
|
}
|
|
|
|
bgBatch = new SpriteBatch(2, bgShader);
|
|
} else {
|
|
bgBatch = new SpriteBatch(2);
|
|
}
|
|
super.show();
|
|
}
|
|
|
|
@Override
|
|
public void render(float delta) {
|
|
Gdx.gl.glClearColor(0f, 0f, 0f, 0f);
|
|
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT | GL20.GL_DEPTH_BUFFER_BIT);
|
|
bgBatch.begin();
|
|
if (bgShader != null) {
|
|
bgBatch.setShader(bgShader);
|
|
bgShader.setUniformf("resolution", Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
|
|
|
|
if (music != null) {
|
|
bgShader.setUniformf("time", music.getPlaybackMusic().getPosition());
|
|
}
|
|
}
|
|
bgBatch.draw(background, 0f, 0f, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
|
|
bgBatch.end();
|
|
|
|
gameArea.getViewport().apply();
|
|
gameArea.draw();
|
|
|
|
gameHUD.getViewport().apply();
|
|
gameHUD.draw();
|
|
if (!gameHUD.isPaused()) {
|
|
gameHUD.setScore(gameArea.getScore());
|
|
gameArea.act(delta);
|
|
|
|
if (gameArea.getPolyjet().isDead()) {
|
|
end(false);
|
|
}
|
|
|
|
gameHUD.act(delta);
|
|
}
|
|
|
|
if (!music.getPlaybackMusic().isPlaying()) {
|
|
end(true);
|
|
}
|
|
|
|
super.render(delta);
|
|
}
|
|
|
|
private void end(boolean trueEnd) {
|
|
if (trueEnd) {
|
|
// TODO they didn't die
|
|
} else {
|
|
// TODO They done goofed and ended up dying.
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public void dispose() {
|
|
gameHUD.dispose();
|
|
gameArea.dispose();
|
|
super.dispose();
|
|
}
|
|
|
|
@Override
|
|
public void pause() {
|
|
gameHUD.setPaused(true);
|
|
super.pause();
|
|
}
|
|
|
|
@Override
|
|
public void resize(int width, int height) {
|
|
gameArea.getViewport().update(width, height, true);
|
|
gameHUD.getViewport().update(width, height, true);
|
|
|
|
super.resize(width, height);
|
|
}
|
|
|
|
} |