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

@ -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{

@ -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(){

@ -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<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() == 2){
if(attackDirection== 0){
Texture attackTexture = new Texture("sprites/AttackVert.png");
Sprite attackSprite = new Sprite(attackTexture);
attackSprite.setX(p.getxPos() - 32f);
attackSprite.setY(p.getyPos() - 8f);
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== 3){
Texture attackTexture = new Texture("sprites/AttackVert.png");
Sprite attackSprite = new Sprite(attackTexture);
attackSprite.setX(p.getxPos() - 32f);
attackSprite.setY(p.getyPos() - 8f);
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== 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());
}
}
}
}
}
}
player.resetAttackState();
}
return e;
return e;
}
public void cleanUp(){

Loading…
Cancel
Save