Ejemplo n.º 1
0
    @Override
    public void update(float deltaTime) {
      List<TouchEvent> touchEvents = game.getInput().getTouchEvents();
      game.getInput().getKeyEvents();

      int len = touchEvents.size();
      for (int i = 0; i < len; i++) {
        TouchEvent event = touchEvents.get(i);

        camera.touchToWorld(touchPos.set(event.x, event.y));

        cannon.angle = touchPos.sub(cannon.position).angle();

        if (event.type == TouchEvent.TOUCH_UP) {
          float radians = cannon.angle * Vector2.TO_RADIANS;
          float ballSpeed = touchPos.len() * 2;
          ball.position.set(cannon.position);

          ball.velocity.x = FloatMath.cos(radians) * ballSpeed;
          ball.velocity.y = FloatMath.sin(radians) * ballSpeed;

          ball.bounds.lowerLeft.set(ball.position.x - 0.1f, ball.position.y - 0.1f);
        }
      }

      ball.velocity.add(gravity.x * deltaTime, gravity.y * deltaTime);
      ball.position.add(ball.velocity.x * deltaTime, ball.velocity.y * deltaTime);
      ball.bounds.lowerLeft.add(ball.velocity.x * deltaTime, ball.velocity.y * deltaTime);

      List<GameObject> colliders = grid.getPotentialColliders(ball);
      len = colliders.size();

      for (int i = 0; i < len; i++) {
        GameObject collider = colliders.get(i);
        if (OverlapTester.overlapRectangle(ball.bounds, collider.bounds)) {
          grid.removeObject(collider);
          targets.remove(collider);
        }
      }

      if (ball.position.y > 0) {
        camera.position.set(ball.position);
        camera.zoom = 1 + ball.position.y / WORLD_HEIGHT;
      } else {
        camera.position.set(WORLD_WIDTH / 2, WORLD_HEIGHT / 2);
        camera.zoom = 1;
      }
    }
Ejemplo n.º 2
0
 public void render() {
   cam.setViewportAndMatrices();
   renderBackground();
   if (board.state != Board.GAME_READY) {
     renderForeground();
   }
 }
Ejemplo n.º 3
0
  @Override
  public void present(float deltaTime) {
    GL10 gl = glGraphics.getGL();
    gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
    gl.glEnable(GL10.GL_TEXTURE_2D);

    renderer.render();

    guiCam.setViewportAndMatrices();
    gl.glEnable(GL10.GL_BLEND);
    gl.glBlendFunc(GL10.GL_SRC_ALPHA, GL10.GL_ONE_MINUS_SRC_ALPHA);
    batcher.beginBatch(Assets.items);
    switch (state) {
      case GAME_READY:
        presentReady();
        break;
      case GAME_RUNNING:
        presentRunning();
        break;
      case GAME_PAUSED:
        presentPaused();
        break;
      case GAME_LEVEL_END:
        presentLevelEnd();
        break;
      case GAME_OVER:
        presentGameOver();
        break;
    }
    batcher.endBatch();
    gl.glDisable(GL10.GL_BLEND);
    fpsCounter.logFrame();
  }
Ejemplo n.º 4
0
  private void updateRunning(float deltaTime) {
    List<TouchEvent> touchEvents = game.getInput().getTouchEvents();
    int len = touchEvents.size();
    for (int i = 0; i < len; i++) {
      TouchEvent event = touchEvents.get(i);
      if (event.type != TouchEvent.TOUCH_UP) continue;

      touchPoint.set(event.x, event.y);
      guiCam.touchToWorld(touchPoint);

      if (OverlapTester.pointInRectangle(pauseBounds, touchPoint)) {
        Assets.playSound(Assets.clickSound);
        state = GAME_PAUSED;
        return;
      }
    }

    world.update(deltaTime, game.getInput().getAccelX());
    if (world.score != lastScore) {
      lastScore = world.score;
      scoreString = "" + lastScore;
    }
    if (world.state == World.WORLD_STATE_NEXT_LEVEL) {
      state = GAME_LEVEL_END;
    }
    if (world.state == World.WORLD_STATE_GAME_OVER) {
      state = GAME_OVER;
      if (lastScore >= Settings.highscores[4]) scoreString = "new highscore: " + lastScore;
      else scoreString = "score: " + lastScore;
      Settings.addScore(lastScore);
      Settings.save(game.getFileIO());
    }
  }
Ejemplo n.º 5
0
  @Override
  public void present(float deltaTime) {
    GL10 gl = glGraphics.getGL();
    gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
    guiCam.setViewportAndMatrices();

    gl.glEnable(GL10.GL_TEXTURE_2D);

    batcher.beginBatch(Assets.background);
    batcher.drawSprite(160, 240, 320, 480, Assets.backgroundRegion);
    batcher.endBatch();

    gl.glEnable(GL10.GL_BLEND);
    gl.glBlendFunc(GL10.GL_SRC_ALPHA, GL10.GL_ONE_MINUS_SRC_ALPHA);

    batcher.beginBatch(Assets.items);

    batcher.drawSprite(160, 480 - 10 - 71, 274, 142, Assets.logo);
    batcher.drawSprite(160, 200, 300, 110, Assets.mainMenu);
    batcher.drawSprite(32, 32, 64, 64, Settings.soundEnabled ? Assets.soundOn : Assets.soundOff);

    batcher.endBatch();

    gl.glDisable(GL10.GL_BLEND);
  }
Ejemplo n.º 6
0
  @Override
  public void update(float deltaTime) {
    List<TouchEvent> touchEvents = game.getInput().getTouchEvents();
    game.getInput().getKeyEvents();

    int len = touchEvents.size();
    for (int i = 0; i < len; i++) {
      TouchEvent event = touchEvents.get(i);
      touchPoint.set(event.x, event.y);
      guiCam.touchToWorld(touchPoint);

      if (event.type == TouchEvent.TOUCH_UP) {
        if (OverlapTester.pointInRectangle(playBounds, touchPoint)) {
          game.setScreen(new GameScreen(game));
          return;
        }
        if (OverlapTester.pointInRectangle(highscoresBounds, touchPoint)) {
          game.setScreen(new HighscoreScreen(game));
          return;
        }
        if (OverlapTester.pointInRectangle(helpBounds, touchPoint)) {
          game.setScreen(new HelpScreen(game));
          return;
        }
        if (OverlapTester.pointInRectangle(soundBounds, touchPoint)) {
          Settings.soundEnabled = !Settings.soundEnabled;
        }
      }
    }
  }
Ejemplo n.º 7
0
    @Override
    public void present(float deltaTime) {
      gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
      camera.setViewportAndMatrices();

      gl.glColor4f(0, 1, 0, 1);
      targetVertices.bind();
      int len = targets.size();
      for (int i = 0; i < len; i++) {
        GameObject target = targets.get(i);
        gl.glLoadIdentity();
        gl.glTranslatef(target.position.x, target.position.y, 0);
        targetVertices.draw(GL10.GL_TRIANGLES, 0, 6);
      }
      targetVertices.unbind();

      gl.glLoadIdentity();
      gl.glTranslatef(ball.position.x, ball.position.y, 0);
      gl.glColor4f(1, 0, 0, 1);
      ballVertices.bind();
      ballVertices.draw(GL10.GL_TRIANGLES, 0, 6);
      ballVertices.unbind();

      gl.glLoadIdentity();
      gl.glTranslatef(cannon.position.x, cannon.position.y, 0);
      gl.glRotatef(cannon.angle, 0, 0, 1);
      gl.glColor4f(1, 1, 1, 1);
      cannonVertices.bind();
      cannonVertices.draw(GL10.GL_TRIANGLES, 0, 3);
      cannonVertices.unbind();
    }
  @Override
  public void update(float deltaTime) {
    List<TouchEvent> events = game.getInput().getTouchEvents();
    int len = events.size();
    for (int i = 0; i < len; i++) {
      TouchEvent event = events.get(i);
      if (event.type != TouchEvent.TOUCH_UP) continue;

      guiCam.touchToWorld(touchPoint.set(event.x, event.y));
      if (OverlapTester.pointInRectangle(playBounds, touchPoint)) {
        Assets.playSound(Assets.clickSound);
        game.setScreen(new GameScreen(game));
      }
      if (OverlapTester.pointInRectangle(settingsBounds, touchPoint)) {
        Assets.playSound(Assets.clickSound);
        game.setScreen(new SettingsScreen(game));
      }
    }
  }
Ejemplo n.º 9
0
  @Override
  public void update(float deltaTime) {
    List<TouchEvent> touchEvents = game.getInput().getTouchEvents();
    game.getInput().getKeyEvents();
    int len = touchEvents.size();
    for (int i = 0; i < len; i++) {
      TouchEvent event = touchEvents.get(i);
      touchPoint.set(event.x, event.y);
      guiCam.touchToWorld(touchPoint);

      if (event.type == TouchEvent.TOUCH_UP) {
        if (OverlapTester.pointInRectangle(nextBounds, touchPoint)) {
          Assets.playSound(Assets.clickSound);
          game.setScreen(new HelpScreen5(game));
          return;
        }
      }
    }
  }
Ejemplo n.º 10
0
  @Override
  public void present(float deltaTime) {
    GL10 gl = glGraphics.getGL();
    gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
    guiCam.setViewportAndMatrices();

    gl.glEnable(GL10.GL_TEXTURE_2D);

    batcher.beginBatch(helpImage);
    batcher.drawSprite(160, 240, 320, 480, helpRegion);
    batcher.endBatch();

    gl.glEnable(GL10.GL_BLEND);
    gl.glBlendFunc(GL10.GL_SRC_ALPHA, GL10.GL_ONE_MINUS_SRC_ALPHA);

    batcher.beginBatch(Assets.items);
    batcher.drawSprite(320 - 32, 32, -64, 64, Assets.arrow);
    batcher.endBatch();

    gl.glDisable(GL10.GL_BLEND);
  }
  @Override
  public void present(float deltaTime) {
    GL10 gl = glGraphics.getGL();
    gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
    guiCam.setViewportAndMatrices();

    gl.glEnable(GL10.GL_TEXTURE_2D);

    batcher.beginBatch(Assets.background);
    batcher.drawSprite(240, 160, 480, 320, Assets.backgroundRegion);
    batcher.endBatch();

    gl.glEnable(GL10.GL_BLEND);
    gl.glBlendFunc(GL10.GL_SRC_ALPHA, GL10.GL_ONE_MINUS_SRC_ALPHA);

    batcher.beginBatch(Assets.items);
    batcher.drawSprite(240, 240, 384, 128, Assets.logoRegion);
    batcher.drawSprite(240, 100, 224, 64, Assets.menuRegion);
    batcher.endBatch();

    gl.glDisable(GL10.GL_BLEND);
    gl.glDisable(GL10.GL_TEXTURE_2D);
  }
Ejemplo n.º 12
0
  private void updatePaused() {
    List<TouchEvent> touchEvents = game.getInput().getTouchEvents();
    int len = touchEvents.size();
    for (int i = 0; i < len; i++) {
      TouchEvent event = touchEvents.get(i);
      if (event.type != TouchEvent.TOUCH_UP) continue;

      touchPoint.set(event.x, event.y);
      guiCam.touchToWorld(touchPoint);

      if (OverlapTester.pointInRectangle(resumeBounds, touchPoint)) {
        Assets.playSound(Assets.clickSound);
        state = GAME_RUNNING;
        return;
      }

      if (OverlapTester.pointInRectangle(quitBounds, touchPoint)) {
        Assets.playSound(Assets.clickSound);
        game.setScreen(new MainMenuScreen(game));
        return;
      }
    }
  }