void wander() {
      float wanderR = 10.0f; // radius for our "wander circle"
      float wanderD = 20.0f; // distance for our "wander circle"
      wandertheta += random(-1, 1); // randomly changet wander theta

      // now we have to calculate the new location to steer towards on the wander circle
      Vector3D v = vel.copy();
      v.normalize(); // our heading
      float xoff =
          wanderD * v.x() + wanderR * cos(wandertheta); // x spot on circle based on heading
      float yoff =
          wanderD * v.y() + wanderR * sin(wandertheta); // y spot on circle based on heading
      Vector3D target = Vector3D.add(loc, new Vector3D(xoff, yoff)); // add the location
      acc.add(steer(target, false)); // steer towards it
    }
示例#2
0
 public void jump(double x, double y) {
   loc.x = x;
   loc.y = y;
 }
 // function to display
 void render() {
   ellipseMode(CENTER);
   noStroke();
   fill(0, 100, 255, timer);
   ellipse(loc.x(), loc.y(), r, r);
 }
示例#4
0
  public void updateWorld(long elapsedTime) {

    float angleVelocity;

    Player player = (Player) gameObjectManager.getPlayer();
    MovingTransform3D playerTransform = player.getTransform();
    Vector3D velocity = playerTransform.getVelocity();

    // playerTransform.stop();
    velocity.x = 0;
    velocity.z = 0;
    float x = -playerTransform.getSinAngleY();
    float z = -playerTransform.getCosAngleY();
    if (goForward.isPressed()) {
      velocity.add(x * PLAYER_SPEED, 0, z * PLAYER_SPEED);
    }
    if (goBackward.isPressed()) {
      velocity.add(-x * PLAYER_SPEED, 0, -z * PLAYER_SPEED);
    }
    if (goLeft.isPressed()) {
      velocity.add(z * PLAYER_SPEED, 0, -x * PLAYER_SPEED);
    }
    if (goRight.isPressed()) {
      velocity.add(-z * PLAYER_SPEED, 0, x * PLAYER_SPEED);
    }
    if (jump.isPressed()) {
      player.setJumping(true);
    }
    if (fire.isPressed()) {
      player.fireProjectile();
    }

    playerTransform.setVelocity(velocity);

    // look up/down (rotate around x)
    angleVelocity = Math.min(tiltUp.getAmount(), 200);
    angleVelocity += Math.max(-tiltDown.getAmount(), -200);
    playerTransform.setAngleVelocityX(angleVelocity * PLAYER_TURN_SPEED / 200);

    // turn (rotate around y)
    angleVelocity = Math.min(turnLeft.getAmount(), 200);
    angleVelocity += Math.max(-turnRight.getAmount(), -200);
    playerTransform.setAngleVelocityY(angleVelocity * PLAYER_TURN_SPEED / 200);

    // update objects
    gameObjectManager.update(elapsedTime);

    // limit look up/down
    float angleX = playerTransform.getAngleX();
    float limit = (float) Math.PI / 2;
    if (angleX < -limit) {
      playerTransform.setAngleX(-limit);
    } else if (angleX > limit) {
      playerTransform.setAngleX(limit);
    }

    // set the camera to be 100 units above the player
    Transform3D camera = polygonRenderer.getCamera();
    camera.setTo(playerTransform);
    camera.getLocation().add(0, CAMERA_HEIGHT, 0);
  }