示例#1
0
  private void drawTrajectory() {
    float offsetX = Constants.WEAPON_OFFSET_FROM_PLAYER_X_FACING_RIGHT;
    float offsetY = Constants.WEAPON_OFFSET_FROM_PLAYER_Y;

    if (player.getFacing() == 0) {
      offsetX = Constants.WEAPON_OFFSET_FROM_PLAYER_X_FACING_RIGHT;
    } else {
      offsetX = Constants.WEAPON_OFFSET_FROM_PLAYER_X_FACING_LEFT;
    }

    Player p = player;

    Float originX = p.getX() + offsetX + Constants.WEAPON_ORIGIN_X;
    Float originY = p.getY() + offsetY + Constants.WEAPON_ORIGIN_Y;

    Float mouseX = player.getTargetX();
    Float mouseY = player.getTargetY();

    Float deltaX = (mouseX - originX);
    Float deltaY = (mouseY - originY);

    Double angle = Math.atan2(deltaY.doubleValue(), deltaX.doubleValue());

    Float x = (float) Math.cos(angle.floatValue());
    Float y = (float) Math.sin(angle.floatValue());

    Float calculatedX = originX + x * Constants.SHOT_DISTANCE_FROM_ORIGIN;
    Float calculatedY = originY + y * Constants.SHOT_DISTANCE_FROM_ORIGIN;

    shapeRenderer.begin(ShapeType.Line);
    shapeRenderer.setColor(Color.RED);
    shapeRenderer.line(calculatedX, calculatedY, mouseX, mouseY);
    shapeRenderer.end();
  }
示例#2
0
 public void render(SpriteBatch sb, ShapeRenderer sr) {
   double drawx = getDrawX();
   double drawy = getDrawY();
   if (drawx < -40 || drawx > Gdx.graphics.getWidth() + 40) return;
   if (drawy < -40 || drawy > Gdx.graphics.getHeight() + 40) return;
   Gdx.gl.glEnable(GL20.GL_BLEND);
   Gdx.gl.glBlendFunc(GL20.GL_SRC_ALPHA, GL10.GL_ONE_MINUS_SRC_ALPHA);
   float red = Math.min(1f, 2f * (1f - health / maxHealth));
   float green = Math.min(1f, 2f * (health / maxHealth));
   sr.setColor(red * 0.75f, green * 0.75f, 0, 0.9f);
   draw(sb, sr, 20, ShapeType.Filled);
   sr.setColor(red, green, 0, 1f);
   draw(sb, sr, 20, ShapeType.Line);
   sr.begin(ShapeType.Filled);
   sr.circle((float) getDrawX(), (float) getDrawY(), 2);
   sr.end();
   Gdx.gl.glDisable(GL20.GL_BLEND);
   if (!arms.isEmpty() && arms.getFirst() != null) arms.getFirst().render(sb, sr);
   //		if(isAI) {
   //			float barWidth = 60;
   //			sr.begin(ShapeType.Filled);
   //			float red = Math.min(1f, 2f * (1f - health / maxHealth));
   //			float green = Math.min(1f, 2f * (health / maxHealth));
   //			sr.setColor(red, green, 0, 1f);
   //			sr.rect((float) getDrawX() - barWidth / 2, (float) getDrawY() + 30, (float) (barWidth *
   // health / maxHealth), 5);
   //			sr.end();
   //		}
 }
示例#3
0
  @Override
  public void render(float arg0) {
    Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
    camera.update();
    if (Gdx.input.isKeyPressed(Input.Keys.ESCAPE)) {
      if (focused) {
        focused = false;
      } else {
        goBack();
      }
    }

    if (focused) {
      shapeRenderer.begin(ShapeType.FilledRectangle);
      Color c = new Color(0.15f, 0.4f, 0.15f, 1f);
      shapeRenderer.setColor(c);
      shapeRenderer.filledRect(focusedBox.x, focusedBox.y, focusedBox.width, focusedBox.height);
      shapeRenderer.end();
    }

    batch.begin();
    ObjectMap.Entries<String, Rectangle> it = bindingButtons.entries();
    // draw back button text
    font.draw(batch, "Back", backButton.x, backButton.y + backButton.height);
    // draw option texts
    while (it.hasNext()) {
      ObjectMap.Entry<String, Rectangle> entry = it.next();
      Rectangle bounds = entry.value;
      font.draw(batch, entry.key, bounds.x, bounds.y + bounds.height);
      Binding binding = game.getBindings().get(entry.key);
      font.draw(batch, binding.character, bounds.x + 200.0f, bounds.y + bounds.height);
    }
    batch.end();
  }
示例#4
0
  /** Renders a blue rectangle showing the field of view of the closeup camera */
  public void render(ShapeRenderer renderer) {
    if (!inCloseupMode) {
      // Figure out the location of the camera corners in the world
      Vector2 bottomLeft = myUnproject(closeupCamera, 0, closeupCamera.viewportHeight);
      Vector2 bottomRight =
          myUnproject(closeupCamera, closeupCamera.viewportWidth, closeupCamera.viewportHeight);
      Vector2 topRight = myUnproject(closeupCamera, closeupCamera.viewportWidth, 0);
      Vector2 topLeft = myUnproject(closeupCamera, 0, 0);

      // Draw a rectangle showing the closeup camera's field of view
      renderer.begin(ShapeType.Line);
      renderer.setColor(Color.BLUE);
      float[] poly = {
        bottomLeft.x,
        bottomLeft.y,
        bottomRight.x,
        bottomRight.y,
        topRight.x,
        topRight.y,
        topLeft.x,
        topLeft.y
      };
      renderer.set(ShapeType.Line);
      renderer.polygon(poly);
      renderer.end();
    }
  }
示例#5
0
  private void drawRecursive(Actor actor) {
    if (!invisibleActors && !actor.isVisible()) return;

    if (allActors) actor.debug();

    if (actor.getDebug()) {
      actor.getDebugRects(debugRects);
      for (DebugRect debugRect : debugRects) drawRect(actor, debugRect);
      debugRects.clear();
      debugRectPool.freeAll(usedRects);
      usedRects.clear();
    }

    boolean draw = true;
    Rectangle scissorBounds = null;
    if (actor instanceof Group) scissorBounds = ((Group) actor).getScissorBounds();
    if (scissorBounds != null) {
      shapes.flush();
      draw = ScissorStack.pushScissors(scissorBounds);
    }
    if (draw) {
      // Children are still rendered, even if the group has no debugging enabled.
      if (actor instanceof Group) {
        Group group = (Group) actor;
        for (Actor child : group.getChildren()) drawRecursive(child);
      }

      if (scissorBounds != null) {
        shapes.flush();
        ScissorStack.popScissors();
      }
    }
  }
  private void renderHP() {
    ShapeRenderer render = new ShapeRenderer();

    int hp = world.thePlayer.hp;

    if (hp >= 50) render.setColor(0.0f, 1.0f, 0.0f, 1);
    else if (hp > 33) render.setColor(1.0f, 1.0f, 0.0f, 1);
    else if (hp > 0) render.setColor(1.0f, 0.0f, 0.0f, 1);

    if (!(hp < 33)) {
      render.begin(ShapeRenderer.ShapeType.FilledRectangle);
      render.filledRect(5, 5, hp * 2, 20);
      render.end();
    }

    if (flickerDraw && (hp < 33)) {
      render.begin(ShapeRenderer.ShapeType.FilledRectangle);
      render.filledRect(5, 5, hp * 2, 20);
      render.end();
      flickerDraw = false;
    } else if (lastFlicker > 3) {
      flickerDraw = true;
      this.lastFlicker = 0;
    } else this.lastFlicker++;
  }
示例#7
0
  @Override
  public void render() {
    viewport.apply();

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

    renderer.setProjectionMatrix(viewport.getCamera().combined);
    renderer.begin(ShapeType.Filled);

    // Since we're using an extend viewport, the world might be bigger than we expect
    float worldCenterX = viewport.getWorldWidth() / 2;
    float worldCenterY = viewport.getWorldHeight() / 2;

    // TODO: Figure out how long it's been since the animation started using TimeUtils.nanoTime()
    long delta = TimeUtils.nanoTime() - appCreationTime;

    // TODO: Use MathUtils.nanoToSec to figure out how many seconds the animation has been running
    float seconds = delta * MathUtils.nanoToSec;

    // TODO: Figure out how many cycles have elapsed since the animation started running
    float cycles = seconds / CYCLE;

    // TODO: Figure out where in the cycle we are
    float cyclePosition = cycles % 1;

    // TODO: Use MathUtils.sin() to set the x position of the circle

    float x = worldCenterX + MOVEMENT_DISTANCE * MathUtils.sin(MathUtils.PI2 * cyclePosition);
    float y = worldCenterY;
    renderer.circle(x, y, CIRCLE_RADIUS);
    renderer.end();
  }
 private void drawProgress() {
   Gdx.gl.glClearColor(0, 0, 0, 1);
   Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
   renderer.setColor(Color.ORANGE);
   renderer.begin(ShapeType.Filled);
   renderer.rect(0, 0, 800, 600);
   renderer.end();
 }
示例#9
0
 /** Draws the debug rects for the specified actor and any children, recursively. */
 public void draw(Actor actor) {
   if (disabled) return;
   shapes.setProjectionMatrix(stage.getCamera().projection);
   shapes.setTransformMatrix(stage.getCamera().view);
   shapes.begin(ShapeType.Line);
   drawRecursive(actor);
   shapes.end();
 }
示例#10
0
 public static void drawPoint(Vector2 point, View view, Color color) {
   ShapeRenderer shapeRenderer = view.getShapeRenderer();
   shapeRenderer.set(ShapeRenderer.ShapeType.Filled);
   shapeRenderer.setColor(color);
   float w, h;
   w = h = 5 * view.getCamera().zoom;
   shapeRenderer.rect(point.x - w / 2, point.y - h / 2, w, h);
 }
示例#11
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);
 }
示例#12
0
 /** Set's the ShapeRenderer's projection matrix depending on the mode of the demo camera. */
 public void setCamera(ShapeRenderer renderer) {
   if (inCloseupMode) {
     closeupCamera.update();
     renderer.setProjectionMatrix(closeupCamera.combined);
   } else {
     overviewCamera.update();
     renderer.setProjectionMatrix(overviewCamera.combined);
   }
 }
示例#13
0
 private void drawRectangles() {
   shapeRenderer.begin(ShapeType.Line);
   Player player = GameController.getInstance().getPlayer();
   float x = player.getX();
   float y = player.getY();
   shapeRenderer.setColor(Color.GREEN);
   shapeRenderer.rect(x, y, player.getWidth(), player.getHeight());
   shapeRenderer.end();
 }
 public void drawSelectedTile() {
   if (selectedTile.getX() != -1) {
     shapeRenderer.setColor(Color.RED);
     shapeRenderer.rect(
         selectedTile.getX() * Game.BLOCK_WIDTH,
         selectedTile.getY() * Game.BLOCK_HEIGHT,
         Game.BLOCK_WIDTH + Game.TILE_OFFSET,
         Game.BLOCK_HEIGHT + Game.TILE_OFFSET);
   }
 }
示例#15
0
 @Override
 public void draw(SpriteBatch batch, float parentAlpha) {
   shapeRenderer.setProjectionMatrix(getStage().getCamera().combined);
   batch.end();
   shapeRenderer.begin(ShapeType.Circle);
   shapeRenderer.setColor(shapeFillColor);
   shapeRenderer.circle(getX(), getY(), 20);
   shapeRenderer.end();
   batch.begin();
 }
示例#16
0
 /**
  * Draws a filled rectangle using a <code>ShapeRenderer</code>.<br>
  * IMPORTANT: Don't forget to set the <code>ShapeRenderer</code>'s projection matrix with {@link
  * #setShapeRendererProjectionMatrix(Matrix4)}!
  *
  * @param batch - Since drawing is done with a <code>ShapeRenderer</code>, the active batch should
  *     be passed to this method to end/start it.
  */
 public static void fillRect(SpriteBatch batch, float x, float y, float w, float h, Color c) {
   batch.end();
   Gdx.gl.glEnable(GL20.GL_BLEND);
   shapes_.begin(ShapeType.Filled);
   shapes_.setColor(c);
   shapes_.rect(x, y, w, h);
   shapes_.end();
   Gdx.gl.glDisable(GL20.GL_BLEND);
   batch.begin();
 }
示例#17
0
 @Override
 public void drawShape(ShapeRenderer shapes) {
   if (state == State.Growing) {
     shapes.setColor(0.0f, 1.0f, 0.0f, 1.0f);
   } else if (state == State.Dead) {
     float color = nutrition / (nutrition_max * age / max_life);
     shapes.setColor(color, color, 0.0f, 1.0f);
   }
   super.drawShape(shapes);
 }
示例#18
0
 /**
  * Draws an outline of a rectangle using a <code>ShapeRenderer</code>.<br>
  * IMPORTANT: Don't forget to set the <code>ShapeRenderer</code>'s projection matrix with {@link
  * #setShapeRendererProjectionMatrix(Matrix4)}!
  *
  * @param batch - Since drawing is done with a <code>ShapeRenderer</code>, the active batch should
  *     be passed to this method to end/start it.
  */
 public static void drawLine(SpriteBatch batch, float x1, float y1, float x2, float y2, Color c) {
   batch.end();
   Gdx.gl.glEnable(GL20.GL_BLEND);
   shapes_.begin(ShapeType.Line);
   shapes_.setColor(c);
   shapes_.line(x1, y1, x2, y2);
   shapes_.end();
   Gdx.gl.glDisable(GL20.GL_BLEND);
   batch.begin();
 }
示例#19
0
 @Override
 public void render(ShapeRenderer renderer, Transform transform) {
   tmp.set(renderer.getColor());
   renderer.setColor(color);
   renderer.circle(
       transform.x + (centre ? 0 : +radius) + ox,
       transform.y + (centre ? 0 : +radius) + oy,
       radius,
       segments);
   renderer.setColor(tmp);
 }
示例#20
0
 private static void renderNodeList(List<Vector2> nodes, ShapeRenderer renderer, Color color) {
   renderer.setColor(color);
   for (int i = 0; i < nodes.size(); i++) {
     Vector2 node = nodes.get(i);
     renderer.circle(node.x, node.y, LevelEditorScreen.getNodeRadius(), 8);
     if (i > 0) {
       Vector2 previousNode = nodes.get(i - 1);
       renderer.line(node.x, node.y, previousNode.x, previousNode.y);
     }
   }
 }
 @Override
 public void render(float delta) {
   Gdx.gl.glEnable(GL10.GL_BLEND);
   if (null != snapPoint) {
     render.begin(ShapeType.FilledRectangle);
     render.setColor(Color.BLUE);
     render.filledRect(snapPoint.x - 5, snapPoint.y - 5, 2 * 5, 2 * 5);
     render.end();
   }
   Gdx.gl.glDisable(GL10.GL_BLEND);
 }
示例#22
0
  public void draw(
      final Ship ship,
      final StarManager starManager,
      final EnemyManager enemyManager,
      final PowerUpManager powerupManager,
      final ShotManager shotManager,
      final GamePhase phase,
      final GameController controller) {
    if (phase == GamePhase.GAMING) {
      shotManager.drawShape(shapeRenderer, ppux, ppuy, border);
      powerupManager.drawShape(shapeRenderer, ppux, ppuy, border);

      shapeRenderer.begin(ShapeType.FilledRectangle);
      enemyManager.drawHealthBar(shapeRenderer, ppux, ppuy, border);
      shapeRenderer.end();
    }
    shapeRenderer.setColor(Color.WHITE);
    starManager.drawShape(shapeRenderer, ppux, ppuy, border);
    ship.drawShape(shapeRenderer, ppux, ppuy, border);

    batch.begin();
    ship.drawSprite(batch, ppux, ppuy, border);
    switch (phase) {
      case LEVEL_LOAD: // just waiting for refresh
      case GAMING:
        shotManager.drawSprite(batch, ppux, ppuy, border);
        powerupManager.drawSprite(batch, ppux, ppuy, border);
        enemyManager.drawSprite(batch, ppux, ppuy, border);
        break;
      case PAUSE:
        drawPauseTextBox();
        break;
      case LEVEL_SCORE:
        // TODO make counter and stuff and at the end change phase
        //			score =
        GameScreen.updatePhase(GamePhase.LEVEL_WAIT);
      case LEVEL_WAIT:
        drawLevelScore(controller, controller.getTimeBonus());
        break;
      case DEAD:
        // TODO death animation
        drawGameOver();
        break;
      case FINISHED:
        drawGameFinished();
        break;
      case GAMESTART:
        break;
      default:
        break;
    }
    batch.end();
  }
示例#23
0
 public static void renderHitboxs(World world, Camera camera) {
   shapeRenderer.setProjectionMatrix(camera.combined);
   shapeRenderer.begin(ShapeType.Line);
   for (GameObject entity : world.getEntities()) {
     if (entity.hitbox != null) {
       shapeRenderer.setColor(0, 1, 1, 1);
       shapeRenderer.rect(
           entity.hitbox.x, entity.hitbox.y, entity.hitbox.width, entity.hitbox.height);
     }
   }
   shapeRenderer.end();
 }
示例#24
0
  public void cleanBorders() {
    shapeRenderer.begin(ShapeType.FilledRectangle);
    shapeRenderer.setColor(Color.BLACK);
    shapeRenderer.filledRect(0, 0, border - 1, Sizes.DEFAULT_WORLD_HEIGHT * ppux);
    shapeRenderer.filledRect(
        border + Sizes.DEFAULT_WORLD_WIDTH * ppux,
        0,
        2 * border + Sizes.DEFAULT_WORLD_WIDTH * ppux,
        Sizes.DEFAULT_WORLD_HEIGHT * ppux);

    shapeRenderer.end();
  }
示例#25
0
  private void drawGrid() {
    int height = GdxController.getInstance().getMapGdx().getForeground().getHeight();
    int width = GdxController.getInstance().getMapGdx().getForeground().getWidth();

    shapeRenderer.begin(ShapeType.Line);
    shapeRenderer.setColor(Color.RED);
    for (int i = 0; i < 50; i++) {
      shapeRenderer.line(0.0f, i * 32.0f, width * 32.0f, i * 32.0f);
      shapeRenderer.line(i * 32.0f, 0.0f, i * 32.0f, height * 32.0f);
    }
    shapeRenderer.end();
  }
示例#26
0
  private void renderWorld() {
    clearScreen();
    sr.setProjectionMatrix(camera.combined);

    mapRenderer.setView(camera);
    mapRenderer.render();

    sr.begin(ShapeType.Filled);
    renderNeighbourCollisionAreas(sr);
    renderPlayer(sr);
    sr.end();
  }
示例#27
0
 @Override
 public void render(
     float delta, OrthographicCamera camera, GDXRenderer gdxRenderer, ShapeRenderer renderer) {
   if (!screen.isLive()) {
     renderer.setProjectionMatrix(camera.combined);
     renderer.begin(ShapeType.Line);
     for (GDXPath object : screen.getLevel().getPaths())
       renderNodeList(object.getNodes(), renderer, Color.GRAY);
     if (pathWindow != null) renderNodeList(pathWindow.getNodes(), renderer, Color.DARK_GRAY);
     renderer.end();
   }
 };
示例#28
0
  private void renderNeighbourCollisionAreas(ShapeRenderer sr) {
    float minorX = player.pos.x - player.width / 2f;
    float majorX = player.pos.x + player.width / 2f;

    float minorY = player.pos.y - player.height / 2f;
    float majorY = player.pos.y + player.height / 2f;

    sr.setColor(Color.NAVY);
    sr.rect(MathUtils.round(minorX), player.pos.y, 1f, 1f);
    sr.rect(MathUtils.round(majorX), player.pos.y, 1f, 1f);
    sr.rect(player.pos.x, MathUtils.round(minorY), 1f, 1f);
    sr.rect(player.pos.x, MathUtils.round(majorY), 1f, 1f);
  }
示例#29
0
  private static void renderLines(Camera camera) {
    shapeRenderer.setProjectionMatrix(camera.combined);
    shapeRenderer.begin(ShapeType.Line);
    Vector2 p0, p1;
    for (Object[] line : lines) {
      p0 = (Vector2) line[0];
      p1 = (Vector2) line[1];
      shapeRenderer.setColor(line[2] != null ? (Color) line[2] : colorLines);

      shapeRenderer.line(p0, p1);
    }
    lines.clear();
    shapeRenderer.end();
  }
示例#30
0
 @Override
 protected void drawChildren(Batch batch, float parentAlpha) {
   batch.end();
   Gdx.gl.glEnable(GL20.GL_BLEND);
   Gdx.gl.glBlendFunc(GL20.GL_ONE, GL20.GL_DST_COLOR);
   Gdx.gl.glBlendEquation(GL20.GL_FUNC_SUBTRACT);
   shapeRenderer.setColor(Color.WHITE);
   shapeRenderer.begin(ShapeType.Line);
   super.drawChildren(batch, parentAlpha);
   shapeRenderer.end();
   Gdx.gl.glBlendEquation(GL20.GL_FUNC_ADD);
   Gdx.gl.glDisable(GL20.GL_BLEND);
   batch.begin();
 }