ki for archer kinda works but works better for swordsman

master
bfz 6 years ago
parent c158ed733a
commit ad8449cac6

@ -49,7 +49,11 @@ public class Controller extends ApplicationAdapter implements InputProcessor{
for(int i = 0; i< e.length; i++){ for(int i = 0; i< e.length; i++){
if(e[i] == null){} if(e[i] == null){}
else{ 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) //PASSIERT IN GAMESCREEN (view)
if(m != null){ if(m != null){
//ENTITIES //ENTITIES
p.setxPos(m.getPlayerSpriteX());
p.setyPos(m.getPlayerSpriteY());
//RENDER //RENDER
@ -145,7 +150,7 @@ public class Controller extends ApplicationAdapter implements InputProcessor{
else if(v.click() == 0){ else if(v.click() == 0){
v = null; v = null;
m = new View(); m = new View();
newEntity(a, 200, 200, 200); newEntity(a, 0, 0, 0);
System.out.println("NICE"); System.out.println("NICE");
} }
} }

@ -3,17 +3,17 @@ package com.dungeoncrawler.model;
public abstract class Entity { public abstract class Entity {
protected int xPos; protected float xPos;
protected int yPos; protected float yPos;
protected int hp; protected int hp;
protected int maxhp; protected int maxhp;
protected int dmg; protected int dmg;
protected int lvl; protected int lvl;
protected int movementX; protected float movementX;
protected int movementY; protected float movementY;
protected int id; protected int id;
public Entity(int xPos, int yPos, int lvl){ public Entity(int xPos, float yPos, int lvl){
this.xPos = xPos; this.xPos = xPos;
this.yPos = yPos; this.yPos = yPos;
this.lvl = lvl; this.lvl = lvl;
@ -35,10 +35,63 @@ public abstract class Entity {
public void move(){ public void move(){
xPos = xPos + movementX; xPos = xPos + movementX;
yPos = yPos + movementY; 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)){
movementX = 1f;
}
else{
movementY = 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)){
movementX = -1;
}
else{
movementY = -1;
}
}
}
move();
/*
switch((int) (Math.random() * 5)){ switch((int) (Math.random() * 5)){
case 0: //left case 0: //left
setMovementX(-3); setMovementX(-3);
@ -57,38 +110,39 @@ public abstract class Entity {
move(); move();
break; break;
} }
*/
} }
public int direction(){ public int direction(){
if(movementX == -3){ if(movementX < 0){
return 3; return 3;
} }
if(movementX == 3){ else if(movementX < 3){
return 1; return 1;
} }
if(movementY == 3){ else if(movementY > 3){
return 0; return 0;
} }
if(movementY == -3){ else if(movementY < -3){
return 2; return 2;
} }
return -1; return -1;
} }
public int getxPos() { public float getxPos() {
return xPos; return xPos;
} }
public void setxPos(int xPos) { public void setxPos(float xPos) {
this.xPos = xPos; this.xPos = xPos;
} }
public int getyPos() { public float getyPos() {
return yPos; return yPos;
} }
public void setyPos(int yPos) { public void setyPos(float yPos) {
this.yPos = yPos; this.yPos = yPos;
} }
@ -124,19 +178,19 @@ public abstract class Entity {
this.lvl = lvl; this.lvl = lvl;
} }
public int getMovementX(){ public float getMovementX(){
return movementX; return movementX;
} }
public void setMovementX(int movementX){ public void setMovementX(float movementX){
this.movementX = movementX; this.movementX = movementX;
} }
public int getMovementY(){ public float getMovementY(){
return movementY; return movementY;
} }
public void setMovementY(int movementY){ public void setMovementY(float movementY){
this.movementY = movementY; this.movementY = movementY;
} }

@ -23,6 +23,7 @@ public class View {
TextureRegion[][] regions; TextureRegion[][] regions;
//ENTITIES //ENTITIES
Texture[] entityTextures; Texture[] entityTextures;
Sprite[] entitySprites; Sprite[] entitySprites;
@ -155,4 +156,31 @@ public class View {
entitySprites[i].setY(y); 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);
}
} }

Loading…
Cancel
Save