예제 #1
0
 @Override
 protected void removed(Entity e) {
   super.removed(e);
   if (tm.get(e).getParent() != null) {
     tm.get(tm.get(e).getParent()).removeChild(e);
   } else roots.remove(e);
 }
예제 #2
0
  private void transform(Entity entity) {
    Bag<Entity> children = tm.get(entity).getChildren();
    SkeletonComponent skl = sm.get(entity);
    for (int i = 0, s = children.size(); s > i; i++) {
      TransformComponent childTC = tm.get(children.get(i));

      childTC.getWorldTransform().set(childTC.getLocalTransform());

      if (childTC.getJoint() != -1 && skl != null) {
        TempVars tempVars = TempVars.get();

        skl.getCurrentPosesMatrices()[childTC.getJoint()].mult(
            skl.getBaseSkeleton().getJoints().get(childTC.getJoint()).base, tempVars.tempMat4);

        tempVars.tempMat4.toTranslationVector(tempVars.vect1);
        tempVars.tempMat4.toRotationQuat(tempVars.quat1);
        tempVars.tempMat4.toScaleVector(tempVars.vect2);
        tempVars.tempTF.set(tempVars.vect1, tempVars.quat1, tempVars.vect2);
        childTC.getWorldTransform().combineFromParent(tempVars.tempTF);

        tempVars.release();
      } else {
      }
      childTC.getWorldTransform().combineFromParent(tm.get(entity).getWorldTransform());
      transform(children.get(i));
    }
  }
  @Override
  protected void process(Entity e) {
    final Buildable buildable = bm.get(e);
    if (!buildable.built) {
      final Bounds bounds = om.get(e);
      final Pos pos = pm.get(e);

      boolean affordable = buildable.resourceCost <= walletCash;
      assetSystem.font.setColor(affordable ? HOLO_COLOR : HOLO_COLOR_RED);
      String cost = "" + buildable.resourceCost + "$";
      assetSystem.font.draw(
          batch,
          cost,
          pos.x + bounds.cx() - assetSystem.font.getBounds(cost).width / 2,
          pos.y + bounds.y2 + 20);

      if (collisionSystem.overlaps(player, e) && affordable) {
        String msg = "'e' to purchase";
        assetSystem.font.draw(
            batch,
            msg,
            pos.x + bounds.cx() - assetSystem.font.getBounds(msg).width / 2,
            pos.y + bounds.y2 + 32);
      }
    }
  }
예제 #4
0
  private void update(List<Entity> moved, ComponentMapper<Mass> mm, ComponentMapper<Position> pm) {
    if (hasEntity()) {
      if (entity.isActive()) {
        VectorD2 p = pm.get(entity).vec;
        if (!contains(p)) {
          moved.add(entity);
          --size;
          this.mass = 0f;
          this.massVector.set(0f, 0f);
          entity = null;
        } else {
          mass = mm.get(entity).mass;
          massVector.set(p).mul(mass);
        }
      }
    } else if (hasChildren()) {
      bl.update(moved, mm, pm);
      br.update(moved, mm, pm);
      tl.update(moved, mm, pm);
      tr.update(moved, mm, pm);

      size = bl.size + br.size + tl.size + tr.size;

      mass = bl.mass + br.mass + tl.mass + tr.mass;

      massVector.set(0f, 0f);
      massVector.add(bl.massVector).add(br.massVector);
      massVector.add(tl.massVector).add(tr.massVector);
    }
  }
예제 #5
0
  public boolean add(Entity entity, ComponentMapper<Mass> mm, ComponentMapper<Position> pm) {
    if (!contains(pm.get(entity).vec)) { // TODO shouldn't be necessary
      return false;
    }

    if (isEmpty()) {
      this.entity = entity;
      this.mass = mm.get(entity).mass;
      this.massVector = pm.get(entity).vec.cpy().mul(mass);
      ++size;
      return true;
    } else {
      if (bl == null) {
        addSubtrees();
        quadrantOf(this.entity, mm, pm).add(this.entity, mm, pm);
        this.entity = null;
      }
      quadrantOf(entity, mm, pm).add(entity, mm, pm);
      double m = mm.get(entity).mass;
      VectorD2 p = pm.get(entity).vec;
      this.massVector.add(p.cpy().mul(m));
      this.mass += m;
      ++size;
      return true;
    }
  }
예제 #6
0
  @Override
  protected void process(Entity e) {
    AnimatedPlayer animation = animationMapper.get(e);
    Position position = positionMapper.get(e);
    Camera camera = cameraMapper.get(e);

    int dX = 0;
    int dY = 0;

    if (animation.isAnimating()) {
      switch (animation.getAnimationDirection()) {
        case UP:
          dY = (int) (-world.delta * ClientConstants.WALK_SPEED);
          break;
        case DOWN:
          dY = (int) (world.delta * ClientConstants.WALK_SPEED);
          break;
        case LEFT:
          dX = (int) (-world.delta * ClientConstants.WALK_SPEED);
          break;
        case RIGHT:
          dX = (int) (world.delta * ClientConstants.WALK_SPEED);
          break;
      }
    }

    camera.scroll(dX, dY);
  }
예제 #7
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);
  }
  @Override
  protected void process(Entity e) {
    final Physics physics = ym.get(e);
    final Pos pos = pm.get(e);
    final Bounds bounds = bm.get(e);

    //  no math required here.
    if (physics.vx != 0 || physics.vy != 0) {

      float px = pos.x + physics.vx * world.delta;
      float py = pos.y + physics.vy * world.delta;

      if ((physics.vx > 0
              && collides(px + bounds.x2, py + bounds.y1 + (bounds.y2 - bounds.y1) * 0.5f))
          || (physics.vx < 0
              && collides(px + bounds.x1, py + bounds.y1 + (bounds.y2 - bounds.y1) * 0.5f))) {
        physics.vx = physics.bounce > 0 ? -physics.vx * physics.bounce : 0;
        px = pos.x;
      }

      if ((physics.vy > 0
              && collides(px + bounds.x1 + (bounds.x2 - bounds.x1) * 0.5f, py + bounds.y2))
          || (physics.vy < 0
              && collides(px + bounds.x1 + (bounds.x2 - bounds.x1) * 0.5f, py + bounds.y1))) {
        physics.vy = physics.bounce > 0 ? -physics.vy * physics.bounce : 0;
      }
    }
  }
 @Override
 protected void process(Entity e) {
   BombAttacker ba = bm.get(e);
   Script s = sm.get(e);
   Velocity velocity = vm.get(e);
   if (ba.isStopped()) {
     try {
       String result = engine.eval(s.content, s.context).toString();
       if (result == null) return;
       String[] actions = result.split(",");
       if (actions.length == 2) {
         if (actions[0].equals(Constants.ScriptingActions.Left)) {
           velocity.vectorX = -30;
         } else if (actions[0].equals(Constants.ScriptingActions.Right)) {
           velocity.vectorX = 30;
         } else if (actions[0].equals(Constants.ScriptingActions.Up)) {
           velocity.vectorY = 30;
         } else if (actions[0].equals(Constants.ScriptingActions.Down)) {
           velocity.vectorY = -30;
         }
         if (actions[1].equals(Constants.ScriptingActions.Bomb)) {}
       }
     } catch (ScriptException e1) {
       // TODO Auto-generated catch block
       e1.printStackTrace();
     }
   }
 }
예제 #10
0
 @Override
 protected void inserted(Entity e) {
   super.inserted(e);
   if (tm.get(e).getParent() != null) {
     tm.get(tm.get(e).getParent()).addChild(e);
   } else if (!roots.contains(e)) roots.add(e);
 }
예제 #11
0
  @Override
  protected void process(Entity e) {
    TextureComponent tc = textureMapper.get(e);

    if (tc.region != null && tc.visible) {
      TransformComponent txc = transformMapper.get(e);

      txc.transform.getScale(this.temp2);
      // The size of the game object
      txc.transform.getTranslation(this.temp2_1);
      // The position of the game object
      float tw = tc.region.getRegionWidth();
      float th = tc.region.getRegionHeight();
      float angle =
          MathUtils.radDeg
              * MathUtils.atan2(txc.transform.val[Matrix3.M10], txc.transform.val[Matrix3.M00]);

      if (tc.region.rotate) {
        angle -= 90;
      }

      this.rendering.batch.draw(
          tc.region,
          this.temp2_1.x - tw / 2,
          this.temp2_1.y - th / 2,
          tw / 2,
          th / 2,
          tw,
          th,
          this.temp2.x,
          this.temp2.y,
          angle);
    }
  }
예제 #12
0
 public static void dispatchEvent(World world, Entity entity, Event event) {
   if (scm.has(entity) && scm.get(entity).hasEventScripts(event.getType()))
     for (Script script : scm.get(entity).getScriptsByEvent(event.getType())) {
       script.run(world, event);
     }
   else
     LOGGER.fine(
         "Dispatch event " + event.getType() + "  to a entity which do not has ScriptComponent");
 }
  @Override
  protected void begin() {
    batch.setProjectionMatrix(cameraSystem.camera.combined);
    batch.begin();
    batch.setColor(1f, 1f, 1f, 1f);

    player = tagManager.getEntity("player");
    walletCash = wm.has(player) ? wm.get(player).resources : 0;
  }
예제 #14
0
 public void setParent(Entity parent, Entity child, String bone) {
   if (tm.get(child).getParent() != null) tm.get(tm.get(child).getParent()).removeChild(child);
   else if (parent != null) roots.remove(child);
   tm.get(child).setParent(parent, bone);
   if (parent != null) {
     tm.get(parent).addChild(child);
   } else {
     if (!roots.contains(child)) roots.add(child);
   }
 }
예제 #15
0
  @Override
  protected void process(Entity e) {
    Layer layer = layerCm.get(e);
    VisGroup group = groupCm.get(e);

    if (layer.layerId != findLayerId) return;
    if (findGroupId != -1) {
      if (group == null || group.groupIds.contains(findGroupId) == false) return;
    }

    result.add(proxyCache.get(e));
  }
  @Override
  protected void process(int entityId) {
    try {
      Position p = posMapper.get(entityId);
      Rotation r = rotMapper.get(entityId);
      Velocity v = velMapper.get(entityId);

      if (physMapper.has(entityId)) {
        Body body = world.getSystem(PhysicsSystem.class).getBody(entityId);
        if (inputMapper.has(entityId)) { // control physics body by input
          processPhysicsMovement(body, inputMapper.get(entityId), p, v, r, entityId);
        } else { // keep image with body for when physics is acting upon it
          p.position.set(body.getPosition());
          r.angle = MathUtils.radiansToDegrees * body.getAngle();
          v.velocity.set(body.getLinearVelocity());
        }
      } else { // move image directly since there is no physics body
        float d = world.getDelta();
        p.position.add(v.velocity.x * d, v.velocity.y * d);
      }

      // Keep equipment with entity
      if (equipMapper.has(entityId)) {
        EquipmentList equipmentList = equipMapper.get(entityId);
        equipmentList.moveEquipment(boundsMapper, posMapper);
        equipmentList.rechargeEquipment(); // TODO: move this to EnergySystem
      }
    } catch (NullPointerException ex) {
      logger.error("MoveSys error; killing offending entity #" + entityId, ex);
      world.getEntity(entityId).getComponent(Lifecycle.class).kill();
    }
  }
 private void renderAmmo() {
   Ammo ammo = ammoMapper.get(player);
   g.translate(container.getWidth() - 64, container.getHeight() - 45);
   {
     font.drawString(-16, 8, "Ammo");
     g.rotate(0, 0, -90);
     float ammoStatus = ammo.getAmmoStatus();
     g.setDrawMode(Graphics.MODE_ADD);
     statusBar.draw(
         0,
         0,
         statusBar.getWidth() * ammoStatus,
         statusBar.getHeight(),
         0,
         0,
         statusBar.getWidth() * ammoStatus,
         statusBar.getHeight(),
         ammoStatus < 0.25 ? Color.red : ammoStatus < 0.6 ? Color.yellow : Color.green);
     statusBar.draw(
         statusBar.getWidth() * ammoStatus,
         0,
         statusBar.getWidth(),
         statusBar.getHeight(),
         statusBar.getWidth() * ammoStatus,
         0,
         statusBar.getWidth(),
         statusBar.getHeight(),
         new Color(0.15f, 0.15f, 0.15f));
     g.setDrawMode(Graphics.MODE_NORMAL);
     g.rotate(0, 0, 90);
   }
   g.translate(-container.getWidth() + 64, -container.getHeight() + 45);
 }
 private void renderHealth() {
   Health health = healthMapper.get(player);
   g.translate(35, container.getHeight() - 45);
   {
     font.drawString(-26, 8, "Health");
     g.rotate(0, 0, -90);
     float healthStatus = health.getHealthStatus();
     g.setDrawMode(Graphics.MODE_ADD);
     statusBar.draw(
         0,
         0,
         statusBar.getWidth() * healthStatus,
         statusBar.getHeight(),
         0,
         0,
         statusBar.getWidth() * healthStatus,
         statusBar.getHeight(),
         healthStatus < 0.25 ? Color.red : healthStatus < 0.6 ? Color.yellow : Color.green);
     statusBar.draw(
         statusBar.getWidth() * healthStatus,
         0,
         statusBar.getWidth(),
         statusBar.getHeight(),
         statusBar.getWidth() * healthStatus,
         0,
         statusBar.getWidth(),
         statusBar.getHeight(),
         new Color(0.15f, 0.15f, 0.15f));
     g.setDrawMode(Graphics.MODE_NORMAL);
     g.rotate(0, 0, 90);
   }
   g.translate(-35, -container.getHeight() + 45);
 }
예제 #19
0
 @Override
 protected void process(int entityId) {
   ScriptComponent sc = mScript.get(entityId);
   // add pending scripts
   for (Script script : sc.add) {
     world.inject(script, false);
     script.world = world;
     script.inserted(entityId);
     sc.scripts.add(script);
   }
   // removed pending scripts
   sc.add.clear();
   for (Script script : sc.remove) {
     if (sc.scripts.removeValue(script, true)) {
       script.removed(entityId);
     }
   }
   sc.remove.clear();
   // process active scripts
   Iterator<Script> it = sc.scripts.iterator();
   while (it.hasNext()) {
     Script next = it.next();
     next.process(entityId);
     if (next.remove) {
       it.remove();
       next.removed(entityId);
     }
   }
 }
예제 #20
0
 @Override
 protected void removed(int entityId) {
   ScriptComponent sc = mScript.get(entityId);
   for (Script script : sc.scripts) {
     script.removed(entityId);
   }
   sc.scripts.clear();
 }
 public List<Discovery> getAvailablePolicies(Entity empire, Policy choice) {
   return discoveries
       .get(empire)
       .done
       .stream()
       .filter(d -> d.groups.contains(choice.name()))
       .collect(toList());
 }
예제 #22
0
 @Override
 protected void processEntities() {
   for (int i = 0, s = roots.size(); s > i; i++) {
     TransformComponent rootTC = tm.get(roots.get(i));
     rootTC.getWorldTransform().set(rootTC.getLocalTransform());
     transform(roots.get(i));
   }
 }
  private void renderMinimap() {
    int minimapWidth = minimapBg.getWidth();
    int minimapHeight = minimapBg.getHeight();

    int boundaryWidth = boundarySystem.getBoundaryWidth();
    int boundaryHeight = boundarySystem.getBoundaryHeight();

    float scaleX = (float) minimapWidth / (float) boundaryWidth;
    float scaleY = (float) minimapHeight / (float) boundaryHeight;

    g.setColor(Color.white);

    g.translate(container.getWidth() - minimapWidth - 20, 20);
    {
      minimapBg.draw();

      float offsetX = cameraSystem.getStartX();
      float offsetY = cameraSystem.getStartY();
      g.drawRect(
          offsetX * scaleX,
          offsetY * scaleY,
          scaleX * cameraSystem.getWidth(),
          scaleY * cameraSystem.getHeight());

      ImmutableBag<Entity> entities = world.getManager(GroupManager.class).getEntities("crates");
      for (int i = 0; entities.size() > i; i++) {
        Entity crate = entities.get(i);
        Physics cratePhysics = physicsMapper.get(crate);
        float crateX = cratePhysics.getX() * scaleX;
        float crateY = cratePhysics.getY() * scaleY;
        g.fillRect(crateX - 1, crateY - 1, 2, 2);
      }

      ImmutableBag<Entity> tanks = world.getManager(GroupManager.class).getEntities("tanks");
      for (int i = 0; tanks.size() > i; i++) {
        Entity t = tanks.get(i);
        String tp = world.getManager(PlayerManager.class).getPlayer(t);
        Physics physics = physicsMapper.get(t);
        g.setColor(Color.green);
        float tx = physics.getX() * scaleX;
        float ty = physics.getY() * scaleY;
        g.fillRect(tx - 3, ty - 3, 6, 6);
      }
    }
    g.translate(-container.getWidth() + minimapWidth + 20, -20);
  }
  @Override
  protected void process(Entity e) {
    PlainPosition pos = positionMapper.get(e);
    pos.x -= 1;
    pos.y += 1;

    voidness.consume(e);
  }
예제 #25
0
  @Override
  protected void process(final Entity e) {
    final Health health = hm.get(e);
    health.getDamageCooldown().reduceDuration(world.getDelta());

    if (!health.recentlyDamaged()) health.addHealth(+10);

    if (!health.isAlive()) world.deleteEntity(e);
  }
예제 #26
0
  public void updateAcceleration(
      Entity e,
      float theta,
      float G,
      ComponentMapper<Mass> mm,
      ComponentMapper<Position> pm,
      ComponentMapper<Acceleration> am,
      float delta) {
    if (isEmpty()) { // TODO also check if M is to small?
      return;
    }
    double M = this.mass;
    VectorD2 p = pm.get(e).vec;
    VectorD2 diff;

    //		if (contains(p)) { // TODO this is only necessary if theta>=1
    //			float m = mm.get(e).mass;
    //			diff = this.massVector.cpy().sub(p.cpy().mul(m)).div(M-m).sub(p);
    //		} else
    diff = this.massVector.cpy().div(M).sub(p);

    double d2 = diff.len2();

    // s/d < theta
    if (this.entity != null || side * side < theta * theta * d2) { // TODO weight with mass.
      if (this.entity == e) { // TODO temporary hack
        return;
      }
      // F = G*m*M/d^2
      // F = m*a
      // a = G*M/d^2
      double a = G * M / d2;
      double k = (float) (a * FastMath.inverseSqrt(d2)); // normalizes diff
      if (!Double.isNaN(k)) {
        VectorD2 accVec = am.get(e).vec;
        accVec.add(diff.mul(k).mul(delta));
      }
    } else {
      bl.updateAcceleration(e, theta, G, mm, pm, am, delta);
      br.updateAcceleration(e, theta, G, mm, pm, am, delta);
      tl.updateAcceleration(e, theta, G, mm, pm, am, delta);
      tr.updateAcceleration(e, theta, G, mm, pm, am, delta);
    }
  }
  @Override
  protected void process(Entity e) {
    Position position = positionMapper.get(e);

    if (Gdx.input.isKeyPressed(Input.Keys.LEFT)) position.x -= 200 * Gdx.graphics.getDeltaTime();
    if (Gdx.input.isKeyPressed(Input.Keys.RIGHT)) position.x += 200 * Gdx.graphics.getDeltaTime();

    if (position.x < 0) position.x = 0;
    if (position.x > 800 - 64) position.x = 800 - 64;
  }
  @Override
  protected void process(int entityId) {
    Particle particle = mParticle.get(entityId);

    if (!particle.particleEffect.isComplete()) {
      particle.particleEffect.draw(batch, world.getDelta());
    } else {
      world.delete(entityId);
    }
  }
  @Override
  protected void process(Entity e) {
    final Attached attached = am.get(e);

    final Entity parent = attached.parent.get();
    if (parent != null) {

      // move attachment to absolute position, adjusted with slack.
      Pos pos = pm.get(e);
      Pos parPos = pm.get(parent);
      pos.xy.x = parPos.xy.x + attached.xo + attached.slackX;
      pos.xy.y = parPos.xy.y + attached.yo + attached.slackY;

      updateSlack(attached);
    } else {
      // parent gone? we gone!
      e.deleteFromWorld();
    }
  }
 public void applyPolicy(Entity entity, Policy policy, Discovery selected) {
   Policies empire = policies.get(entity);
   Discovery old = empire.policies.put(policy, selected);
   if (old != null) {
     effects.apply(old.effects, entity, true);
     empire.stability -= STABILITY_LOSS_WHEN_SWITCHING;
   }
   if (selected != null) {
     effects.apply(selected.effects, entity, false);
   }
 }