From 8122e961eeb31910a528f7b777aea6d89c06a511 Mon Sep 17 00:00:00 2001 From: Evan Debenham Date: Sat, 2 Sep 2017 02:37:35 -0400 Subject: [PATCH] v0.6.2: all enemies now have health bars if they are injured removed sad ghost specific health bar --- .../items/wands/CursedWand.java | 4 +- .../levels/PrisonBossLevel.java | 4 +- .../scenes/GameScene.java | 20 +++--- .../sprites/CharSprite.java | 30 ++++++-- .../sprites/GhostSprite.java | 29 -------- .../ui/AttackIndicator.java | 2 +- .../ui/CharHealthIndicator.java | 72 +++++++++++++++++++ .../ui/DangerIndicator.java | 2 +- .../shatteredpixeldungeon/ui/HealthBar.java | 8 +-- .../ui/QuickSlotButton.java | 2 +- ...icator.java => TargetHealthIndicator.java} | 6 +- 11 files changed, 120 insertions(+), 59 deletions(-) create mode 100644 core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/ui/CharHealthIndicator.java rename core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/ui/{HealthIndicator.java => TargetHealthIndicator.java} (91%) diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/wands/CursedWand.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/wands/CursedWand.java index a9735d582..5edffef92 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/wands/CursedWand.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/wands/CursedWand.java @@ -62,7 +62,7 @@ import com.shatteredpixel.shatteredpixeldungeon.messages.Messages; import com.shatteredpixel.shatteredpixeldungeon.plants.Plant; import com.shatteredpixel.shatteredpixeldungeon.scenes.GameScene; import com.shatteredpixel.shatteredpixeldungeon.scenes.InterlevelScene; -import com.shatteredpixel.shatteredpixeldungeon.ui.HealthIndicator; +import com.shatteredpixel.shatteredpixeldungeon.ui.TargetHealthIndicator; import com.shatteredpixel.shatteredpixeldungeon.utils.GLog; import com.shatteredpixel.shatteredpixeldungeon.windows.WndOptions; import com.watabou.noosa.Game; @@ -299,7 +299,7 @@ public class CursedWand { ch.destroy(); ch.sprite.killAndErase(); Dungeon.level.mobs.remove(ch); - HealthIndicator.instance.target(null); + TargetHealthIndicator.instance.target(null); GameScene.add(sheep); CellEmitter.get(sheep.pos).burst(Speck.factory(Speck.WOOL), 4); } else { diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/PrisonBossLevel.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/PrisonBossLevel.java index afef33fd8..42f019da6 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/PrisonBossLevel.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/PrisonBossLevel.java @@ -41,7 +41,7 @@ import com.shatteredpixel.shatteredpixeldungeon.messages.Messages; import com.shatteredpixel.shatteredpixeldungeon.plants.Plant; import com.shatteredpixel.shatteredpixeldungeon.scenes.GameScene; import com.shatteredpixel.shatteredpixeldungeon.tiles.CustomTiledVisual; -import com.shatteredpixel.shatteredpixeldungeon.ui.HealthIndicator; +import com.shatteredpixel.shatteredpixeldungeon.ui.TargetHealthIndicator; import com.watabou.noosa.Group; import com.watabou.noosa.audio.Sample; import com.watabou.utils.Bundlable; @@ -310,7 +310,7 @@ public class PrisonBossLevel extends Level { Actor.remove(tengu); mobs.remove(tengu); - HealthIndicator.instance.target(null); + TargetHealthIndicator.instance.target(null); tengu.sprite.kill(); Room maze = new MazeRoom(); diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/scenes/GameScene.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/scenes/GameScene.java index c7ef91d7a..714f5901a 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/scenes/GameScene.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/scenes/GameScene.java @@ -70,12 +70,13 @@ import com.shatteredpixel.shatteredpixeldungeon.ui.ActionIndicator; import com.shatteredpixel.shatteredpixeldungeon.ui.AttackIndicator; import com.shatteredpixel.shatteredpixeldungeon.ui.Banner; import com.shatteredpixel.shatteredpixeldungeon.ui.BusyIndicator; +import com.shatteredpixel.shatteredpixeldungeon.ui.CharHealthIndicator; import com.shatteredpixel.shatteredpixeldungeon.ui.GameLog; -import com.shatteredpixel.shatteredpixeldungeon.ui.HealthIndicator; import com.shatteredpixel.shatteredpixeldungeon.ui.LootIndicator; import com.shatteredpixel.shatteredpixeldungeon.ui.QuickSlotButton; import com.shatteredpixel.shatteredpixeldungeon.ui.ResumeIndicator; import com.shatteredpixel.shatteredpixeldungeon.ui.StatusPane; +import com.shatteredpixel.shatteredpixeldungeon.ui.TargetHealthIndicator; import com.shatteredpixel.shatteredpixeldungeon.ui.Toast; import com.shatteredpixel.shatteredpixeldungeon.ui.Toolbar; import com.shatteredpixel.shatteredpixeldungeon.ui.Window; @@ -147,6 +148,7 @@ public class GameScene extends PixelScene { private Group spells; private Group statuses; private Group emoicons; + private Group healthIndicators; private Toolbar toolbar; private Toast prompt; @@ -156,9 +158,6 @@ public class GameScene extends PixelScene { private ActionIndicator action; private ResumeIndicator resume; - //temporary, see Ghostsprite - public Group ghostHP; - @Override public void create() { @@ -230,12 +229,11 @@ public class GameScene extends PixelScene { emitters = new Group(); effects = new Group(); emoicons = new Group(); + healthIndicators = new Group(); mobs = new Group(); add( mobs ); - ghostHP = new Group(); - for (Mob mob : Dungeon.level.mobs) { addMobSprite( mob ); if (Statistics.amuletObtained) { @@ -283,10 +281,10 @@ public class GameScene extends PixelScene { hero.place( Dungeon.hero.pos ); hero.updateArmor(); mobs.add( hero ); - - add( new HealthIndicator() ); - add( ghostHP ); + add( healthIndicators ); + //always appears ontop of other health indicators + add( new TargetHealthIndicator() ); add( cellSelector = new CellSelector( tiles ) ); @@ -701,6 +699,10 @@ public class GameScene extends PixelScene { scene.emoicons.add( icon ); } + public static void add( CharHealthIndicator indicator ){ + if (scene != null) scene.healthIndicators.add(indicator); + } + public static void effect( Visual effect ) { scene.effects.add( effect ); } diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/sprites/CharSprite.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/sprites/CharSprite.java index dc66c873e..8f0f06186 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/sprites/CharSprite.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/sprites/CharSprite.java @@ -39,6 +39,7 @@ import com.shatteredpixel.shatteredpixeldungeon.messages.Messages; import com.shatteredpixel.shatteredpixeldungeon.scenes.GameScene; import com.shatteredpixel.shatteredpixeldungeon.scenes.PixelScene; import com.shatteredpixel.shatteredpixeldungeon.tiles.DungeonTilemap; +import com.shatteredpixel.shatteredpixeldungeon.ui.CharHealthIndicator; import com.watabou.glwrap.Matrix; import com.watabou.glwrap.Vertexbuffer; import com.watabou.noosa.Camera; @@ -96,7 +97,7 @@ public class CharSprite extends MovieClip implements Tweener.Listener, MovieClip protected Emitter chilled; protected Emitter marked; protected Emitter levitation; - protected Emitter health; + protected Emitter healing; protected IceBlock iceBlock; protected DarkBlock darkBlock; @@ -104,6 +105,7 @@ public class CharSprite extends MovieClip implements Tweener.Listener, MovieClip protected AlphaTweener invisible; protected EmoIcon emo; + protected CharHealthIndicator health; private Tweener jumpTweener; private Callback jumpCallback; @@ -129,6 +131,14 @@ public class CharSprite extends MovieClip implements Tweener.Listener, MovieClip place( ch.pos ); turnTo( ch.pos, Random.Int( Dungeon.level.length() ) ); renderShadow = true; + + if (ch != Dungeon.hero) { + if (health == null) { + health = new CharHealthIndicator(ch); + } else { + health.target(ch); + } + } ch.updateSpriteState(); } @@ -238,6 +248,10 @@ public class CharSprite extends MovieClip implements Tweener.Listener, MovieClip if (emo != null) { emo.killAndErase(); } + + if (health != null){ + health.killAndErase(); + } } public Emitter emitter() { @@ -324,8 +338,8 @@ public class CharSprite extends MovieClip implements Tweener.Listener, MovieClip marked.pour(ShadowParticle.UP, 0.1f); break; case HEALING: - health = emitter(); - health.pour(Speck.factory(Speck.HEALING), 0.5f); + healing = emitter(); + healing.pour(Speck.factory(Speck.HEALING), 0.5f); } } @@ -384,9 +398,9 @@ public class CharSprite extends MovieClip implements Tweener.Listener, MovieClip } break; case HEALING: - if (health != null){ - health.on = false; - health = null; + if (healing != null){ + healing.on = false; + healing = null; } break; } @@ -477,6 +491,10 @@ public class CharSprite extends MovieClip implements Tweener.Listener, MovieClip if (emo != null) { emo.killAndErase(); } + + if (health != null){ + health.killAndErase(); + } } private float[] shadowMatrix = new float[16]; diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/sprites/GhostSprite.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/sprites/GhostSprite.java index 92eec1824..f3ebe629f 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/sprites/GhostSprite.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/sprites/GhostSprite.java @@ -24,24 +24,14 @@ package com.shatteredpixel.shatteredpixeldungeon.sprites; import android.opengl.GLES20; import com.shatteredpixel.shatteredpixeldungeon.Assets; -import com.shatteredpixel.shatteredpixeldungeon.ShatteredPixelDungeon; -import com.shatteredpixel.shatteredpixeldungeon.actors.Char; import com.shatteredpixel.shatteredpixeldungeon.effects.Speck; import com.shatteredpixel.shatteredpixeldungeon.effects.particles.ShaftParticle; -import com.shatteredpixel.shatteredpixeldungeon.items.artifacts.DriedRose; -import com.shatteredpixel.shatteredpixeldungeon.scenes.GameScene; -import com.shatteredpixel.shatteredpixeldungeon.ui.HealthBar; import com.watabou.noosa.TextureFilm; import javax.microedition.khronos.opengles.GL10; -//FIXME the healthbar added here is a quick fix. -// The game should have a much more flexible health bar system which works for any character -// However I want a ghost HP bar to get into 0.6.1, so this will have to do for now. public class GhostSprite extends MobSprite { - private HealthBar hpBar; - public GhostSprite() { super(); @@ -64,24 +54,6 @@ public class GhostSprite extends MobSprite { play( idle ); } - @Override - public void link(Char ch) { - super.link(ch); - if (ch instanceof DriedRose.GhostHero){ - final Char finalCH = ch; - hpBar = new HealthBar(){ - @Override - public synchronized void update() { - super.update(); - hpBar.setRect(finalCH.sprite.x, finalCH.sprite.y-3, finalCH.sprite.width, hpBar.height()); - hpBar.level( finalCH ); - visible = finalCH.sprite.visible; - } - }; - ((GameScene)ShatteredPixelDungeon.scene()).ghostHP.add(hpBar); - } - } - @Override public void draw() { GLES20.glBlendFunc( GL10.GL_SRC_ALPHA, GL10.GL_ONE ); @@ -92,7 +64,6 @@ public class GhostSprite extends MobSprite { @Override public void die() { super.die(); - if (hpBar != null) hpBar.killAndErase(); emitter().start( ShaftParticle.FACTORY, 0.3f, 4 ); emitter().start( Speck.factory( Speck.LIGHT ), 0.2f, 3 ); } diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/ui/AttackIndicator.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/ui/AttackIndicator.java index 3aa540cbe..82dbb5acd 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/ui/AttackIndicator.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/ui/AttackIndicator.java @@ -178,7 +178,7 @@ public class AttackIndicator extends Tag { lastTarget = (Mob)target; instance.updateImage(); - HealthIndicator.instance.target( target ); + TargetHealthIndicator.instance.target( target ); } public static void updateState() { diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/ui/CharHealthIndicator.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/ui/CharHealthIndicator.java new file mode 100644 index 000000000..da91d6521 --- /dev/null +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/ui/CharHealthIndicator.java @@ -0,0 +1,72 @@ +/* + * Pixel Dungeon + * Copyright (C) 2012-2015 Oleg Dolya + * + * Shattered Pixel Dungeon + * Copyright (C) 2014-2017 Evan Debenham + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see + */ + +package com.shatteredpixel.shatteredpixeldungeon.ui; + +import com.shatteredpixel.shatteredpixeldungeon.actors.Char; +import com.shatteredpixel.shatteredpixeldungeon.scenes.GameScene; +import com.shatteredpixel.shatteredpixeldungeon.sprites.CharSprite; + +public class CharHealthIndicator extends HealthBar { + + private static final int HEIGHT = 1; + + private Char target; + + public CharHealthIndicator( Char c ){ + target = c; + GameScene.add(this); + } + + @Override + protected void createChildren() { + super.createChildren(); + height = HEIGHT; + } + + @Override + public void update() { + super.update(); + + if (target != null && target.isAlive() && target.sprite.visible) { + CharSprite sprite = target.sprite; + width = sprite.width()*(4/6f); + x = sprite.x + sprite.width()/6f; + y = sprite.y - 2; + level( target ); + visible = target.HP < target.HT; + } else { + visible = false; + } + } + + public void target( Char ch ) { + if (ch != null && ch.isAlive()) { + target = ch; + } else { + target = null; + } + } + + public Char target() { + return target; + } +} diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/ui/DangerIndicator.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/ui/DangerIndicator.java index e03187436..699527427 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/ui/DangerIndicator.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/ui/DangerIndicator.java @@ -102,7 +102,7 @@ public class DangerIndicator extends Tag { Mob target = Dungeon.hero.visibleEnemy(enemyIndex++); - HealthIndicator.instance.target(target == HealthIndicator.instance.target() ? null : target); + TargetHealthIndicator.instance.target(target == TargetHealthIndicator.instance.target() ? null : target); if (Dungeon.hero.curAction == null) { Camera.main.target = null; diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/ui/HealthBar.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/ui/HealthBar.java index 8e803045c..2d808597e 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/ui/HealthBar.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/ui/HealthBar.java @@ -60,15 +60,13 @@ public class HealthBar extends Component { Bg.x = Shld.x = Hp.x = x; Bg.y = Shld.y = Hp.y = y; - Bg.size( width, HEIGHT ); + Bg.size( width, height ); //logic here rounds up to the nearest pixel float pixelWidth = width; if (camera() != null) pixelWidth *= camera().zoom; - Shld.size( width * (float)Math.ceil(shield * pixelWidth)/pixelWidth, HEIGHT ); - Hp.size( width * (float)Math.ceil(health * pixelWidth)/pixelWidth, HEIGHT ); - - height = HEIGHT; + Shld.size( width * (float)Math.ceil(shield * pixelWidth)/pixelWidth, height ); + Hp.size( width * (float)Math.ceil(health * pixelWidth)/pixelWidth, height ); } public void level( float value ) { diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/ui/QuickSlotButton.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/ui/QuickSlotButton.java index 6f8da23bc..392923341 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/ui/QuickSlotButton.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/ui/QuickSlotButton.java @@ -230,7 +230,7 @@ public class QuickSlotButton extends Button implements WndBag.Listener { if (target != Dungeon.hero) { lastTarget = target; - HealthIndicator.instance.target( target ); + TargetHealthIndicator.instance.target( target ); } } diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/ui/HealthIndicator.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/ui/TargetHealthIndicator.java similarity index 91% rename from core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/ui/HealthIndicator.java rename to core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/ui/TargetHealthIndicator.java index 7296fac21..4d70e915f 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/ui/HealthIndicator.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/ui/TargetHealthIndicator.java @@ -24,13 +24,13 @@ package com.shatteredpixel.shatteredpixeldungeon.ui; import com.shatteredpixel.shatteredpixeldungeon.actors.Char; import com.shatteredpixel.shatteredpixeldungeon.sprites.CharSprite; -public class HealthIndicator extends HealthBar { +public class TargetHealthIndicator extends HealthBar { - public static HealthIndicator instance; + public static TargetHealthIndicator instance; private Char target; - public HealthIndicator() { + public TargetHealthIndicator() { super(); instance = this;