java泡泡龙小游戏_frozengame.java 源代码在线查看 - 本代码为java编写的泡泡龙游戏 资源下载 虫虫电子下载站...

{if (levelManager.getLevelIndex() == 1) { this.getGameApplet().setCurrentScreen(new SplashScreen(getGameApplet()));}else { if (this.getGameApplet().getParameter(this.PARAMETER_OFFLINE) == null && !this.getGameApplet().isApplication()) { String playerName = this.getGameApplet().getParameter(this.PARAMETER_PLAYER); if (playerName == null) { this.getGameApplet().setCurrentScreen(new EnterNameScreen(getGameApplet())); } else { playerName = playerName.trim(); if (!"".equals(playerName)) { ((HighscoreManager)this.getGameApplet().getGameContext().getObject("highscoreManager")).sendRecord(playerName); // The following line is only reached when an error occurs this.getGameApplet().setCurrentScreen(new SplashScreen(getGameApplet())); } } } else { this.getGameApplet().setCurrentScreen(new HighscoreScreen(getGameApplet())); } }}else{addToBackground(background, new Point(0, 0));highscoreManager.startLevel();}}//处理事件的代码public void play(int[] keyCodes, Point mouseCoord, boolean leftButton, boolean rightButton) {int[] move = new int[2];boolean newModeKeyState = false; boolean newSoundKeyState = false; //解析事件for (int i=0 ; i{int current = keyCodes[i]; if (current == KEY_M) //模式切换 { newModeKeyState = true; } if (current == KEY_S) //声音切换 { newSoundKeyState = true; } if (current == KEY_LEFT || current == KEY_RIGHT)//左右移动{if (move[HORIZONTAL_MOVE] == 0){move[HORIZONTAL_MOVE] = current;}else{move[HORIZONTAL_MOVE] = 0;}}if (current == KEY_UP || current == KEY_SHIFT)//发射{move[FIRE] = KEY_UP;}}//处理模式切换事件 if (newModeKeyState != modeKeyPressed) //进行切换模式 { if (newModeKeyState) { FrozenBubble.switchMode(); // Redraw nextBubble if (FrozenBubble.getMode() == FrozenBubble.GAME_NORMAL) { nextBubble.changeImage(bubbles[nextColor]); } else { nextBubble.changeImage(bubblesBlind[nextColor]); } } modeKeyPressed = newModeKeyState; } //处理声音切换事件 if (newSoundKeyState != soundKeyPressed) //切找声音 { if (newSoundKeyState) { soundManager.setSoundState(!soundManager.getSoundState()); } soundKeyPressed = newSoundKeyState; } if (move[FIRE] == 0){readyToFire = true;}if (endOfGame)//游戏结束了{if (move[FIRE] == KEY_UP && readyToFire)//重新开始游戏{if (frozenify){lifeManager.decrease();}if (levelManager.getCurrentLevel() == null){getGameApplet().setCurrentScreen(new EnterNameScreen(getGameApplet()));}else{getGameApplet().setCurrentScreen(new FrozenGame(getGameApplet()));}}else//冻结游戏{penguin.updateState(PenguinSprite.STATE_VOID);if (frozenify){frozenify();}}}else{if (move[FIRE] == KEY_UP || hurryTime > 480)//发射一个泡泡{if (movingBubble == null && readyToFire){nbBubbles++;movingBubble = new BubbleSprite(new Rectangle(302, 390, 32, 32), launchBubblePosition, bubbles[currentColor], bubblesBlind[currentColor], frozenBubbles[currentColor], targetedBubbles, bubbleBlink, bubbleManager, soundManager, this);this.addSprite(movingBubble);currentColor = nextColor;nextColor = bubbleManager.nextBubbleIndex(random); if (FrozenBubble.getMode() == FrozenBubble.GAME_NORMAL) { nextBubble.changeImage(bubbles[nextColor]); } else { nextBubble.changeImage(bubblesBlind[nextColor]); } launchBubble.changeColor(currentColor);penguin.updateState(PenguinSprite.STATE_FIRE);soundManager.playSound(FrozenBubble.SOUND_LAUNCH);readyToFire = false;hurryTime = 0;removeSprite(hurrySprite);}else{penguin.updateState(PenguinSprite.STATE_VOID);}}else if (move[HORIZONTAL_MOVE] == KEY_LEFT)//向左摆动{if (launchBubblePosition>1){launchBubblePosition--;}launchBubble.changeDirection(launchBubblePosition);penguin.updateState(PenguinSprite.STATE_TURN_LEFT);}else if (move[HORIZONTAL_MOVE] == KEY_RIGHT)//向右摆动{if (launchBubblePosition{launchBubblePosition++;}launchBubble.changeDirection(launchBubblePosition);penguin.updateState(PenguinSprite.STATE_TURN_RIGHT);}else{penguin.updateState(PenguinSprite.STATE_VOID);}}//移动当前的泡泡if (movingBubble != null){movingBubble.move();if (movingBubble.fixed())//当有一个泡泡固定的话,进行如下的操作{if (movingBubble.getSpritePosition().y>=380 && !movingBubble.released())//游戏失败{penguin.updateState(PenguinSprite.STATE_GAME_LOST);endOfGame = true;initFrozenify();soundManager.playSound(FrozenBubble.SOUND_LOST);}else if (bubbleManager.countBubbles() == 0)//游戏成功{penguin.updateState(PenguinSprite.STATE_GAME_WON);this.addSprite(new ImageSprite(new Rectangle(152, 190, 337, 116), gameWon));highscoreManager.endLevel(nbBubbles);levelManager.goToNextLevel();endOfGame = true;soundManager.playSound(FrozenBubble.SOUND_WON);}else{fixedBubbles++;blinkDelay = 0;if (fixedBubbles == 8)//每增加8个固定的泡泡,则向下压一行{fixedBubbles = 0;sendBubblesDown();}}movingBubble = null;}//使用两次,提高一些速度if (movingBubble != null){movingBubble.move();if (movingBubble.fixed()){if (movingBubble.getSpritePosition().y>=380 && !movingBubble.released()){penguin.updateState(PenguinSprite.STATE_GAME_LOST);endOfGame = true;initFrozenify();soundManager.playSound(FrozenBubble.SOUND_LOST);}else if (bubbleManager.countBubbles() == 0){penguin.updateState(PenguinSprite.STATE_GAME_WON);this.addSprite(new ImageSprite(new Rectangle(152, 190, 337, 116), gameWon));highscoreManager.endLevel(nbBubbles);levelManager.goToNextLevel();endOfGame = true;soundManager.playSound(FrozenBubble.SOUND_WON);}else{fixedBubbles++;blinkDelay = 0;if (fixedBubbles == 8){fixedBubbles = 0;sendBubblesDown();}}movingBubble = null;}}}//发射延时处理if (movingBubble == null && !endOfGame){hurryTime++;if (hurryTime>=240){if (hurryTime % 40 == 10){addSprite(hurrySprite);soundManager.playSound(FrozenBubble.SOUND_HURRY);}else if (hurryTime % 40 == 35){removeSprite(hurrySprite);}}}//闪亮延时处理,fixedBubbles代表当前固定泡泡的个数if (fixedBubbles == 6){if (blinkDelay < 15){blinkLine(blinkDelay);}blinkDelay++;if (blinkDelay == 40){blinkDelay = 0;}}else if (fixedBubbles == 7){if (blinkDelay < 15){blinkLine(blinkDelay);}blinkDelay++;if (blinkDelay == 25){blinkDelay = 0;}}//移动向下掉的泡泡for (int i=0 ; i{((BubbleSprite)falling.elementAt(i)).fall();}//移动向上跳的泡泡for (int i=0 ; i{((BubbleSprite)jumping.elementAt(i)).jump();}}}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值