master
Jonathan Hager 6 years ago
parent 0e8f29cc6a
commit 0a03c8d8cf

@ -215,10 +215,16 @@ public class Controller extends ApplicationAdapter implements InputProcessor{
}
}
if(delete && d.getCurrentEntities()[i].getId() == 2 || d.getCurrentEntities()[i].getToDelete()){
if(delete || d.getCurrentEntities()[i].getToDelete()){
if(d.getCurrentEntities()[i].getId() == 2){
d.getCurrentEntities()[i] = null;
gs.deleteEntitySprite(i);
}
else{
}
}
}
}
}

@ -23,6 +23,7 @@ public class Archer extends Entity{
@Override
public boolean move(int xPosPlayer, int yPosPlayer) {
if(!toDelete){
float deltaX = xPosPlayer - (int) xPos;
float deltaY = yPosPlayer - (int) yPos;
@ -79,13 +80,16 @@ public class Archer extends Entity{
}
counter++;
}
return false;
}
@Override
public Entity shoot(int xPosPlayer, int yPosPlayer){
Arrow a = null;
if(!toDelete){
float deltaX = xPosPlayer - (int) xPos;
float deltaY = yPosPlayer - (int) yPos;
@ -109,7 +113,7 @@ public class Archer extends Entity{
alpha = 2*Math.PI - alpha;
}
}
Arrow a = new Arrow(this.xPos, this.yPos, this.lvl, 0);
a = new Arrow(this.xPos, this.yPos, this.lvl, 0);
movementX = (int) (6 * Math.cos(alpha));
movementY = (int) (6 * Math.sin(alpha));
@ -123,6 +127,7 @@ public class Archer extends Entity{
else{
setDirection(0);
}
}
return a;
}

@ -19,6 +19,7 @@ public class Swordsman extends Entity {
@Override
public boolean move(int xPosPlayer, int yPosPlayer){
if(!toDelete){
float deltaX = xPosPlayer - (int) xPos;
float deltaY = yPosPlayer - (int) yPos;
@ -50,7 +51,7 @@ public class Swordsman extends Entity {
yPos += movementY;
updateDirection();
}
return false;
}

@ -24,13 +24,7 @@ public class EntitySprite {
private TextureRegion[][][] regions;
private int[] frames;
private int attackState;
private Texture healthBarContainerTexture;
private Sprite healthBarContainerSprite;
private Texture healthBarTexture;
private Sprite healthBarSprite;
boolean healthBarExists;
private int die;
// 0: links, 1: rechts
private int direction;
@ -39,12 +33,11 @@ public class EntitySprite {
sprites = new Sprite[1];
regions = new TextureRegion[1][][];
healthBarExists = true;
// 0: idle, 1: walking, 2: attack
frames = new int[3];
// 0: idle, 1: walking, 2: attack, 3: die
frames = new int[4];
direction = 0;
attackState = 0;
die = 0;
for(int i = 0; i < sprites.length; i++){
regions[i] = TextureRegion.split(textures[i], width, height);
@ -64,7 +57,10 @@ public class EntitySprite {
direction = e.getDirection();
if(attackState == 1){
if(die >= 1){
updateDie();
}
else if(attackState == 1){
updateAttack();
}
else if(moves){
@ -76,6 +72,17 @@ public class EntitySprite {
}
}
public void updateDie(){
if(frames[3] >= 9){
die = 2;
}
else{
frames[3]++;
sprites[0].setRegion(regions[0][4][frames[3]]);
updateFlip();
}
}
public void updateAttack(){
frames[0] = 0;
frames[1] = 0;
@ -137,32 +144,12 @@ 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);
getFullCollisionSprite().setPosition(xPos, yPos);
@ -181,15 +168,6 @@ 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
*/

Loading…
Cancel
Save