Gegner laufen auf Player zu

master
Jonathan Hager 6 years ago
parent f45ef144b8
commit 29d35fc1eb

@ -104,11 +104,12 @@ public class Controller extends ApplicationAdapter implements InputProcessor{
public void run() {
for(int i = 0; i < d.getCurrentEntities().length; i++){
if(d.getCurrentEntities()[i] != null){
d.getCurrentEntities()[i].randomMove(roomX, roomY);
//d.getCurrentEntities()[i].randomMove(roomX, roomY);
d.getCurrentEntities()[i].move((int) d.getPlayer().getxPos(), (int) d.getPlayer().getyPos());
}
}
}
},0,1f);
},0, 0.03f);
}

@ -1,8 +1,5 @@
package com.dungeoncrawler.model;
import com.badlogic.gdx.utils.Timer;
public abstract class Entity {
protected float xPos;
@ -14,7 +11,7 @@ public abstract class Entity {
protected float movementX;
protected float movementY;
protected int id;
protected int facing;
protected int direction;
protected Inventory inv;
@ -25,16 +22,9 @@ public abstract class Entity {
this.lvl = lvl;
this.movementX = 0;
this.movementY = 0;
this.facing = 2;
this.direction = 2;
}
public void attack(){
}
@ -62,24 +52,13 @@ public abstract class Entity {
movementY = 0;
}
public void rdmMove(){
}
public int direction(){ // returns direction the entity is facing depending on its movement
if(movementX == -3f){ // TIS IS SHIT - NEED REWORK
facing = 3;
}
else if(movementX == 3f){
facing = 1;
}
else if(movementY == 3f){
facing = 0;
public void updateDirection(){
if(movementX > 1){
direction = 1;
}
else if(movementY == -3f){
facing = 2;
else if(movementX < -1){
direction = 0;
}
return facing;
}
@ -152,15 +131,18 @@ public abstract class Entity {
return this.id;
}
public int getFacing(){
return facing;
public int getDirection(){
return direction;
}
public void setFacing(int facing){
this.facing = facing;
public void setDirection(int direction){
this.direction = direction;
}
public void randomMove(int x, int y){
}
}
abstract public void move(int xPosPlayer, int yPosPlayer);
}

@ -17,7 +17,7 @@ public class Archer extends Entity{
this.maxhp = 5*lvl;
this.hp = this.maxhp;
this.facing = 2;
this.direction = 2;
this.dmg = 3*lvl;
this.id = 0;
// TODO: Sinnvolle Werte finden
@ -28,12 +28,12 @@ public class Archer extends Entity{
tleft = new Timer();
isRunning = false;
timerRuns = 0;
facing = 2;
direction = 2;
tup.scheduleTask(new Timer.Task() {
@Override
public void run() {
setFacing(0);
setDirection(0);
setyPos(getyPos() + 1f);
setTimerRuns(getTimerRuns() + 1);
if(getTimerRuns() >= 48){
@ -47,7 +47,7 @@ public class Archer extends Entity{
tright.scheduleTask(new Timer.Task() {
@Override
public void run() {
setFacing(1);
setDirection(1);
setxPos(getxPos() + 1f);
setTimerRuns(getTimerRuns() + 1);
if(getTimerRuns() >= 48){
@ -61,7 +61,7 @@ public class Archer extends Entity{
tdown.scheduleTask(new Timer.Task() {
@Override
public void run() {
setFacing(2);
setDirection(2);
setyPos(getyPos() - 1f);
setTimerRuns(getTimerRuns() + 1);
if(getTimerRuns() >= 48){
@ -75,7 +75,7 @@ public class Archer extends Entity{
tleft.scheduleTask(new Timer.Task() {
@Override
public void run() {
setFacing(3);
setDirection(3);
setxPos(getxPos() - 1f);
setTimerRuns(getTimerRuns() + 1);
@ -153,6 +153,11 @@ public class Archer extends Entity{
timerRuns = n;
}
@Override
public void move(int xPosPlayer, int yPosPlayer) {
// Nothing
}
}

@ -84,4 +84,9 @@ public class Arrow extends Entity{
public float getyStart(){
return yStart;
}
@Override
public void move(int xPosPlayer, int yPosPlayer) {
// Nothing
}
}

@ -35,4 +35,9 @@ public class Player extends Entity {
return inv;
}
@Override
public void move(int xPosPlayer, int yPosPlayer) {
// Nothing
}
}

@ -16,7 +16,7 @@ public class Swordsman extends Entity {
this.maxhp = 5*lvl;
this.hp = this.maxhp;
this.facing = 2;
this.direction = 2;
this.dmg = 3*lvl;
this.id = 1;
// TODO: Sinnvolle Werte finden
@ -26,13 +26,13 @@ public class Swordsman extends Entity {
tleft = new Timer();
isRunning = false;
timerRuns = 0;
facing = 2;
direction = 2;
tup.scheduleTask(new Timer.Task() {
@Override
public void run() {
setFacing(0);
setDirection(0);
setyPos(getyPos() + 1f);
setTimerRuns(getTimerRuns() + 1);
if(getTimerRuns() >= 48){
@ -46,7 +46,7 @@ public class Swordsman extends Entity {
tright.scheduleTask(new Timer.Task() {
@Override
public void run() {
setFacing(1);
setDirection(1);
setxPos(getxPos() + 1f);
setTimerRuns(getTimerRuns() + 1);
if(getTimerRuns() >= 48){
@ -60,7 +60,7 @@ public class Swordsman extends Entity {
tdown.scheduleTask(new Timer.Task() {
@Override
public void run() {
setFacing(2);
setDirection(2);
setyPos(getyPos() - 1f);
setTimerRuns(getTimerRuns() + 1);
if(getTimerRuns() >= 48){
@ -74,7 +74,7 @@ public class Swordsman extends Entity {
tleft.scheduleTask(new Timer.Task() {
@Override
public void run() {
setFacing(3);
setDirection(3);
setxPos(getxPos() - 1f);
setTimerRuns(getTimerRuns() + 1);
@ -148,5 +148,48 @@ public class Swordsman extends Entity {
timerRuns = n;
}
@Override
public void move(int xPosPlayer, int yPosPlayer){
int deltaX = xPosPlayer - (int) xPos;
int deltaY = yPosPlayer - (int) yPos;
double alpha;
if(deltaX == 0 && deltaY >= 0){
alpha = Math.PI / 2;
}
else if(deltaX == 0 && deltaY < 0){
alpha = Math.PI / -2;
}
else{
alpha = Math.abs(Math.atan(deltaY / deltaX));
if(deltaX < 0 && deltaY < 0){
alpha = Math.PI + alpha;
}
else if(deltaX < 0 && deltaY > 0){
alpha = Math.PI - alpha;
}
else if(deltaX > 0 && deltaY < 0){
alpha = 2*Math.PI - alpha;
}
}
movementX = (int) (3 * Math.cos(alpha));
movementY = (int) (3 * Math.sin(alpha));
/*
if(deltaX < 0 || deltaY < 0){
movementX *= -1;
movementY *= -1;
}
else if(deltaY < 0){
movementX *= -1;
}
*/
xPos += movementX;
yPos += movementY;
}
}

@ -279,7 +279,7 @@ public class GameScreen {
//DRAW'T JEDES ENTITY - prueft vorher ob vorhanden
for(int i = 0; i < e.length; i++){
if(e[i] != null){
switch(e[i].getFacing()){
switch(e[i].getDirection()){
case -1:
break;
case 0:
@ -355,7 +355,7 @@ public class GameScreen {
public Entity[] playerAttack(Entity e[], Player p, SpriteBatch batch){
if(p.direction() == 0){
if(p.getDirection() == 0){
Texture attackTexture = new Texture("sprites/AttackHori.png");
Sprite attackSprite = new Sprite(attackTexture);
attackSprite.setX(p.getxPos() - 8f);
@ -376,7 +376,7 @@ public class GameScreen {
}
}
}
else if(p.direction() == 1){
else if(p.getDirection()== 1){
Texture attackTexture = new Texture("sprites/AttackVert.png");
Sprite attackSprite = new Sprite(attackTexture);
attackSprite.setX(p.getxPos()+ 32f);
@ -396,7 +396,7 @@ public class GameScreen {
}
}
}
else if(p.direction() == 2){
else if(p.getDirection()== 2){
Texture attackTexture = new Texture("sprites/AttackHori.png");
Sprite attackSprite = new Sprite(attackTexture);
attackSprite.setX(p.getxPos() - 8f);
@ -416,7 +416,7 @@ public class GameScreen {
}
}
}
else if(p.direction() == 3){
else if(p.getDirection()== 3){
Texture attackTexture = new Texture("sprites/AttackVert.png");
Sprite attackSprite = new Sprite(attackTexture);
attackSprite.setX(p.getxPos() - 32f);

Loading…
Cancel
Save