123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051 |
- package me.hammerle.supersnuvi.entity.ai;
- import me.hammerle.supersnuvi.entity.Entity;
- import me.hammerle.supersnuvi.entity.Hero;
- import me.hammerle.supersnuvi.tiles.Location;
- import me.hammerle.supersnuvi.util.Face;
- public class FollowHeroController extends EntityController
- {
- private final double motion;
-
- public FollowHeroController(Entity ent, double motion)
- {
- super(ent);
- this.motion = motion;
- }
- @Override
- public void tick()
- {
- Hero hero = ent.getLevel().getHero();
- if(hero.squaredDistance(ent) <= 102400)
- {
- double distance = ent.signedDistanceX(hero);
- if(distance < 0)
- {
- ent.setMotionX(motion);
- }
- else if(distance > 0)
- {
- ent.setMotionX(-motion);
- }
- }
- }
- @Override
- public void onCollideWithEntity(Entity ent, Face face)
- {
- }
- @Override
- public void onCollideWithTile(Location loc, Face face)
- {
- if((face == Face.LEFT || face == Face.RIGHT) &&
- Math.abs(ent.getPreviousMotionX() - ent.getMotionX()) > 0.001 &&
- Math.abs(ent.signedDistanceX(ent.getLevel().getHero())) > 0.001)
- {
- ent.jump();
- }
- }
- }
|