diff --git a/core/assets/sprites/entityHealthBar.png b/core/assets/sprites/entityHealthBar.png new file mode 100644 index 0000000..59298a7 Binary files /dev/null and b/core/assets/sprites/entityHealthBar.png differ diff --git a/core/assets/sprites/entityHealthBarContainer.png b/core/assets/sprites/entityHealthBarContainer.png new file mode 100644 index 0000000..a66298c Binary files /dev/null and b/core/assets/sprites/entityHealthBarContainer.png differ diff --git a/core/assets/tilesets/tileset_floor_1.png b/core/assets/tilesets/tileset_floor_1.png index 4977497..d0f31cd 100644 Binary files a/core/assets/tilesets/tileset_floor_1.png and b/core/assets/tilesets/tileset_floor_1.png differ diff --git a/core/assets/tilesets/tileset_floor_2.png b/core/assets/tilesets/tileset_floor_2.png index bac7e37..6b2de00 100644 Binary files a/core/assets/tilesets/tileset_floor_2.png and b/core/assets/tilesets/tileset_floor_2.png differ diff --git a/core/assets/tilesets/tileset_floor_3.png b/core/assets/tilesets/tileset_floor_3.png index 1819278..34ab31f 100644 Binary files a/core/assets/tilesets/tileset_floor_3.png and b/core/assets/tilesets/tileset_floor_3.png differ diff --git a/core/assets/tilesets/tileset_floor_4.png b/core/assets/tilesets/tileset_floor_4.png index 5acff2e..9219aa8 100644 Binary files a/core/assets/tilesets/tileset_floor_4.png and b/core/assets/tilesets/tileset_floor_4.png differ diff --git a/core/assets/tilesets/tileset_floor_5.png b/core/assets/tilesets/tileset_floor_5.png index 5acff2e..2422f29 100644 Binary files a/core/assets/tilesets/tileset_floor_5.png and b/core/assets/tilesets/tileset_floor_5.png differ diff --git a/core/assets/tilesets/tileset_floor_6.png b/core/assets/tilesets/tileset_floor_6.png index 5acff2e..a62b1a4 100644 Binary files a/core/assets/tilesets/tileset_floor_6.png and b/core/assets/tilesets/tileset_floor_6.png differ diff --git a/core/assets/tilesets/tileset_floor_7.png b/core/assets/tilesets/tileset_floor_7.png index 5acff2e..222bb74 100644 Binary files a/core/assets/tilesets/tileset_floor_7.png and b/core/assets/tilesets/tileset_floor_7.png differ diff --git a/core/src/com/dungeoncrawler/view/EntitySprite.java b/core/src/com/dungeoncrawler/view/EntitySprite.java index 7e5696e..8311a49 100644 --- a/core/src/com/dungeoncrawler/view/EntitySprite.java +++ b/core/src/com/dungeoncrawler/view/EntitySprite.java @@ -25,12 +25,21 @@ public class EntitySprite { private int[] frames; private int attackState; + private Texture healthBarContainerTexture; + private Sprite healthBarContainerSprite; + private Texture healthBarTexture; + private Sprite healthBarSprite; + boolean healthBarExists; + + // 0: links, 1: rechts private int direction; public EntitySprite(Texture[] textures, int width, int height){ sprites = new Sprite[1]; regions = new TextureRegion[1][][]; + + healthBarExists = true; // 0: idle, 1: walking, 2: attack frames = new int[3]; @@ -83,6 +92,8 @@ public class EntitySprite { } } + + public void updateIdle(){ frames[1] = 0; frames[2] = 0; @@ -126,12 +137,32 @@ public class EntitySprite { public void update(int xPos, int yPos){ for(int i = 0; i < sprites.length; i++){ sprites[i].setPosition(xPos - 16, yPos); + if(healthBarExists == true){ + } } updateCollision(xPos, yPos); } + public void updateHealthBar(float hp, float maxHp, float xPos, float yPos){ + float n = hp / maxHp; + healthBarTexture = new Texture("sprites/entityHealthBar.png"); + int newWidth = (int) (n * healthBarTexture.getWidth()); + TextureRegion[][] playerHealthRegion = TextureRegion.split(healthBarTexture,newWidth, healthBarTexture.getHeight()); + healthBarSprite = new Sprite(playerHealthRegion[0][0]); + healthBarSprite.setPosition(xPos, yPos); + healthBarContainerSprite.setPosition(xPos, yPos); + } + + public void createHealthBar(){ + healthBarContainerTexture = new Texture("sprites/entityHealthBarContainer.png"); + healthBarContainerSprite = new Sprite(healthBarContainerTexture); + healthBarExists = true; + } + + + public void updateCollision(int xPos, int yPos){ collisionSprite.setPosition(xPos, yPos); } @@ -149,6 +180,15 @@ public class EntitySprite { return sprites; } + public Sprite getHealthBarContainerSprite(){ + return healthBarContainerSprite; + } + public Sprite getHealthBarSprite(){ + return healthBarSprite; + } + public boolean healthBarIsExisting(){ + return healthBarExists; + } /** * @param sprites the sprites to set */ diff --git a/core/src/com/dungeoncrawler/view/GameScreen.java b/core/src/com/dungeoncrawler/view/GameScreen.java index 6d7fd9b..d51560c 100644 --- a/core/src/com/dungeoncrawler/view/GameScreen.java +++ b/core/src/com/dungeoncrawler/view/GameScreen.java @@ -33,7 +33,6 @@ public class GameScreen { Texture archerTexture; TextureRegion[][] swordsmanRegions; Texture swordsmanTexture; - Texture healthBar; Entity[] entities; Texture[] arrowTextures; @@ -244,20 +243,9 @@ public class GameScreen { if(e[i] != null){ entitySprites[i].getSprites()[0].draw(batch); - - if(e[i].getId() != 2){ - if(e[i].getHp() < e[i].getMaxhp() && e[i].getHp() > 0){ - healthBar = new Texture("sprites/halfHealthEntity.png"); - Sprite healthBarSprite = new Sprite(healthBar); - healthBarSprite.setPosition(e[i].getxPos(), e[i].getyPos()); - healthBarSprite.draw(batch); - } - else if(e[i].getHp() == e[i].getMaxhp()){ - healthBar = new Texture("sprites/fullHealthEntity.png"); - Sprite healthBarSprite = new Sprite(healthBar); - healthBarSprite.setPosition(e[i].getxPos(), e[i].getyPos()); - healthBarSprite.draw(batch); - } + if(entitySprites[i].healthBarExists == true){ + entitySprites[i].getHealthBarContainerSprite().draw(batch); + entitySprites[i].getHealthBarSprite().draw(batch); } } } @@ -287,10 +275,12 @@ public class GameScreen { if(e.getId() == 0){ //nimmt entity ID -> 0 = Archer || 1 = Swordsman || 2 = Arrow tx[0] = new Texture("sprites/archer.png"); entitySprites[i] = new EntitySprite(tx, 64, 64); + entitySprites[i].createHealthBar(); } if(e.getId() == 1){ tx[0] = new Texture("sprites/swordsman.png"); entitySprites[i] = new EntitySprite(tx, 64, 64); + entitySprites[i].createHealthBar(); } if(e.getId() == 2){ tx[0] = new Texture("sprites/arrow.png"); @@ -298,7 +288,9 @@ public class GameScreen { } entitySprites[i].update((int) e.getxPos() + 32, (int) e.getyPos() + 32); - + if(e.getId() != 2 && e.getId() != -1){ + entitySprites[i].updateHealthBar(e.getHp(), e.getMaxhp(), e.getxPos(), e.getyPos()); + } if(e.getId() == 2){ entitySprites[i].getSprites()[0].setRotation((float) Math.toDegrees(e.getAngle())); }