public Vector2f getPosition() {
    if (currentPosition == null) {
      if (isOnLastPoint()) return path.getPoint(index);

      Vector2f p0 = path.getPoint(index);
      Vector2f p1 = path.getPoint(index + 1);

      Vector2f direction = p1.copy().sub(p0).normalise();

      currentPosition = p0.copy().add(direction.scale(innerDistance));
    }
    return currentPosition.copy();
  }
  public Vector2f getTangent() {
    if (currentTangent == null) {
      if (path.getPoints().size() == 1) return new Vector2f();

      if (isOnLastPoint())
        return path.getPoint(index).copy().sub(path.getPoint(index - 1)).normalise();
      else return path.getPoint(index + 1).copy().sub(path.getPoint(index)).normalise();
    }
    return currentTangent.copy();
  }
Example #3
0
 private Vector2f getCurrentPosition() throws EndOfRoadException {
   if (this.arrivedAtEndOfEdge(lastKnownPosition)) {
     if (this.currentEdge.getDestinationNode().equals(this.destination)) {
       throw new EndOfRoadException();
     }
     Edge nextDestination =
         this.findNextDestination(currentEdge.getDestinationNode(), destination);
     if (nextDestination == null) {
       throw new EndOfRoadException();
     }
     this.setNextDestination(nextDestination);
     onRoadChange(nextDestination);
   }
   Vector2f direction =
       this.currentEdge.getDestinationNode().getPosition().sub(this.lastKnownPosition);
   direction.normalise();
   this.direction = direction.copy();
   direction.scale(this.getCurrentSpeed());
   return lastKnownPosition.copy().add(direction);
 }
Example #4
0
 public Ball(
     String name,
     Image image,
     Vector2f position,
     float ballSpeed,
     Vector2f initialDirection,
     Shape collisionShape,
     int collisionType) {
   super(name, image, position, collisionShape, collisionType);
   this.ballSpeed = ballSpeed;
   this.direction = initialDirection.copy();
 }
Example #5
0
  /**
   * Renders the player to the screen
   *
   * @param x the x position to render the player to
   * @param y the y position to render the player to
   * @param g the graphics context
   * @param viewerRole the role of the one viewing this player
   */
  public void draw(float x, float y, Graphics g, Role viewerRole) {

    if (Role.isRestriced(viewerRole) && "Fuzzi_Traitor.png".equals(texture)) {
      image = RessourceManager.loadImage("Fuzzi_Innocent.png");
    } else image = RessourceManager.loadImage(texture);

    image.rotate(lookAngle - image.getRotation() + 90);
    image.draw(x, y);

    if (this.getInventory()[this.getCurrentWeapon()] != null)
      this.getInventory()[this.getCurrentWeapon()].draw(x, y);

    g.setColor(Color.black);
    g.drawRect(x, y - 12, 32, 8);
    g.setColor(Color.red);
    g.fillRect(x + 1, y - 11, lifepoints * 0.31f, 7);

    Vector2f v = new Vector2f(x + 16, y + 16);
    Vector2f v1 = new Vector2f(getLookAngle()).scale(130f);
    Vector2f v2 = v.copy().add(v1);

    g.drawLine(v.x, v.y, v2.x, v2.y);
  }
Example #6
0
 public void setShootDirection(Vector2f shootDirection) {
   this.shootDirection = shootDirection.copy();
 }
Example #7
0
 public void setDirection(Vector2f direction) {
   this.direction = direction.copy();
 }