diff --git a/res/raw/whip.ogg b/res/raw/whip.ogg new file mode 100644 index 0000000..8a3de2f Binary files /dev/null and b/res/raw/whip.ogg differ diff --git a/src/com/efortin/frozenbubble/HighscoreManager.java b/src/com/efortin/frozenbubble/HighscoreManager.java index 48c51a2..ad3e3b0 100644 --- a/src/com/efortin/frozenbubble/HighscoreManager.java +++ b/src/com/efortin/frozenbubble/HighscoreManager.java @@ -67,7 +67,6 @@ public class HighscoreManager { private int currentLevel = 0; - private int lastLevel = 0; private long startTime = 0; private long pausedTime = 0; private long lastScoreId = -1; @@ -122,7 +121,6 @@ public void lostLevel() { public void startLevel(int level) { startTime = System.currentTimeMillis(); - lastLevel = currentLevel; currentLevel = level; pausedTime = 0; // Log.i("FrozenBubble-highscore", "startLevel(" + level + ")"); @@ -160,8 +158,8 @@ public List getHighscore(int level, int limit) { return db.selectByLevel(level, limit); } - public int getLastLevel() { - return lastLevel; + public int getLevel() { + return currentLevel; } public long getLastScoreId() { diff --git a/src/org/jfedor/frozenbubble/FrozenBubble.java b/src/org/jfedor/frozenbubble/FrozenBubble.java index 14c5664..87aa56a 100644 --- a/src/org/jfedor/frozenbubble/FrozenBubble.java +++ b/src/org/jfedor/frozenbubble/FrozenBubble.java @@ -106,7 +106,8 @@ public class FrozenBubble extends Activity public final static int SOUND_HURRY = 6; public final static int SOUND_NEWROOT = 7; public final static int SOUND_NOH = 8; - public final static int NUM_SOUNDS = 9; + public final static int SOUND_WHIP = 9; + public final static int NUM_SOUNDS = 10; public final static int GAME_NORMAL = 0; public final static int GAME_COLORBLIND = 1; diff --git a/src/org/jfedor/frozenbubble/FrozenGame.java b/src/org/jfedor/frozenbubble/FrozenGame.java index d25c580..0ae15e5 100644 --- a/src/org/jfedor/frozenbubble/FrozenGame.java +++ b/src/org/jfedor/frozenbubble/FrozenGame.java @@ -137,6 +137,7 @@ public class FrozenGame extends GameScreen { SoundManager soundManager; boolean readyToFire; + boolean swapPressed; boolean endOfGame; boolean frozenify; int frozenifyX, frozenifyY; @@ -180,6 +181,7 @@ public FrozenGame(BmpWrap background_arg, play_result = GAME_PLAYING; game_result = GAME_LOST; launchBubblePosition = 20; + swapPressed = false; penguin = new PenguinSprite(penguins_arg, random); this.addSprite(penguin); @@ -215,7 +217,7 @@ public FrozenGame(BmpWrap background_arg, } currentColor = bubbleManager.nextBubbleIndex(random); - nextColor = bubbleManager.nextBubbleIndex(random); + nextColor = bubbleManager.nextBubbleIndex(random); if (FrozenBubble.getMode() == FrozenBubble.GAME_NORMAL) { nextBubble = new ImageSprite(new Rect(302, 440, 302 + 32, 440 + 32), @@ -562,12 +564,14 @@ private void blinkLine(int number) } } - public int play(boolean key_left, boolean key_right, boolean key_fire, + public int play(boolean key_left, boolean key_right, + boolean key_fire, boolean key_swap, double trackball_dx, boolean touch_fire, double touch_x, double touch_y, boolean ats_touch_fire, double ats_touch_dx) { boolean ats = FrozenBubble.getAimThenShoot(); + if ((ats && ats_touch_fire) || (!ats && touch_fire)) { key_fire = true; } @@ -581,11 +585,22 @@ public int play(boolean key_left, boolean key_right, boolean key_fire, } else { move[HORIZONTAL_MOVE] = 0; } + if (key_fire) { move[FIRE] = KEY_UP; } else { move[FIRE] = 0; } + + if (key_swap) { + if (!swapPressed) { + swapNextLaunchBubble(); + swapPressed = true; + } + } else { + swapPressed = false; + } + if (!ats && touch_fire && movingBubble == null) { double xx = touch_x - 318; double yy = 406 - touch_y; @@ -657,7 +672,7 @@ public int play(boolean key_left, boolean key_right, boolean key_fire, this.addSprite(movingBubble); currentColor = nextColor; - nextColor = bubbleManager.nextBubbleIndex(random); + nextColor = bubbleManager.nextBubbleIndex(random); if (FrozenBubble.getMode() == FrozenBubble.GAME_NORMAL) { nextBubble.changeImage(bubbles[nextColor]); @@ -848,4 +863,23 @@ public void setPosition(double value) { launchBubble.changeDirection((int)launchBubblePosition); penguin.updateState(PenguinSprite.STATE_VOID); } + + public void swapNextLaunchBubble() + { + if (currentColor != nextColor) + { + int tempColor = currentColor; + currentColor = nextColor; + nextColor = tempColor; + + launchBubble.changeColor(currentColor); + + if (FrozenBubble.getMode() == FrozenBubble.GAME_NORMAL) + nextBubble.changeImage(bubbles[nextColor]); + else + nextBubble.changeImage(bubblesBlind[nextColor]); + + soundManager.playSound(FrozenBubble.SOUND_WHIP); + } + } } diff --git a/src/org/jfedor/frozenbubble/GameScreen.java b/src/org/jfedor/frozenbubble/GameScreen.java index 4dea810..45aeb07 100644 --- a/src/org/jfedor/frozenbubble/GameScreen.java +++ b/src/org/jfedor/frozenbubble/GameScreen.java @@ -117,7 +117,8 @@ public void paint(Canvas c, double scale, int dx, int dy) { } public abstract int play(boolean key_left, boolean key_right, - boolean key_fire, double trackball_dx, + boolean key_fire, boolean key_swap, + double trackball_dx, boolean touch_fire, double touch_x, double touch_y, boolean ats_touch_fire, double ats_touch_dx); diff --git a/src/org/jfedor/frozenbubble/GameView.java b/src/org/jfedor/frozenbubble/GameView.java index 2d1d6cd..871a1f4 100644 --- a/src/org/jfedor/frozenbubble/GameView.java +++ b/src/org/jfedor/frozenbubble/GameView.java @@ -100,6 +100,8 @@ class GameView extends SurfaceView implements SurfaceHolder.Callback { + private Context mContext; + private GameThread thread; //********************************************************** // Listener interface for various events //********************************************************** @@ -129,8 +131,6 @@ class GameThread extends Thread public static final int STATE_RUNNING = 1; public static final int STATE_PAUSE = 2; public static final int STATE_ABOUT = 4; - public static final int STATE_HIGHSCORE = 8; - public static final int STATE_LEVELENDED = 16; public static final int GAMEFIELD_WIDTH = 320; public static final int GAMEFIELD_HEIGHT = 480; @@ -138,24 +138,30 @@ class GameThread extends Thread private static final double TRACKBALL_COEFFICIENT = 5; private static final double TOUCH_FIRE_Y_THRESHOLD = 380; + private static final double TOUCH_SWAP_X_THRESHOLD = 10; private static final double ATS_TOUCH_COEFFICIENT = 0.2; private static final double ATS_TOUCH_FIRE_Y_THRESHOLD = 350; private long mLastTime; private int mMode; private int mModeWas; - private boolean mRun = false; + + private boolean mRun = false; + private boolean mShowScores = false; private boolean mLeft = false; private boolean mRight = false; private boolean mUp = false; + private boolean mDown = false; private boolean mFire = false; private boolean mWasLeft = false; private boolean mWasRight = false; private boolean mWasFire = false; private boolean mWasUp = false; + private boolean mWasDown = false; private double mTrackballDX = 0; private boolean mTouchFire = false; + private boolean mTouchSwap = false; private double mTouchX; private double mTouchY; private boolean mATSTouchFire = false; @@ -450,13 +456,16 @@ public void pause( ) { synchronized ( mSurfaceHolder ) { - setState(STATE_PAUSE); - if ( mGameListener != null ) + if (mMode == STATE_RUNNING) { - mGameListener.onGameEvent( EVENT_GAME_PAUSED ); + setState(STATE_PAUSE); + + if ( mGameListener != null ) + mGameListener.onGameEvent( EVENT_GAME_PAUSED ); + + mFrozenGame .pause( ); + mHighscoreManager.pauseLevel( ); } - mFrozenGame .pause( ); - mHighscoreManager.pauseLevel( ); } } @@ -464,8 +473,11 @@ public void resumeGame( ) { synchronized ( mSurfaceHolder ) { - mFrozenGame.resume( ); - mHighscoreManager.resumeLevel( ); + if (mMode == STATE_RUNNING) + { + mFrozenGame .resume( ); + mHighscoreManager.resumeLevel( ); + } } } @@ -510,23 +522,22 @@ public void run( ) { drawAboutScreen(c); } - else if ( mMode == STATE_HIGHSCORE ) + else if (mMode == STATE_PAUSE) { - drawHighscoreScreen(c, mHighscoreManager.getLastLevel( )); + if (mShowScores) + drawHighscoreScreen(c, mHighscoreManager.getLevel( )); + else + doDraw(c); } else { - if ( mMode == STATE_RUNNING ) + if (mMode == STATE_RUNNING) { - if ( mModeWas != STATE_RUNNING ) + if (mModeWas != STATE_RUNNING) { - if ( ( mModeWas == STATE_PAUSE ) || - ( mModeWas == STATE_ABOUT ) ) + if (mGameListener != null) { - if ( mGameListener != null ) - { - mGameListener.onGameEvent( EVENT_GAME_RESUME ); - } + mGameListener.onGameEvent(EVENT_GAME_RESUME); } mModeWas = STATE_RUNNING; resumeGame( ); @@ -669,28 +680,34 @@ boolean doKeyDown( int keyCode, KeyEvent msg ) //Log.i("frozen-bubble", "STATE RUNNING"); if ( keyCode == KeyEvent.KEYCODE_DPAD_LEFT ) { - mLeft = true; + mLeft = true; mWasLeft = true; return true; } else if ( keyCode == KeyEvent.KEYCODE_DPAD_RIGHT ) { - mRight = true; + mRight = true; mWasRight = true; return true; } else if ( keyCode == KeyEvent.KEYCODE_DPAD_CENTER ) { - mFire = true; + mFire = true; mWasFire = true; return true; } else if ( keyCode == KeyEvent.KEYCODE_DPAD_UP ) { - mUp = true; + mUp = true; mWasUp = true; return true; } + else if ( keyCode == KeyEvent.KEYCODE_DPAD_DOWN ) + { + mDown = true; + mWasDown = true; + return true; + } } return false; @@ -723,6 +740,11 @@ else if ( keyCode == KeyEvent.KEYCODE_DPAD_UP ) mUp = false; return true; } + else if ( keyCode == KeyEvent.KEYCODE_DPAD_DOWN ) + { + mDown = false; + return true; + } } return false; } @@ -792,6 +814,8 @@ boolean doTouchEvent( MotionEvent event ) mTouchX = x; mTouchY = y; } + else if ( Math.abs( x - 318 ) <= TOUCH_SWAP_X_THRESHOLD ) + mTouchSwap = true; } // Set the values used when Aim Then Shoot is on. @@ -848,20 +872,21 @@ else if ( event.getAction( ) == MotionEvent.ACTION_DOWN ) { switch ( mMode ) { - case STATE_HIGHSCORE: - setState( STATE_RUNNING ); - if ( mGameListener != null ) - { - mGameListener.onGameEvent( EVENT_LEVEL_START ); - } - return true; - case STATE_ABOUT: setState( STATE_RUNNING ); return true; - case STATE_LEVELENDED: case STATE_PAUSE: + if ( mShowScores ) + { + mShowScores = false; + nextLevel( ); + if ( mGameListener != null ) + { + mGameListener.onGameEvent( EVENT_LEVEL_START ); + } + return true; + } setState( STATE_RUNNING ); break; @@ -873,11 +898,6 @@ else if ( event.getAction( ) == MotionEvent.ACTION_DOWN ) return false; } - public void setPosition( double value ) - { - mFrozenGame.setPosition( value ); - } - private void drawBackground( Canvas c ) { Sprite.drawImage( mBackground, 0, 0, c, mDisplayScale, @@ -1032,18 +1052,20 @@ private void updateGameState( ) int game_state = mFrozenGame.play( mLeft || mWasLeft, mRight || mWasRight, mFire || mUp || mWasFire || mWasUp, + mDown || mWasDown || mTouchSwap, mTrackballDX, mTouchFire, mTouchX, mTouchY, mATSTouchFire, mATSTouchDX ); if ( ( game_state == FrozenGame.GAME_NEXT_LOST ) || ( game_state == FrozenGame.GAME_NEXT_WON ) ) { - nextLevel( ); - if ( game_state == FrozenGame.GAME_NEXT_WON ) - setState( STATE_HIGHSCORE ); + { + mShowScores = true; + pause( ); + } else - setState( STATE_LEVELENDED ); + nextLevel( ); if ( mGameListener != null ) { @@ -1057,8 +1079,10 @@ private void updateGameState( ) mWasRight = false; mWasFire = false; mWasUp = false; + mWasDown = false; mTrackballDX = 0; mTouchFire = false; + mTouchSwap = false; mATSTouchFire = false; mATSTouchDX = 0; } @@ -1229,10 +1253,12 @@ public void cleanUp( ) mLevelManager = null; } } - } - private Context mContext; - private GameThread thread; + public void setPosition( double value ) + { + mFrozenGame.setPosition( value ); + } + } public GameView( Context context, AttributeSet attrs ) { diff --git a/src/org/jfedor/frozenbubble/SoundManager.java b/src/org/jfedor/frozenbubble/SoundManager.java index 7c3456b..180aabb 100644 --- a/src/org/jfedor/frozenbubble/SoundManager.java +++ b/src/org/jfedor/frozenbubble/SoundManager.java @@ -87,6 +87,8 @@ public SoundManager( Context context ) soundPool.load( context, R.raw.newroot_solo, 1 ); sm[ FrozenBubble.SOUND_NOH ] = soundPool.load( context, R.raw.noh, 1 ); + sm[ FrozenBubble.SOUND_WHIP ] = + soundPool.load( context, R.raw.whip, 1 ); } public final void playSound( int sound )