Ejemplo n.º 1
0
 public void spawnBirds() {
   for (Vector2f coordinate :
       birdformations.getRandomBirdFormation(
           (random.nextFloat() * 1300) + 0, (random.nextFloat() * 420) + 0)) {
     sceneHandler.spawn(coordinate.getX(), coordinate.getY(), PBird.class);
   }
 }
Ejemplo n.º 2
0
  @Override
  public void update(GameContainer gc, StateBasedGame sb, int delta) {

    float rotation = owner.getRotation();
    float scale = owner.getScale();
    Vector2f position = owner.getPosition();

    Input input = gc.getInput();

    if (input.isKeyDown(Input.KEY_LEFT)) {
      rotation += -0.2f * delta;
    }

    if (input.isKeyDown(Input.KEY_RIGHT)) {
      rotation += 0.2f * delta;
    }

    if (input.isKeyDown(Input.KEY_UP)) {
      float hip = 0.45f * delta;

      position.x += hip * java.lang.Math.sin(java.lang.Math.toRadians(rotation));
      position.y -= hip * java.lang.Math.cos(java.lang.Math.toRadians(rotation));
    }

    owner.setPosition(position);
    owner.setRotation(rotation);
    owner.setScale(scale);
  }
Ejemplo n.º 3
0
Archivo: Geom.java Proyecto: J2/shade
 /** The angle should be in radians. */
 public static Vector2f calculateVector(float magnitude, float angle) {
   Vector2f v = new Vector2f();
   v.x = (float) Math.sin(angle);
   v.x *= magnitude;
   v.y = (float) -Math.cos(angle);
   v.y *= magnitude;
   return v;
 }
Ejemplo n.º 4
0
 public void goPath(Timer timer) {
   update(timer);
   if (position.equals(target) && (pCount == p.getLength() - 1)) {
     pathing = false;
   } else if (position.equals(target)) {
     pCount++;
     target.set(p.getX(pCount), p.getY(pCount));
   }
 }
Ejemplo n.º 5
0
  @Override
  public void update(GameContainer container, int delta) {
    Input input = container.getInput();

    // move player
    if (input.isKeyDown(Input.KEY_W)) {
      //        	if(input.isKeyDown(Input.KEY_A)){
      //        		setDirection(Direction.NORTHWEST);
      //        	} else if(input.isKeyDown(Input.KEY_D)){
      //        		setDirection(Direction.NORTHEAST);
      //        	} else {
      setDirection(Direction.NORTH);
      //        	}
    } else if (input.isKeyDown(Input.KEY_S)) {
      //        	if(input.isKeyDown(Input.KEY_A)){
      //        		setDirection(Direction.SOUTHWEST);
      //        	} else if(input.isKeyDown(Input.KEY_D)){
      //        		setDirection(Direction.SOUTHEAST);
      //        	} else {
      setDirection(Direction.SOUTH);
      //        	}
    } else if (input.isKeyDown(Input.KEY_A)) {
      setDirection(Direction.WEST);
    } else if (input.isKeyDown(Input.KEY_D)) {
      setDirection(Direction.EAST);
    } else {
      setDirection(Direction.STOP);
    }

    if (input.isKeyPressed(Input.KEY_SPACE)) {
      //            float x = getPosition().x + (getImage().getWidth() / 2);
      //            float y = getPosition().y + (getImage().getHeight() / 2);
      //            currentWeapon.activate(new Vector2f(x, y));
      currentWeapon.activate(getPosition().copy());
    }

    move(delta);

    Vector2f pos = getPosition();
    pos.x = Math.max(0, pos.x);
    pos.x = Math.min(container.getWidth(), pos.x);
    pos.y = Math.max(0, pos.y);
    pos.y = Math.min(container.getHeight(), pos.y);
  }
Ejemplo n.º 6
0
  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();
  }
Ejemplo n.º 7
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);
 }
Ejemplo n.º 8
0
    /**
     * Get the value to use at a given time value
     *
     * @param t The time value (expecting t in [0,1])
     * @return The value to use at the specified time
     */
    @Override
    public float getValue(float t) {
      // first: determine the segment we are in
      Vector2f p0 = curve.get(0);
      for (int i = 1; i < curve.size(); i++) {
        Vector2f p1 = curve.get(i);

        if (t >= p0.getX() && t <= p1.getX()) {
          // found the segment
          float st = (t - p0.getX()) / (p1.getX() - p0.getX());
          float r = p0.getY() + st * (p1.getY() - p0.getY());
          // System.out.println( "t: " + t + ", " + p0.x + ", " + p0.y + " : " + p1.x + ", " + p1.y
          // + " => " + r );

          return r;
        }

        p0 = p1;
      }
      return 0;
    }
Ejemplo n.º 9
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();
 }
Ejemplo n.º 10
0
 /**
  * Has the car arrived at the end of its current edge?
  *
  * @param currentPosition
  * @return
  */
 public boolean arrivedAtEndOfEdge(Vector2f currentPosition) {
   float distance = currentPosition.distance(currentEdge.getDestinationNode().getPosition());
   if (distance < 0) {
     distance = distance * -1f;
   }
   if ((distance * 0.99999) >= lastDistance) { // Vermeidet Rundungsfehler
     return true;
   } else {
     this.lastDistance = distance;
     return false;
   }
 }
Ejemplo n.º 11
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);
  }
Ejemplo n.º 12
0
  public void rotate(TestPlayerShip playerShip, int delta) {
    hero = new Vector2f(this.position.x, this.position.y);
    target = new Vector2f(playerShip.position.x, playerShip.position.y);
    target.sub(hero);
    float finalRotation = (int) target.getTheta();

    if ((currentRotation <= finalRotation + 45 && currentRotation >= finalRotation - 45)) {
      shoot(delta);
    }

    if (!(currentRotation <= finalRotation + 1 && currentRotation >= finalRotation - 1)) {
      // shoot(delta);

      double tempVal;
      if (currentRotation < finalRotation) {
        tempVal = finalRotation - currentRotation;

        if (tempVal > 180) {
          currentRotation -= 0.1f * delta;
        } else {
          currentRotation += 0.1f * delta;
        }
      } else if (currentRotation > finalRotation) {
        tempVal = currentRotation - finalRotation;
        if (tempVal < 180) {
          currentRotation -= 0.1f * delta;
        } else {
          currentRotation += 0.1f * delta;
        }
      }
    }
    if (currentRotation < 0) currentRotation = 359;

    if (currentRotation > 360) currentRotation = 1;

    rotation = ((int) (currentRotation + 90));
  }
Ejemplo n.º 13
0
  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();
  }
Ejemplo n.º 14
0
  @Override
  protected void stopAction() {
    Vector2f pos = getLevelBowPosition();
    Vector2f speed = controllerUtils.getCurrentDirection(SPEED, getScreenBowPosition());

    projectileController.add(
        new Arrow(
            pos.getX(), pos.getY(), playerController.getPlayer(), speed.getX(), speed.getY()));
    soundController.play(bowSound, 0.7f);
  }
  public BulletPulse(Vector2f position, Tower Owner, float anglo_saxon, float barrelLength) {
    super("pulsey.png", position);

    setPos(
        position.add(
            new Vector2f(
                barrelLength * (float) Math.cos(Math.toRadians(anglo_saxon)),
                barrelLength * (float) Math.sin(Math.toRadians(anglo_saxon)))));

    sprite.setRotation(anglo_saxon);

    owner = Owner;

    step =
        new Vector2f(
            speed * (float) Math.cos(Math.toRadians(anglo_saxon)),
            speed * (float) Math.sin(Math.toRadians(anglo_saxon)));
  }
Ejemplo n.º 16
0
 void update(Timer timer) {
   if (pathing) {
     distance = position.distance(target);
     float x = (target.getX() - position.getX());
     float y = (target.getY() - position.getY());
     float vx = speed * slf * (x / distance);
     float vy = speed * slf * (y / distance);
     velocity.set(vx, vy);
     scaledVelocity.set(vx * scale, vy * scale);
     if ((timer.getTick() % (timer.getTimerSetting().getSpeed() * 0.05f)) == 0) {
       Vector2f v = velocity.scale(0.05f);
       // Vector2f sv = velocity.scale(0.05f);
       if (distance < 1f) {
         position.set(target);
         setPosition(position.getX(), position.getY());
       } else {
         position.set(position.getX() + (v.getX() * scale), position.getY() + (v.getY() * scale));
         setPosition(position.getX(), position.getY());
       }
     }
   }
 }
Ejemplo n.º 17
0
 public void setShootDirection(Vector2f shootDirection) {
   this.shootDirection = shootDirection.copy();
 }
Ejemplo n.º 18
0
 public void setPos(float x, float y) {
   position.x = x;
   position.y = y;
 }
Ejemplo n.º 19
0
 protected void translate(Vector2f difference) {
   this.position =
       new Point(
           this.position.getX() + difference.getX(), this.position.getY() + difference.getY());
 }
Ejemplo n.º 20
0
 public void setDirection(Vector2f direction) {
   this.direction = direction.copy();
 }
Ejemplo n.º 21
0
 public void setPath(Path p) {
   pCount = 0;
   this.p = p;
   target.set(p.getX(pCount), p.getY(pCount));
   pathing = true;
 }
Ejemplo n.º 22
0
 // Setters
 public void setTarget(float x, float y) {
   target.set(x, y);
   pathing = true;
 }