@Override public Object clone() throws CloneNotSupportedException { Mario m = (Mario) super.clone(); boolean[] k = new boolean[5]; for (int i = 0; i < 5; i++) k[i] = keys[i]; m.keys = k; return m; }
public void bump(int x, int y, boolean canBreakBricks) { byte block = level.getBlock(x, y); if ((Level.TILE_BEHAVIORS[block & 0xff] & Level.BIT_BUMPABLE) > 0) { bumpInto(x, y - 1); level.setBlock(x, y, (byte) 4); // level.setBlockData(x, y, (byte) 4); if (((Level.TILE_BEHAVIORS[block & 0xff]) & Level.BIT_SPECIAL) > 0) { if (!mario.large) { addSprite(new Mushroom(this, x * 16 + 8, y * 16 + 8)); } else { addSprite(new FireFlower(this, x * 16 + 8, y * 16 + 8)); } } else { mario.getCoin(); coinsCollected++; // addSprite(new CoinAnim(x, y)); } } if ((Level.TILE_BEHAVIORS[block & 0xff] & Level.BIT_BREAKABLE) > 0) { bumpInto(x, y - 1); if (canBreakBricks) { level.setBlock(x, y, (byte) 0); } else { // level.setBlockData(x, y, (byte) 4); } } }
public void bumpInto(int x, int y) { byte block = level.getBlock(x, y); if (((Level.TILE_BEHAVIORS[block & 0xff]) & Level.BIT_PICKUPABLE) > 0) { mario.getCoin(); coinsCollected++; level.setBlock(x, y, (byte) 0); } for (Sprite sprite : sprites) { sprite.bumpCheck(x, y); } }
@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 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(); }