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(); sound.play( Art.samples[Art.SAMPLE_GET_COIN], new FixedSoundSource(x * 16 + 8, y * 16 + 8), 1, 1, 1); level.setBlock(x, y, (byte) 0); addSprite(new CoinAnim(x, y + 1)); // TODO no idea when this happens... maybe remove coin count if (recorder != null) recorder.recordCoin(); } for (Sprite sprite : sprites) { sprite.bumpCheck(x, y); } }
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); if (((Level.TILE_BEHAVIORS[block & 0xff]) & Level.BIT_SPECIAL) > 0) { sound.play( Art.samples[Art.SAMPLE_ITEM_SPROUT], new FixedSoundSource(x * 16 + 8, y * 16 + 8), 1, 1, 1); if (!Mario.large) { addSprite(new Mushroom(this, x * 16 + 8, y * 16 + 8)); } else { addSprite(new FireFlower(this, x * 16 + 8, y * 16 + 8)); } if (recorder != null) { recorder.blockPowerDestroyRecord(); } } else { // TODO should only record hidden coins (in boxes) if (recorder != null) { recorder.blockCoinDestroyRecord(); } Mario.getCoin(); sound.play( Art.samples[Art.SAMPLE_GET_COIN], new FixedSoundSource(x * 16 + 8, y * 16 + 8), 1, 1, 1); addSprite(new CoinAnim(x, y)); } } if ((Level.TILE_BEHAVIORS[block & 0xff] & Level.BIT_BREAKABLE) > 0) { bumpInto(x, y - 1); if (canBreakBricks) { if (recorder != null) { recorder.blockEmptyDestroyRecord(); } sound.play( Art.samples[Art.SAMPLE_BREAK_BLOCK], new FixedSoundSource(x * 16 + 8, y * 16 + 8), 1, 1, 1); level.setBlock(x, y, (byte) 0); for (int xx = 0; xx < 2; xx++) for (int yy = 0; yy < 2; yy++) addSprite( new Particle( x * 16 + xx * 8 + 4, y * 16 + yy * 8 + 4, (xx * 2 - 1) * 4, (yy * 2 - 1) * 4 - 8)); } } }
public void render(Graphics g, float alpha) { int xCam = (int) (mario.xOld + (mario.x - mario.xOld) * alpha) - 160; int yCam = (int) (mario.yOld + (mario.y - mario.yOld) * alpha) - 120; // int xCam = (int) (xCamO + (this.xCam - xCamO) * alpha); // int yCam = (int) (yCamO + (this.yCam - yCamO) * alpha); if (xCam < 0) xCam = 0; if (yCam < 0) yCam = 0; if (xCam > level.getWidth() * 16 - 320) xCam = level.getWidth() * 16 - 320; if (yCam > level.getHeight() * 16 - 240) yCam = level.getHeight() * 16 - 240; // g.drawImage(Art.background, 0, 0, null); for (int i = 0; i < 2; i++) { bgLayer[i].setCam(xCam, yCam); bgLayer[i].render(g, tick, alpha); } g.translate(-xCam, -yCam); for (Sprite sprite : sprites) { if (sprite.layer == 0) sprite.render(g, alpha); } g.translate(xCam, yCam); // //////////THIS RENDERS THE LEVEL layer.setCam(xCam, yCam); layer.render(g, tick, paused ? 0 : alpha); layer.renderExit0(g, tick, paused ? 0 : alpha, mario.winTime == 0); // //////////END OF LEVEL RENDER // //////////RENDERS SPRITES g.translate(-xCam, -yCam); for (Sprite sprite : sprites) { if (sprite.layer == 1) sprite.render(g, alpha); } g.translate(xCam, yCam); g.setColor(Color.BLACK); layer.renderExit1(g, tick, paused ? 0 : alpha); // //////////END OF SPRITE RENDERING drawStringDropShadow(g, "MARIO " + df.format(Mario.lives), 0, 0, 7); // drawStringDropShadow(g, "00000000", 0, 1, 7); drawStringDropShadow(g, "COIN", 14, 0, 7); drawStringDropShadow(g, " " + df.format(Mario.coins), 14, 1, 7); drawStringDropShadow(g, "WORLD", 24, 0, 7); drawStringDropShadow(g, " " + Mario.levelString, 24, 1, 7); drawStringDropShadow(g, "TIME", 35, 0, 7); int time = (timeLeft + 15 - 1) / 15; if (time < 0) time = 0; drawStringDropShadow(g, " " + df2.format(time), 35, 1, 7); renderDirectionArrow(g); if (startTime > 0) { float t = startTime + alpha - 2; t = t * t * 0.6f; renderBlackout(g, 160, 120, (int) (t)); } // mario.x>level.xExit*16 if (mario.winTime > 0) { float t = mario.winTime + alpha; t = t * t * 0.2f; if (t > 0) { if (recorder != null) { recorder.stopRecord(); recorder.levelWon(); // recorder.printAll(); } } if (t > 900) { winActions(); return; // replayer = new Replayer(recorder.getBytes()); // init(); } renderBlackout( g, (int) (mario.xDeathPos - xCam), (int) (mario.yDeathPos - yCam), (int) (320 - t)); } if (mario.deathTime > 0) { g.setColor(Color.BLACK); float t = mario.deathTime + alpha; t = t * t * 0.4f; if (t > 0 && Mario.lives <= 0) { if (recorder != null) { recorder.stopRecord(); } } if (t > 1800) { Mario.lives--; deathActions(); } renderBlackout( g, (int) (mario.xDeathPos - xCam), (int) (mario.yDeathPos - yCam), (int) (320 - t)); } }