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();
  }
  public GameStateManager(States s) {
    sb = new SpriteBatch();
    sr = new ShapeRenderer();
    setState(s, true);
    left = new Rectangle();
    right = new Rectangle();
    shoot = new Ellipse();
    jump = new Ellipse();
    start = new Rectangle();
    leftSt = new Rectangle();
    rightSt = new Rectangle();
    shootSt = new Ellipse();
    jumpSt = new Ellipse();
    startSt = new Rectangle();
    lefts = new boolean[MyConstants.NUM_TOUCHES];
    rights = new boolean[MyConstants.NUM_TOUCHES];
    shoots = new boolean[MyConstants.NUM_TOUCHES];
    jumps = new boolean[MyConstants.NUM_TOUCHES];
    starts = new boolean[MyConstants.NUM_TOUCHES];

    cam = new MyCamera();
    view = new StretchViewport(MyConstants.WOLRD_WIDTH, MyConstants.WORLD_HEIGHT, cam);
    view.apply(true);
    view.update((int) Game.SIZE.x, (int) Game.SIZE.y, true);
  }
예제 #3
0
 /**
  * Calculates window scissor coordinates from local coordinates using the batch's current
  * transformation matrix.
  *
  * @see ScissorStack#calculateScissors(Camera, float, float, float, float, Matrix4, Rectangle,
  *     Rectangle)
  */
 public void calculateScissors(Rectangle localRect, Rectangle scissorRect) {
   viewport.calculateScissors(batch.getTransformMatrix(), localRect, scissorRect);
   Matrix4 transformMatrix;
   if (debugShapes != null && debugShapes.isDrawing())
     transformMatrix = debugShapes.getTransformMatrix();
   else transformMatrix = batch.getTransformMatrix();
   viewport.calculateScissors(transformMatrix, localRect, scissorRect);
 }
예제 #4
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);
  }
예제 #5
0
 public boolean isTouched(float x, float y, Camera camera, Viewport view) {
   Vector3 temp =
       camera.unproject(
           new Vector3(x, y, 0),
           view.getScreenX(),
           view.getScreenY(),
           view.getScreenWidth(),
           view.getScreenHeight());
   return this.getSprite().getBoundingRectangle().contains(temp.x, temp.y);
 }
  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;
  }
  @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();
  }
 @Override
 public void resize(int width, int height) {
   // Whenever a resize event occurs, the viewport needs to be informed
   // about it and updated. This will automatically recalculate the
   // viewport parameters and update the camera (centered to the screen)
   Gdx.app.log(TAG, "Resizing to " + width + "x" + height);
   viewport.update(width, height, true);
 }
예제 #9
0
 @Override
 // this does not do anything
 public void resize(int nWidth, int nHeight) {
   dAspect = nWidth / nHeight;
   nViewH = (int) (nViewW / dAspect);
   viewport.update(nViewW, nViewH);
   camera.position.set(camera.viewportWidth / 2, camera.viewportHeight / 2, 0);
 }
예제 #10
0
  private void _touchButton() {
    Long time = System.currentTimeMillis();
    if (time - lastClickTime > 200) {
      lastClickTime = time;

      touchPos.set(Gdx.input.getX(), Gdx.input.getY(), 0);
      touchPos = viewport.unproject(touchPos);
      dragonWarsEngine.touch(touchPos.x, touchPos.y);
    }
  }
예제 #11
0
  /**
   * Creates a stage with the specified viewport and batch. This can be used to avoid creating a new
   * batch (which can be somewhat slow) if multiple stages are used during an application's life
   * time.
   *
   * @param batch Will not be disposed if {@link #dispose()} is called, handle disposal yourself.
   */
  public Stage(Viewport viewport, Batch batch) {
    if (viewport == null) throw new IllegalArgumentException("viewport cannot be null.");
    if (batch == null) throw new IllegalArgumentException("batch cannot be null.");
    this.viewport = viewport;
    this.batch = batch;

    root = new Group();
    root.setStage(this);

    viewport.update(Gdx.graphics.getWidth(), Gdx.graphics.getHeight(), true);
  }
예제 #12
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;
    }
  }
예제 #13
0
 public void update(float deltaTime) {
   camera.update();
   if (DebugViewSettings.drawModels) {
     drawShadowBatch();
     viewport.apply();
     modelBatch.begin(camera);
     modelBatch.render(engine.getModelCache(), environment);
     for (GameModel mdl : engine.getDynamicModels()) {
       if (isVisible(camera, mdl)) {
         modelBatch.render(mdl.modelInstance, environment);
       }
     }
     if (markerBillboard != null && isVisible(camera, markerBillboard)) {
       modelBatch.render(markerBillboard.modelInstance, environment);
     }
     modelBatch.end();
   }
   if (DebugViewSettings.drawArmature) {
     shapeRenderer.setProjectionMatrix(viewport.getCamera().combined);
     armatureDebugDrawer.drawArmature(shapeRenderer, selectedCharacter, "armature");
   }
   if (DebugViewSettings.drawSteering) {
     drawSteering();
   }
   if (DebugViewSettings.drawNavmesh) {
     shapeRenderer.setProjectionMatrix(viewport.getCamera().combined);
     navMeshDebugDrawer.drawNavMesh(
         shapeRenderer,
         spriteBatch,
         engine.getScene().navMesh,
         selectedCharacter,
         visibleLayers,
         viewport.getCamera(),
         font);
   }
   if (DebugViewSettings.drawMouseNavMeshPos) {
     shapeRenderer.setProjectionMatrix(viewport.getCamera().combined);
     drawMouseWorldAxis();
   }
 }
예제 #14
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();
  }
예제 #15
0
  /**
   * Applies a touch down event to the stage and returns true if an actor in the scene {@link
   * Event#handle() handled} the event.
   */
  public boolean touchDown(int screenX, int screenY, int pointer, int button) {
    if (screenX < viewport.getScreenX()
        || screenX >= viewport.getScreenX() + viewport.getScreenWidth()) return false;
    if (Gdx.graphics.getHeight() - screenY < viewport.getScreenY()
        || Gdx.graphics.getHeight() - screenY >= viewport.getScreenY() + viewport.getScreenHeight())
      return false;

    pointerTouched[pointer] = true;
    pointerScreenX[pointer] = screenX;
    pointerScreenY[pointer] = screenY;

    screenToStageCoordinates(tempCoords.set(screenX, screenY));

    InputEvent event = Pools.obtain(InputEvent.class);
    event.setType(Type.touchDown);
    event.setStage(this);
    event.setStageX(tempCoords.x);
    event.setStageY(tempCoords.y);
    event.setPointer(pointer);
    event.setButton(button);

    Actor target = hit(tempCoords.x, tempCoords.y, true);
    if (target == null) {
      if (root.getTouchable() == Touchable.enabled) root.fire(event);
    } else {
      target.fire(event);
    }

    boolean handled = event.isHandled();
    Pools.free(event);
    return handled;
  }
예제 #16
0
  /**
   * Applies a mouse moved event to the stage and returns true if an actor in the scene {@link
   * Event#handle() handled} the event. This event only occurs on the desktop.
   */
  public boolean mouseMoved(int screenX, int screenY) {
    if (screenX < viewport.getScreenX()
        || screenX >= viewport.getScreenX() + viewport.getScreenWidth()) return false;
    if (Gdx.graphics.getHeight() - screenY < viewport.getScreenY()
        || Gdx.graphics.getHeight() - screenY >= viewport.getScreenY() + viewport.getScreenHeight())
      return false;

    mouseScreenX = screenX;
    mouseScreenY = screenY;

    screenToStageCoordinates(tempCoords.set(screenX, screenY));

    InputEvent event = Pools.obtain(InputEvent.class);
    event.setStage(this);
    event.setType(Type.mouseMoved);
    event.setStageX(tempCoords.x);
    event.setStageY(tempCoords.y);

    Actor target = hit(tempCoords.x, tempCoords.y, true);
    if (target == null) target = root;

    target.fire(event);
    boolean handled = event.isHandled();
    Pools.free(event);
    return handled;
  }
  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();
  }
예제 #18
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());
    }
  }
예제 #19
0
  public void draw() {
    Camera camera = viewport.getCamera();
    camera.update();

    if (!root.isVisible()) return;

    Batch batch = this.batch;
    if (batch != null) {
      batch.setProjectionMatrix(camera.combined);
      batch.begin();
      root.draw(batch, 1);
      batch.end();
    }

    if (debug) drawDebug();
  }
예제 #20
0
  @Override
  public void create() {
    System.out.println("Create...");
    dragonWarsEngine = new DragonWarsEngine(this);
    CommonResources.reset();

    // camera = new OrthographicCamera();
    // camera.setToOrtho(false, SCREEN_X, );

    camera = new OrthographicCamera();
    viewport = new FitViewport(SCREEN_X, SCREEN_Y, camera);
    viewport.apply();

    camera.position.set(camera.viewportWidth / 2, camera.viewportHeight / 2, 0);

    batch = new SpriteBatch();
  }
 public AbstractGameScreen(DirectedGame game) {
   this.game = game;
   if (camera == null) {
     camera = new OrthographicCamera();
   }
   if (viewport == null) {
     Gdx.app.log(
         TAG,
         "New viewport with width: "
             + TARGET_SCREEN_WIDTH
             + " and height: "
             + TARGET_SCREEN_HEIGHT);
     viewport = new ExtendViewport(TARGET_SCREEN_WIDTH, TARGET_SCREEN_HEIGHT, camera);
   }
   viewport.apply();
   Gdx.input.setCatchBackKey(false); // will be set to true only when the
   // child override the InputAdapter
   // class methods
 }
예제 #22
0
 // base code
 // http://www.gamefromscratch.com/post/2014/05/01/LibGDX-Tutorial-11-Tiled-Maps-Part-2-Adding-a-character-sprite.aspx
 // veiw port from here
 // http://www.gamefromscratch.com/post/2014/12/09/LibGDX-Tutorial-Part-17-Viewports.aspx
 // ______________________________________________________________________________________________
 @Override
 public void create() {
   // get screen size and set aspect
   dAspect = 1280 / 720;
   dViewH = (nViewW / dAspect);
   nViewH = (int) dViewH;
   // images
   batch = new SpriteBatch();
   spMenu = new Sprite(new Texture(Gdx.files.internal("mainmenu.png")));
   spMenu.setSize(320, 180);
   imgEnemy = new Texture("player.png");
   spMenu.setPosition(340, 510);
   imgPlayer = new Texture("player.png");
   for (int i = 0; i < 5; i++) {
     imgBaseKey[i] = new Texture("BaseKey.png");
     imgRedKey[i] = new Texture("RedKey.png");
     imgBaseWall[i] = new Texture("BaseFLW.png");
     imgRedwall[i] = new Texture("RedFLW.png");
     nKn[i] = 0;
   }
   for (int i = 0; i < 10; i++) {
     nKy[i] = nKx[i] = -100000;
     //  recKey[i].setSize(6,11);
     // recKey[i].setPosition(nKx[i],nKy[i]);
   }
   nWx[0] = 480;
   nWy[0] = 832;
   imgNum[0] = new Texture("Num 0.png");
   imgNum[1] = new Texture("Num 0.png");
   imgNum[2] = new Texture("Num 0.png");
   imgHud = new Texture("BASE HUD.png");
   // tiled map
   tiledMap = new TmxMapLoader().load("MyMap.tmx");
   tiledMapRenderer = new OrthogonalTiledMapRenderer(tiledMap);
   // viewport
   camera = new OrthographicCamera();
   viewport = new FillViewport(320, 180, camera);
   nPx = (int) 500 + (int) (camera.viewportWidth) / 2;
   nPy = (int) 600 + (int) (camera.viewportHeight) / 2;
   viewport.apply();
   camera.position.set(500, 600, 0);
 }
예제 #23
0
  public void render(float delta) {
    if (cameraCache != viewport.getCamera())
      cameraCache = (OrthographicCamera) viewport.getCamera();

    viewport.getCamera().position.add(speed.x * delta, speed.y * delta, 0f);
    for (int i = 0; i < layers.length; i++) {

      cameraProjectionCache.set(viewport.getCamera().projection);
      cameraProjectionCache.scl(cameraCache.zoom);

      batch.setProjectionMatrix(cameraProjectionCache);
      batch.begin();
      float currentX =
          -viewport.getCamera().position.x
              * layers[i].parallaxRatio.x
              % (layers[i].region.getRegionWidth() + layers[i].padding.x);

      if (speed.x < 0) currentX += -(layers[i].region.getRegionWidth() + layers[i].padding.x);
      do {
        /* Y REPEATING DISABLED:
        float currentY = -viewport.getCamera().position.y * layers[i].parallaxRatio.y % (layers[i].region.getRegionHeight() + layers[i].padding.y);

        if (speed.y < 0)
            currentY += -(layers[i].region.getRegionHeight() + layers[i].padding.y);

        do {
            batch.draw(layers[i].region,
                    -viewport.getCamera().viewportWidth / 2 + currentX + layers[i].startPosition.x,
                    -viewport.getCamera().viewportHeight / 2 + currentY + layers[i].startPosition.y);

            currentY += (layers[i].region.getRegionHeight() + layers[i].padding.y);
        } while (currentY < viewport.getCamera().viewportHeight);*/

        batch.draw(
            layers[i].region,
            -viewport.getCamera().viewportWidth / 2 + currentX + layers[i].startPosition.x,
            -viewport.getCamera().viewportHeight / 2 + layers[i].startPosition.y);

        currentX += (layers[i].region.getRegionWidth() + layers[i].padding.x);
      } while (currentX < viewport.getCamera().viewportWidth);
      batch.end();
    }
  }
예제 #24
0
  private void drawDebug() {
    if (debugShapes == null) {
      debugShapes = new ShapeRenderer();
      debugShapes.setAutoShapeType(true);
    }

    if (debugUnderMouse || debugParentUnderMouse || debugTableUnderMouse != Debug.none) {
      screenToStageCoordinates(tempCoords.set(Gdx.input.getX(), Gdx.input.getY()));
      Actor actor = hit(tempCoords.x, tempCoords.y, true);
      if (actor == null) return;

      if (debugParentUnderMouse && actor.parent != null) actor = actor.parent;

      if (debugTableUnderMouse == Debug.none) actor.setDebug(true);
      else {
        while (actor != null) {
          if (actor instanceof Table) break;
          actor = actor.parent;
        }
        if (actor == null) return;
        ((Table) actor).debug(debugTableUnderMouse);
      }

      if (debugAll && actor instanceof Group) ((Group) actor).debugAll();

      disableDebug(root, actor);
    } else {
      if (debugAll) root.debugAll();
    }

    Gdx.gl.glEnable(GL20.GL_BLEND);
    debugShapes.setProjectionMatrix(viewport.getCamera().combined);
    debugShapes.begin();
    root.drawDebug(debugShapes);
    debugShapes.end();
  }
 @Override
 public void resize(int width, int height) {
   gamePort.update(width, height);
 }
예제 #26
0
 /**
  * Transforms the coordinates to screen coordinates. The coordinates can be anywhere in the stage
  * since the transform matrix describes how to convert them. The transform matrix is typically
  * obtained from {@link Batch#getTransformMatrix()} during {@link Actor#draw(Batch, float)}.
  *
  * @see Actor#localToStageCoordinates(Vector2)
  */
 public Vector2 toScreenCoordinates(Vector2 coords, Matrix4 transformMatrix) {
   return viewport.toScreenCoordinates(coords, transformMatrix);
 }
예제 #27
0
 /**
  * Transforms the stage coordinates to screen coordinates.
  *
  * @param stageCoords Input stage coordinates and output for resulting screen coordinates.
  */
 public Vector2 stageToScreenCoordinates(Vector2 stageCoords) {
   viewport.project(stageCoords);
   stageCoords.y = viewport.getScreenHeight() - stageCoords.y;
   return stageCoords;
 }
예제 #28
0
 /**
  * Transforms the screen coordinates to stage coordinates.
  *
  * @param screenCoords Input screen coordinates and output for resulting stage coordinates.
  */
 public Vector2 screenToStageCoordinates(Vector2 screenCoords) {
   viewport.unproject(screenCoords);
   return screenCoords;
 }
예제 #29
0
 /** The viewport's camera. */
 public Camera getCamera() {
   return viewport.getCamera();
 }
예제 #30
0
 /** The viewport's world height. */
 public float getHeight() {
   return viewport.getWorldHeight();
 }