richtig geil ich bin so gut

master
Jonathan Hager 6 years ago
parent b591c38e13
commit 9f7a5489fd

@ -126,7 +126,18 @@ public class Controller extends ApplicationAdapter implements InputProcessor{
d.getCurrentEntities()[i].attack(d.getPlayer()); d.getCurrentEntities()[i].attack(d.getPlayer());
} }
else{ else{
switch(m.entitySprites[i].getAttackState()){
case 0:
m.entitySprites[i].startAttack();
break;
case 1:
break;
case 2:
d.getCurrentEntities()[i].attack(d.getPlayer());
m.entitySprites[i].resetAttackState();
break;
default:
}
} }
} }

@ -22,6 +22,7 @@ public class EntitySprite {
private Rectangle fullCollisionSprite; private Rectangle fullCollisionSprite;
private TextureRegion[][][] regions; private TextureRegion[][][] regions;
private int[] frames; private int[] frames;
private int attackState;
// 0: links, 1: rechts // 0: links, 1: rechts
private int direction; private int direction;
@ -29,8 +30,11 @@ public class EntitySprite {
public EntitySprite(Texture[] textures){ public EntitySprite(Texture[] textures){
sprites = new Sprite[1]; sprites = new Sprite[1];
regions = new TextureRegion[1][][]; regions = new TextureRegion[1][][];
frames = new int[2];
// 0: idle, 1: walking, 2: attack
frames = new int[3];
direction = 0; direction = 0;
attackState = 0;
for(int i = 0; i < regions.length; i++){ for(int i = 0; i < regions.length; i++){
regions[i] = TextureRegion.split(textures[i], 64, 64); regions[i] = TextureRegion.split(textures[i], 64, 64);
@ -41,8 +45,37 @@ public class EntitySprite {
fullCollisionSprite = sprites[0].getBoundingRectangle(); fullCollisionSprite = sprites[0].getBoundingRectangle();
} }
public void updateAnimation(boolean moves){
if(attackState == 1){
updateAttack();
}
else if(moves){
updateWalking();
}
else{
updateIdle();
}
}
public void updateAttack(){
frames[0] = 0;
frames[1] = 0;
if(frames[2] >= 9){
frames[2] = 0;
attackState = 2;
}
else{
frames[2]++;
sprites[0].setRegion(regions[0][3][frames[2]]);
updateFlip();
}
}
public void updateIdle(){ public void updateIdle(){
frames[1] = 0; frames[1] = 0;
frames[2] = 0;
if(frames[0] >= 9){ if(frames[0] >= 9){
frames[0] = 0; frames[0] = 0;
@ -57,6 +90,7 @@ public class EntitySprite {
public void updateWalking(){ public void updateWalking(){
frames[0] = 0; frames[0] = 0;
frames[2] = 0;
if(frames[1] >= 9){ if(frames[1] >= 9){
frames[1] = 0; frames[1] = 0;
@ -174,4 +208,16 @@ public class EntitySprite {
public Rectangle getFullCollisionSprite() { public Rectangle getFullCollisionSprite() {
return fullCollisionSprite; return fullCollisionSprite;
} }
public int getAttackState(){
return this.attackState;
}
public void resetAttackState(){
this.attackState = 0;
}
public void startAttack(){
this.attackState = 1;
}
} }

@ -142,6 +142,12 @@ public class GameScreen {
else{ else{
player.updateWalking(); player.updateWalking();
} }
for(int i = 0; i < entitySprites.length; i++){
if(entitySprites[i] != null){
entitySprites[i].updateAnimation(true);
}
}
} }
}, 0, animationSpeed); }, 0, animationSpeed);

Loading…
Cancel
Save