Пример #1
0
 public void addedToEngine(Engine engine) {
   movedEntities =
       engine.getEntitiesFor(
           Family.getFamilyFor(
               BoundsComponent.class, PositionComponent.class, MovementComponent.class));
   entities = engine.getEntitiesFor(Family.getFamilyFor(BoundsComponent.class));
 }
Пример #2
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;
  }
Пример #3
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();
    }
  }
Пример #4
0
  public MainGameScreen(SpaceInvadersGame game) {
    this.game = game;

    state = GAME_RUNNING;
    guiCam = new OrthographicCamera(640, 480);
    guiCam.position.set(640 / 2, 480 / 2, 0);
    touchPoint = new Vector3();
    collisionListener =
        new CollisionListener() {

          @Override
          public void jump() {}

          @Override
          public void hit() {}

          @Override
          public void highJump() {}

          @Override
          public void coin() {}
        };

    engine = new Engine();
    world = new World(engine);

    engine.addSystem(new DefenderSystem(world));
    engine.addSystem(new AlienSystem(world));
    engine.addSystem(new CameraSystem());
    engine.addSystem(new MovementSystem());
    engine.addSystem(new BoundsSystem());
    engine.addSystem(new StateSystem());
    engine.addSystem(new AnimationSystem());
    engine.addSystem(new CollisionSystem(world, collisionListener));
    engine.addSystem(new RenderingSystem(game.batcher));

    world.create();

    lastScore = 0;
    scoreString = "SCORE: 0";

    resumeSystems();
  }
Пример #5
0
 private void resumeSystems() {
   // engine.getSystem(BobSystem.class).setProcessing(true);
   // engine.getSystem(SquirrelSystem.class).setProcessing(true);
   // engine.getSystem(PlatformSystem.class).setProcessing(true);
   // engine.getSystem(GravitySystem.class).setProcessing(true);
   engine.getSystem(MovementSystem.class).setProcessing(true);
   engine.getSystem(BoundsSystem.class).setProcessing(true);
   engine.getSystem(StateSystem.class).setProcessing(true);
   engine.getSystem(AnimationSystem.class).setProcessing(true);
   engine.getSystem(CollisionSystem.class).setProcessing(true);
   engine.getSystem(DefenderSystem.class).setProcessing(true);
   engine.getSystem(AlienSystem.class).setProcessing(true);
 }
Пример #6
0
  public void update(float deltaTime) {
    if (deltaTime > 0.1f) deltaTime = 0.1f;

    engine.update(deltaTime);

    switch (state) {
      case GAME_READY:
        updateReady();
        break;
      case GAME_RUNNING:
        updateRunning(deltaTime);
        break;
      case GAME_PAUSED:
        // updatePaused();
        break;
      case GAME_LEVEL_END:
        // updateLevelEnd();
        break;
      case GAME_OVER:
        // updateGameOver();
        break;
    }
  }
Пример #7
0
  // Kill if dead
  public void processEntity(Entity entity, float deltaTime) {
    if (Mappers.life.get(entity).justDied) {
      Mappers.life.get(entity).updateJustDied();
      if (Mappers.type.get(entity).type == TypeComponent.EntityType.Altar) {
        UltraManager.setState(UltraManager.State.GameOverDialog);
        return;
      }
      if (Mappers.enemy.has(entity)) {
        if (--SpawnSystem.aliveEnemies == 0 && SpawnSystem.lastRound) {

          ItemFactory.spawnAltarEnabler(
              Mappers.position.get(entity).x,
              Mappers.position.get(entity).y,
              ItemSpawnSystem.getAltarEnablerId());
        }
      }
      AudioManager.kill.play();
      PositionComponent pos = Mappers.position.get(entity);
      FXFactory.makeDissapearEnemy(
          pos.x, pos.y, Mappers.enemy.get(entity), Mappers.render_comp.get(entity).invert);
      engine.removeEntity(entity);
    }
  }
Пример #8
0
 @Override
 public void addedToEngine(Engine engine) {
   entities = engine.getEntitiesFor(Family.all(PositionComponent.class).get());
 }
 @Override
 public void addedToEngine(Engine engine) {
   entities =
       engine.getEntitiesFor(Family.all(BodyComponent.class).exclude(PlayerComponent.class).get());
   players = engine.getEntitiesFor(Family.all(PlayerComponent.class).get());
 }
 public void addedToEngine(Engine engine) {
   player = engine.getEntitiesFor(Family.all(PlayerSteerableComponent.class).get());
   entities = engine.getEntitiesFor(Family.all(TalkComponent.class).get());
 }