示例#1
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();
    }
  }
示例#2
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();
  }