Ejemplo n.º 1
0
  protected void renderParticles() {
    particleFrameBuffer.begin();
    batch.begin();

    Color initialColor = batch.getColor();

    Values<Entity> values = particleEntities.values();

    while (values.hasNext()) {
      Entity entity = values.next();
      ParticleComponent particle = entity.getComponent(ParticleComponent.class);
      ColorComponent color = entity.getComponent(ColorComponent.class);

      if (color != null) {
        batch.setColor(color.color);
      }

      particle.effect.draw(batch);

      batch.setColor(initialColor);
    }

    batch.end();
    particleFrameBuffer.end();

    batch.begin();
    batch.draw(particleRegion, 0.0f, 0.0f);
    batch.end();
  }
Ejemplo n.º 2
0
  protected void renderMap() {
    // If there are no map entities, dispose the renderer
    if (mapEntities.size == 0) {
      if (mapRenderer != null) {
        mapRenderer.dispose();
        mapRenderer = null;
      }
    } else {
      Entity mapEntity = mapEntities.values().next();
      MapComponent mapComponent = mapEntity.getComponent(MapComponent.class);

      if (map != mapComponent.map) {
        if (mapRenderer != null) {
          mapRenderer.dispose();
        }

        map = mapComponent.map;
        mapRenderer = new OrthogonalTiledMapRenderer(map, Env.pixelsToMetres);
      }

      // Render
      mapRenderer.setView(camera);
      mapRenderer.render();
    }
  }
Ejemplo n.º 3
0
    @Override
    public int compare(Entity e1, Entity e2) {
      TransformComponent t1 = e1.getComponent(TransformComponent.class);
      TransformComponent t2 = e2.getComponent(TransformComponent.class);

      if (t1 == null) return -1;
      if (t2 == null) return 1;

      return (int) (t2.position.z - t1.position.z);
    }
Ejemplo n.º 4
0
  @Override
  public void doProcessEntity(Entity entity, float delta) {
    TouchedComponent touched = entity.getComponent(TouchedComponent.class);

    TouchesComponent touchInteraction = entity.getComponent(TouchesComponent.class);

    for (Type type : touched.getEvents()) {
      for (RuntimeTouch runtimeTouch : touchInteraction.getBehaviors()) {
        if (runtimeTouch.getType() == type) {
          addEffects(entity, runtimeTouch.getEffects());
        }
      }
    }
  }
Ejemplo n.º 5
0
  protected void renderWorldEntities() {

    Values<Entity> values = worldEntities.values();

    while (values.hasNext()) {
      Entity entity = values.next();

      TextureComponent texture = entity.getComponent(TextureComponent.class);
      TransformComponent transform = entity.getComponent(TransformComponent.class);

      if (isInFustrum(texture, transform)) {
        sortedEntities.add(entity);
      }
    }

    values = spineAnimatedEntities.values();

    while (values.hasNext()) {
      sortedEntities.add(values.next());
    }

    sortedEntities.sort(sorter);
    batch.setProjectionMatrix(camera.combined);

    for (Entity entity : sortedEntities) {
      if (entity.hasComponent(TextureComponent.class)) {
        TextureComponent texture = entity.getComponent(TextureComponent.class);
        TransformComponent transform = entity.getComponent(TransformComponent.class);

        float scale = transform.scale * Env.pixelsToMetres;
        float width = texture.region.getRegionWidth();
        float height = texture.region.getRegionHeight();
        float originX = width * 0.5f;
        float originY = height * 0.5f;

        batch.draw(
            texture.region,
            transform.position.x - originX,
            transform.position.y - originY,
            originX,
            originY,
            width,
            height,
            scale,
            scale,
            MathUtils.radiansToDegrees * transform.angle);
      } else {
        SpineComponent animation = entity.getComponent(SpineComponent.class);
        skeletonRenderer.draw(batch, animation.skeleton);
      }
    }

    sortedEntities.clear();
  }
Ejemplo n.º 6
0
  public void processEntity(Entity entity, float deltaTime) {
    Position position = entity.getComponent(Position.class);
    Velocity velocity = entity.getComponent(Velocity.class);

    if (fastmo) {
      position.x += velocity.x * deltaTime * 5;
      position.y += velocity.y * deltaTime * 5;
    } else {
      position.x += velocity.x * deltaTime;
      position.y += velocity.y * deltaTime;
    }
  }
Ejemplo n.º 7
0
 @Override
 public void execute(Entity target, AddComponent effect) {
   // Build component to be added
   Component component = componentLoader.toEngineComponent(effect.getComponent());
   if (component != null) {
     // Add to entity
     if (target instanceof EngineEntity) {
       componentLoader.addComponent((EngineEntity) target, component);
     } else {
       target.add(component);
     }
   }
 }