v0.3.5: added functionality for a shield ontop of health for characters
This commit is contained in:
parent
346b4b78e6
commit
fae5fc7c6c
BIN
assets/shield_bar.png
Normal file
BIN
assets/shield_bar.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 2.7 KiB |
|
@ -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";
|
||||
|
|
|
@ -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) {
|
||||
|
@ -241,7 +257,15 @@ 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 :
|
||||
|
|
|
@ -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 );
|
||||
|
||||
hpLvl = new ColorBlock( 1, 1, COLOR_LVL );
|
||||
add( hpLvl );
|
||||
Shld = new ColorBlock( 1, 1, COLOR_SHLD );
|
||||
add( Shld );
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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 );
|
||||
|
|
Loading…
Reference in New Issue
Block a user