v0.3.5: added functionality for a shield ontop of health for characters
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user