From 5cff3a6191ddf5313e05a1afbf5d2d3842754e31 Mon Sep 17 00:00:00 2001 From: Evan Debenham Date: Sun, 13 Sep 2015 04:52:43 -0400 Subject: [PATCH] v0.3.1d: added a health bar for bosses --- assets/boss_hp.png | Bin 0 -> 462 bytes .../shatteredpixeldungeon/Assets.java | 3 +- .../actors/mobs/DM300.java | 9 ++ .../actors/mobs/Goo.java | 8 +- .../actors/mobs/King.java | 3 + .../actors/mobs/Tengu.java | 11 +- .../actors/mobs/Yog.java | 13 +- .../levels/CavesBossLevel.java | 2 +- .../levels/CityBossLevel.java | 2 +- .../ui/BossHealthBar.java | 118 ++++++++++++++++++ .../shatteredpixeldungeon/ui/StatusPane.java | 9 +- 11 files changed, 170 insertions(+), 8 deletions(-) create mode 100644 assets/boss_hp.png create mode 100644 src/com/shatteredpixel/shatteredpixeldungeon/ui/BossHealthBar.java diff --git a/assets/boss_hp.png b/assets/boss_hp.png new file mode 100644 index 0000000000000000000000000000000000000000..22eaf4886c55b3b823211d0781b04c9b70c4bcec GIT binary patch literal 462 zcmeAS@N?(olHy`uVBq!ia0vp^4nVBH!3-p)I`?e@Qk(@Ik;M!Q+`=Ht$S`Y;1W=H@ z#M9T6{XQozhoSHsvz1Cfq3Qsi5LX}#0WxwDvhtF03R3cl(h5p4ipsJ|DssxI@+xWy zs_HDrfU}^7Ym7Eq+l$%)HP~6pA zx?tJVW#*onSIyXI>wdo804CxyP?& zQ&%xV0h4inu#3b~vm(L3DY%DE|llO*7 z8rrj;uhD#(FE3~$mGiLOeN+*n@?~F=!3)0UpA{E= rmuz0Gx3ndGxkOBCL(A;hH|rSYe+yamzjFUFP-uI)`njxgN@xNAh-#tG literal 0 HcmV?d00001 diff --git a/src/com/shatteredpixel/shatteredpixeldungeon/Assets.java b/src/com/shatteredpixel/shatteredpixeldungeon/Assets.java index ff6fde5f7..394f5e4d2 100644 --- a/src/com/shatteredpixel/shatteredpixeldungeon/Assets.java +++ b/src/com/shatteredpixel/shatteredpixeldungeon/Assets.java @@ -36,7 +36,8 @@ public class Assets { public static final String HP_BAR = "hp_bar.png"; public static final String XP_BAR = "exp_bar.png"; public static final String TOOLBAR = "toolbar.png"; - public static final String SHADOW = "shadow.png"; + public static final String SHADOW = "shadow.png"; + public static final String BOSSHP = "boss_hp.png"; public static final String WARRIOR = "warrior.png"; public static final String MAGE = "mage.png"; diff --git a/src/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/DM300.java b/src/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/DM300.java index b34ffdef5..306f82d49 100644 --- a/src/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/DM300.java +++ b/src/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/DM300.java @@ -25,6 +25,7 @@ import java.util.HashSet; import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Terror; import com.shatteredpixel.shatteredpixeldungeon.items.artifacts.CapeOfThorns; import com.shatteredpixel.shatteredpixeldungeon.items.artifacts.LloydsBeacon; +import com.shatteredpixel.shatteredpixeldungeon.ui.BossHealthBar; import com.watabou.noosa.Camera; import com.watabou.noosa.audio.Sample; import com.shatteredpixel.shatteredpixeldungeon.Assets; @@ -47,6 +48,7 @@ import com.shatteredpixel.shatteredpixeldungeon.levels.Terrain; import com.shatteredpixel.shatteredpixeldungeon.scenes.GameScene; import com.shatteredpixel.shatteredpixeldungeon.sprites.DM300Sprite; import com.shatteredpixel.shatteredpixeldungeon.utils.GLog; +import com.watabou.utils.Bundle; import com.watabou.utils.Random; public class DM300 extends Mob { @@ -150,6 +152,7 @@ public class DM300 extends Mob { @Override public void notice() { super.notice(); + BossHealthBar.assignBoss(this); yell( "Unauthorised personnel detected." ); } @@ -182,4 +185,10 @@ public class DM300 extends Mob { public HashSet> immunities() { return IMMUNITIES; } + + @Override + public void restoreFromBundle(Bundle bundle) { + super.restoreFromBundle(bundle); + BossHealthBar.assignBoss(this); + } } diff --git a/src/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/Goo.java b/src/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/Goo.java index 1ced0ca1b..fac39f6b1 100644 --- a/src/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/Goo.java +++ b/src/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/Goo.java @@ -28,6 +28,7 @@ import com.shatteredpixel.shatteredpixeldungeon.actors.blobs.GooWarn; import com.shatteredpixel.shatteredpixeldungeon.actors.blobs.ToxicGas; import com.shatteredpixel.shatteredpixeldungeon.effects.CellEmitter; import com.shatteredpixel.shatteredpixeldungeon.effects.particles.ElmoParticle; +import com.shatteredpixel.shatteredpixeldungeon.ui.BossHealthBar; import com.watabou.noosa.Camera; import com.shatteredpixel.shatteredpixeldungeon.Badges; import com.shatteredpixel.shatteredpixeldungeon.Dungeon; @@ -159,8 +160,9 @@ public class Goo extends Mob { for (int i=0; i < Level.NEIGHBOURS9.length; i++) { int j = pos + Level.NEIGHBOURS9[i]; - GameScene.add( Blob.seed( j , 2, GooWarn.class )); - + if (Level.passable[j]) { + GameScene.add(Blob.seed(j, 2, GooWarn.class)); + } } if (Dungeon.visible[pos]) { @@ -211,6 +213,7 @@ public class Goo extends Mob { @Override public void notice() { super.notice(); + BossHealthBar.assignBoss(this); yell( "GLURP-GLURP!" ); } @@ -240,6 +243,7 @@ public class Goo extends Mob { super.restoreFromBundle( bundle ); pumpedUp = bundle.getInt( PUMPEDUP ); + if (state != SLEEPING) BossHealthBar.assignBoss(this); } private static final HashSet> RESISTANCES = new HashSet>(); diff --git a/src/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/King.java b/src/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/King.java index e7afcf85b..050cf9dc7 100644 --- a/src/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/King.java +++ b/src/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/King.java @@ -25,6 +25,7 @@ import java.util.HashSet; import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Vertigo; import com.shatteredpixel.shatteredpixeldungeon.items.artifacts.LloydsBeacon; import com.shatteredpixel.shatteredpixeldungeon.items.scrolls.ScrollOfTeleportation; +import com.shatteredpixel.shatteredpixeldungeon.ui.BossHealthBar; import com.shatteredpixel.shatteredpixeldungeon.utils.GLog; import com.watabou.noosa.audio.Sample; import com.shatteredpixel.shatteredpixeldungeon.Assets; @@ -80,6 +81,7 @@ public class King extends Mob { public void restoreFromBundle( Bundle bundle ) { super.restoreFromBundle( bundle ); nextPedestal = bundle.getBoolean( PEDESTAL ); + BossHealthBar.assignBoss(this); } @Override @@ -218,6 +220,7 @@ public class King extends Mob { @Override public void notice() { super.notice(); + BossHealthBar.assignBoss(this); yell( "How dare you!" ); } diff --git a/src/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/Tengu.java b/src/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/Tengu.java index 33ba00b23..c527c04cf 100644 --- a/src/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/Tengu.java +++ b/src/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/Tengu.java @@ -24,6 +24,7 @@ import java.util.HashSet; import com.shatteredpixel.shatteredpixeldungeon.items.artifacts.LloydsBeacon; import com.shatteredpixel.shatteredpixeldungeon.levels.traps.PoisonTrap; +import com.shatteredpixel.shatteredpixeldungeon.ui.BossHealthBar; import com.shatteredpixel.shatteredpixeldungeon.utils.GLog; import com.watabou.noosa.audio.Sample; import com.shatteredpixel.shatteredpixeldungeon.Assets; @@ -46,6 +47,7 @@ import com.shatteredpixel.shatteredpixeldungeon.levels.Terrain; import com.shatteredpixel.shatteredpixeldungeon.mechanics.Ballistica; import com.shatteredpixel.shatteredpixeldungeon.scenes.GameScene; import com.shatteredpixel.shatteredpixeldungeon.sprites.TenguSprite; +import com.watabou.utils.Bundle; import com.watabou.utils.Random; public class Tengu extends Mob { @@ -180,7 +182,8 @@ public class Tengu extends Mob { @Override public void notice() { super.notice(); - yell( "Gotcha, " + Dungeon.hero.givenName() + "!" ); + BossHealthBar.assignBoss(this); + yell("Gotcha, " + Dungeon.hero.givenName() + "!"); } @Override @@ -202,4 +205,10 @@ public class Tengu extends Mob { public HashSet> resistances() { return RESISTANCES; } + + @Override + public void restoreFromBundle(Bundle bundle) { + super.restoreFromBundle(bundle); + BossHealthBar.assignBoss(this); + } } diff --git a/src/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/Yog.java b/src/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/Yog.java index 2d07a263a..1f27be7ea 100644 --- a/src/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/Yog.java +++ b/src/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/Yog.java @@ -52,8 +52,10 @@ import com.shatteredpixel.shatteredpixeldungeon.sprites.CharSprite; import com.shatteredpixel.shatteredpixeldungeon.sprites.LarvaSprite; import com.shatteredpixel.shatteredpixeldungeon.sprites.RottingFistSprite; import com.shatteredpixel.shatteredpixeldungeon.sprites.YogSprite; +import com.shatteredpixel.shatteredpixeldungeon.ui.BossHealthBar; import com.shatteredpixel.shatteredpixeldungeon.utils.GLog; import com.shatteredpixel.shatteredpixeldungeon.utils.Utils; +import com.watabou.utils.Bundle; import com.watabou.utils.Random; public class Yog extends Mob { @@ -89,6 +91,8 @@ public class Yog extends Mob { GameScene.add( fist1 ); GameScene.add( fist2 ); + + notice(); } @Override @@ -169,6 +173,7 @@ public class Yog extends Mob { @Override public void notice() { super.notice(); + BossHealthBar.assignBoss(this); yell( "Hope is an illusion..." ); } @@ -196,7 +201,13 @@ public class Yog extends Mob { public HashSet> immunities() { return IMMUNITIES; } - + + @Override + public void restoreFromBundle(Bundle bundle) { + super.restoreFromBundle(bundle); + BossHealthBar.assignBoss(this); + } + public static class RottingFist extends Mob { private static final int REGENERATION = 4; diff --git a/src/com/shatteredpixel/shatteredpixeldungeon/levels/CavesBossLevel.java b/src/com/shatteredpixel/shatteredpixeldungeon/levels/CavesBossLevel.java index c982f2dd7..033da9dd7 100644 --- a/src/com/shatteredpixel/shatteredpixeldungeon/levels/CavesBossLevel.java +++ b/src/com/shatteredpixel/shatteredpixeldungeon/levels/CavesBossLevel.java @@ -233,7 +233,7 @@ public class CavesBossLevel extends Level { seal(); Mob boss = Bestiary.mob( Dungeon.depth ); - boss.state = boss.HUNTING; + boss.state = boss.WANDERING; do { boss.pos = Random.Int( LENGTH ); } while ( diff --git a/src/com/shatteredpixel/shatteredpixeldungeon/levels/CityBossLevel.java b/src/com/shatteredpixel/shatteredpixeldungeon/levels/CityBossLevel.java index 162ca0415..a27a74776 100644 --- a/src/com/shatteredpixel/shatteredpixeldungeon/levels/CityBossLevel.java +++ b/src/com/shatteredpixel/shatteredpixeldungeon/levels/CityBossLevel.java @@ -187,7 +187,7 @@ public class CityBossLevel extends Level { seal(); Mob boss = Bestiary.mob( Dungeon.depth ); - boss.state = boss.HUNTING; + boss.state = boss.WANDERING; int count = 0; do { boss.pos = Random.Int( LENGTH ); diff --git a/src/com/shatteredpixel/shatteredpixeldungeon/ui/BossHealthBar.java b/src/com/shatteredpixel/shatteredpixeldungeon/ui/BossHealthBar.java new file mode 100644 index 000000000..6e2e486a9 --- /dev/null +++ b/src/com/shatteredpixel/shatteredpixeldungeon/ui/BossHealthBar.java @@ -0,0 +1,118 @@ +/* + * Pixel Dungeon + * Copyright (C) 2012-2015 Oleg Dolya + * + * Shattered Pixel Dungeon + * Copyright (C) 2014-2015 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.Assets; +import com.shatteredpixel.shatteredpixeldungeon.Dungeon; +import com.shatteredpixel.shatteredpixeldungeon.actors.mobs.Mob; +import com.shatteredpixel.shatteredpixeldungeon.effects.particles.BloodParticle; +import com.watabou.noosa.Image; +import com.watabou.noosa.particles.Emitter; +import com.watabou.noosa.ui.Component; + +public class BossHealthBar extends Component { + + private Image bar; + private Image hp; + + private static Mob boss; + + private Image skull; + private Emitter blood; + + private static String asset = Assets.BOSSHP; + + private static BossHealthBar instance; + private static boolean bleeding; + + BossHealthBar() { + super(); + visible = active = (boss != null); + instance = this; + } + + @Override + protected void createChildren() { + bar = new Image(asset, 0, 0, 64, 16); + add(bar); + + width = bar.width; + height = bar.height; + + hp = new Image(asset, 15, 19, 47, 4); + add(hp); + + skull = new Image(asset, 5, 18, 6, 6); + add(skull); + + blood = new Emitter(); + blood.pos(skull); + blood.pour(BloodParticle.FACTORY, 0.3f); + blood.autoKill = false; + blood.on = false; + add( blood ); + } + + @Override + protected void layout() { + bar.x = x; + bar.y = y; + + hp.x = bar.x+15; + hp.y = bar.y+6; + + skull.x = bar.x+5; + skull.y = bar.y+5; + } + + @Override + public void update() { + super.update(); + if (boss != null){ + if (!boss.isAlive() || !Dungeon.level.mobs.contains(boss)){ + boss = null; + visible = active = false; + } else { + hp.scale.x = (float)boss.HP/boss.HT; + if (hp.scale.x < 0.25f) bleed( true ); + + if (bleeding != blood.on){ + if (bleeding) skull.tint( 0xcc0000, 0.6f ); + else skull.resetColor(); + blood.on = bleeding; + } + } + } + } + + public static void assignBoss(Mob boss){ + BossHealthBar.boss = boss; + bleed(false); + if (instance != null) { + instance.visible = instance.active = true; + } + } + + public static void bleed(boolean value){ + bleeding = value; + } + +} diff --git a/src/com/shatteredpixel/shatteredpixeldungeon/ui/StatusPane.java b/src/com/shatteredpixel/shatteredpixeldungeon/ui/StatusPane.java index 783345f37..caa759037 100644 --- a/src/com/shatteredpixel/shatteredpixeldungeon/ui/StatusPane.java +++ b/src/com/shatteredpixel/shatteredpixeldungeon/ui/StatusPane.java @@ -52,6 +52,8 @@ public class StatusPane extends Component { private Image hp; private Image exp; + private BossHealthBar bossHP; + private int lastLvl = -1; private int lastKeys = -1; @@ -104,6 +106,9 @@ public class StatusPane extends Component { exp = new Image( Assets.XP_BAR ); add( exp ); + bossHP = new BossHealthBar(); + add( bossHP ); + level = new BitmapText( PixelScene.pixelFont); level.hardlight( 0xFFEBA4 ); add( level ); @@ -141,12 +146,14 @@ public class StatusPane extends Component { hp.x = 30; hp.y = 3; + bossHP.setPos( 6 + (width - bossHP.width())/2, 20); + depth.x = width - 24 - depth.width() - 18; depth.y = 6; keys.y = 6; - danger.setPos( width - danger.width(), 18 ); + danger.setPos( width - danger.width(), 20 ); buffs.setPos( 31, 9 );