Example #1
0
  @Override
  protected void process(int entityId) {
    //		float scale = this.scale * swarmSize;
    Pos pos = mPos.get(entityId);
    Swarmer swarmer = mSwarmer.get(entityId);
    //		swarmer.age += world.delta;
    swarmer.angle -= world.delta * swarmer.angularSpeed / (scale * 10);
    if (swarmer.angle >= 360) swarmer.angle -= 360;
    if (swarmer.angle < 0) swarmer.angle += 360;
    if (pos.xy.dst2(sPos) <= sRadius2) {
      for (int i = 0; i < size; i++) {
        int eid = data[i];
        Bounds eb = mCircleBounds.get(eid);
        if (eb.b.contains(pos.xy)) {
          pos.set(eb.b.x, eb.b.y);
          pos.xy.add(
              MathUtils.randomTriangular(-eb.radius, eb.radius, 0),
              MathUtils.randomTriangular(-eb.radius, eb.radius, 0));
          return;
        }
      }
    }
    pos.xy.set(1, 0).setAngle(swarmer.angle).scl(swarmer.dst * dstScale).add(cs.xy);

    Tint tint = mTint.get(entityId);
    tint.set(1, 1 - (swarmer.clamp * scale), (swarmer.clamp * scale) / 5, 1);
  }
Example #2
0
 private void createSwarmer() {
   EntityEdit e = world.createEntity().edit();
   float angSpeed = MathUtils.randomTriangular(15, 180, 45);
   Swarmer swarmer = e.create(Swarmer.class);
   swarmer.setAngle(MathUtils.random(360)).setAngularSpeed(angSpeed);
   swarmer.dst = (swarmer.angularSpeed - 15) / 180;
   swarmer.clamp = MathUtils.clamp(swarmer.dst + MathUtils.random(-.1f, .1f), 0, 1);
   e.create(Tint.class).set(1, 1 - swarmer.clamp, 0, 1);
   e.create(Pos.class).set(cs.xy);
   e.create(Renderable.class).layer = 1;
   Anim anim = e.create(Anim.class);
   anim.id = "one";
   anim.age = MathUtils.random();
   e.create(Scale.class).scale = MathUtils.random(.25f, 1.25f);
   swarmSize++;
 }