From 29c30290fb827d7da1d2342b9813565d66225cc1 Mon Sep 17 00:00:00 2001 From: Recrown Date: Tue, 8 Aug 2017 02:26:34 -0500 Subject: [PATCH] added border to show status effects, preparing for better score system --- android/assets/uiskin.atlas | 7 +++++ ...{PolyJetEntity.java => PolyjetEntity.java} | 15 ++++------ .../rhythmbullet/entity/enemies/Bar.java | 4 +-- .../rhythmbullet/screens/CreativeScreen.java | 4 +-- .../rhythmbullet/screens/GameScreen.java | 7 ++--- .../rhythmbullet/ui/builders/HealthBar.java | 17 ++++++++++- .../rhythmbullet/ui/stages/GameHUD.java | 27 +++++++++++++---- .../rhythmbullet/ui/stages/GamePlayArea.java | 29 ++++++------------- .../rhythmbullet/util/ScoreManager.java | 17 +++++++++++ 9 files changed, 84 insertions(+), 43 deletions(-) rename core/src/zero1hd/rhythmbullet/entity/ally/{PolyJetEntity.java => PolyjetEntity.java} (83%) create mode 100755 core/src/zero1hd/rhythmbullet/util/ScoreManager.java diff --git a/android/assets/uiskin.atlas b/android/assets/uiskin.atlas index 183734c..cc17006 100755 --- a/android/assets/uiskin.atlas +++ b/android/assets/uiskin.atlas @@ -318,4 +318,11 @@ large-pane split: 4, 4, 13, 13 orig: 9, 27 offset: 0, 0 + index: -1 +gradient-bar + rotate: false + xy: 26, 7 + size: 3, 1 + orig: 3, 1 + offset: 0, 0 index: -1 \ No newline at end of file diff --git a/core/src/zero1hd/rhythmbullet/entity/ally/PolyJetEntity.java b/core/src/zero1hd/rhythmbullet/entity/ally/PolyjetEntity.java similarity index 83% rename from core/src/zero1hd/rhythmbullet/entity/ally/PolyJetEntity.java rename to core/src/zero1hd/rhythmbullet/entity/ally/PolyjetEntity.java index a6adae4..266e3c0 100755 --- a/core/src/zero1hd/rhythmbullet/entity/ally/PolyJetEntity.java +++ b/core/src/zero1hd/rhythmbullet/entity/ally/PolyjetEntity.java @@ -9,26 +9,24 @@ import com.badlogic.gdx.scenes.scene2d.actions.Actions; import zero1hd.rhythmbullet.RhythmBullet; import zero1hd.rhythmbullet.entity.Entity; -import zero1hd.rhythmbullet.ui.builders.HealthBar; -public class PolyJetEntity extends Entity { +public class PolyjetEntity extends Entity { public float health; private ParticleEffect thrust; private Texture polyjet; private ParticleEffect teleportCloak; - private HealthBar hpBar; public boolean moveLeft, moveRight, moveUp, moveDown, teleporting, accelerate; private float speed, accel; private float rate; - public PolyJetEntity(AssetManager assets, float speed, float accel, String jet, HealthBar hpBar) { + private int maxH; + public PolyjetEntity(AssetManager assets, float speed, float accel,int maxHealth, String jet) { nonStnrd = true; health = 100; this.speed = speed; this.accel = accel; - this.hpBar = hpBar; setSize(1.5f, 1.5f); setPosition(RhythmBullet.GAME_AREA_WIDTH/2 - getWidth()/2, -4f); - + maxH = maxHealth; hitbox = new Rectangle(getX(), getY(), getWidth(), getHeight()); polyjet = assets.get("polyjet-" + jet + ".png", Texture.class); thrust = assets.get("standard_thrust.p", ParticleEffect.class); @@ -72,8 +70,8 @@ public class PolyJetEntity extends Entity { if (health <= 0) { dead = true; - } else if (health > hpBar.getMaxHealth()) { - health = hpBar.getMaxHealth(); + } else if (health > maxH) { + health = maxH; } super.act(delta); @@ -95,7 +93,6 @@ public class PolyJetEntity extends Entity { } public void setHealth(float health) { - hpBar.setHealth(health); this.health = health; } } diff --git a/core/src/zero1hd/rhythmbullet/entity/enemies/Bar.java b/core/src/zero1hd/rhythmbullet/entity/enemies/Bar.java index 2210d12..6e4069d 100755 --- a/core/src/zero1hd/rhythmbullet/entity/enemies/Bar.java +++ b/core/src/zero1hd/rhythmbullet/entity/enemies/Bar.java @@ -8,7 +8,7 @@ import com.badlogic.gdx.math.Rectangle; import zero1hd.rhythmbullet.RhythmBullet; import zero1hd.rhythmbullet.entity.Entity; -import zero1hd.rhythmbullet.entity.ally.PolyJetEntity; +import zero1hd.rhythmbullet.entity.ally.PolyjetEntity; public class Bar extends Entity { @@ -47,7 +47,7 @@ public class Bar extends Entity { @Override public void collided(Entity entity) { - if (entity.getClass() == PolyJetEntity.class) { + if (entity.getClass() == PolyjetEntity.class) { dead = true; } } diff --git a/core/src/zero1hd/rhythmbullet/screens/CreativeScreen.java b/core/src/zero1hd/rhythmbullet/screens/CreativeScreen.java index b0035b2..7769b29 100755 --- a/core/src/zero1hd/rhythmbullet/screens/CreativeScreen.java +++ b/core/src/zero1hd/rhythmbullet/screens/CreativeScreen.java @@ -25,8 +25,8 @@ public class CreativeScreen extends ScreenAdapter { Preferences prefs; public CreativeScreen(RhythmBullet core, MainMenu mainMenu) { - ghud = new GameHUD(core.getDefaultSkin(), 100f); - gamePlayArea = new GamePlayArea(core.getAssetManager(), core.getPrefs(), ghud); + gamePlayArea = new GamePlayArea(core.getAssetManager(), core.getPrefs()); + ghud = new GameHUD(core.getDefaultSkin(), 100f, gamePlayArea); chud = new CreativeHUD(core, mainMenu, gamePlayArea); inputs = new InputMultiplexer(chud, gamePlayArea); diff --git a/core/src/zero1hd/rhythmbullet/screens/GameScreen.java b/core/src/zero1hd/rhythmbullet/screens/GameScreen.java index d41a8cf..0f093f7 100755 --- a/core/src/zero1hd/rhythmbullet/screens/GameScreen.java +++ b/core/src/zero1hd/rhythmbullet/screens/GameScreen.java @@ -46,9 +46,8 @@ public class GameScreen extends ScreenAdapter { } }); - gameHUD = new GameHUD(core.getDefaultSkin(), 100f); - gameArea = new GamePlayArea(core.getAssetManager(), core.getPrefs(), gameHUD); - + gameArea = new GamePlayArea(core.getAssetManager(), core.getPrefs()); + gameHUD = new GameHUD(core.getDefaultSkin(), 100f, gameArea); inputs = new InputMultiplexer(); inputs.addProcessor(gameHUD); inputs.addProcessor(gameArea); @@ -114,7 +113,7 @@ public class GameScreen extends ScreenAdapter { //actual game and hud if (!gameHUD.isPaused()) { gameArea.act(delta); - if (gameArea.getPolyjet().isDead()) { + if (gameArea.getPolyjetEntity().isDead()) { end(false); } gameHUD.act(delta); diff --git a/core/src/zero1hd/rhythmbullet/ui/builders/HealthBar.java b/core/src/zero1hd/rhythmbullet/ui/builders/HealthBar.java index 76c96c8..f5938e7 100755 --- a/core/src/zero1hd/rhythmbullet/ui/builders/HealthBar.java +++ b/core/src/zero1hd/rhythmbullet/ui/builders/HealthBar.java @@ -6,11 +6,15 @@ import com.badlogic.gdx.scenes.scene2d.ui.Image; import com.badlogic.gdx.scenes.scene2d.ui.Skin; import com.badlogic.gdx.scenes.scene2d.ui.WidgetGroup; +import zero1hd.rhythmbullet.entity.ally.PolyjetEntity; + public class HealthBar extends WidgetGroup { Image empty; Image filler; float health; float maxHealth; + + PolyjetEntity pje; public HealthBar(Skin skin, float maxHealth) { super(); filler = new Image(skin.getPatch("bar-fill")); @@ -19,17 +23,28 @@ public class HealthBar extends WidgetGroup { empty = new Image(skin.getPatch("bar-empty")); addActor(empty); - this.maxHealth = maxHealth; } + public void setPolyjetEntity(PolyjetEntity pje) { + this.pje = pje; + } + public void setHealth(float health) { this.health = health; filler.addAction(Actions.sizeTo(getWidth(), MathUtils.round((health/maxHealth)*getHeight()), 0.1f));; } + @Override + public void act(float delta) { + if (pje != null) { + health = pje.health; + } + super.act(delta); + } + @Override public void setSize(float width, float height) { empty.setSize(width, height); diff --git a/core/src/zero1hd/rhythmbullet/ui/stages/GameHUD.java b/core/src/zero1hd/rhythmbullet/ui/stages/GameHUD.java index 8801aa8..5ce070a 100755 --- a/core/src/zero1hd/rhythmbullet/ui/stages/GameHUD.java +++ b/core/src/zero1hd/rhythmbullet/ui/stages/GameHUD.java @@ -4,7 +4,6 @@ import com.badlogic.gdx.Gdx; import com.badlogic.gdx.Input.Keys; import com.badlogic.gdx.audio.Music; import com.badlogic.gdx.graphics.Color; -import com.badlogic.gdx.graphics.Texture; import com.badlogic.gdx.scenes.scene2d.Actor; import com.badlogic.gdx.scenes.scene2d.Stage; import com.badlogic.gdx.scenes.scene2d.ui.Image; @@ -59,18 +58,23 @@ public class GameHUD extends Stage { pauseMenu.setPosition((Gdx.graphics.getWidth()-pauseMenu.getWidth())/2f, (Gdx.graphics.getHeight()-pauseMenu.getHeight())/2f); healthBar = new HealthBar(skin, maxHealth); - healthBar.setSize(20f, Gdx.graphics.getHeight()/3); + healthBar.setSize(30f, Gdx.graphics.getHeight()/3); healthBar.setHealth(maxHealth); healthBar.setPosition(Gdx.graphics.getWidth()-healthBar.getWidth() -10f, (Gdx.graphics.getHeight()-healthBar.getHeight())/2f); addActor(healthBar); + healthBar.setPolyjetEntity(gpa.getPolyjetEntity()); leftStatusBar = new Image(skin.getDrawable("gradient-bar")); - leftStatusBar.setSize(20f, getHeight()); - leftStatusBar.setPosition(gpa.getViewport().getScreenX(), 0); + leftStatusBar.setSize(30f, getHeight()); + leftStatusBar.setPosition(gpa.getViewport().getScreenX()-leftStatusBar.getWidth()/2f, 0); + addActor(leftStatusBar); rightStatusBar = new Image(skin.getDrawable("gradient-bar")); rightStatusBar.setSize(20f, getHeight()); - rightStatusBar.setPosition(gpa.getViewport().getScreenX()+gpa.getViewport().getScreenWidth(), 0); + rightStatusBar.setPosition(gpa.getViewport().getScreenX()+gpa.getViewport().getScreenWidth()-rightStatusBar.getWidth()/2f, 0); + addActor(rightStatusBar); + + setStatusColor(1, 1, 1, 0.5f); } /** @@ -132,6 +136,19 @@ public class GameHUD extends Stage { this.music = music; } + public void setStatusColor(float r, float g, float b, float a) { + leftStatusBar.setColor(r, g, b, a); + rightStatusBar.setColor(r, g, b, a); + } + + public void setLeftStatusColor(float r, float g, float b, float a) { + leftStatusBar.setColor(r, g, b, a); + } + + public void setRightStatusColor(float r, float g, float b, float a) { + rightStatusBar.setColor(r, g, b, a); + } + public HealthBar getHealthBar() { return healthBar; } diff --git a/core/src/zero1hd/rhythmbullet/ui/stages/GamePlayArea.java b/core/src/zero1hd/rhythmbullet/ui/stages/GamePlayArea.java index 64f7a1e..b277cbd 100755 --- a/core/src/zero1hd/rhythmbullet/ui/stages/GamePlayArea.java +++ b/core/src/zero1hd/rhythmbullet/ui/stages/GamePlayArea.java @@ -20,35 +20,33 @@ 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; +import zero1hd.rhythmbullet.entity.ally.PolyjetEntity; import zero1hd.rhythmbullet.entity.coordinator.CoordinatorManager; +import zero1hd.rhythmbullet.util.ScoreManager; public class GamePlayArea extends Stage { - public PolyJetEntity polyjet; + public PolyjetEntity polyjet; private GamePlayMap audioMap; - private GameHUD gameHUD; - public CoordinatorManager cm; public EntityManager em; private CollisionDetector collisionDetector; - private int score; + public ScoreManager score = new ScoreManager(); private ShaderProgram glowShader; private FrameBuffer blurTarget; TextureRegion fboRegion; private int fboSize; - public GamePlayArea(AssetManager assetManager, Preferences prefs, GameHUD gameHUD) { + public GamePlayArea(AssetManager assetManager, Preferences prefs) { super(new FitViewport(RhythmBullet.GAME_AREA_WIDTH, RhythmBullet.GAME_AREA_HEIGHT)); Gdx.app.debug("Game Area", "new area created"); - polyjet = new PolyJetEntity(assetManager, 25f, 25f, "standard", gameHUD.getHealthBar()); + polyjet = new PolyjetEntity(assetManager, 25f, 25f, 100, "standard"); em = new EntityManager(assetManager, prefs, this); cm = new CoordinatorManager(em); - this.gameHUD = gameHUD; collisionDetector = new CollisionDetector(em.activeEnemies, em.activeAllies, assetManager, prefs); em.activeAllies.add(polyjet); @@ -58,7 +56,7 @@ public class GamePlayArea extends Stage { public void setAudioMap(GamePlayMap audioMap) { this.audioMap = audioMap; } - + /** * needs to be called right after set as screen (should be called in show method). * @param prefs @@ -141,7 +139,7 @@ public class GamePlayArea extends Stage { } collisionDetector.collisionCheck(); - addScore(collisionDetector.getAmassedPoints()); + score.addScore(collisionDetector.getAmassedPoints()); if (polyjet.getX() <= 1) { polyjet.moveLeft = false; @@ -165,10 +163,6 @@ public class GamePlayArea extends Stage { super.act(delta); } - public void addScore (int score) { - setScore(this.score += score); - } - @Override public boolean keyDown(int keycode) { if (keycode == KeyMap.left) { @@ -219,15 +213,10 @@ public class GamePlayArea extends Stage { return false; } - public PolyJetEntity getPolyjet() { + public PolyjetEntity getPolyjetEntity() { return polyjet; } - public void setScore(int score) { - this.score = score; - gameHUD.setScore(score); - } - @Override public void dispose() { if (glowShader != null) { diff --git a/core/src/zero1hd/rhythmbullet/util/ScoreManager.java b/core/src/zero1hd/rhythmbullet/util/ScoreManager.java new file mode 100755 index 0000000..ff09380 --- /dev/null +++ b/core/src/zero1hd/rhythmbullet/util/ScoreManager.java @@ -0,0 +1,17 @@ +package zero1hd.rhythmbullet.util; + +public class ScoreManager { + public int score; + + public void setScore(int score) { + this.score = score; + } + + public int getScore() { + return score; + } + + public void addScore(int addedScore) { + score += addedScore; + } +}