Collisions and animation updates working

master
Jonathan Hager 5 years ago
commit 25453d2cf6

@ -45,19 +45,6 @@ public class AnimatedSprite {
} }
} }
/*
public void updateBackwards(){
if(getFrame() <= 0){
setFrame(texture[0].length - 1);
}
else{
setFrame(getFrame() - 1);
}
sprite.setRegion(texture[getRow()][getFrame()]);
}
*/
public void draw(Batch batch) { public void draw(Batch batch) {
sprite.draw(batch); sprite.draw(batch);
} }

@ -27,6 +27,8 @@ public class Player extends Actor{
float movementX = 0; float movementX = 0;
float movementY = 0; float movementY = 0;
float speed = 2f; float speed = 2f;
// 0: up, 1: left, 2: down, 3: right
int facing = 0;
public Player(int xPos, int yPos){ public Player(int xPos, int yPos){
@ -49,15 +51,19 @@ public class Player extends Actor{
public void act(float delta) { public void act(float delta) {
if(Gdx.input.isKeyPressed(Input.Keys.D)){ if(Gdx.input.isKeyPressed(Input.Keys.D)){
movementX = speed; movementX = speed;
facing = 3;
} }
if(Gdx.input.isKeyPressed(Input.Keys.A)){ if(Gdx.input.isKeyPressed(Input.Keys.A)){
movementX = -speed; movementX = -speed;
facing = 1;
} }
if(Gdx.input.isKeyPressed(Input.Keys.W)){ if(Gdx.input.isKeyPressed(Input.Keys.W)){
movementY = speed; movementY = speed;
facing = 0;
} }
if(Gdx.input.isKeyPressed(Input.Keys.S)){ if(Gdx.input.isKeyPressed(Input.Keys.S)){
movementY = -speed; movementY = -speed;
facing = 2;
} }
/** /**
* return * return
@ -81,12 +87,20 @@ public class Player extends Actor{
case 3: case 3:
break; break;
} }
int animationRow = 0;
if(movementX != 0 || movementY != 0) {
animationRow = 8;
}
playerSprite.setRow(animationRow + facing);
movementX = 0; movementX = 0;
movementY = 0; movementY = 0;
playerSprite.updateAnimation(delta); playerSprite.updateAnimation(delta);
super.act(delta); //To change body of generated methods, choose Tools | Templates. super.act(delta); //To change body of generated methods, choose Tools | Templates.
} }
@Override @Override
@ -155,5 +169,4 @@ public class Player extends Actor{
return 3; return 3;
} }
} }

Loading…
Cancel
Save