private void win() { xDeathPos = (int) x; yDeathPos = (int) y; world.paused = true; winTime = 1; status = Mario.STATUS_WIN; }
public void die() { if (world.verbose > 1) System.out.println("[die!]"); damage += 2; xDeathPos = (int) x; yDeathPos = (int) y; world.paused = true; deathTime = 1; status = Mario.STATUS_DEAD; }
public void getMushroom() { if (deathTime > 0 || world.paused) return; if (!large) { world.paused = true; powerUpTime = 3 * FractionalPowerUpTime; world.mario.setLarge(true, false); world.powerUpsCollected++; } else { getCoin(); } }
@Override public Object clone() throws CloneNotSupportedException { LevelScene c = (LevelScene) super.clone(); c.mario = (Mario) this.mario.clone(); c.level = (Level) this.level.clone(); c.mario.world = c; List<Sprite> clone = new ArrayList<Sprite>(this.sprites.size()); for (Sprite item : this.sprites) { if (item == mario) { clone.add(c.mario); } else { Sprite s = (Sprite) item.clone(); if (s.kind == Sprite.KIND_SHELL && ((Shell) s).carried && c.mario.carried != null) c.mario.carried = s; s.world = c; clone.add(s); } } c.sprites = clone; return c; }
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 stomp(Shell shell) { if (deathTime > 0 || world.paused) return; if (keys[KEY_SPEED] && shell.facing == 0) { carried = shell; shell.carried = true; world.otherTricks += 2; } else { float targetY = shell.y - shell.height / 2; move(0, targetY - y); xJumpSpeed = 0; yJumpSpeed = -1.9f; jumpTime = 8; ya = jumpTime * yJumpSpeed; onGround = false; sliding = false; invulnerableTime = 1; world.otherTricks++; } }
private boolean isBlocking(float _x, float _y, float xa, float ya) { int x = (int) (_x / 16); int y = (int) (_y / 16); if (x == (int) (this.x / 16) && y == (int) (this.y / 16)) return false; boolean blocking = world.level.isBlocking(x, y, xa, ya); byte block = world.level.getBlock(x, y); if (((Level.TILE_BEHAVIORS[block & 0xff]) & Level.BIT_PICKUPABLE) > 0) { getCoin(); world.level.setBlock(x, y, (byte) 0); } if (blocking && ya < 0) { world.bump(x, y, large); if (world.verbose > 0) System.out.println("Sim Mario bumps a crate!"); } // System.out.println("Sim Mario blockcheck: pos: " + _x + " "+_y + " discrete: "+x + " "+y+ // " block: "+block+" blocking?: " + (blocking? "true":"false") + "behaviourvalue: " // + ((Level.TILE_BEHAVIORS[block & 0xff]) & Level.BIT_PICKUPABLE)); return blocking; }
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); }