diff --git a/core/src/com/dungeoncrawler/model/Entity.java b/core/src/com/dungeoncrawler/model/Entity.java index abda571..1d88243 100644 --- a/core/src/com/dungeoncrawler/model/Entity.java +++ b/core/src/com/dungeoncrawler/model/Entity.java @@ -1,9 +1,5 @@ package com.dungeoncrawler.model; -import com.badlogic.gdx.maps.MapObject; -import com.badlogic.gdx.maps.MapObjects; -import com.badlogic.gdx.math.Rectangle; - public abstract class Entity { protected float xPos; diff --git a/core/src/com/dungeoncrawler/model/entities/Archer.java b/core/src/com/dungeoncrawler/model/entities/Archer.java index bb1f123..808fbb2 100644 --- a/core/src/com/dungeoncrawler/model/entities/Archer.java +++ b/core/src/com/dungeoncrawler/model/entities/Archer.java @@ -71,6 +71,13 @@ public class Archer extends Entity{ yPos += movementY; } + if(alpha >= Math.PI / -2 && alpha <= Math.PI / 2){ + setDirection(1); + } + else{ + setDirection(0); + } + counter++; return false; @@ -110,6 +117,13 @@ public class Archer extends Entity{ a.setMovementY(movementY); a.setAngle(alpha); + if(alpha >= Math.PI / -2 && alpha <= Math.PI / 2){ + setDirection(1); + } + else{ + setDirection(0); + } + return a; } diff --git a/core/src/com/dungeoncrawler/model/entities/Swordsman.java b/core/src/com/dungeoncrawler/model/entities/Swordsman.java index 9b2b982..838caf5 100644 --- a/core/src/com/dungeoncrawler/model/entities/Swordsman.java +++ b/core/src/com/dungeoncrawler/model/entities/Swordsman.java @@ -49,6 +49,8 @@ public class Swordsman extends Entity { xPos += movementX; yPos += movementY; + updateDirection(); + return false; } diff --git a/core/src/com/dungeoncrawler/view/EntitySprite.java b/core/src/com/dungeoncrawler/view/EntitySprite.java index d68f2a9..7e5696e 100644 --- a/core/src/com/dungeoncrawler/view/EntitySprite.java +++ b/core/src/com/dungeoncrawler/view/EntitySprite.java @@ -9,6 +9,7 @@ import com.badlogic.gdx.graphics.Texture; import com.badlogic.gdx.graphics.g2d.Sprite; import com.badlogic.gdx.graphics.g2d.TextureRegion; import com.badlogic.gdx.math.Rectangle; +import com.dungeoncrawler.model.Entity; /** * @@ -45,15 +46,24 @@ public class EntitySprite { fullCollisionSprite = sprites[0].getBoundingRectangle(); } - public void updateAnimation(boolean moves){ - if(attackState == 1){ - updateAttack(); - } - else if(moves){ - updateWalking(); - } - else{ - updateIdle(); + public void updateAnimation(Entity e){ + if(e != null){ + boolean moves = false; + if(e.getMovementX() != 0 || e.getMovementY() != 0){ + moves = true; + } + + direction = e.getDirection(); + + if(attackState == 1){ + updateAttack(); + } + else if(moves){ + updateWalking(); + } + else{ + updateIdle(); + } } } diff --git a/core/src/com/dungeoncrawler/view/GameScreen.java b/core/src/com/dungeoncrawler/view/GameScreen.java index f9afcf9..43d4a5e 100644 --- a/core/src/com/dungeoncrawler/view/GameScreen.java +++ b/core/src/com/dungeoncrawler/view/GameScreen.java @@ -33,6 +33,7 @@ public class GameScreen { TextureRegion[][] swordsmanRegions; Texture swordsmanTexture; Texture healthBar; + Entity[] entities; Texture[] arrowTextures; Sprite[] arrowSprites; @@ -75,6 +76,8 @@ public class GameScreen { controls.setX(-400f); controls.setY(0); */ + + entities = d.getCurrentEntities(); //PLAYER Texture[] playerTexture = new Texture[4]; @@ -145,7 +148,7 @@ public class GameScreen { for(int i = 0; i < entitySprites.length; i++){ if(entitySprites[i] != null){ - entitySprites[i].updateAnimation(true); + entitySprites[i].updateAnimation(entities[i]); } } } @@ -183,6 +186,7 @@ public class GameScreen { public void render (SpriteBatch batch, Player p, Entity[] e, int tileX, int tileY, int level, int roomPosX, int roomPosY) { + entities = e; Gdx.gl.glClearColor(0, 0, 0, 1); Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); @@ -293,7 +297,7 @@ public class GameScreen { entitySprites[i].update((int) e.getxPos(), (int) e.getyPos()); if(e.getId() == 2){ - entitySprites[i].getSprites()[0].setRotation((float) Math.toDegrees(e.getAngle() + Math.PI)); + entitySprites[i].getSprites()[0].setRotation((float) Math.toDegrees(e.getAngle())); } } }