public void getHurt() {
    if (world.verbose > 1) System.out.print("[hurt!]");
    damage++;
    // if (deathTime > 0 || world.paused) return;
    if (invulnerableTime > 0) return;

    if (large) {
      world.paused = true;
      powerUpTime = -3 * FractionalPowerUpTime;
      if (fire) {
        setLarge(true, false);
      } else {
        setLarge(false, false);
      }
      invulnerableTime = 32;
    } else {
      die();
    }
  }
  public void move() {
    if (winTime > 0) {
      winTime++;

      xa = 0;
      ya = 0;
      return;
    }

    if (deathTime > 0) {
      deathTime++;
      if (deathTime < 11) {
        xa = 0;
        ya = 0;
      } else if (deathTime == 11) {
        ya = -15;
      } else {
        ya += 2;
      }
      x += xa;
      y += ya;
      return;
    }

    // if (world.paused)
    //	System.out.println("Sim World Paused!");
    if (powerUpTime != 0) {
      if (powerUpTime > 0) {
        powerUpTime--;
      } else {
        powerUpTime++;
      }

      if (powerUpTime == 0) {
        if (world.paused) System.out.println("Sim World Unpaused!");
        world.paused = false;
      }
      return;
    }

    if (invulnerableTime > 0) invulnerableTime--;
    wasOnGround = onGround;
    float sideWaysSpeed = keys[KEY_SPEED] ? 1.2f : 0.6f;
    //        float sideWaysSpeed = onGround ? 2.5f : 1.2f;

    if (onGround) {
      if (keys[KEY_DOWN] && large) {
        ducking = true;
      } else {
        ducking = false;
      }
    }

    if (xa > 2) {
      facing = 1;
    }
    if (xa < -2) {
      facing = -1;
    }

    if (keys[KEY_JUMP] || (jumpTime < 0 && !onGround && !sliding)) {
      if (jumpTime < 0) {
        xa = xJumpSpeed;
        ya = -jumpTime * yJumpSpeed;
        jumpTime++;
      } else if (onGround && mayJump) {
        xJumpSpeed = 0;
        yJumpSpeed = -1.9f;
        jumpTime = 7;
        ya = jumpTime * yJumpSpeed;
        onGround = false;
        sliding = false;
      } else if (sliding && mayJump) {
        xJumpSpeed = -facing * 6.0f;
        yJumpSpeed = -2.0f;
        jumpTime = -6;
        xa = xJumpSpeed;
        ya = -jumpTime * yJumpSpeed;
        onGround = false;
        sliding = false;
        facing = -facing;
      } else if (jumpTime > 0) {
        xa += xJumpSpeed;
        ya = jumpTime * yJumpSpeed;
        jumpTime--;
      }
    } else {
      jumpTime = 0;
    }

    if (keys[KEY_LEFT] && !ducking) {
      if (facing == 1) sliding = false;
      xa -= sideWaysSpeed;
      if (jumpTime >= 0) facing = -1;
    }

    if (keys[KEY_RIGHT] && !ducking) {
      if (facing == -1) sliding = false;
      xa += sideWaysSpeed;
      if (jumpTime >= 0) facing = 1;
    }

    if ((!keys[KEY_LEFT] && !keys[KEY_RIGHT]) || ducking || ya < 0 || onGround) {
      sliding = false;
    }

    if (keys[KEY_SPEED] && canShoot && this.fire && world.fireballsOnScreen < 2) {
      // System.out.println("Adding fireball!");
      world.addSprite(new Fireball(world, x + facing * 6, y - 20, facing));
    }

    world.paused = GlobalOptions.pauseWorld;
    canShoot = !keys[KEY_SPEED];

    mayJump = (onGround || sliding) && !keys[KEY_JUMP];

    runTime += (Math.abs(xa)) + 5;
    if (Math.abs(xa) < 0.5f) {
      runTime = 0;
      xa = 0;
    }

    if (sliding) {
      ya *= 0.5f;
    }

    onGround = false;
    move(xa, 0);
    move(0, ya);

    // System.out.println("Mario Sim Speed: "+xa);
    if (y > world.level.height * 16 + 16) {
      die();
    }

    if (x < 0) {
      x = 0;
      xa = 0;
    }

    if (x > world.level.xExit * 16) {
      win();
    }

    if (x > world.level.width * 16) {
      x = world.level.width * 16;
      xa = 0;
    }

    ya *= 0.85f;
    if (onGround) {
      xa *= GROUND_INERTIA;
    } else {
      xa *= AIR_INERTIA;
    }

    if (!onGround) {
      ya += 3;
    }

    if (carried != null) {
      carried.x = x + facing * 8;
      carried.y = y - 2;
      if (!keys[KEY_SPEED]) {
        // System.out.println("Releasing shell!");
        carried.release(this);
        carried = null;
      }
    }
    // System.out.println("Mariopos: "+x+" "+y);
  }
示例#3
0
  public void tick() {
    // advance the world state. directly from the original physics engine.
    timeLeft--;
    if (timeLeft == 0) {
      mario.die();
    }
    xCamO = xCam;
    yCamO = yCam;

    if (startTime > 0) {
      startTime++;
    }

    float targetXCam = mario.x - 160;

    xCam = targetXCam;

    if (xCam < 0) xCam = 0;
    if (xCam > level.width * 16 - 320) xCam = level.width * 16 - 320;

    fireballsOnScreen = 0;

    for (Sprite sprite : sprites) {
      if (sprite != mario) {
        float xd = sprite.x - xCam;
        float yd = sprite.y - yCam;
        if (xd < -64 || xd > 320 + 64 || yd < -64 || yd > 240 + 64) {
          removeSprite(sprite);
        } else {
          if (sprite instanceof Fireball) {
            fireballsOnScreen++;
          }
        }
      }
    }
    if (paused) {
      for (Sprite sprite : sprites) {
        if (sprite == mario) {
          sprite.tick();
        } else {
          sprite.tickNoMove();
        }
      }
    } else {
      tick++;
      level.tick();

      for (int x = (int) xCam / 16 - 1; x <= (int) (xCam + 320) / 16 + 1; x++)
        for (int y = (int) yCam / 16 - 1; y <= (int) (yCam + 240) / 16 + 1; y++) {
          int dir = 0;

          if (x * 16 + 8 > mario.x + 16) dir = -1;
          if (x * 16 + 8 < mario.x - 16) dir = 1;

          if (dir != 0) {
            byte b = level.getBlock(x, y);
            if (((Level.TILE_BEHAVIORS[b & 0xff]) & Level.BIT_ANIMATED) > 0) {
              if ((b % 16) / 4 == 3 && b / 16 == 0) {
                if ((tick - x * 2) % 100 == 0) {
                  addSprite(new BulletBill(this, x * 16 + 8 + dir * 8, y * 16 + 15, dir));
                }
              }
            }
          }
        }

      for (Sprite sprite : sprites) {
        sprite.tick();
      }

      for (Sprite sprite : sprites) {
        sprite.collideCheck();
      }
      // System.out.println("Sim Mario ya: " + mario.ya);
      for (Shell shell : shellsToCheck) {
        for (Sprite sprite : sprites) {
          if (sprite != shell && !shell.dead) {
            if (sprite.shellCollideCheck(shell)) {
              if (mario.carried == shell && !shell.dead) {
                mario.carried = null;
                shell.die();
              }
              enemiesKilled++;
            }
          }
        }
      }
      shellsToCheck.clear();

      for (Fireball fireball : fireballsToCheck) {
        for (Sprite sprite : sprites) {
          if (sprite != fireball && !fireball.dead) {
            if (sprite.fireballCollideCheck(fireball)) {
              fireball.die();
              enemiesKilled++;
            }
          }
        }
      }
      fireballsToCheck.clear();
    }

    sprites.addAll(0, spritesToAdd);
    sprites.removeAll(spritesToRemove);
    spritesToAdd.clear();
    spritesToRemove.clear();
  }