master
GammelJan 6 years ago
parent aadc0d8516
commit 7f482f42bd

Binary file not shown.

After

Width:  |  Height:  |  Size: 628 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 627 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 27 KiB

After

Width:  |  Height:  |  Size: 18 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 26 KiB

After

Width:  |  Height:  |  Size: 27 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 44 KiB

After

Width:  |  Height:  |  Size: 28 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 13 KiB

After

Width:  |  Height:  |  Size: 29 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 13 KiB

After

Width:  |  Height:  |  Size: 29 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 13 KiB

After

Width:  |  Height:  |  Size: 29 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 13 KiB

After

Width:  |  Height:  |  Size: 29 KiB

@ -25,6 +25,13 @@ 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;
@ -32,6 +39,8 @@ public class EntitySprite {
sprites = new Sprite[1];
regions = new TextureRegion[1][][];
healthBarExists = true;
// 0: idle, 1: walking, 2: attack
frames = new int[3];
direction = 0;
@ -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
*/

@ -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()));
}

Loading…
Cancel
Save