diff --git a/core/src/com/dungeoncrawler/control/Controller.java b/core/src/com/dungeoncrawler/control/Controller.java index 3d4d0db..4dcc6f9 100644 --- a/core/src/com/dungeoncrawler/control/Controller.java +++ b/core/src/com/dungeoncrawler/control/Controller.java @@ -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(gs != null && gs.getIsLoading() == false){ - d.setCurrentEntities(gs.playerAttack(d.getCurrentEntities(), d.getPlayer(), 0, batch)); - } - } - 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)); + d.setCurrentEntities(gs.playerAttack(d.getCurrentEntities(), d.getPlayer(), 0)); } } diff --git a/core/src/com/dungeoncrawler/model/entities/Archer.java b/core/src/com/dungeoncrawler/model/entities/Archer.java index 9a988e7..10e76f6 100644 --- a/core/src/com/dungeoncrawler/model/entities/Archer.java +++ b/core/src/com/dungeoncrawler/model/entities/Archer.java @@ -121,7 +121,7 @@ public class Archer extends Entity{ a.setMovementY(movementY); 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); } else{ diff --git a/core/src/com/dungeoncrawler/view/EntitySprite.java b/core/src/com/dungeoncrawler/view/EntitySprite.java index a9289ff..4482d2c 100644 --- a/core/src/com/dungeoncrawler/view/EntitySprite.java +++ b/core/src/com/dungeoncrawler/view/EntitySprite.java @@ -45,7 +45,7 @@ public class EntitySprite { 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){ @@ -247,6 +247,7 @@ public class EntitySprite { public void resetAttackState(){ this.attackState = 0; + frames[2] = 0; } public void startAttack(){ diff --git a/core/src/com/dungeoncrawler/view/GameScreen.java b/core/src/com/dungeoncrawler/view/GameScreen.java index f39b416..98fd871 100644 --- a/core/src/com/dungeoncrawler/view/GameScreen.java +++ b/core/src/com/dungeoncrawler/view/GameScreen.java @@ -22,7 +22,6 @@ public class GameScreen { //PLAYER - Texture p; EntitySprite player; @@ -59,6 +58,8 @@ public class GameScreen { boolean playerMoving; + Player p; + HudContainer hc; // Sound @@ -140,7 +141,11 @@ public class GameScreen { animatePlayer.scheduleTask(new Timer.Task() { @Override public void run() { - if(!playerMoving){ + + if(player.getAttackState() == 1){ + player.updateAttack(); + } + else if(!playerMoving){ player.updateIdle(); } else{ @@ -152,6 +157,9 @@ public class GameScreen { entitySprites[i].updateAnimation(entities[i]); } } + if(player.getAttackState() == 2){ + playerAttack(entities, p, player.getDirection()); + } } }, 0, animationSpeed); @@ -190,7 +198,9 @@ public class GameScreen { entities = e; Gdx.gl.glClearColor(0, 0, 0, 1); Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); - + + this.p = p; + playerMoving = (p.getMovementX() != 0 || p.getMovementY() != 0); //setzt player Sprite auf richtige Position @@ -227,6 +237,8 @@ public class GameScreen { updateEntitySprites(e); + + //BATCH batch.begin(); @@ -306,89 +318,61 @@ public class GameScreen { entitySprites[i] = null; } - public Entity[] playerAttack(Entity e[], Player p, int attackDirection, SpriteBatch batch){ - if(attackDirection == 0){ - Texture attackTexture = new Texture("sprites/AttackHori.png"); - 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()); - } - } - } - } - } + public Entity[] playerAttack(Entity e[], Player p, int attackDirection){ + if(player.getAttackState() == 0){ + player.startAttack(); } - else if(attackDirection== 1){ - Texture attackTexture = new Texture("sprites/AttackVert.png"); - Sprite attackSprite = new Sprite(attackTexture); - 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(player.getAttackState() == 1){ + player.resetAttackState(); + player.startAttack(); } - else if(attackDirection== 2){ - Texture attackTexture = new Texture("sprites/AttackHori.png"); - Sprite attackSprite = new Sprite(attackTexture); - attackSprite.setX(p.getxPos() - 8f); - attackSprite.setY(p.getyPos()); - for(int i = 0; i