示例#1
0
  // Sets target for pursuit or evade behaviors
  public boolean setTarget(Entity target, String action) {
    if (target == null) {
      return false;

    } else {

      if (action.contains("Evade")) {
        ComponentMapper<EvadeComponent> em = ComponentMapper.getFor(EvadeComponent.class);
        EvadeComponent ec = em.get(this);
        if (ec == null) {
          ec = new EvadeComponent();
        }
        ec.target = target;
        this.add(ec);
        return true;
      } else if (action.contains("Pursuit")) {
        ComponentMapper<PursuitComponent> pm = ComponentMapper.getFor(PursuitComponent.class);
        PursuitComponent pc = pm.get(this);

        if (pc == null) {
          pc = new PursuitComponent();
        }
        pc.target = target;
        this.add(pc);
        return true;
      }
      return false;
    }
  }
  public void update(float delta) {
    Entity playerEntity = player.get(0);

    PlayerSteerableComponent psc = cmpsc.get(playerEntity);

    for (int i = 0; i < entities.size(); i++) {
      Entity entity = entities.get(i);

      TalkComponent tc = cmtc.get(entity);
      NonControllablePersonSteerableComponent ncpstc = cmstc.get(entity);
      if (ncpstc.x - 160 < psc.getPosition().x
          && psc.getPosition().x < ncpstc.x + 160
          && ncpstc.y - 210 < psc.getPosition().y
          && psc.getPosition().y < ncpstc.y + 210) {
        layout.setText(font, tc.textToSay);
        float x = ncpstc.x - (layout.width / 2);
        float y = ncpstc.y + layout.height + 15;
        batch.end();
        shapeRenderer.setProjectionMatrix(TwoD.getMain().camera.combined);
        shapeRenderer.begin(ShapeType.Filled);
        shapeRenderer.setColor(Color.WHITE);
        shapeRenderer.rect(x - 13, y + 2, 26 + layout.width, 26 + layout.height);
        shapeRenderer.setColor(Color.BLACK);
        shapeRenderer.rect(x - 10, y + 5, 20 + layout.width, 20 + layout.height);
        shapeRenderer.end();
        batch.begin();
        font.draw(batch, layout, x, y + 25);
      }
    }
  }
  @Override
  public void set(byte index, Inventory inventory) {
    SlotElement slot = m_slots[index];

    Entity item = inventory.item(index);
    ItemComponent itemComponent = itemMapper.get(item);
    m_slots[index].itemCountLabel.setText(Integer.toString(itemComponent.stackSize));

    TextureRegion region;
    SpriteComponent spriteComponent = spriteMapper.get(item);
    if (blockMapper.get(item) != null) {
      // hack
      region =
          m_client.m_world.m_tileRenderer.m_tilesAtlas.findRegion(
              spriteComponent.textureName.concat("-00"));
    } else {
      region = m_client.m_world.m_atlas.findRegion(spriteComponent.textureName);
    }

    Image slotImage = slot.itemImage;
    //        //m_blockAtlas.findRegion("stone"));
    slotImage.setDrawable(new TextureRegionDrawable(region));
    slotImage.setSize(region.getRegionWidth(), region.getRegionHeight());
    slotImage.setScaling(Scaling.fit);

    setHotbarSlotVisible(index, true);

    // do not exceed the max size/resort to horrible upscaling. prefer native size of each inventory
    // sprite.
    // .maxSize(region.getRegionWidth(), region.getRegionHeight()).expand().center();

  }
  @Override
  protected void processEntity(Entity entity, float deltaTime) {
    TransformComponent tfm = tm.get(entity);
    BoundsComponent bounds = bm.get(entity);

    bounds.bounds.x = tfm.position.x - bounds.bounds.width * 0.5f;
    bounds.bounds.y = tfm.position.y - bounds.bounds.height * 0.5f;
  }
示例#5
0
  // Gibt Gegner Position zur�ueck, die am naechersten ist, falls keiner im
  // Sichtfeld = null
  public Entity searchTarget() {
    ComponentMapper<PositionComponent> pm = ComponentMapper.getFor(PositionComponent.class);
    Entity result = null;
    ImmutableArray<Entity> entities = engine.getEntities();
    float smallestDistance = sightRadius * sightRadius;
    float collisionDistance = 30f;

    for (Entity entity : entities) {

      // check if entity is a point of interest
      if (entity.getClass() == PointOfInterestEntity.class) {
        PointOfInterestEntity pie = (PointOfInterestEntity) entity;
        PositionComponent piePosition = pm.get(pie);

        // if the POI is a target and the distance < collision distance => collision
        if (team == Team.GREEN
            && pie.toString() == "target"
            && piePosition.position.dst2(pm.get(this).position)
                <= (collisionDistance * collisionDistance)) {
          // add a new green boid entity
          BoidEntity boidR = new BoidEntity(BoidEntity.Team.GREEN, engine, new EvadeState());
          boidR.add(new PositionComponent());
          pm.get(boidR).position = piePosition.position.cpy();
          boidR.add(new VelocityComponent());
          boidR.add(new RenderComponent());
          boidR.add(new BoidCenterComponent());
          boidR.add(new BoidDistanceComponent());
          boidR.add(new BoidMatchVelocityComponent());
          boidR.add(new RessourceComponent());
          boidR.setPointOfInterest(pie);
          engine.addEntity(boidR);
          // heal the boid that collected the cross
          this.resetRessources();
          // set new target position
          piePosition.position.set(
              MathUtils.random(0, Gdx.graphics.getWidth()),
              MathUtils.random(0, Gdx.graphics.getHeight()));
        }
      }
      if (entity.getComponent(BoidCenterComponent.class) == null) continue;

      BoidEntity currentBoid = (BoidEntity) entity;

      float newDistance = pm.get(this).position.dst2(pm.get(currentBoid).position);
      // Checke falls Gegner in Sicht => pursue Gegner
      if (this.team != currentBoid.team && newDistance < smallestDistance) {
        smallestDistance = newDistance;
        result = currentBoid;
      }
    }

    return result;
  }
示例#6
0
  @Override
  public void processEntity(Entity entity, float deltaTime) {
    TextureComponent tex = tm.get(entity);
    AnimationComponent anim = am.get(entity);
    StateComponent state = sm.get(entity);

    Animation animation = anim.animations.get(state.get());

    if (animation != null) {
      tex.region = animation.getKeyFrame(state.time);
    }

    state.time += deltaTime;
  }
  @Override
  protected void processEntity(Entity entity, float deltaTime) {

    TransformComponent transformComponent = transformComponentMapper.get(entity);
    SpineObjectComponent spineObjectComponent = spineObjectComponentMapper.get(entity);

    spineObjectComponent.skeleton.updateWorldTransform(); //
    spineObjectComponent.state.update(deltaTime); // Update the animation time.
    spineObjectComponent.state.apply(
        spineObjectComponent
            .skeleton); // Poses skeleton using current animations. This sets the bones' local SRT.
    spineObjectComponent.skeleton.setPosition(
        transformComponent.x - spineObjectComponent.minX,
        transformComponent.y - spineObjectComponent.minY);
  }
 @Override
 protected void processEntity(Entity entity, float deltaTime) {
   Health health = healthComponentMapper.get(entity);
   if (health.value > 0) {
     aliveSettlements++;
   }
 }
  public void endContact(float delta, Contact contact) {
    for (Entity e : entities) {

      if (contact.getFixtureA() == bm.get(e).body.getFixtureList().first()) {
        for (Entity player : players) {
          if (bm.has(player) && contact.getFixtureB() == sensorm.get(player).sensor) {

            e.remove(CollisionComponent.class);
            player.remove(CollisionComponent.class);
            System.out.println("No longer a touch");
            return;
          }
        }
      }
    }
  }
示例#10
0
  public void resetRessources() {
    ComponentMapper<RessourceComponent> rm = ComponentMapper.getFor(RessourceComponent.class);
    RessourceComponent rc = rm.get(this);

    rc.fuel = 100;
    rc.health = 100;
  }
  public void addContact(float delta, Contact contact) {
    for (Entity e : entities) {

      if (contact.getFixtureA() == bm.get(e).body.getFixtureList().first()) {
        for (Entity player : players) {
          if (contact.getFixtureB() == sensorm.get(player).sensor) {
            e.add(new CollisionComponent(player.getId(), contact.getWorldManifold()));
            player.add(new CollisionComponent(e.getId(), contact.getWorldManifold()));
            System.out.println("hit a player");

            return;
          }
        }
      }
    }
  }
示例#12
0
  @Override
  protected void processEntity(Entity entity, float deltaTime) {
    PlayerComponent player = playerM.get(entity);
    ShapeComponent shape = shapeM.get(entity);

    float life = 0;
    for (int i = 0; i < player.orbs.size; i++) {
      life += player.orbs.get(i).getComponent(OrbComponent.class).life;
    }

    batch.begin();
    font.draw(batch, "Position: " + shape.body.getPosition(), 10, 80);
    font.draw(batch, "Speed: " + shape.body.getLinearVelocity(), 10, 60);
    font.draw(batch, "Orbs: " + player.orbs.size, 10, 40);
    font.draw(batch, String.format("Life:  %.1f", life), 10, 20);
    batch.end();
  }
  @Override
  protected void processEntity(Entity entity, float deltaTime) {
    ExplosionComponent explosion = _explosionComponents.get(entity);
    explosion.timeLeft -= (float) Time.time;
    if (explosion.timeLeft < 0f) EntityManager.getInstance().destroyEntity(entity);

    if (explosion.destroyedEnemy) explosion.lethal = false;
  }
示例#14
0
  @Override
  public void processEntity(Entity entity, float deltatime) {
    TransformComponent tc = mTransforms.get(entity);
    MovementComponent mc = mMovements.get(entity);
    OrbitComponent oc = mOrbits.get(entity);

    float R = mWorld.mOrbitRadius.get(oc.id);
    float radians = (float) Math.toRadians(tc.rotation);

    tc.position.x = (float) (R * Math.cos(radians)) + mWorld.mOribitCentre.get(oc.id).x;
    tc.position.y = (float) (R * Math.sin(radians)) + mWorld.mOribitCentre.get(oc.id).y;

    tc.rotation += mc.angularVelocity * deltatime;
    mc.angularVelocity += mc.angularAcceleration;

    if (tc.rotation >= 360) tc.rotation = 0;
  }
示例#15
0
  @Override
  public void processEntity(Entity entity, float deltaTime) {
    Sprite thisSprite = spriteMap.get(entity).sprites.first();
    PositionComponent position = positionMap.get(entity);

    //        thisSprite.setX((float) ((attachedSprite.getX() + attachedSprite.getWidth() / 2) -
    // (thisSprite.getWidth() / 2) + Math.sin(-Math.toRadians(angle)) * distance));
    //        thisSprite.setY((float) ((attachedSprite.getY() + attachedSprite.getHeight() / 2) -
    // (thisSprite.getHeight() / 2) + Math.cos(Math.toRadians(angle)) * distance));

    position.x += GameInput.MouseForce.x * 0.7f;
    position.y += GameInput.MouseForce.y * 0.7f;

    if (Gdx.input.isButtonPressed(Input.Buttons.LEFT)) {
      SoundManager.playSoundAtPosition(
          "Sounds/laser.wav", 0.5f, new Vector3(position.x, position.y, 0));
    }
  }
示例#16
0
 @Override
 protected void processEntity(Entity entity, float deltaTime) {
   PositionComponent position = positionMapper.get(entity);
   OutOfBoundsComponent outOfBounds = outOfBoundsMapper.get(entity);
   if (position.x > viewport.getWorldWidth() / 2
       || position.x < -viewport.getWorldWidth() / 2
       || position.y > viewport.getWorldHeight() / 2
       || position.y < -viewport.getWorldHeight() / 2) {
     if (outOfBounds.action == AdequateAction.RESPAWN) {
       position.x = MathUtils.random(-viewport.getWorldWidth() / 2, viewport.getWorldWidth() / 2);
       position.y =
           MathUtils.random(-viewport.getWorldHeight() / 2, viewport.getWorldHeight() / 2);
     } else if (outOfBounds.action == AdequateAction.ALERT) {
       lightsManager.ambientLight = 0.1f;
     } else if (outOfBounds.action == AdequateAction.DISPOSE) {
       BodyComponent body = bodyMapper.get(entity);
       if (body != null) bodyGenerator.destroyBody(entity);
       engine.removeEntity(entity);
     }
   }
 }
  @Override
  public void update(float deltaTime) {
    super.update(deltaTime);
    float frameTime = Math.min(deltaTime, 0.25f);
    accumulator += frameTime;
    if (accumulator >= MAX_STEP_TIME) {
      world.step(MAX_STEP_TIME, 6, 2);
      accumulator -= MAX_STEP_TIME;

      // Entity Queue
      for (Entity entity : bodiesQueue) {
        TransformComponent tfm = tm.get(entity);
        BodyComponent bodyComp = bm.get(entity);
        Vector2 position = bodyComp.body.getPosition();
        tfm.position.x = position.x;
        tfm.position.y = position.y;
        tfm.rotation = bodyComp.body.getAngle() * MathUtils.radiansToDegrees;
      }
    }

    bodiesQueue.clear();
  }
示例#18
0
  @Override
  public void update(float deltaTime) {
    super.update(deltaTime);
    debugRenderer.render(world, camera.combined);
    float frameTime = Math.min(deltaTime, 0.25f);
    accumulator += frameTime;
    if (accumulator >= MAX_STEP_TIME) {
      world.step(MAX_STEP_TIME, 6, 2);
      accumulator -= MAX_STEP_TIME;

      // Entity Queue
      for (Entity entity : bodiesQueue) {
        TransformComponent t = tm.get(entity);
        BodyComponent body = bm.get(entity);
        Vector2 pos = body.body.getPosition();
        pos.x = t.pos.x;
        pos.y = t.pos.y;
        body.body.setTransform(pos, t.rotation * MathUtils.degreesToRadians);
      }
    }
    bodiesQueue.clear();
  }
  @Override
  protected void processEntity(Entity entity, float deltaTime) {
    TransformComponent transform = tm.get(entity);
    BodyComponent body = bm.get(entity);
    ControllerComponent controller = cm.get(entity);

    // TODO: Implement controller usage

    // Controller pad = Controllers.getControllers().first();
    controller.leftAxis.set(0, 0);
    controller.rightAxis.set(0, 0);

    // Left stick
    if (Gdx.input.isKeyPressed(Input.Keys.A)) {
      controller.leftAxis.x = -1;
    }

    if (Gdx.input.isKeyPressed(Input.Keys.D)) {
      controller.leftAxis.x = 1;
    }

    if (Gdx.input.isKeyPressed(Input.Keys.W)) {
      controller.leftAxis.y = 1;
    }

    if (Gdx.input.isKeyPressed(Input.Keys.S)) {
      controller.leftAxis.y = -1;
    }

    // Right stick
    if (Gdx.input.isKeyPressed(Input.Keys.LEFT)) {
      controller.rightAxis.x = -1;
    }

    if (Gdx.input.isKeyPressed(Input.Keys.RIGHT)) {
      controller.rightAxis.x = 1;
    }

    if (Gdx.input.isKeyPressed(Input.Keys.UP)) {
      controller.rightAxis.y = 1;
    }

    if (Gdx.input.isKeyPressed(Input.Keys.DOWN)) {
      controller.rightAxis.y = -1;
    }

    // set transform rotation
    if (!controller.rightAxis.equals(Vector2.Zero)) {
      transform.rotation = controller.rightAxis.angle() - 90f;
    } else if (!controller.leftAxis.equals(Vector2.Zero)) {
      transform.rotation = controller.leftAxis.angle() - 90f;
    }

    //        if(!Controllers.getRightAxis().equals(Vector2.Zero)) {
    //            transform.rotation = Controllers.getRightAxis().angle() - 90f;
    //        }
    //        else if(!Controllers.getLeftAxis().equals(Vector2.Zero)) {
    //            transform.rotation = Controllers.getLeftAxis().angle() - 90f;
    //        }

    // set linear velocity
    body.body.setLinearVelocity(
        controller.leftAxis.x * body.moveSpeed.x, controller.leftAxis.y * body.moveSpeed.y);
    // body.body.setLinearVelocity(Controllers.getLeftAxis().x * body.moveSpeed.x,
    // Controllers.getLeftAxis().y * body.moveSpeed.y);
  }
 @Override
 public void countChanged(byte index, Inventory inventory) {
   ItemComponent itemComponent = itemMapper.get(inventory.item(index));
   m_slots[index].itemCountLabel.setText(Integer.toString(itemComponent.stackSize));
 }