From a5cd73bbc3e82469b4e2f972142d5592bb438172 Mon Sep 17 00:00:00 2001 From: Jeasonfire Date: Sun, 17 May 2015 18:48:50 +0300 Subject: [PATCH] Added healthbars. --- core/assets/sprites/player/healthbar.png | Bin 0 -> 237 bytes .../gladiator/components/CCombat.java | 4 ++ .../gladiator/systems/RenderingSystem.java | 37 ++++++++++++++---- .../com/saltosion/gladiator/util/Name.java | 1 + .../gladiator/util/SpriteLoader.java | 3 +- 5 files changed, 37 insertions(+), 8 deletions(-) create mode 100644 core/assets/sprites/player/healthbar.png diff --git a/core/assets/sprites/player/healthbar.png b/core/assets/sprites/player/healthbar.png new file mode 100644 index 0000000000000000000000000000000000000000..ed984e8f34519cf1ce9a3bcea5a71c947577425f GIT binary patch literal 237 zcmeAS@N?(olHy`uVBq!ia0vp^3P3Eu!3HE}2mdz#QjEnx?oJHr&dIz4a#+$GeH|GX zHuiJ>Nn{1`ISV`@iy0XB4ude`@%$AjKtYKT*NBqf{Irtt#G+J&g2c?c61}|C5(N`I z13lB!R-;s)nmA7v#}E(iw^t1L4k++AUyNy$4te$W!Lvf=c8|3Y2PJb}b~Cn_Co=Tx z;*=;f5OQd+VtAFsaKXWof$f*Vz46E69dms4!D1=F+ cVfsVHo)hI0yN~`?2HM2n>FVdQ&MBb@0GWzTg#Z8m literal 0 HcmV?d00001 diff --git a/core/src/com/saltosion/gladiator/components/CCombat.java b/core/src/com/saltosion/gladiator/components/CCombat.java index b634f3b..23be610 100644 --- a/core/src/com/saltosion/gladiator/components/CCombat.java +++ b/core/src/com/saltosion/gladiator/components/CCombat.java @@ -80,6 +80,10 @@ public class CCombat extends Component { return this.maxHealth; } + public int getHealth() { + return this.health; + } + public int getDamage() { float minDmg = damage * 0.9f; float maxDmg = damage * 1.1f; diff --git a/core/src/com/saltosion/gladiator/systems/RenderingSystem.java b/core/src/com/saltosion/gladiator/systems/RenderingSystem.java index 4e1eeec..8c9a310 100644 --- a/core/src/com/saltosion/gladiator/systems/RenderingSystem.java +++ b/core/src/com/saltosion/gladiator/systems/RenderingSystem.java @@ -28,6 +28,8 @@ import com.saltosion.gladiator.gui.nodes.TextNode; import com.saltosion.gladiator.gui.properties.TextProperty; import com.saltosion.gladiator.util.AppUtil; import com.saltosion.gladiator.util.Global; +import com.saltosion.gladiator.util.Log; +import com.saltosion.gladiator.util.Name; import com.saltosion.gladiator.util.SpriteLoader; import com.saltosion.gladiator.util.SpriteSequence; import java.util.ArrayList; @@ -60,6 +62,7 @@ public class RenderingSystem extends EntitySystem { private List drawableText; + private Sprite[] healthbar; private float xMin = -15, xMax = 15; @Override @@ -81,6 +84,11 @@ public class RenderingSystem extends EntitySystem { fontCamera.setToOrtho(false, Global.FONT_SCALE, Global.FONT_SCALE); drawableText = new ArrayList(); + + healthbar = new Sprite[3]; + healthbar[0] = SpriteLoader.loadSprite(Name.HEALTHBARIMG, 0, 0, 32, 8); + healthbar[1] = SpriteLoader.loadSprite(Name.HEALTHBARIMG, 0, 1, 32, 8); + healthbar[2] = SpriteLoader.loadSprite(Name.HEALTHBARIMG, 0, 2, 32, 8); } public void setViewport(int width, int height) { @@ -90,11 +98,6 @@ public class RenderingSystem extends EntitySystem { @Override public void update(float deltaTime) { - if (AppUtil.player != null) { - CPhysics phys = pm.get(AppUtil.player); - //camera.position.set(phys.getPosition().x, phys.getPosition().y, 0); - //fontCamera.position.set(camera.position.x * Global.FONT_SCALE, camera.position.y * Global.FONT_SCALE, 0); - } camera.update(); fontCamera.update(); @@ -190,6 +193,7 @@ public class RenderingSystem extends EntitySystem { ro.playAnimation("legs", "Legs-Run-" + dirMove); } else if (combat) { ro.playAnimation("torso", "Torso-Combat-" + dirSwing); + ro.playAnimation("legs", "Legs-Idle-" + dirMove); } else if (moving) { ro.playAnimation("torso", "Torso-Run-" + dirMove); ro.playAnimation("legs", "Legs-Run-" + dirMove); @@ -207,17 +211,17 @@ public class RenderingSystem extends EntitySystem { batch.setProjectionMatrix(camera.combined); batch.begin(); for (int i = 0; i < entities.size(); i++) { + CPhysics physics = pm.get(entities.get(i)); CRenderedObject renderedObject = rom.get(entities.get(i)); if (renderedObject == null) { continue; } + // Draw entity for (String channel : renderedObject.getChannels()) { SpriteSequence currSequence = renderedObject.getSequence(renderedObject.getCurrentSequence(channel)); int currFrame = (int) Math.floor(renderedObject.getCurrentFrame(channel)); Sprite currSprite = currSequence.getSprite(currFrame); - CPhysics physics = pm.get(entities.get(i)); - int spriteHeight = currSprite.getRegionHeight(); int spriteWidth = currSprite.getRegionWidth(); @@ -228,6 +232,25 @@ public class RenderingSystem extends EntitySystem { float nextFrame = renderedObject.getCurrentFrame(channel) + deltaTime * currSequence.getPlayspeed(); renderedObject.setCurrentFrame(channel, nextFrame % currSequence.frameCount()); } + + // Draw healthbars + CCombat combat = cm.get(entities.get(i)); + if (combat != null) { + float spriteWidth = healthbar[0].getWidth(); + float spriteHeight = healthbar[0].getHeight(); + float hp = (float) combat.getHealth() / (float) combat.getMaxHealth(); + + healthbar[0].setPosition(((physics.getPosition().x - spriteWidth / 2) + getCameraOffset(playerPhys, physics).x), + (physics.getPosition().y - spriteHeight / 2 + 2.5f) + getCameraOffset(playerPhys, physics).y); + healthbar[0].draw(batch); + healthbar[1].setPosition(((physics.getPosition().x - spriteWidth / 2) + getCameraOffset(playerPhys, physics).x), + (physics.getPosition().y - spriteHeight / 2 + 2.5f) + getCameraOffset(playerPhys, physics).y); + healthbar[1].setSize(spriteWidth * hp, spriteHeight); + healthbar[1].draw(batch); + healthbar[2].setPosition(((physics.getPosition().x - spriteWidth / 2) + getCameraOffset(playerPhys, physics).x), + (physics.getPosition().y - spriteHeight / 2 + 2.5f) + getCameraOffset(playerPhys, physics).y); + healthbar[2].draw(batch); + } } batch.end(); } diff --git a/core/src/com/saltosion/gladiator/util/Name.java b/core/src/com/saltosion/gladiator/util/Name.java index 4ef36b4..8d73b40 100644 --- a/core/src/com/saltosion/gladiator/util/Name.java +++ b/core/src/com/saltosion/gladiator/util/Name.java @@ -11,6 +11,7 @@ public class Name { public static final String WALLIMG = "WALLIMG"; public static final String SWINGHITBOXIMG = "SWINGHITBOXIMG"; public static final String AUDIENCEIMG = "AUDIENCEIMG"; + public static final String HEALTHBARIMG = "HEALTHBARIMG"; public static final String BUTTON_HUGE = "BUTTON_HUGE"; public static final String BUTTON_HUGE_HOVER = "BUTTON_HUGE_HOVER"; diff --git a/core/src/com/saltosion/gladiator/util/SpriteLoader.java b/core/src/com/saltosion/gladiator/util/SpriteLoader.java index f8737f2..815b2f2 100644 --- a/core/src/com/saltosion/gladiator/util/SpriteLoader.java +++ b/core/src/com/saltosion/gladiator/util/SpriteLoader.java @@ -17,6 +17,7 @@ public class SpriteLoader { loadTexture(Name.GROUNDIMG, "sprites/ground.png"); loadTexture(Name.WALLIMG, "sprites/wall.png"); loadTexture(Name.AUDIENCEIMG, "sprites/audience.png"); + loadTexture(Name.HEALTHBARIMG, "sprites/player/healthbar.png"); loadTexture(Name.BUTTON_HUGE, "sprites/buttons/button_huge.png"); loadTexture(Name.BUTTON_HUGE_HOVER, "sprites/buttons/button_huge_hover.png"); @@ -24,7 +25,7 @@ public class SpriteLoader { loadTexture(Name.BUTTON_BIG_HOVER, "sprites/buttons/button_big_hover.png"); loadTexture(Name.BUTTON_SMALL, "sprites/buttons/button_small.png"); loadTexture(Name.BUTTON_SMALL_HOVER, "sprites/buttons/button_small_hover.png"); - + loadTexture(Name.TITLE_LOGO, "sprites/title_logo.png"); loadTexture(Name.MENU_BACKGROUND, "sprites/menu_background.png"); loadTexture(Name.GPLV3_LOGO, "sprites/gplv3_logo.png");