Пример #1
0
  private void updatePosition() {
    updatePosLast();

    pos.setLocation(pos.x + vel.x * Wuigi.time(), pos.y + vel.y * Wuigi.time());

    if (!dead && pos.y + Wuigi.GROUND_LEVEL < 0) {
      kill(true);
      // pos.y = pos.y + Wuigi.GROUND_LEVEL + 1;
      falling = false;
    } else if (pos.y < 0 && !dead && !piped && (!falling || invulerable)) {
      setPos(pos.x, 0);
      // yOffset = Wuigi.GROUND_LEVEL;
    }

    if (pos.x > lastX + 20 || pos.x < lastX - 20) {
      rightFoot = !rightFoot;
      lastX = pos.x;
    }
    if (piped && pos.y + height < lineToCross && vel.y < 0) changeWorlds = true;
    if (piped && pos.y > lineToCross && vel.y > 0) {
      vel.y = 0;
      pos.y = lineToCross;
      piped = false;
    }
  }
Пример #2
0
  public void think() {
    if (dead && deadTime > 0) {
      deadTime -= Wuigi.time();
      if (deadTime < 0) {
        vel.x = 0;
        vel.y = 15;
      }
      return;
    }

    if (star) {
      starTime += Wuigi.time();
      if (starTime > 10000 / 15) { // if you've been in starman mode for more than 10 seconds, stop
        star = false;
        starTime = 0;
        setSpriteColor(spriteColor, true);
      } else {
        setSpriteColor((int) (Math.random() * 6), true);
      }
    }

    if (invulerable) {
      invulerableTime += Wuigi.time();
      if (invulerableTime > 5000 / 15) {
        invulerable = false;
        invulerableTime = 0;
      }
    }

    if (cape) {
      capeTime += Wuigi.time();
      if (capeTime > 10000 / 15) {
        cape = false;
        capeTime = 0;
      }
    }

    updatePosition();
    xOffset += pos.x - posLast.x;
    if (xOffset > X_OFFSET) xOffset = X_OFFSET;
    else if (xOffset < -X_OFFSET) xOffset = -X_OFFSET;

    yOffset += pos.y - posLast.y;
    if (!(dead || falling)) {
      if (yOffset > Y_OFFSET) yOffset = Y_OFFSET;
      else if (yOffset < Y_OFFSET / 8) yOffset = Y_OFFSET / 8;
    }
    updateVelocity();
    // double v = vel.y;
    // if(v > 0 && vel.y < 0){
    //	System.out.println("position: " + pos.y);
    // }
    falling = false;
  }
Пример #3
0
 // double jolt =
 private void jumpAdd() {
   if (vel.y == 0 || dead) {
     jumpAdd = 0;
   } else {
     double add = 0.4 * jumpAdd / Wuigi.COMPLETE_JUMP_TIME * Wuigi.time();
     vel.y += add;
   }
 }
Пример #4
0
  private void updateVelocity() {
    if (piped) {
      return;
    }
    if (jumpAdd > 0) {
      jumpAdd -= Wuigi.time();
      jumpAdd();
      acc.y = 0;
    }
    if (jumping) {
      jumping = false;
    } else if (!dead) {
      int tempMove = move;
      if (move == 0) {
        if (vel.x > 0) tempMove = -1;
        else tempMove = 1;
      }
      double xadd;
      // stopping
      if (vel.x > 0 && move <= 0 || vel.x < 0 && move >= 0) {
        xadd = tempMove * X_VEL_PER_TICK * 2.0 * Wuigi.time();
        // moving forward
      } else {
        xadd = tempMove * X_VEL_PER_TICK * Wuigi.time();
      }
      if (vel.y < 0 && !metal) {
        vel.x += xadd / 3;
      } else {
        vel.x += xadd;
      }
      if (move == 0 && tempMove * vel.x > 0) {
        vel.x = 0;
      }
      if (!infSpeed) {
        if (vel.x < -MAX_X_VEL) vel.x = -MAX_X_VEL;
        else if (vel.x > MAX_X_VEL) vel.x = MAX_X_VEL;
      }
    }

    if (vel.x < X_VEL_PER_TICK * Wuigi.time() && vel.x > -X_VEL_PER_TICK * Wuigi.time()) vel.x = 0;

    vel.x += acc.x * Wuigi.time();
    vel.y += acc.y * Wuigi.time();

    // S//ystem.out.println(acc.y);
    if (falling && invulerable) {
      falling = false;
    }
    if (pos.y > 0 && !(cape && movingUp) || falling) {
      acc.y = -Wuigi.GRAVITY;
      if (cape) {
        acc.y /= 4;
      }
    } else if (cape && movingUp && vel.y > 5) {
      acc.y = 0;
      vel.y = 5;
    } else if (!jumping && !dead && !(cape && movingUp)) {
      vel.y = 0;
      acc.y = 0;
    }
  }