Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package entity;
- import java.awt.Image;
- import controller.Controller;
- import controller.PlayerController;
- import core.Direction;
- import core.Motion;
- import core.Position;
- import game.state.State;
- import gfx.AnimationManager;
- import gfx.SpriteLibrary;
- public abstract class MovingEntity extends GameObject {
- public static int PROXIMITY_RANGE = 5;
- protected Controller controller;
- protected Motion motion;
- protected AnimationManager animationManager;
- protected Direction direction;
- public MovingEntity(Controller controller, SpriteLibrary spriteLibrary, Position startingPosition) {
- super();
- super.position = startingPosition;
- homePosition = startingPosition;
- this.controller = controller;
- this.motion = new Motion(3);
- this.direction = Direction.S;
- this.animationManager = new AnimationManager(spriteLibrary.getEntity("bouly"));
- }
- @Override
- public void update(State state) {
- motion.update(controller, direction);
- position.apply(motion);
- manageDirection();
- decideAnimation();
- animationManager.update(direction);
- }
- private void decideAnimation() {
- if(motion.isMoving() && controller.getClass().getName() == PlayerController.class.getName()) {
- animationManager.playAnimation("walking", 3, 4);
- } else if(motion.isMoving()){
- animationManager.playAnimation("walking", 5, 0);
- } else
- animationManager.playAnimation("idle", 10, 0);
- }
- private void manageDirection() {
- if(motion.isMoving())
- this.direction = Direction.fromMotion(motion);
- }
- @Override
- public Image getSprite() {
- return animationManager.getSprite();
- }
- public Controller getController() {
- return controller;
- }
- public Position getHomePosition() {
- return homePosition;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement