improved structure by making game screen parent of creative screen

This commit is contained in:
Harrison Deng 2017-09-03 23:29:38 -05:00
parent 3e41c17d10
commit fd66c4703a
2 changed files with 25 additions and 41 deletions

View File

@ -1,59 +1,35 @@
package zero1hd.rhythmbullet.screens; package zero1hd.rhythmbullet.screens;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.InputMultiplexer;
import com.badlogic.gdx.Preferences; import com.badlogic.gdx.Preferences;
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 zero1hd.rhythmbullet.RhythmBullet; import zero1hd.rhythmbullet.RhythmBullet;
import zero1hd.rhythmbullet.stages.CreativeHUD; import zero1hd.rhythmbullet.stages.CreativeHUD;
import zero1hd.rhythmbullet.stages.GameHUD;
import zero1hd.rhythmbullet.stages.GamePlayArea;
public class CreativeScreen extends ScreenAdapter { public class CreativeScreen extends GameScreen {
CreativeHUD chud; CreativeHUD chud;
GameHUD ghud;
GamePlayArea gamePlayArea;
InputMultiplexer inputs;
Preferences prefs; Preferences prefs;
public CreativeScreen(RhythmBullet core, MainMenu mainMenu) { public CreativeScreen(RhythmBullet core, MainMenu mainMenu) {
gamePlayArea = new GamePlayArea(core.getAssetManager(), core.getPrefs()); super(core, mainMenu);
ghud = new GameHUD(core.getDefaultSkin(), 100f, gamePlayArea, mainMenu, core); chud = new CreativeHUD(core, mainMenu, gameArea, gameHUD);
chud = new CreativeHUD(core, mainMenu, gamePlayArea, ghud); inputs.addProcessor(chud);
inputs = new InputMultiplexer(chud, ghud, gamePlayArea);
this.prefs = core.getPrefs(); this.prefs = core.getPrefs();
} }
@Override @Override
public void show() { public void show() {
Gdx.input.setInputProcessor(inputs);
gamePlayArea.loadShaders(prefs);
super.show(); super.show();
} }
@Override @Override
public void render(float delta) { public void render(float delta) {
Gdx.gl.glClearColor(0.2f, 0.2f, 0.2f, 1f); super.render(delta);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
gamePlayArea.getViewport().apply();
gamePlayArea.act();
gamePlayArea.draw();
ghud.getViewport().apply();
ghud.act();
ghud.draw();
chud.getViewport().apply(); chud.getViewport().apply();
chud.act(); chud.act();
chud.draw(); chud.draw();
super.render(delta);
} }
@Override @Override

View File

@ -16,15 +16,20 @@ import zero1hd.rhythmbullet.stages.GameHUD;
import zero1hd.rhythmbullet.stages.GamePlayArea; import zero1hd.rhythmbullet.stages.GamePlayArea;
public class GameScreen extends ScreenAdapter { public class GameScreen extends ScreenAdapter {
private GamePlayArea gameArea;
private GameHUD gameHUD;
private InputMultiplexer inputs; protected GamePlayArea gameArea;
public GameHUD gameHUD;
protected InputMultiplexer inputs;
public RhythmBullet core; public RhythmBullet core;
private CoreMusicInfo music; private CoreMusicInfo music;
/**
* The game screen where the game play area, and hud are placed.
* @param core The game context object
* @param screen the screen to return to if player decides to press "quit" button.
*/
public GameScreen(RhythmBullet core, Screen screen) { public GameScreen(RhythmBullet core, Screen screen) {
this.core = core; this.core = core;
@ -56,20 +61,14 @@ public class GameScreen extends ScreenAdapter {
@Override @Override
public void show() { public void show() {
if (music == null) new NullPointerException("Idiot, you can't have a music game not have music on the gameplay screen...");
Gdx.input.setInputProcessor(inputs); Gdx.input.setInputProcessor(inputs);
gameArea.loadShaders(core.getPrefs()); gameArea.loadShaders(core.getPrefs());
if (!gameHUD.isPaused()) {
music.getPlaybackMusic().play();
}
super.show(); super.show();
} }
@Override @Override
public void render(float delta) { public void render(float delta) {
Gdx.gl.glClearColor(0f, 0f, 0f, 0f); Gdx.gl.glClearColor(0f, 0f, 0f, 1f);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
//actual game and hud //actual game and hud
if (!gameHUD.isPaused()) { if (!gameHUD.isPaused()) {
@ -80,10 +79,11 @@ public class GameScreen extends ScreenAdapter {
gameHUD.act(delta); gameHUD.act(delta);
} }
gameArea.getViewport().apply(); gameArea.getViewport().apply();
gameArea.draw(); gameArea.draw();
gameHUD.getViewport().apply(); gameHUD.getViewport().apply();
gameHUD.draw(); gameHUD.draw();
if (!music.getPlaybackMusic().isPlaying()) { if (music != null && !music.getPlaybackMusic().isPlaying()) {
end(true); end(true);
} }
@ -122,4 +122,12 @@ public class GameScreen extends ScreenAdapter {
public GamePlayArea getGameArea() { public GamePlayArea getGameArea() {
return gameArea; return gameArea;
} }
public void play() {
if (music == null) throw new NullPointerException("Idiot, you can't have a music game not have music on the gameplay screen...");
Gdx.input.setInputProcessor(inputs);
if (!gameHUD.isPaused()) {
music.getPlaybackMusic().play();
}
}
} }