master
GammelJan 6 years ago
parent d0fdc415e2
commit 6377ab95d6

@ -478,28 +478,10 @@ public class Controller extends ApplicationAdapter implements InputProcessor{
} }
} }
if(keycode == Input.Keys.UP){ if(keycode == Input.Keys.SPACE){
if(mm != null){} if(mm != null){}
if(gs != null && gs.getIsLoading() == false){ if(gs != null && gs.getIsLoading() == false){
d.setCurrentEntities(gs.playerAttack(d.getCurrentEntities(), d.getPlayer(), 0, batch)); d.setCurrentEntities(gs.playerAttack(d.getCurrentEntities(), d.getPlayer(), 0));
}
}
if(keycode == Input.Keys.RIGHT){
if(mm != null){}
if(gs != null && gs.getIsLoading() == false){
d.setCurrentEntities(gs.playerAttack(d.getCurrentEntities(), d.getPlayer(), 1, batch));
}
}
if(keycode == Input.Keys.DOWN){
if(mm != null){}
if(gs != null && gs.getIsLoading() == false){
d.setCurrentEntities(gs.playerAttack(d.getCurrentEntities(), d.getPlayer(), 2, batch));
}
}
if(keycode == Input.Keys.LEFT){
if(mm != null){}
if(gs != null && gs.getIsLoading() == false){
d.setCurrentEntities(gs.playerAttack(d.getCurrentEntities(), d.getPlayer(), 3, batch));
} }
} }

@ -121,7 +121,7 @@ public class Archer extends Entity{
a.setMovementY(movementY); a.setMovementY(movementY);
a.setAngle(alpha); a.setAngle(alpha);
if(alpha >= Math.PI / -2 && alpha <= Math.PI / 2){ if((alpha >= 0 && alpha <= Math.PI / 2) || (alpha <= 2 * Math.PI && alpha >= 2 * Math.PI - Math.PI / 2)){
setDirection(1); setDirection(1);
} }
else{ else{

@ -45,7 +45,7 @@ public class EntitySprite {
collisionSprite = new Rectangle(0, 0, 32, 16); collisionSprite = new Rectangle(0, 0, 32, 16);
} }
this.fullCollisionSprite = sprites[0].getBoundingRectangle(); this.fullCollisionSprite = new Rectangle(0,0,32,64);
} }
public void updateAnimation(Entity e){ public void updateAnimation(Entity e){
@ -247,6 +247,7 @@ public class EntitySprite {
public void resetAttackState(){ public void resetAttackState(){
this.attackState = 0; this.attackState = 0;
frames[2] = 0;
} }
public void startAttack(){ public void startAttack(){

@ -22,7 +22,6 @@ public class GameScreen {
//PLAYER //PLAYER
Texture p;
EntitySprite player; EntitySprite player;
@ -59,6 +58,8 @@ public class GameScreen {
boolean playerMoving; boolean playerMoving;
Player p;
HudContainer hc; HudContainer hc;
// Sound // Sound
@ -140,7 +141,11 @@ public class GameScreen {
animatePlayer.scheduleTask(new Timer.Task() { animatePlayer.scheduleTask(new Timer.Task() {
@Override @Override
public void run() { public void run() {
if(!playerMoving){
if(player.getAttackState() == 1){
player.updateAttack();
}
else if(!playerMoving){
player.updateIdle(); player.updateIdle();
} }
else{ else{
@ -152,6 +157,9 @@ public class GameScreen {
entitySprites[i].updateAnimation(entities[i]); entitySprites[i].updateAnimation(entities[i]);
} }
} }
if(player.getAttackState() == 2){
playerAttack(entities, p, player.getDirection());
}
} }
}, 0, animationSpeed); }, 0, animationSpeed);
@ -190,7 +198,9 @@ public class GameScreen {
entities = e; entities = e;
Gdx.gl.glClearColor(0, 0, 0, 1); Gdx.gl.glClearColor(0, 0, 0, 1);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
this.p = p;
playerMoving = (p.getMovementX() != 0 || p.getMovementY() != 0); playerMoving = (p.getMovementX() != 0 || p.getMovementY() != 0);
//setzt player Sprite auf richtige Position //setzt player Sprite auf richtige Position
@ -227,6 +237,8 @@ public class GameScreen {
updateEntitySprites(e); updateEntitySprites(e);
//BATCH //BATCH
batch.begin(); batch.begin();
@ -306,89 +318,61 @@ public class GameScreen {
entitySprites[i] = null; entitySprites[i] = null;
} }
public Entity[] playerAttack(Entity e[], Player p, int attackDirection, SpriteBatch batch){ public Entity[] playerAttack(Entity e[], Player p, int attackDirection){
if(attackDirection == 0){ if(player.getAttackState() == 0){
Texture attackTexture = new Texture("sprites/AttackHori.png"); player.startAttack();
Sprite attackSprite = new Sprite(attackTexture);
attackSprite.setX(p.getxPos() - 8f);
attackSprite.setY(p.getyPos() + 32f);
for(int i = 0; i< e.length ; i++){
if(e[i] != null){
if(Intersector.overlaps(entitySprites[i].getCollisionSprite(), attackSprite.getBoundingRectangle())){
if(e[i] != null){
if(e[i].getHp() - p.getDmg() <= 0){
e[i].setToDelete(true);
}
else{
e[i].setHp(e[i].getHp() - p.getDmg());
}
}
}
}
}
} }
else if(attackDirection== 1){ else if(player.getAttackState() == 1){
Texture attackTexture = new Texture("sprites/AttackVert.png"); player.resetAttackState();
Sprite attackSprite = new Sprite(attackTexture); player.startAttack();
attackSprite.setX(p.getxPos()+ 32f);
attackSprite.setY(p.getyPos()- 2f);
for(int i = 0; i< e.length ; i++){
if(entitySprites[i] != null){
if(Intersector.overlaps(entitySprites[i].getCollisionSprite(), attackSprite.getBoundingRectangle())){
if(e[i] != null){
if(e[i].getHp() - p.getDmg() <= 0){
e[i].setToDelete(true);
}
else{
e[i].setHp(e[i].getHp() - p.getDmg());
}
}
}
}
}
} }
else if(attackDirection== 2){ else if(player.getAttackState() == 2){
Texture attackTexture = new Texture("sprites/AttackHori.png");
Sprite attackSprite = new Sprite(attackTexture); if(attackDirection== 0){
attackSprite.setX(p.getxPos() - 8f); Texture attackTexture = new Texture("sprites/AttackVert.png");
attackSprite.setY(p.getyPos()); Sprite attackSprite = new Sprite(attackTexture);
for(int i = 0; i<e.length ; i++){ attackSprite.setX(p.getxPos() - 32f);
if(entitySprites[i] != null){ attackSprite.setY(p.getyPos() - 8f);
if(Intersector.overlaps(entitySprites[i].getCollisionSprite(), attackSprite.getBoundingRectangle())){ for(int i = 0; i < e.length ; i++){
if(e[i] != null){ if(entitySprites[i] != null){
if(e[i].getHp() - p.getDmg() <= 0){ if(Intersector.overlaps(entitySprites[i].getCollisionSprite(), attackSprite.getBoundingRectangle())){
e[i].setToDelete(true); if(e[i] != null){
} if(e[i].getHp() - p.getDmg() <= 0){
else{ e[i].setToDelete(true);
e[i].setHp(e[i].getHp() - p.getDmg()); }
else{
e[i].setHp(e[i].getHp() - p.getDmg());
}
} }
} }
} }
} }
} }
} else if(attackDirection== 1){
else if(attackDirection== 3){ Texture attackTexture = new Texture("sprites/AttackVert.png");
Texture attackTexture = new Texture("sprites/AttackVert.png"); Sprite attackSprite = new Sprite(attackTexture);
Sprite attackSprite = new Sprite(attackTexture); attackSprite.setX(p.getxPos()+ 32f);
attackSprite.setX(p.getxPos() - 32f); attackSprite.setY(p.getyPos()- 2f);
attackSprite.setY(p.getyPos() - 8f); for(int i = 0; i< e.length ; i++){
for(int i = 0; i < e.length ; i++){ if(entitySprites[i] != null){
if(entitySprites[i] != null){ if(Intersector.overlaps(entitySprites[i].getCollisionSprite(), attackSprite.getBoundingRectangle())){
if(Intersector.overlaps(entitySprites[i].getCollisionSprite(), attackSprite.getBoundingRectangle())){ if(e[i] != null){
if(e[i] != null){ if(e[i].getHp() - p.getDmg() <= 0){
if(e[i].getHp() - p.getDmg() <= 0){ e[i].setToDelete(true);
e[i].setToDelete(true); }
} else{
else{ e[i].setHp(e[i].getHp() - p.getDmg());
e[i].setHp(e[i].getHp() - p.getDmg()); }
} }
} }
} }
} }
} }
player.resetAttackState();
} }
return e;
return e;
} }
public void cleanUp(){ public void cleanUp(){

Loading…
Cancel
Save