diff --git a/core/src/com/dungeoncrawler/control/Controller.java b/core/src/com/dungeoncrawler/control/Controller.java index 5067fc7..f6d0ebd 100644 --- a/core/src/com/dungeoncrawler/control/Controller.java +++ b/core/src/com/dungeoncrawler/control/Controller.java @@ -49,7 +49,11 @@ public class Controller extends ApplicationAdapter implements InputProcessor{ for(int i = 0; i< e.length; i++){ if(e[i] == null){} else{ - e[i].rdmMove(); + e[i].rdmMove(p.getxPos(), p.getyPos()); + m.setPlayerSpriteX(p.getxPos()); + m.setPlayerSpriteY(p.getyPos()); + m.setEntitySpriteX(i,p.getxPos()); + m.setEntitySpriteY(i,p.getxPos()); } } } @@ -66,7 +70,8 @@ public class Controller extends ApplicationAdapter implements InputProcessor{ //PASSIERT IN GAMESCREEN (view) if(m != null){ //ENTITIES - + p.setxPos(m.getPlayerSpriteX()); + p.setyPos(m.getPlayerSpriteY()); //RENDER diff --git a/core/src/com/dungeoncrawler/model/Entity.java b/core/src/com/dungeoncrawler/model/Entity.java index eb3b2be..c2c2fef 100644 --- a/core/src/com/dungeoncrawler/model/Entity.java +++ b/core/src/com/dungeoncrawler/model/Entity.java @@ -3,17 +3,17 @@ package com.dungeoncrawler.model; public abstract class Entity { - protected int xPos; - protected int yPos; + protected float xPos; + protected float yPos; protected int hp; protected int maxhp; protected int dmg; protected int lvl; - protected int movementX; - protected int movementY; + protected float movementX; + protected float movementY; protected int id; - public Entity(int xPos, int yPos, int lvl){ + public Entity(int xPos, float yPos, int lvl){ this.xPos = xPos; this.yPos = yPos; this.lvl = lvl; @@ -35,10 +35,62 @@ public abstract class Entity { public void move(){ xPos = xPos + movementX; yPos = yPos + movementY; + movementX = 0; + movementY = 0; } - public void rdmMove(){ - + public void rdmMove(float xPlayer, float yPlayer){ + if(xPlayer == xPos){ + if(yPlayer == yPos){} + else if(yPlayer > yPos){movementY = -1f;} + else if(yPlayer < yPos){movementY = 1f;} + } + else if(yPlayer == yPos){ + if(xPlayer == xPos){} + else if(xPlayer > xPos){movementX = 1f;} + else if(xPlayer < xPos){movementX = -1f;} + } + else if(xPlayer > xPos){ + if(yPlayer > yPos){ //archer ist im Quadrant III + if((yPos - yPlayer) > (xPos - xPlayer)){ + movementY = 1f; + } + else{ + movementX = 1f; + } + } + else if(yPlayer < yPos){ //archer ist im Quadrant IV + if((yPos - yPlayer) > (xPlayer - xPos)){ + movementX = 1f; + } + else{ + movementY = -1f; + } + } + } + else if(xPlayer < xPos){ + if(yPlayer < yPos){ //archer ist im Quadrant II + if((yPlayer - yPos) > (xPlayer - xPos)){ + movementX = -1f; + } + else{ + movementY = 1f; + } + } + else if(yPlayer > yPos){ //archer ist im Quadrant I + if((yPlayer - yPos) > (xPos - xPlayer)){ + movementY = -1; + } + else{ + movementX = -1; + } + } + } + + move(); + + + /* switch((int) (Math.random() * 5)){ case 0: //left setMovementX(-3); @@ -57,7 +109,24 @@ public abstract class Entity { move(); break; } + */ + } + + public int direction(){ + if(movementX < 0f){ + return 3; } + else if(movementX < 3f){ + return 1; + } + else if(movementY > 3f){ + return 0; + } + else if(movementY < -3f){ + return 2; + } + return -1; + } public int direction(){ if(movementX == -3){ @@ -76,19 +145,19 @@ public abstract class Entity { } - public int getxPos() { + public float getxPos() { return xPos; } - public void setxPos(int xPos) { + public void setxPos(float xPos) { this.xPos = xPos; } - public int getyPos() { + public float getyPos() { return yPos; } - public void setyPos(int yPos) { + public void setyPos(float yPos) { this.yPos = yPos; } @@ -124,19 +193,19 @@ public abstract class Entity { this.lvl = lvl; } - public int getMovementX(){ + public float getMovementX(){ return movementX; } - public void setMovementX(int movementX){ + public void setMovementX(float movementX){ this.movementX = movementX; } - public int getMovementY(){ + public float getMovementY(){ return movementY; } - public void setMovementY(int movementY){ + public void setMovementY(float movementY){ this.movementY = movementY; } diff --git a/core/src/com/dungeoncrawler/view/Hud.java b/core/src/com/dungeoncrawler/view/Hud.java new file mode 100644 index 0000000..38e7dc1 --- /dev/null +++ b/core/src/com/dungeoncrawler/view/Hud.java @@ -0,0 +1,17 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package com.dungeoncrawler.view; + +import com.dungeoncrawler.model.entities.Player; +/** + * + * @author Jan + */ +public class Hud { + + public Hud(Player p){} + +} diff --git a/core/src/com/dungeoncrawler/view/View.java b/core/src/com/dungeoncrawler/view/View.java index a3b7ea2..0956e7e 100644 --- a/core/src/com/dungeoncrawler/view/View.java +++ b/core/src/com/dungeoncrawler/view/View.java @@ -23,6 +23,7 @@ public class View { TextureRegion[][] regions; + //ENTITIES Texture[] entityTextures; Sprite[] entitySprites; @@ -155,4 +156,31 @@ public class View { entitySprites[i].setY(y); } } + + public float getPlayerSpriteX(){ + return player.getX(); + } + public float getPlayerSpriteY(){ + return player.getY(); + } + public void setPlayerSpriteX(float x){ + player.setX(x); + } + public void setPlayerSpriteY(float y){ + player.setY(y); + } + + public float getEntitySpriteX(int i){ + return entitySprites[i].getX(); + } + public float getEntitySpriteY(int i){ + return entitySprites[i].getY(); + } + public void setEntitySpriteX(int i,float x){ + entitySprites[i].setX(x); + } + public void setEntitySpriteY(int i,float y){ + entitySprites[i].setY(y); + } + }