From fae5fc7c6c228967a990df9a35e8c8b023ee1ea2 Mon Sep 17 00:00:00 2001 From: Evan Debenham Date: Sat, 5 Mar 2016 02:43:52 -0500 Subject: [PATCH] v0.3.5: added functionality for a shield ontop of health for characters --- assets/shield_bar.png | Bin 0 -> 2809 bytes .../shatteredpixeldungeon/Assets.java | 1 + .../shatteredpixeldungeon/actors/Char.java | 32 ++++++++++-- .../shatteredpixeldungeon/ui/HealthBar.java | 47 +++++++++++++----- .../ui/HealthIndicator.java | 30 ++--------- .../shatteredpixeldungeon/ui/StatusPane.java | 30 +++++++---- .../windows/WndInfoMob.java | 8 +-- 7 files changed, 91 insertions(+), 57 deletions(-) create mode 100644 assets/shield_bar.png diff --git a/assets/shield_bar.png b/assets/shield_bar.png new file mode 100644 index 0000000000000000000000000000000000000000..ca455484a93790e0518b0884d6d7d2fc117ea3f0 GIT binary patch literal 2809 zcmV|D^_ww@lRz|vCuzLs)$;-`! zo*{AqUjza0dRV*yaMRE;fKCVhpQKsoe1Yhg01=zBIT!& zC1$=TK@rP|Ibo3vKKm@PqnO#LJhq6%Ij6Hz*<$V$@wQAMN5qJ)hzm2hoGcOF60t^# zFqJFfH{#e-4l@G)6iI9sa9D{VHW4w29}?su;^hF~NC{tY+*d5%WDCTXa!E_i;d2ub z1#}&jF5T4HnnCyEWTkKf0>c0%E1Ah>(_PY1)0w;+02c53Su*0<(nUqKG_|(0G&D0Z z{i;y^b@OjZ+}lNZ8Th$p5Uu}MTtq^NHl z*T1?CO*}7&0ztZsv2j*bmJyf3G7=Z`5B*PvzoDiKdLpOAxi2$L0#SX*@cY_n(^h55xYX z#km%V()bZjV~l{*bt*u9?FT3d5g^g~#a;iSZ@&02Abxq_DwB(I|L-^bXThc7C4-yr zInE_0gw7K3GZ**7&k~>k0Z0NWkO#^@9q0fwx1%qjZ=)yBuQ3=5 z4Wo^*!gyjLF-e%Um=erBOdIALW)L%unZshS@>qSW9o8Sq#0s#5*edK%>{;v(b^`kb zN5rY%%y90wC>#%$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R zcH#y9#i!p(Udq2b^lI6wp1FXzN3T;~FU%Lck$-deE#qz9yYP3D3t8{6?<+s(e(3(_ z^YOu_)K8!O1p}D#{JO;G(*OVf24YJ`L;(K){{a7>y{D4^000SaNLh0L01FcU01FcV z0GgZ_00007bV*G`2jBw*209t literal 0 HcmV?d00001 diff --git a/src/com/shatteredpixel/shatteredpixeldungeon/Assets.java b/src/com/shatteredpixel/shatteredpixeldungeon/Assets.java index b20284274..f3c09194d 100644 --- a/src/com/shatteredpixel/shatteredpixeldungeon/Assets.java +++ b/src/com/shatteredpixel/shatteredpixeldungeon/Assets.java @@ -35,6 +35,7 @@ public class Assets { public static final String ICONS = "icons.png"; public static final String STATUS = "status_pane.png"; public static final String HP_BAR = "hp_bar.png"; + public static final String SHLD_BAR = "shield_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"; diff --git a/src/com/shatteredpixel/shatteredpixeldungeon/actors/Char.java b/src/com/shatteredpixel/shatteredpixeldungeon/actors/Char.java index 8aed081ba..fbe572839 100644 --- a/src/com/shatteredpixel/shatteredpixeldungeon/actors/Char.java +++ b/src/com/shatteredpixel/shatteredpixeldungeon/actors/Char.java @@ -22,7 +22,19 @@ package com.shatteredpixel.shatteredpixeldungeon.actors; import com.shatteredpixel.shatteredpixeldungeon.Assets; import com.shatteredpixel.shatteredpixeldungeon.Dungeon; -import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.*; +import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Bless; +import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Buff; +import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Charm; +import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Chill; +import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Cripple; +import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.EarthImbue; +import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.FireImbue; +import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Frost; +import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.MagicalSleep; +import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Paralysis; +import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Slow; +import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Speed; +import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Vertigo; import com.shatteredpixel.shatteredpixeldungeon.actors.hero.Hero; import com.shatteredpixel.shatteredpixeldungeon.actors.hero.HeroSubClass; import com.shatteredpixel.shatteredpixeldungeon.levels.Level; @@ -31,8 +43,8 @@ import com.shatteredpixel.shatteredpixeldungeon.levels.features.Door; import com.shatteredpixel.shatteredpixeldungeon.messages.Messages; import com.shatteredpixel.shatteredpixeldungeon.sprites.CharSprite; import com.shatteredpixel.shatteredpixeldungeon.utils.GLog; -import com.watabou.noosa.audio.Sample; import com.watabou.noosa.Camera; +import com.watabou.noosa.audio.Sample; import com.watabou.utils.Bundlable; import com.watabou.utils.Bundle; import com.watabou.utils.GameMath; @@ -50,6 +62,7 @@ public abstract class Char extends Actor { public int HT; public int HP; + public int SHLD; protected float baseSpeed = 1; @@ -71,6 +84,7 @@ public abstract class Char extends Actor { private static final String POS = "pos"; private static final String TAG_HP = "HP"; private static final String TAG_HT = "HT"; + private static final String TAG_SHLD = "SHLD"; private static final String BUFFS = "buffs"; @Override @@ -81,6 +95,7 @@ public abstract class Char extends Actor { bundle.put( POS, pos ); bundle.put( TAG_HP, HP ); bundle.put( TAG_HT, HT ); + bundle.put( TAG_SHLD, SHLD ); bundle.put( BUFFS, buffs ); } @@ -92,6 +107,7 @@ public abstract class Char extends Actor { pos = bundle.getInt( POS ); HP = bundle.getInt( TAG_HP ); HT = bundle.getInt( TAG_HT ); + SHLD = bundle.getInt( TAG_SHLD ); for (Bundlable b : bundle.getCollection( BUFFS )) { if (b != null) { @@ -240,8 +256,16 @@ public abstract class Char extends Actor { } } } - - HP -= dmg; + + if (SHLD >= dmg){ + SHLD -= dmg; + } else if (SHLD > 0) { + HP -= (dmg - SHLD); + SHLD = 0; + } else { + HP -= dmg; + } + if (dmg > 0 || src instanceof Char) { sprite.showStatus( HP > HT / 2 ? CharSprite.WARNING : diff --git a/src/com/shatteredpixel/shatteredpixeldungeon/ui/HealthBar.java b/src/com/shatteredpixel/shatteredpixeldungeon/ui/HealthBar.java index f11e4a433..55b7ea17d 100644 --- a/src/com/shatteredpixel/shatteredpixeldungeon/ui/HealthBar.java +++ b/src/com/shatteredpixel/shatteredpixeldungeon/ui/HealthBar.java @@ -20,28 +20,35 @@ */ package com.shatteredpixel.shatteredpixeldungeon.ui; +import com.shatteredpixel.shatteredpixeldungeon.actors.Char; import com.watabou.noosa.ColorBlock; import com.watabou.noosa.ui.Component; public class HealthBar extends Component { private static final int COLOR_BG = 0xFFCC0000; - private static final int COLOR_LVL = 0xFF00EE00; + private static final int COLOR_HP = 0xFF00EE00; + private static final int COLOR_SHLD = 0xFFBBEEBB; private static final int HEIGHT = 2; - private ColorBlock hpBg; - private ColorBlock hpLvl; + private ColorBlock Bg; + private ColorBlock Shld; + private ColorBlock Hp; - private float level; + private float health; + private float shield; @Override protected void createChildren() { - hpBg = new ColorBlock( 1, 1, COLOR_BG ); - add( hpBg ); + Bg = new ColorBlock( 1, 1, COLOR_BG ); + add( Bg ); + + Shld = new ColorBlock( 1, 1, COLOR_SHLD ); + add( Shld ); - hpLvl = new ColorBlock( 1, 1, COLOR_LVL ); - add( hpLvl ); + Hp = new ColorBlock( 1, 1, COLOR_HP ); + add( Hp ); height = HEIGHT; } @@ -49,17 +56,31 @@ public class HealthBar extends Component { @Override protected void layout() { - hpBg.x = hpLvl.x = x; - hpBg.y = hpLvl.y = y; + Bg.x = Shld.x = Hp.x = x; + Bg.y = Shld.y = Hp.y = y; - hpBg.size( width, HEIGHT ); - hpLvl.size( width * level, HEIGHT ); + Bg.size( width, HEIGHT ); + Shld.size( width * shield, HEIGHT ); + Hp.size( width * health, HEIGHT ); height = HEIGHT; } public void level( float value ) { - level = value; + level( value, 0f ); + } + + public void level( float health, float shield ){ + this.health = health; + this.shield = shield; layout(); } + + public void level(Char c){ + float health = c.HP; + float shield = c.SHLD; + float max = Math.max(health+shield, c.HT); + + level(health/max, (health+shield)/max); + } } diff --git a/src/com/shatteredpixel/shatteredpixeldungeon/ui/HealthIndicator.java b/src/com/shatteredpixel/shatteredpixeldungeon/ui/HealthIndicator.java index 6d5eb4f02..5eeca1f4b 100644 --- a/src/com/shatteredpixel/shatteredpixeldungeon/ui/HealthIndicator.java +++ b/src/com/shatteredpixel/shatteredpixeldungeon/ui/HealthIndicator.java @@ -20,51 +20,31 @@ */ package com.shatteredpixel.shatteredpixeldungeon.ui; -import com.watabou.gltextures.TextureCache; -import com.watabou.noosa.Image; -import com.watabou.noosa.ui.Component; import com.shatteredpixel.shatteredpixeldungeon.actors.Char; import com.shatteredpixel.shatteredpixeldungeon.sprites.CharSprite; -public class HealthIndicator extends Component { - - private static final float HEIGHT = 2; +public class HealthIndicator extends HealthBar { public static HealthIndicator instance; private Char target; - private Image bg; - private Image level; - public HealthIndicator() { super(); instance = this; } - @Override - protected void createChildren() { - bg = new Image( TextureCache.createSolid( 0xFFcc0000 ) ); - bg.scale.y = HEIGHT; - add( bg ); - - level = new Image( TextureCache.createSolid( 0xFF00cc00 ) ); - level.scale.y = HEIGHT; - add( level ); - } - @Override public void update() { super.update(); if (target != null && target.isAlive() && target.sprite.visible) { CharSprite sprite = target.sprite; - bg.scale.x = sprite.width; - level.scale.x = sprite.width * target.HP / target.HT; - bg.x = level.x = sprite.x; - bg.y = level.y = sprite.y - HEIGHT - 1; - + width = sprite.width; + x = sprite.x; + y = sprite.y - 3; + level( target ); visible = true; } else { visible = false; diff --git a/src/com/shatteredpixel/shatteredpixeldungeon/ui/StatusPane.java b/src/com/shatteredpixel/shatteredpixeldungeon/ui/StatusPane.java index 78248c07e..391a3b731 100644 --- a/src/com/shatteredpixel/shatteredpixeldungeon/ui/StatusPane.java +++ b/src/com/shatteredpixel/shatteredpixeldungeon/ui/StatusPane.java @@ -45,12 +45,13 @@ import com.watabou.noosa.ui.Component; public class StatusPane extends Component { - private NinePatch shield; + private NinePatch bg; private Image avatar; private Emitter blood; private int lastTier = 0; + private Image shield; private Image hp; private Image exp; @@ -72,8 +73,8 @@ public class StatusPane extends Component { @Override protected void createChildren() { - shield = new NinePatch( Assets.STATUS, 80, 0, 30 + 18, 0 ); - add( shield ); + bg = new NinePatch( Assets.STATUS, 80, 0, 30 + 18, 0 ); + add( bg ); add( new TouchArea( 0, 1, 31, 31 ) { @Override @@ -102,6 +103,9 @@ public class StatusPane extends Component { compass = new Compass( Dungeon.level.exit ); add( compass ); + shield = new Image( Assets.SHLD_BAR ); + add(shield); + hp = new Image( Assets.HP_BAR ); add( hp ); @@ -137,18 +141,18 @@ public class StatusPane extends Component { height = 32; - shield.size( width, shield.height ); + bg.size( width, bg.height ); - avatar.x = shield.x + 15 - avatar.width / 2f; - avatar.y = shield.y + 16 - avatar.height / 2f; + avatar.x = bg.x + 15 - avatar.width / 2f; + avatar.y = bg.y + 16 - avatar.height / 2f; PixelScene.align(avatar); compass.x = avatar.x + avatar.width / 2f - compass.origin.x; compass.y = avatar.y + avatar.height / 2f - compass.origin.y; PixelScene.align(compass); - hp.x = 30; - hp.y = 3; + hp.x = shield.x = 30; + hp.y = shield.y = 3; bossHP.setPos( 6 + (width - bossHP.width())/2, 20); @@ -168,12 +172,14 @@ public class StatusPane extends Component { public void update() { super.update(); - float health = (float)Dungeon.hero.HP / Dungeon.hero.HT; + float health = Dungeon.hero.HP; + float shield = Dungeon.hero.SHLD; + float max = Math.max(health+shield, Dungeon.hero.HT); if (health == 0) { avatar.tint( 0x000000, 0.6f ); blood.on = false; - } else if (health < 0.25f) { + } else if ((health/Dungeon.hero.HT) < 0.25f) { avatar.tint( 0xcc0000, 0.4f ); blood.on = true; } else { @@ -181,7 +187,9 @@ public class StatusPane extends Component { blood.on = false; } - hp.scale.x = health; + hp.scale.x = health/max; + this.shield.scale.x = (health+shield)/max; + exp.scale.x = (width / exp.width) * Dungeon.hero.exp / Dungeon.hero.maxExp(); if (Dungeon.hero.lvl != lastLvl) { diff --git a/src/com/shatteredpixel/shatteredpixeldungeon/windows/WndInfoMob.java b/src/com/shatteredpixel/shatteredpixeldungeon/windows/WndInfoMob.java index 28fbea3c0..e934a1f71 100644 --- a/src/com/shatteredpixel/shatteredpixeldungeon/windows/WndInfoMob.java +++ b/src/com/shatteredpixel/shatteredpixeldungeon/windows/WndInfoMob.java @@ -20,14 +20,14 @@ */ package com.shatteredpixel.shatteredpixeldungeon.windows; -import com.shatteredpixel.shatteredpixeldungeon.messages.Messages; -import com.watabou.noosa.RenderedText; -import com.watabou.noosa.ui.Component; import com.shatteredpixel.shatteredpixeldungeon.actors.mobs.Mob; +import com.shatteredpixel.shatteredpixeldungeon.messages.Messages; import com.shatteredpixel.shatteredpixeldungeon.scenes.PixelScene; import com.shatteredpixel.shatteredpixeldungeon.sprites.CharSprite; import com.shatteredpixel.shatteredpixeldungeon.ui.BuffIndicator; import com.shatteredpixel.shatteredpixeldungeon.ui.HealthBar; +import com.watabou.noosa.RenderedText; +import com.watabou.noosa.ui.Component; public class WndInfoMob extends WndTitledMessage { @@ -65,7 +65,7 @@ public class WndInfoMob extends WndTitledMessage { add( image ); health = new HealthBar(); - health.level((float) mob.HP / mob.HT); + health.level(mob); add( health ); buffs = new BuffIndicator( mob );