Exemplo n.º 1
0
  public void recalculateButtonPositions() {

    moveLeftCenter.set(Constants.BUTTON_SIZE * 3 / 4, Constants.BUTTON_SIZE);
    moveRightCenter.set(Constants.BUTTON_SIZE * 2, Constants.BUTTON_SIZE * 3 / 4);

    shootCenter.set(
        viewport.getWorldWidth() - Constants.BUTTON_SIZE * 2f, Constants.BUTTON_SIZE * 3 / 4);

    jumpCenter.set(viewport.getWorldWidth() - Constants.BUTTON_SIZE * 3 / 4, Constants.BUTTON_SIZE);
  }
  public void update(float delta) {
    if (MathUtils.random() < delta * Constants.ICICLE_SPAWNS_PER_SECOND) {

      Vector2 newIciclePosition =
          new Vector2(MathUtils.random() * viewport.getWorldWidth(), viewport.getWorldHeight());
      Icicle newIcicle = new Icicle(newIciclePosition);
      icicleList.add(newIcicle);
    }

    for (Icicle icicle : icicleList) {
      icicle.update(delta);
    }

    // TODO: begin a removal session
    icicleList.begin();

    // TODO: Remove any icicle completely off the bottom of the screen
    for (int i = 0; i < icicleList.size; i++) {
      if (icicleList.get(i).position.y < -Constants.ICICLES_HEIGHT) {
        icicleList.removeIndex(i);
      }
    }

    // TODO: End removal session
    icicleList.end();
  }
Exemplo n.º 3
0
  @Override
  public void update(float deltaTime) {
    Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);

    int width = Gdx.graphics.getWidth();
    int height = Gdx.graphics.getHeight();

    viewport.update(width, height);

    renderMap();

    batch.begin();
    renderWorldEntities();
    batch.end();

    renderParticles();

    uiViewport.update(width, height);
    uiCamera.position.set(
        uiViewport.getWorldWidth() * 0.5f, uiViewport.getWorldHeight() * 0.5f, 0.0f);
    Env.game.getStage().draw();

    viewport.update(width, height);
    debugDrawWorld();

    uiViewport.update(width, height);
    debugDrawUI();

    if (previousWidth != width || previousHeight != height) {
      Env.game.resize(width, height);
      previousWidth = width;
      previousHeight = height;
    }
  }
  @Override
  public void render(float delta) {
    update(delta);

    Gdx.gl.glClearColor(0, 0, 0, 1);
    Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);

    game.batch.setProjectionMatrix(gameCamera.combined);
    game.batch.begin();
    game.batch.draw(background, 0, 0, gamePort.getWorldWidth(), gamePort.getWorldHeight());
    game.batch.draw(
        selectionArea, POSITIONS[pos][0], POSITIONS[pos][1], POSITIONS[pos][2], POSITIONS[pos][3]);
    game.batch.end();
  }
  public CharacterSelect(RPGGame game) {
    this.game = game;

    gameCamera = new OrthographicCamera();
    gamePort =
        new FitViewport(
            (RPGGame.V_WIDTH) / RPGGame.PPM, (RPGGame.V_HEIGHT) / RPGGame.PPM, gameCamera);
    gameCamera.position.x = gamePort.getWorldWidth() - ((RPGGame.V_WIDTH / RPGGame.PPM) / 2);
    gameCamera.position.y = gamePort.getWorldHeight() - ((RPGGame.V_HEIGHT / RPGGame.PPM) / 2);

    background = new TextureRegion(new Texture("characterSelection.png"));
    selectionArea = new TextureRegion(new Texture("backglow.png"));
    pos = 0;
  }
Exemplo n.º 6
0
  protected void debugDrawUI() {
    if (Env.debug) {
      if (Env.drawFPS) {
        String fpsText = String.format("%d FPS", Gdx.graphics.getFramesPerSecond());
        TextBounds bounds = debugFont.getBounds(fpsText);
        batch.setProjectionMatrix(uiCamera.combined);
        batch.begin();
        debugFont.setColor(1.0f, 1.0f, 1.0f, 1.0f);
        debugFont.draw(batch, fpsText, uiViewport.getWorldWidth() - bounds.width - 20.0f, 20.0f);
        batch.end();
      }

      Table.drawDebug(Env.game.getStage());
    }
  }
Exemplo n.º 7
0
  private void updateCamera() {
    direction.set(0.0f, 0.0f);
    int mouseX = Gdx.input.getX();
    int mouseY = Gdx.input.getY();
    int width = Gdx.graphics.getWidth();
    int height = Gdx.graphics.getHeight();

    if (Gdx.input.isKeyPressed(Input.Keys.LEFT)
        || (Gdx.input.isTouched() && mouseX < width * 0.75f)) {
      direction.x = -1;
    } else if (Gdx.input.isKeyPressed(Input.Keys.RIGHT)
        || (Gdx.input.isTouched() && mouseX > width * 0.75f)) {
      direction.x = 1;
    }

    if (Gdx.input.isKeyPressed(Input.Keys.UP)
        || (Gdx.input.isTouched() && mouseY < height * 0.75f)) {
      direction.y = 1;
    } else if (Gdx.input.isKeyPressed(Input.Keys.DOWN)
        || (Gdx.input.isTouched() && mouseY > height * 0.75f)) {
      direction.y = -1;
    }

    direction.nor().scl(CAMERA_SPEED * Gdx.graphics.getDeltaTime());

    camera.position.x += direction.x;
    camera.position.y += direction.y;

    TiledMapTileLayer layer = (TiledMapTileLayer) tiledMap.getLayers().get(0);

    float cameraMinX = viewport.getWorldWidth() * 0.5f;
    float cameraMinY = viewport.getWorldHeight() * 0.5f;
    float cameraMaxX = layer.getWidth() * layer.getTileWidth() + (playerWidth - cameraMinX);
    float cameraMaxY = layer.getHeight() * layer.getTileHeight() - cameraMinY;

    camera.position.x = MathUtils.clamp(sprite.getX(), cameraMinX, cameraMaxX);
    camera.position.y = MathUtils.clamp(sprite.getY(), cameraMinY, cameraMaxY);

    camera.update();
  }
  public void update(float delta) {
    if (MathUtils.random() < delta * Constants.ICICLE_SPAWNS_PER_SECOND) {
      Vector2 newIciclePosition =
          new Vector2(MathUtils.random() * viewport.getWorldWidth(), viewport.getWorldHeight());
      Icicle newIcicle = new Icicle(newIciclePosition);
      icicleList.add(newIcicle);
    }

    for (Icicle icicle : icicleList) {
      icicle.update(delta);
    }

    icicleList.begin();
    for (int i = 0; i < icicleList.size; i++) {
      if (icicleList.get(i).position.y < -Constants.ICICLES_HEIGHT) {
        // TODO: Increment count of icicles dodged
        iciclesDodged++;
        icicleList.removeIndex(i);
      }
    }
    icicleList.end();
  }
Exemplo n.º 9
0
 /** The viewport's world width. */
 public float getWidth() {
   return viewport.getWorldWidth();
 }