movementX u. Y aus Controller in Entity umgelagert

master
GammelJan 6 years ago
parent 1141b109bc
commit 7e2f3ff7cf

@ -22,8 +22,6 @@ public class Controller extends ApplicationAdapter implements InputProcessor{
View v; View v;
Player p; Player p;
Archer a; Archer a;
float movementX = 0f;
float movementY = 0f;
Timer t; Timer t;
@Override @Override
@ -45,7 +43,7 @@ public class Controller extends ApplicationAdapter implements InputProcessor{
@Override @Override
public void render(){ public void render(){
v.render(batch, movementX ,movementY, a.getxPos(), a.getyPos()); v.render(batch, p , a);
} }
@Override @Override
@ -56,23 +54,19 @@ public class Controller extends ApplicationAdapter implements InputProcessor{
@Override @Override
public boolean keyDown(int keycode) { public boolean keyDown(int keycode) {
if(keycode == Input.Keys.LEFT){ if(keycode == Input.Keys.LEFT){
movementX = -3f; p.setMovementX(-3);
v.render(batch, movementX, movementY, a.getxPos(), a.getyPos());
} }
if(keycode == Input.Keys.RIGHT){ if(keycode == Input.Keys.RIGHT){
movementX = 3f; p.setMovementX(3);
v.render(batch, movementX, movementY, a.getxPos(), a.getyPos());
} }
if(keycode == Input.Keys.UP){ if(keycode == Input.Keys.UP){
movementY = 2f; p.setMovementY(3);
v.render(batch, movementX, movementY, a.getxPos(), a.getyPos());
} }
if(keycode == Input.Keys.DOWN){ if(keycode == Input.Keys.DOWN){
movementY = -2f; p.setMovementY(-3);
v.render(batch, movementX, movementY, a.getxPos(), a.getyPos());
} }
if(keycode == Input.Keys.W){ if(keycode == Input.Keys.W){
@ -83,22 +77,22 @@ public class Controller extends ApplicationAdapter implements InputProcessor{
@Override @Override
public boolean keyUp(int keycode) { public boolean keyUp(int keycode) {
if(keycode == Input.Keys.LEFT){ if(keycode == Input.Keys.LEFT){
movementX = 0f; p.setMovementX(0);
v.tlinksstop(); v.tlinksstop();
} }
if(keycode == Input.Keys.RIGHT){ if(keycode == Input.Keys.RIGHT){
movementX = 0f; p.setMovementX(0);
v.trechtsstop(); v.trechtsstop();
} }
if(keycode == Input.Keys.DOWN){ if(keycode == Input.Keys.DOWN){
movementY = 0f; p.setMovementY(0);
v.tuntenstop(); v.tuntenstop();
} }
if(keycode == Input.Keys.UP){ if(keycode == Input.Keys.UP){
movementY = 0f; p.setMovementY(0);
v.tobenstop(); v.tobenstop();
} }
return true; return true;

@ -31,7 +31,7 @@ public abstract class Entity {
public void die(){ public void die(){
} }
public void move(int movementX, int movementY){ public void move(){
xPos = xPos + movementX; xPos = xPos + movementX;
yPos = yPos + movementY; yPos = yPos + movementY;
} }
@ -40,16 +40,20 @@ public abstract class Entity {
switch((int) (Math.random() * 5)){ switch((int) (Math.random() * 5)){
case 0: //left case 0: //left
move(-3 , 0); setMovementX(-3);
move();
break; break;
case 1: //right case 1: //right
move(3 , 0); setMovementX(3);
move();
break; break;
case 2: //up case 2: //up
move(0 , 3); setMovementY(3);
move();
break; break;
case 3: //down case 3: //down
move(0 , -3); setMovementY(-3);
move();
break; break;
} }
} }
@ -102,6 +106,20 @@ public abstract class Entity {
public void setLvl(int lvl) { public void setLvl(int lvl) {
this.lvl = lvl; this.lvl = lvl;
} }
public int getMovementX(){
return movementX;
}
public void setMovementX(int movementX){
this.movementX = movementX;
}
public int getMovementY(){
return movementY;
}
public void setMovementY(int movementY){
this.movementY = movementY;
}
} }

@ -7,6 +7,7 @@ import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.g2d.Sprite; import com.badlogic.gdx.graphics.g2d.Sprite;
import com.badlogic.gdx.utils.Timer; import com.badlogic.gdx.utils.Timer;
import com.badlogic.gdx.graphics.g2d.TextureRegion; import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.dungeoncrawler.model.entities.*;
public class View { public class View {
Texture b; Texture b;
@ -133,21 +134,21 @@ public class View {
} }
public void render (SpriteBatch batch, float x, float y, int archerX, int archerY) { public void render (SpriteBatch batch, Player p, Archer a) {
Gdx.gl.glClearColor(0, 0, 0, 1); Gdx.gl.glClearColor(0, 0, 0, 1);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
player.setX(player.getX()+x); player.setX(player.getX()+ (float) p.getMovementX());
player.setY(player.getY()+y); player.setY(player.getY()+ (float) p.getMovementY());
archer.setX(archerX); archer.setX((float)a.getxPos());
archer.setY(archerY); archer.setY((float)a.getyPos());
if(x == 3f){ if(p.getMovementX() == 3){
trechts.start(); trechts.start();
if(player.isFlipX() == true){ if(player.isFlipX() == true){
player.flip(false, false); player.flip(false, false);
} }
} }
if(x == -3f){ if(p.getMovementX() == -3){
tlinks.start(); tlinks.start();
if(player.isFlipX() == true){ if(player.isFlipX() == true){
@ -156,10 +157,10 @@ public class View {
player.flip(true, false); player.flip(true, false);
} }
} }
if(y == 3f){ if(p.getMovementY() == 3){
toben.start(); toben.start();
} }
if(y == -3f){ if(p.getMovementY() == -3){
tunten.start(); tunten.start();
} }

Loading…
Cancel
Save