Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package core;
- import controller.Controller;
- public class Motion {
- private Vector2D vector;
- private double speed;
- public Motion(double speed) {
- this.vector = new Vector2D(0, 0);
- this.speed = speed;
- }
- public void update(Controller controller, Direction direction) {
- movement(controller, direction);
- vector.normalize();
- vector.multiply(speed);
- }
- private void movement(Controller controller, Direction direction) {
- int deltaX = 0, deltaY = 0;
- if(controller.isRequestingUp()) {deltaY--; deltaX = 0;}
- if(controller.isRequestingDown()) {deltaY++; deltaX = 0;}
- if(controller.isRequestingLeft()) {deltaX--; deltaY = 0;}
- if(controller.isRequestingRight()) {deltaX++; deltaY = 0;}
- //For Overriding moves
- if(controller.getRequestedDirection() == Direction.N) {deltaY--; deltaX = 0;}
- if(controller.getRequestedDirection() == Direction.S) {deltaY++; deltaX = 0;}
- if(controller.getRequestedDirection() == Direction.W) {deltaX--; deltaY = 0;}
- if(controller.getRequestedDirection() == Direction.E) {deltaX++; deltaY = 0;}
- vector = new Vector2D(deltaX, deltaY);
- }
- public Vector2D getVector() {
- return vector;
- }
- public boolean isMoving() {
- return vector.length() > 0;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment