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);
      }
    }
  }
  @Test
  public void resetEntityCorrectly() {
    PooledEngine engine = new PooledEngine();

    ComponentCounterListener addedListener = new ComponentCounterListener();
    ComponentCounterListener removedListener = new ComponentCounterListener();

    // force the engine to create a Family so family bits get set
    ImmutableArray<Entity> familyEntities =
        engine.getEntitiesFor(Family.all(PositionComponent.class).get());

    Entity[] entities = new Entity[10];
    final int totalEntities = 10;

    for (int i = 0; i < totalEntities; i++) {
      entities[i] = engine.createEntity();

      entities[i].flags = 5;

      entities[i].componentAdded.add(addedListener);
      entities[i].componentRemoved.add(removedListener);

      entities[i].add(engine.createComponent(PositionComponent.class));
      engine.addEntity(entities[i]);

      assertNotNull(entities[i].componentOperationHandler);
      assertEquals(1, entities[i].getComponents().size());
      assertFalse(entities[i].getFamilyBits().isEmpty());
      assertTrue(familyEntities.contains(entities[i], true));
    }

    assertEquals(totalEntities, addedListener.totalCalls);
    assertEquals(0, removedListener.totalCalls);

    engine.removeAllEntities();

    assertEquals(totalEntities, addedListener.totalCalls);
    assertEquals(totalEntities, removedListener.totalCalls);

    for (int i = 0; i < totalEntities; i++) {
      assertEquals(0, entities[i].flags);
      assertNull(entities[i].componentOperationHandler);
      assertEquals(0, entities[i].getComponents().size());
      assertTrue(entities[i].getFamilyBits().isEmpty());
      assertFalse(familyEntities.contains(entities[i], true));

      entities[i].componentAdded.dispatch(entities[i]);
      entities[i].componentRemoved.dispatch(entities[i]);
    }

    assertEquals(totalEntities, addedListener.totalCalls);
    assertEquals(totalEntities, removedListener.totalCalls);
  }
 @Override
 public void update(float deltaTime) {
   if (counter >= 6 && counter <= 8) {
     getEngine().removeEntity(allEntities.get(2));
   }
   counter++;
 }
 @Override
 public void update(float deltaTime) {
   Entity entity;
   PooledEngine engine = (PooledEngine) getEngine();
   for (int i = 0; i < 10; i++) {
     entity = engine.createEntity();
     assertEquals(0, entity.flags);
     entity.flags = 1;
     entity.add(engine.createComponent(PositionComponent.class));
     engine.addEntity(entity);
   }
   for (int i = 0; i < entities.size(); ++i) {
     entity = entities.get(i);
     engine.removeEntity(entity);
     engine.removeEntity(entity);
   }
 }
Esempio n. 5
0
  private void updateRunning(float deltaTime) {
    // Implement Pause button check here
    /* See ashley-jumper -> GameScreen -> line 155 */

    ApplicationType appType = Gdx.app.getType();

    float accelX = 0.0f;
    boolean fireMissile = false;
    if (appType == ApplicationType.Android || appType == ApplicationType.iOS) {
      accelX = Gdx.input.getAccelerometerX();
      if (Gdx.input.isTouched()) {
        fireMissile = true;
      }
    } else {
      if (Gdx.input.isKeyPressed(Keys.DPAD_LEFT)) {
        accelX = 5f;
      }
      if (Gdx.input.isKeyPressed(Keys.DPAD_RIGHT)) {
        accelX = -5f;
      }
      if (Gdx.input.isKeyPressed(Keys.F)) {
        fireMissile = true;
      }
    }

    engine.getSystem(DefenderSystem.class).setAccelX(accelX);
    engine.getSystem(DefenderSystem.class).setIsFiring(fireMissile);

    // Check if all aliens are gone
    ImmutableArray<Entity> aliens =
        engine.getEntitiesFor(
            Family.all(
                    AlienComponent.class,
                    BoundsComponent.class,
                    MovementComponent.class,
                    TransformComponent.class,
                    StateComponent.class)
                .get());
    if (aliens.size() == 0) {
      world.state = World.WORLD_STATE_GAME_OVER;
    }
    if (world.state == World.WORLD_STATE_GAME_OVER) {
      state = GAME_OVER;
      pauseSystems();
    }
  }