changing to a different way of handling entities (no longer using scene2d)

This commit is contained in:
2018-02-01 14:59:51 -06:00
parent 08fb879b1f
commit 1fbdefaecd
19 changed files with 138 additions and 1164 deletions

View File

@@ -9,11 +9,8 @@ import zero1hd.rhythmbullet.RhythmBullet;
import zero1hd.rhythmbullet.audio.AudioDataPackage;
import zero1hd.rhythmbullet.entity.EntityManager;
import zero1hd.rhythmbullet.entity.coordinator.CoordinatorManager;
import zero1hd.rhythmbullet.util.MiniEvents;
import zero1hd.rhythmbullet.util.MiniSender;
public class RhythmMapAlgorithm implements Runnable {
private MiniSender sender;
private EntityManager em;
private CoordinatorManager cm;
@@ -38,8 +35,6 @@ public class RhythmMapAlgorithm implements Runnable {
this.cm = cm;
this.em = em;
sender = new MiniSender();
bassPeaks = adp.getBassPeaks();
mPeaks = adp.getmPeaks();
umPeaks = adp.getuMPeaks();
@@ -64,82 +59,8 @@ public class RhythmMapAlgorithm implements Runnable {
@Override
public void run() {
map.beginBuild();
for (int index = 0; index < bassPeaks.size; index++) {
if (bassPeaks.get(index) != 0 || umPeaks.get(index) != 0) {
if (bassPeaks.get(index) != 0) {
//If there is a value of some sorts that is not zero, we generate some beat for the map
if (index > 1.5*windowPerSecond && bassPeaks.get(index) > avgBass) {
//If bass peak is greater than the bass peak average, then:
int normalIndexPos = map.setIndex((int) (map.getIndex() - windowPerSecond*1.5f));
float waitTime = 1.5f;
float endRadius = (bassPeaks.get(index)/bassMax)*(RhythmBullet.GAME_AREA_HEIGHT/4f);
esi = map.addEntity(em.voidCircle, null);
esi.parameters.put("warningTime", waitTime);
esi.parameters.put("endRadius", endRadius);
esi.parameters.put("growthRate", endRadius/(avgSPB*0.8f));
esi.parameters.put("x", rand.nextFloat()*RhythmBullet.GAME_AREA_WIDTH);
esi.parameters.put("y", rand.nextFloat()*RhythmBullet.GAME_AREA_HEIGHT);
map.setIndex(normalIndexPos);
} else {
}
}
if (umPeaks.get(index) != 0) {
if (umPeaks.get(index) >= avgUM*1.75f) {
//If upper midrange peaks are greater than average, the:
esi = map.addEntity(em.flake, null);
float xSpawn = (rand.nextFloat()*RhythmBullet.GAME_AREA_WIDTH) < RhythmBullet.GAME_AREA_WIDTH/2f ? 0 : RhythmBullet.GAME_AREA_WIDTH;
float ySpawn = (rand.nextFloat()*RhythmBullet.GAME_AREA_HEIGHT < RhythmBullet.GAME_AREA_HEIGHT/2f ? 0 : RhythmBullet.GAME_AREA_HEIGHT);
float angle = rand.nextFloat()*90;
if (xSpawn == 0) {
if (ySpawn != 0) {
angle += 270;
}
} else {
if (ySpawn == 0) {
angle += 90;
} else {
angle += 180;
}
}
esi.parameters.put("shardCount", (1f+(difficultyMod/100f))*4f);
esi.parameters.put("x", xSpawn);
esi.parameters.put("y", ySpawn);
esi.parameters.put("rate", (5/avgSPB)*speedMod);
esi.parameters.put("fuse", avgSPB*10f);
esi.parameters.put("angle", angle);
} else {
}
}
if (rand.nextFloat() < 0.15f) {
switch(rand.nextInt(10)) {
case 0:
break;
}
}
}
map.nextWindowData();
progress = MathUtils.round(100f*index/bassPeaks.size);
if (bassPeaks.get(index) > avgBass) {
map.setHUDType((byte) 1);
} else if (umPeaks.get(index) > avgUM) {
map.setHUDType((byte) 2);
}
sender.send(MiniEvents.MAPGEN_ITERATED);
}
//TODO Map gen algorithm
map.endBuild();
sender.send(MiniEvents.MAP_GENERATED);
}
public synchronized GamePlayMap getMap() {
@@ -149,8 +70,4 @@ public class RhythmMapAlgorithm implements Runnable {
public synchronized int getProgress() {
return progress;
}
public MiniSender getSender() {
return sender;
}
}

View File

@@ -86,12 +86,14 @@ public class AnalysisPage extends Page {
speedModifierSlider.setDisabled(true);
healthModifierSlider.setDisabled(true);
difficultyModifierSlider.setDisabled(true);
progressLabel.setText("Loading...");
}
});
adjustment.add(confirmButton).colspan(3).fillX();
adjustment.row();
progressLabel = new Label("Loading... ", skin);
progressLabel = new Label("Please confirm... ", skin);
adjustment.add(progressLabel).colspan(2).left().spaceTop(20f);
backButton = new TextButton("Cancel", skin);
@@ -127,9 +129,11 @@ public class AnalysisPage extends Page {
@Override
public void act(float delta) {
if (aa != null && aa.isDone() && confirmed) {
//TODO GAMESCREEN!!!
}
if (aa != null && aa.isDone()) {
if (confirmed) {
}
}
super.act(delta);
}

View File

@@ -1,119 +0,0 @@
package zero1hd.rhythmbullet.desktop.graphics.ui.windows;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Input.Keys;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.scenes.scene2d.ui.List;
import com.badlogic.gdx.scenes.scene2d.ui.ScrollPane;
import com.badlogic.gdx.scenes.scene2d.ui.Skin;
import com.badlogic.gdx.scenes.scene2d.ui.Slider;
import com.badlogic.gdx.scenes.scene2d.ui.Window;
import com.badlogic.gdx.utils.Array;
import zero1hd.rhythmbullet.entity.Entity;
import zero1hd.rhythmbullet.entity.EntityFrame;
import zero1hd.rhythmbullet.entity.EntityManager;
import zero1hd.rhythmbullet.entity.ally.Laser;
import zero1hd.rhythmbullet.entity.coordinator.Coordinator;
import zero1hd.rhythmbullet.entity.coordinator.CoordinatorFrame;
import zero1hd.rhythmbullet.entity.coordinator.CoordinatorManager;
import zero1hd.rhythmbullet.entity.enemies.Flake;
import zero1hd.rhythmbullet.entity.enemies.Pellet;
import zero1hd.rhythmbullet.entity.enemies.Shard;
import zero1hd.rhythmbullet.entity.enemies.VoidCircle;
public class SpawnerWindow extends Window {
private Stage stage;
private Array<EntityFrame<? extends Entity>> entityFrames = new Array<>();
private List<EntityFrame<? extends Entity>> listOfEntities;
private ScrollPane entityListScroller;
private Array<CoordinatorFrame<? extends Coordinator>> coordinatorFrames = new Array<>();
private List<CoordinatorFrame<? extends Coordinator>> listOfCoordinators;
private ScrollPane coordinatorListScroller;
private Slider mod1;
private Slider mod2;
private Slider mod3;
private Slider mod4;
public SpawnerWindow(String title, Skin skin, EntityManager em, CoordinatorManager cm, Stage stageForEntities) {
super(title, skin, "tinted");
stage = stageForEntities;
defaults().pad(15f);
mod1 = new Slider(0.1f, 50f, 0.01f, true, skin);
mod2 = new Slider(0f, 15f, 0.01f, true, skin);
mod3 = new Slider(0.1f, 15f, 0.01f, true, skin);
mod4 = new Slider(1f, 12f, 0.01f, true, skin);
add(mod1, mod2, mod3, mod4);
listOfEntities = new List<>(skin);
entityFrames.add(em.flake);
entityFrames.add(em.laser);
entityFrames.add(em.pellet);
entityFrames.add(em.shard);
entityFrames.add(em.voidCircle);
listOfEntities.setItems(entityFrames);
entityListScroller = new ScrollPane(listOfEntities, skin);
add(entityListScroller).width(100f).fillY();
listOfCoordinators = new List<>(skin);
coordinatorFrames.add(cm.slowLeft);
coordinatorFrames.add(cm.slowRight);
listOfCoordinators.setItems(coordinatorFrames);
coordinatorListScroller = new ScrollPane(listOfCoordinators, skin);
add(coordinatorListScroller).width(100f).fillY();
pack();
}
@Override
public boolean remove() {
return super.remove();
}
private Vector2 coords = new Vector2();
@Override
public void act(float delta) {
if (Gdx.input.justTouched() && Gdx.input.isKeyPressed(Keys.CONTROL_LEFT)) {
coords.set(Gdx.input.getX(), Gdx.input.getY());
stage.screenToStageCoordinates(coords);
Entity entity = listOfEntities.getSelected().buildEntity();
if (Gdx.input.isKeyPressed(Keys.ALT_LEFT)) {
entity.setCoordinator(listOfCoordinators.getSelected().buildCoordinator());
}
if (entity.getClass() == Laser.class) {
Laser laser = (Laser) entity;
laser.init(coords.x, coords.y, mod1.getValue());
} else if (entity.getClass() == Pellet.class) {
Pellet pellet = (Pellet) entity;
pellet.init(coords.x, coords.y, mod2.getValue()/mod2.getMaxValue()*360f, mod1.getValue());
} else if (entity.getClass() == VoidCircle.class) {
VoidCircle voidCircle = (VoidCircle) entity;
voidCircle.init(mod2.getValue(), coords.x, coords.y, mod1.getValue(), mod3.getValue());
} else if (entity.getClass() == Shard.class) {
Shard shard = (Shard) entity;
shard.init(coords.x, coords.y, mod2.getValue()/mod2.getMaxValue()*360f, mod1.getValue(), (int) mod3.getValue());
} else if (entity.getClass() == Flake.class) {
Flake flake = (Flake) entity;
flake.init(coords.x, coords.y, mod1.getValue(), mod3.getValue(), mod2.getValue()/mod2.getMaxValue()*360f, (int) mod4.getValue());
}
stage.addActor(entity);
}
super.act(delta);
}
}

View File

@@ -1,290 +0,0 @@
package zero1hd.rhythmbullet.desktop.screens;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.InputMultiplexer;
import com.badlogic.gdx.Screen;
import com.badlogic.gdx.ScreenAdapter;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.Pixmap.Format;
import com.badlogic.gdx.graphics.g2d.Batch;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.graphics.glutils.FrameBuffer;
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 com.badlogic.gdx.utils.viewport.ScreenViewport;
import zero1hd.rhythmbullet.RhythmBullet;
import zero1hd.rhythmbullet.desktop.audio.map.GamePlayMap;
import zero1hd.rhythmbullet.desktop.stages.GameHUD;
import zero1hd.rhythmbullet.desktop.stages.GamePlayArea;
import zero1hd.rhythmbullet.util.MusicManager;
public class GameScreen extends ScreenAdapter {
protected GamePlayArea gameArea;
public GameHUD gameHUD;
protected InputMultiplexer inputs;
public RhythmBullet core;
private MusicManager music;
private ShaderProgram gaussianBlurShader;
private ShaderProgram brightFilterShader;
private ShaderProgram combineShader;
private FrameBuffer lightFilterBuffer;
private FrameBuffer normalBuffer;
private FrameBuffer hBlur, vBlur;
private TextureRegion fboRegion;
private int fboSize;
private Batch batch;
private ScreenViewport screenViewport;
private int blurlvl = 4;
/**
* 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) {
this.core = core;
// 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();
}
});
gameArea = new GamePlayArea(core.getAssetManager(), core.getPrefs());
gameHUD = new GameHUD(core.getDefaultSkin(), 100f, gameArea, screen, core);
inputs = new InputMultiplexer();
inputs.addProcessor(gameHUD);
inputs.addProcessor(gameArea);
}
public void setGamePlayMap(GamePlayMap gpm) {
music = gpm.getMusicData();
gameArea.setAudioMap(gpm);
gameHUD.setMusic(gpm.getMusicData());
}
@Override
public void show() {
Gdx.input.setInputProcessor(inputs);
loadShaders();
super.show();
}
/**
* needs to be called right after set as screen (should be called in show method).
* This is due to the saving preference being done once the screen is hidden.
* @param prefs
*/
public void loadShaders() {
if (core.getPrefs().getBoolean("glow shader")) {
batch = new SpriteBatch();
screenViewport = new ScreenViewport();
Gdx.app.debug("Shader", "using glow shader");
brightFilterShader = new ShaderProgram(Gdx.files.internal("shaders/basic.vsh"), Gdx.files.internal("shaders/bright_filter.fsh"));
if (!brightFilterShader.isCompiled()) {
Gdx.app.error("Shader failed to compile", brightFilterShader.getLog());
System.exit(0);
}
if (brightFilterShader.getLog().length() != 0) {
Gdx.app.error("Shader", brightFilterShader.getLog());
}
gaussianBlurShader = new ShaderProgram(Gdx.files.internal("shaders/basic.vsh"), Gdx.files.internal("shaders/gaussian_blur.fsh"));
if (!gaussianBlurShader.isCompiled()) {
Gdx.app.error("Shader failed to compile", gaussianBlurShader.getLog());
System.exit(0);
}
if (gaussianBlurShader.getLog().length() != 0) {
Gdx.app.error("Shader", gaussianBlurShader.getLog());
}
combineShader = new ShaderProgram(Gdx.files.internal("shaders/basic.vsh"), Gdx.files.internal("shaders/combine.fsh"));
if (!combineShader.isCompiled()) {
Gdx.app.error("Shader failed to compile", combineShader.getLog());
System.exit(0);
}
if (combineShader.getLog().length() != 0) {
Gdx.app.error("Shader", combineShader.getLog());
}
if (Gdx.graphics.getWidth() < 1024) {
fboSize = 2048;
} else if (Gdx.graphics.getWidth() < 2048) {
fboSize = 4096;
} else {
fboSize = 4096;
}
lightFilterBuffer = new FrameBuffer(Format.RGBA8888, fboSize/2, fboSize/2, false);
normalBuffer = new FrameBuffer(Format.RGBA8888, fboSize, fboSize, false);
hBlur = new FrameBuffer(Format.RGBA8888, fboSize/2, fboSize/2, false);
vBlur = new FrameBuffer(Format.RGBA8888, fboSize/2, fboSize/2, false);
fboRegion = new TextureRegion(normalBuffer.getColorBufferTexture());
fboRegion.flip(false, true);
combineShader.begin();
combineShader.setUniformi("u_texture1", 1);
combineShader.end();
vBlur.getColorBufferTexture().bind(1);
Gdx.gl.glActiveTexture(GL20.GL_TEXTURE0);
}
ShaderProgram.pedantic = false;
}
@Override
public void render(float delta) {
Gdx.gl.glClearColor(0f, 0f, 0f, 1f);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
//actual game and hud
if (!gameHUD.isPaused()) {
gameArea.act(delta);
if (gameArea.getPolyjetEntity().isDead()) {
end(false);
}
gameHUD.act(delta);
}
gameArea.getViewport().apply();
blurlvl = 4;
if (gaussianBlurShader != null) {
//Begin drawing a normal version of screen
gameArea.getViewport().apply();
normalBuffer.begin();
Gdx.gl.glClearColor(0.22f, 0f, 0f, 1f);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
gameArea.draw();
normalBuffer.end();
//END STAGE BATCH
//BEGINNING NORMAL SCREEN RENDER
screenViewport.apply();
//Begin light filtering
lightFilterBuffer.begin();
Gdx.gl.glClearColor(0f, 0f, 0f, 1f);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
fboRegion.setTexture(normalBuffer.getColorBufferTexture());
batch.setShader(brightFilterShader);
batch.begin(); //BATCH STARTS HERE
batch.draw(fboRegion, 0, 0, gameArea.getWidth(), gameArea.getHeight());
batch.flush();
lightFilterBuffer.end();
for (int i = 0; i < blurlvl; i++) {
//Horizontal gaussian blur
hBlur.begin();
if (i > 0) {
fboRegion.setTexture(vBlur.getColorBufferTexture());
} else {
fboRegion.setTexture(lightFilterBuffer.getColorBufferTexture());
} batch.setShader(gaussianBlurShader);
gaussianBlurShader.setUniformi("horizontal", 1);
batch.draw(fboRegion, 0f, 0f, gameArea.getWidth(), gameArea.getHeight());
batch.flush();
hBlur.end();
//Vertical gaussian blur
vBlur.begin();
fboRegion.setTexture(hBlur.getColorBufferTexture());
batch.setShader(gaussianBlurShader);
gaussianBlurShader.setUniformi("horizontal", 0);
batch.draw(fboRegion, 0f, 0f, gameArea.getWidth(), gameArea.getHeight());
batch.flush();
vBlur.end();
}
//draw a final copy to a fbo
Gdx.gl.glClearColor(0f, 0f, 0f, 0f);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
batch.setShader(combineShader);
fboRegion.setTexture(normalBuffer.getColorBufferTexture());
batch.draw(fboRegion, 0f, 0f, gameArea.getWidth(), gameArea.getHeight());
batch.setShader(null);
batch.end(); //STAGE BATCH ENDS HERE
} else {
gameArea.draw();
}
gameHUD.getViewport().apply();
gameHUD.draw();
if (music != null && !music.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();
if (gaussianBlurShader != null) {
normalBuffer.dispose();
lightFilterBuffer.dispose();
hBlur.dispose();
vBlur.dispose();
brightFilterShader.dispose();
gaussianBlurShader.dispose();
combineShader.dispose();
gaussianBlurShader.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);
}
public GamePlayArea getGameArea() {
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.play();
}
}
}

View File

@@ -1,18 +1,15 @@
package zero1hd.rhythmbullet.desktop.stages;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.InputProcessor;
import com.badlogic.gdx.Preferences;
import com.badlogic.gdx.assets.AssetManager;
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.utils.viewport.FitViewport;
import com.badlogic.gdx.graphics.g2d.Batch;
import com.badlogic.gdx.utils.Disposable;
import zero1hd.rhythmbullet.RhythmBullet;
import zero1hd.rhythmbullet.controls.KeyMap;
import zero1hd.rhythmbullet.desktop.audio.map.EntitySpawnInfo;
import zero1hd.rhythmbullet.desktop.audio.map.GamePlayMap;
import zero1hd.rhythmbullet.desktop.audio.map.MapWindowData;
import zero1hd.rhythmbullet.entity.CollisionDetector;
import zero1hd.rhythmbullet.entity.Entity;
import zero1hd.rhythmbullet.entity.EntityManager;
import zero1hd.rhythmbullet.entity.ally.Laser;
import zero1hd.rhythmbullet.entity.ally.PolyjetEntity;
@@ -20,7 +17,7 @@ import zero1hd.rhythmbullet.entity.coordinator.CoordinatorManager;
import zero1hd.rhythmbullet.util.ScoreManager;
public class GamePlayArea extends Stage {
public class GameController implements Disposable, InputProcessor {
public PolyjetEntity polyjet;
private GamePlayMap audioMap;
@@ -30,17 +27,35 @@ public class GamePlayArea extends Stage {
public ScoreManager score = new ScoreManager();
public GamePlayArea(AssetManager assetManager, Preferences prefs) {
super(new FitViewport(RhythmBullet.GAME_AREA_WIDTH, RhythmBullet.GAME_AREA_HEIGHT));
public GameController(AssetManager assetManager, Preferences prefs) {
Gdx.app.debug("Game Area", "new area created");
polyjet = new PolyjetEntity(assetManager, 25f, 25f, 100, "standard");
em = new EntityManager(assetManager, prefs, this);
em = new EntityManager(assetManager, prefs);
cm = new CoordinatorManager(em);
collisionDetector = new CollisionDetector(em.activeEnemies, em.activeAllies, assetManager, prefs);
em.activeAllies.add(polyjet);
addActor(polyjet);
}
public void draw(Batch batch) {
batch.begin();
for (int i = 0; i < em.activeEnemies.size; i++) {
em.activeEnemies.get(i).draw(batch);
}
for (int i = 0; i < em.activeAllies.size; i++) {
em.activeAllies.get(i).draw(batch);
}
batch.end();
}
public void prepare(float delta) {
for (int i = 0; i < em.activeEnemies.size; i++) {
em.activeEnemies.get(i).updatePosition();
}
for (int i = 0; i < em.activeAllies.size; i++) {
em.activeAllies.get(i).updatePosition();
}
}
public void setAudioMap(GamePlayMap audioMap) {
@@ -51,38 +66,6 @@ public class GamePlayArea extends Stage {
return audioMap;
}
@Override
public void draw() {
super.draw();
}
@Override
public void act(float delta) {
MapWindowData mwd;
if (audioMap != null && audioMap.getMusicData().isPlaying()) {
audioMap.getMusicData().playbackIndexUpdate();
if ((mwd = audioMap.getCurrentWindowBasedOnIndex()) != null) {
EntitySpawnInfo[] currentSpawnInfo = mwd.getArray();
if (currentSpawnInfo != null) {
for (int i = 0; i < currentSpawnInfo.length; i++) {
Entity entity = currentSpawnInfo[i].getEntityToSpawn().buildEntity();
if (currentSpawnInfo[i].getEntityCoordinator() != null) {
entity.setCoordinator(currentSpawnInfo[i].getEntityCoordinator().buildCoordinator());
}
entity.init(currentSpawnInfo[i].parameters);
addActor(entity);
}
}
}
}
collisionDetector.collisionCheck();
score.addScore(collisionDetector.getAmassedPoints());
super.act(delta);
}
@Override
public boolean keyDown(int keycode) {
if (keycode == KeyMap.left) {
@@ -128,7 +111,6 @@ public class GamePlayArea extends Stage {
if (keycode == KeyMap.shoot) {
Laser laser = em.laser.buildEntity();
laser.init(polyjet.getX() + polyjet.getWidth()/2f, polyjet.getY() + polyjet.getHeight()+1f, 60f);
addActor(laser);
}
return false;
}
@@ -139,10 +121,39 @@ public class GamePlayArea extends Stage {
@Override
public void dispose() {
super.dispose();
}
public CollisionDetector getCollisionDetector() {
return collisionDetector;
}
@Override
public boolean keyTyped(char character) {
return false;
}
@Override
public boolean touchDown(int screenX, int screenY, int pointer, int button) {
return false;
}
@Override
public boolean touchUp(int screenX, int screenY, int pointer, int button) {
return false;
}
@Override
public boolean touchDragged(int screenX, int screenY, int pointer) {
return false;
}
@Override
public boolean mouseMoved(int screenX, int screenY) {
return false;
}
@Override
public boolean scrolled(int amount) {
return false;
}
}

View File

@@ -1,241 +0,0 @@
package zero1hd.rhythmbullet.desktop.stages;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Input.Keys;
import com.badlogic.gdx.Screen;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.Pixmap;
import com.badlogic.gdx.graphics.Pixmap.Format;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.Texture.TextureFilter;
import com.badlogic.gdx.scenes.scene2d.Actor;
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.scenes.scene2d.actions.Actions;
import com.badlogic.gdx.scenes.scene2d.ui.Image;
import com.badlogic.gdx.scenes.scene2d.ui.ImageButton;
import com.badlogic.gdx.scenes.scene2d.ui.Label;
import com.badlogic.gdx.scenes.scene2d.ui.Skin;
import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener;
import zero1hd.rhythmbullet.RhythmBullet;
import zero1hd.rhythmbullet.desktop.graphics.ui.components.HealthBar;
import zero1hd.rhythmbullet.desktop.graphics.ui.windows.FPSWindow;
import zero1hd.rhythmbullet.desktop.graphics.ui.windows.PauseMenu;
import zero1hd.rhythmbullet.util.MusicManager;
import zero1hd.rhythmbullet.util.ScoreManager;
public class GameHUD extends Stage {
private Screen returnScreen;
private Label scoreLabel;
private ImageButton pause;
private boolean paused;
private FPSWindow fpsWindow;
private PauseMenu pauseMenu;
private HealthBar healthBar;
private Pixmap pixmap;
private Texture leftStatTexture;
private Texture rightStatTexture;
private Image leftStatusBar;
private Image rightStatusBar;
private GamePlayArea gpa;
private MusicManager music;
private ScoreManager sm;
private Color original, bass, um;
public GameHUD(Skin skin, float maxHealth, GamePlayArea gpa, Screen rs, final RhythmBullet core) {
super();
scoreLabel = new Label("Score: 0", skin, "default-font", Color.WHITE);
scoreLabel.setPosition(10f, Gdx.graphics.getHeight()-scoreLabel.getHeight() - 10f);
addActor(scoreLabel);
this.sm = gpa.score;
this.gpa = gpa;
this.returnScreen = rs;
pause = new ImageButton(skin.getDrawable("pause"),
skin.getDrawable("pause-down"));
pause.setPosition(Gdx.graphics.getWidth() - pause.getWidth() - 15f,
Gdx.graphics.getHeight() - pause.getHeight() - 15f);
pause.addListener(new ChangeListener() {
@Override
public void changed(ChangeEvent event, Actor actor) {
setPaused(true);
}
});
addActor(pause);
fpsWindow = new FPSWindow("FPS", skin);
fpsWindow.setPosition(15f, 15f);
pauseMenu = new PauseMenu(skin);
pauseMenu.getResumeButton().addListener(new ChangeListener() {
@Override
public void changed(ChangeEvent event, Actor actor) {
setPaused(false);
}
});
pauseMenu.getQuitButton().addListener(new ChangeListener() {
@Override
public void changed(ChangeEvent event, Actor actor) {
core.setScreen(returnScreen);
}
});
pauseMenu.setPosition((Gdx.graphics.getWidth()-pauseMenu.getWidth())/2f, (Gdx.graphics.getHeight()-pauseMenu.getHeight())/2f);
healthBar = new HealthBar(skin, maxHealth);
healthBar.setSize(30f, Gdx.graphics.getHeight()/3);
healthBar.setHealth(maxHealth);
healthBar.setPosition(Gdx.graphics.getWidth() -(gpa.getViewport().getRightGutterWidth()/4f), (Gdx.graphics.getHeight()-healthBar.getHeight())/2f);
addActor(healthBar);
healthBar.setPolyjetEntity(gpa.getPolyjetEntity());
pixmap = new Pixmap(3, 3, Format.RGBA8888);
int excess = 2*gpa.getViewport().getLeftGutterWidth()/pixmap.getWidth();
Gdx.app.debug("GHUD", "offset on size: " + excess);
pixmap.setColor(Color.WHITE);
pixmap.drawLine(0, 0, 0, 2);
pixmap.setColor(1f, 1f, 1f, 0.5f);
pixmap.drawLine(1, 0, 1, 2);
leftStatTexture = new Texture(pixmap);
leftStatTexture.setFilter(TextureFilter.Linear, TextureFilter.Linear);
leftStatusBar = new Image(leftStatTexture);
leftStatusBar.setSize(gpa.getViewport().getLeftGutterWidth()+excess, getHeight());
leftStatusBar.setPosition(0, 0);
addActor(leftStatusBar);
leftStatusBar.toBack();
pixmap.dispose();
pixmap = new Pixmap(3, 3, Format.RGBA8888);
pixmap.setColor(Color.WHITE);
pixmap.drawLine(2, 0, 2, 2);
pixmap.setColor(1f, 1f, 1f, 0.5f);
pixmap.drawLine(1, 0, 1, 2);
rightStatTexture = new Texture(pixmap);
rightStatTexture.setFilter(TextureFilter.Linear, TextureFilter.Linear);
rightStatusBar = new Image(rightStatTexture);
rightStatusBar.setSize(gpa.getViewport().getRightGutterWidth()+excess, getHeight());
rightStatusBar.setPosition(getWidth()-gpa.getViewport().getRightGutterWidth()-excess, 0f);
addActor(rightStatusBar);
rightStatusBar.toBack();
pixmap.dispose();
original = new Color(0.6f, 0.8f, 255f, 0.55f);
bass = new Color(0.8f, 0, 1, 0.9f);
um = new Color(1f, 0.6f, 0.4f, 0.9f);
setStatusColor(original);
}
@Override
public void act(float delta) {
if (sm.checkDifferent()) {
setScore(sm.getScore());
}
if (gpa.getAudioMap() != null && gpa.getAudioMap().getHudType().length > gpa.getAudioMap().getIndex()) {
if (gpa.getAudioMap() != null && gpa.getAudioMap().getHudType()[gpa.getAudioMap().getIndex()] != 0) {
switch (gpa.getAudioMap().getHudType()[gpa.getAudioMap().getIndex()]) {
case 1:
changeStatusColor(bass, 0.2f, original);
break;
case 2:
changeStatusColor(um, 0.2f, original);
}
}
}
super.act(delta);
}
/**
* sets the label for scoring to the designated score
* @param score designated score
*/
public void setScore(int score) {
this.scoreLabel.setText("Score: " + score);
}
public void setPaused(boolean paused) {
if (paused) {
addActor(pauseMenu);
if (music != null) {
music.pause();
}
} else {
pauseMenu.remove();
if (music != null) {
music.play();
}
}
this.paused = paused;
}
/**
* toggle's between the two states of paused and unpaused
* @return whatever the new game state is (true for paused)
*/
public boolean togglePause() {
if (isPaused()) {
setPaused(false);
} else {
setPaused(true);
}
return isPaused();
}
public boolean isPaused() {
return paused;
}
@Override
public boolean keyUp(int keycode) {
switch (keycode) {
case Keys.F3:
if (fpsWindow.hasParent()) {
fpsWindow.remove();
} else {
addActor(fpsWindow);
}
break;
case Keys.ESCAPE:
togglePause();
break;
default:
break;
}
return false;
}
public void setMusic(MusicManager music) {
this.music = music;
}
public void setStatusColor(Color color) {
leftStatusBar.setColor(color);
rightStatusBar.setColor(color);
}
public void setLeftStatusColor(Color color) {
leftStatusBar.setColor(color);
}
public void setRightStatusColor(Color color) {
rightStatusBar.setColor(color);
}
public void changeStatusColor(Color color, float duration, Color endColor) {
leftStatusBar.clearActions();
rightStatusBar.clearActions();
leftStatusBar.addAction(Actions.sequence(Actions.color(color, duration*0.8f), Actions.color(endColor, duration)));
rightStatusBar.addAction(Actions.sequence(Actions.color(color, duration*0.8f), Actions.color(endColor, duration)));
}
public HealthBar getHealthBar() {
return healthBar;
}
@Override
public void dispose() {
leftStatTexture.dispose();
rightStatTexture.dispose();
super.dispose();
}
}