Beispiel #1
0
  public RunBoss() {
    super("YOU SHOULD PROBABLY RUN");

    health = 1;
    maxHealth = 1;
    damageOnTouch = 2;

    size.getTarget().set(50, 50);

    getBody().setType(BodyDef.BodyType.KinematicBody);
    getBody().setTransform(-50, 0, 0);

    fixture = rectCollision(200, 50, -75, 0);
    fixture.setSensor(true);
  }
Beispiel #2
0
  @Override
  public void kill() {
    super.kill();
    fixture.setSensor(false);

    for (int i = 0; i < 10; i++) {
      HPPickup hpp = new HPPickup(0.5f);
      hpp.getBody().setTransform(getBody().getPosition(), 0);
      hpp.getBody().setLinearVelocity(MathUtils.random(-50, 50), MathUtils.random(-50, 50));
      GameScreen.i.getEntities().add(hpp);
    }

    MaxHPPickup mh = new MaxHPPickup(3);
    mh.getBody().setTransform(getBody().getPosition(), 0);
    GameScreen.i.getEntities().add(mh);
  }
Beispiel #3
0
 private Body createBody(float x, float y, float width, float height, boolean sensor) {
   BodyDef bodyDef = new BodyDef();
   bodyDef.type = BodyDef.BodyType.KinematicBody;
   bodyDef.position.set(new Vector2(x, y));
   bodyDef.allowSleep = true;
   PolygonShape shape = new PolygonShape();
   shape.setAsBox(width / 2, height / 2, new Vector2(0, 0), 0);
   Body _body = WorldUtils.world.createBody(bodyDef);
   Fixture fixture = _body.createFixture(shape, 1.0f);
   fixture.setFriction(0);
   fixture.setSensor(sensor);
   if (!sensor) {
     fixture.setUserData(Constants.POTION_FIXTURE);
   } else {
     fixture.setUserData(Constants.NOT_COLLIDER_FIXTURE);
   }
   Filter filter = new Filter();
   filter.categoryBits = Constants.COLLISION_CREATURE;
   filter.maskBits =
       Constants.COLLISION_GROUND + Constants.COLLISION_CREATURE + Constants.COLLISION_FIELD;
   fixture.setFilterData(filter);
   _body.setUserData(this);
   return _body;
 }
Beispiel #4
0
  @Override
  public void update(float delta) {
    super.update(delta);

    if (state == BossState.WAITING) {
      getBody().setType(BodyDef.BodyType.KinematicBody);
      getBody().setLinearVelocity(0, 0);
      if (GameScreen.i.getBossState() == GameScreen.BossState.FIGHTING) {
        state = BossState.DROPPING;
        upCount = 2;
      }
    } else if (state == BossState.DROPPING) {
      timer += delta;

      centerSpring.getPosition().set(getBody().getPosition());
      centerSpring.getTarget().set(GameScreen.i.getPlayer().getBody().getPosition().x, 20);
      centerSpring.update(delta);
      getBody().setLinearVelocity(centerSpring.getVelocity());

      if (timer > 1) {
        getBody().setType(BodyDef.BodyType.DynamicBody);
        getBody().setLinearVelocity(0, -300);
        size.getVelocity().set(-50, 50);
        state = BossState.FALL;
        fixture.setSensor(false);
      }
    } else if (state == BossState.CENTER) {
      float last = timer;
      timer += delta;
      getBody().setType(BodyDef.BodyType.DynamicBody);

      if (timer > 1) {
        if (last <= 1) {
          Assets.downy.play();
        }
        centerSpring.getPosition().set(getBody().getPosition());
        centerSpring.update(delta);
        getBody().setLinearVelocity(centerSpring.getVelocity());
      }

      getBody().setGravityScale(0);
      if (getBody().getPosition().dst(centerSpring.getTarget()) < 1f) {
        color = Palette.FOREGROUND;
        size.getVelocity().set(-50, -50);
        Assets.shut.play();
        getBody().setType(BodyDef.BodyType.KinematicBody);
        getBody().setLinearVelocity(0, 0);
        getBody().setAngularVelocity(-5);
        state = BossState.FREEZE;
        timer = 0;
      }
    } else if (state == BossState.FREEZE) {
      float last = timer;
      timer += delta;
      if (timer > 1 && last <= 1) {
        size.getVelocity().set(40, 40);

        spawnChasers();
      }

      if (timer > 1) {
        boolean allDead = true;
        for (LivingEntity e : offspring) {
          if (e.health > 0) allDead = false;
        }

        if (allDead) {
          offspring.clear();
          color = Palette.HIGHLIGHT;
          getBody().setType(BodyDef.BodyType.DynamicBody);
          getBody().setGravityScale(0);
          state = BossState.CHASE;
          Assets.ding.play();
          timer = 0;
        }
      }
    } else if (state == BossState.CHASE) {
      timer += delta;

      centerSpring.getTarget().set(GameScreen.i.getPlayer().getBody().getPosition());
      centerSpring.getPosition().set(getBody().getPosition());
      centerSpring.update(delta);
      getBody().setLinearVelocity(centerSpring.getVelocity());

      if (timer > 3) {
        state = BossState.BACKFORTH;
        timer = 0;
      }
    } else if (state == BossState.BACKFORTH) {
      float last = timer;
      timer += delta;

      if (MathUtils.floor(last % 2) != MathUtils.floor(timer % 2)) {
        float direction = MathUtils.floor(last % 2) == 0 ? 1 : -1;
        centerSpring
            .getTarget()
            .set(
                levelCenter + (10 * direction), GameScreen.i.getPlayer().getBody().getPosition().y);
        Assets.boop.play();
      }

      centerSpring.getPosition().set(getBody().getPosition());
      centerSpring.update(delta);
      getBody().setLinearVelocity(centerSpring.getVelocity());
      centerSpring.setFrequency(4);

      if (timer > 5) {
        centerSpring.setFrequency(1);

        upCount = 0;
        state = BossState.UP;
        getBody().setGravityScale(0);
        fixture.setSensor(true);
        getBody().setLinearVelocity(0, 100);
        timer = 0;
      }
    } else if (state == BossState.UP) {
      if (getBody().getPosition().y > 15) {
        getBody().setGravityScale(0);
        state = BossState.DROPPING;
      }
    } else if (state == BossState.LANDWAIT) {
      timer += delta;

      if (timer > 1) {
        if (upCount == 2) {
          state = BossState.CENTER;
          timer = 0;
          centerSpring.getPosition().set(getBody().getPosition());
          centerSpring.getTarget().set(levelCenter, 14);
        } else {
          size.getVelocity().set(-50, 50);
          upCount++;
          state = BossState.UP;
          timer = 0;
          getBody().setLinearVelocity(0, 100);
          fixture.setSensor(true);
          Assets.uppy.play();
        }
      }
    }
  }