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

@ -31,7 +31,7 @@ public abstract class Entity {
public void die(){
}
public void move(int movementX, int movementY){
public void move(){
xPos = xPos + movementX;
yPos = yPos + movementY;
}
@ -40,16 +40,20 @@ public abstract class Entity {
switch((int) (Math.random() * 5)){
case 0: //left
move(-3 , 0);
setMovementX(-3);
move();
break;
case 1: //right
move(3 , 0);
setMovementX(3);
move();
break;
case 2: //up
move(0 , 3);
setMovementY(3);
move();
break;
case 3: //down
move(0 , -3);
setMovementY(-3);
move();
break;
}
}
@ -102,6 +106,20 @@ public abstract class Entity {
public void setLvl(int 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.utils.Timer;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.dungeoncrawler.model.entities.*;
public class View {
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.glClear(GL20.GL_COLOR_BUFFER_BIT);
player.setX(player.getX()+x);
player.setY(player.getY()+y);
archer.setX(archerX);
archer.setY(archerY);
player.setX(player.getX()+ (float) p.getMovementX());
player.setY(player.getY()+ (float) p.getMovementY());
archer.setX((float)a.getxPos());
archer.setY((float)a.getyPos());
if(x == 3f){
if(p.getMovementX() == 3){
trechts.start();
if(player.isFlipX() == true){
player.flip(false, false);
}
}
if(x == -3f){
if(p.getMovementX() == -3){
tlinks.start();
if(player.isFlipX() == true){
@ -156,10 +157,10 @@ public class View {
player.flip(true, false);
}
}
if(y == 3f){
if(p.getMovementY() == 3){
toben.start();
}
if(y == -3f){
if(p.getMovementY() == -3){
tunten.start();
}

Loading…
Cancel
Save