AI 146646: am: CL 146645 am: CL 146643 Clean up and commenting of the JetBoy JET demo code:

Fixed JetPlayer initialization code and pause when the app loses focus.
  Removed mute mask hack.
  Cleaned up event ID declaration and check (event value is a byte, not a String).
  Add extensive comments for the JetPlayer code.
  Original author: jmtrivi
  Merged from: //branches/cupcake/...
  Original author: android-build

Automated import of CL 146646
This commit is contained in:
Jean-Michel Trivi
2009-04-18 22:17:27 -07:00
committed by The Android Open Source Project
parent e2404ec9d7
commit 477c7f5a52
2 changed files with 118 additions and 154 deletions

View File

@@ -14,7 +14,8 @@
* limitations under the License. * limitations under the License.
*/ */
// FIXME: review and cleanup // Android JET demonstration code:
// See the JetBoyView.java file for examples on the use of the JetPlayer class.
package com.example.android.jetboy; package com.example.android.jetboy;
@@ -79,6 +80,7 @@ public class JetBoy extends Activity implements View.OnClickListener {
mJetBoyView.SetTextView(mTextView); mJetBoyView.SetTextView(mTextView);
} }
/** /**
* Handles component interaction * Handles component interaction

View File

@@ -15,7 +15,8 @@
* *
*/ */
// FIXME: review and cleanup // Android JET demonstration code:
// All inline comments related to the use of the JetPlayer class are preceded by "JET info:"
package com.example.android.jetboy; package com.example.android.jetboy;
@@ -119,20 +120,19 @@ public class JetBoyView extends SurfaceView implements SurfaceHolder.Callback {
public byte value; public byte value;
} }
// JET info: the JetBoyThread receives all the events from the JET player
// JET info: through the OnJetEventListener interface.
class JetBoyThread extends Thread implements OnJetEventListener { class JetBoyThread extends Thread implements OnJetEventListener {
/* /**
* State-tracking constants we don't actually use all of these in * State-tracking constants.
* JetBoy, borrowed wholesale from lunar lander.
*/ */
public static final int STATE_START = -1; public static final int STATE_START = -1;
public static final int STATE_PLAY = 0; public static final int STATE_PLAY = 0;
public static final int STATE_LOSE = 1; public static final int STATE_LOSE = 1;
public static final int STATE_PAUSE = 2; public static final int STATE_PAUSE = 2;
public static final int STATE_READY = 3; public static final int STATE_RUNNING = 3;
public static final int STATE_RUNNING = 4;
public static final int STATE_WIN = 5;
// how many frames per beat? The basic animation can be changed for // how many frames per beat? The basic animation can be changed for
// instance to 3/4 by changing this to 3. // instance to 3/4 by changing this to 3.
// untested is the impact on other parts of game logic for non 4/4 time. // untested is the impact on other parts of game logic for non 4/4 time.
@@ -170,11 +170,11 @@ public class JetBoyView extends SurfaceView implements SurfaceHolder.Callback {
/** The drawable to use as the close background of the animation canvas */ /** The drawable to use as the close background of the animation canvas */
private Bitmap mBackgroundImageNear; private Bitmap mBackgroundImageNear;
// event ID within JET file. 80,81, 82 are tested to use. // JET info: event IDs within the JET file.
// in this game 80 is used for sending asteroid // JET info: in this game 80 is used for sending asteroid across the screen
// 82 is used as game time for 1/4 note beat. // JET info: 82 is used as game time for 1/4 note beat.
private final String mSendEvent = "80"; private final byte NEW_ASTEROID_EVENT = 80;
private final String mTimerEvent = "82"; private final byte TIMER_EVENT = 82;
// used to track beat for synch of mute/unmute actions // used to track beat for synch of mute/unmute actions
private int mBeatCount = 1; private int mBeatCount = 1;
@@ -196,8 +196,6 @@ public class JetBoyView extends SurfaceView implements SurfaceHolder.Callback {
private Bitmap mLaserShot; private Bitmap mLaserShot;
// used to save the beat event system time. // used to save the beat event system time.
// right now we use System.currentMillis
// should it use android stuff??
private long mLastBeatTime; private long mLastBeatTime;
private long mPassedTime; private long mPassedTime;
@@ -209,7 +207,7 @@ public class JetBoyView extends SurfaceView implements SurfaceHolder.Callback {
// but which land they start in is random. // but which land they start in is random.
private Random mRandom = new Random(); private Random mRandom = new Random();
// the star of our show, a reference to the JetPlayer object. // JET info: the star of our show, a reference to the JetPlayer object.
private JetPlayer mJet = null; private JetPlayer mJet = null;
private boolean mJetPlaying = false; private boolean mJetPlaying = false;
@@ -260,7 +258,7 @@ public class JetBoyView extends SurfaceView implements SurfaceHolder.Callback {
private int mBGFarMoveX = 0; private int mBGFarMoveX = 0;
private int mBGNearMoveX = 0; private int mBGNearMoveX = 0;
// this is has "high" (close to top) that jet boy can fly // how far up (close to top) jet boy can fly
private int mJetBoyYMin = 40; private int mJetBoyYMin = 40;
private int mJetBoyX = 0; private int mJetBoyX = 0;
private int mJetBoyY = 0; private int mJetBoyY = 0;
@@ -271,14 +269,11 @@ public class JetBoyView extends SurfaceView implements SurfaceHolder.Callback {
// how far up asteroid can be painted // how far up asteroid can be painted
private int mAsteroidMinY = 40; private int mAsteroidMinY = 40;
// Jet does not pick up volume and pan changes?
private boolean mMuteArrayHack = false;
Resources mRes; Resources mRes;
// eight music beds, added a 9th to fix some kind of bug in JET around // array to store the mute masks that are applied during game play to respond to
// pans and volume controls // the player's hit streaks
// ask Jenn about this
private boolean muteMask[][] = new boolean[9][32]; private boolean muteMask[][] = new boolean[9][32];
/** /**
@@ -290,15 +285,13 @@ public class JetBoyView extends SurfaceView implements SurfaceHolder.Callback {
*/ */
public JetBoyThread(SurfaceHolder surfaceHolder, Context context, Handler handler) { public JetBoyThread(SurfaceHolder surfaceHolder, Context context, Handler handler) {
// get handles to some important objects
mSurfaceHolder = surfaceHolder; mSurfaceHolder = surfaceHolder;
mHandler = handler; mHandler = handler;
mContext = context; mContext = context;
mRes = context.getResources(); mRes = context.getResources();
// this are the mute arrays associated with the music beds in the // JET info: this are the mute arrays associated with the music beds in the
// JET file // JET info: JET file
for (int ii = 0; ii < 8; ii++) { for (int ii = 0; ii < 8; ii++) {
for (int xx = 0; xx < 32; xx++) { for (int xx = 0; xx < 32; xx++) {
muteMask[ii][xx] = true; muteMask[ii][xx] = true;
@@ -360,9 +353,7 @@ public class JetBoyView extends SurfaceView implements SurfaceHolder.Callback {
muteMask[7][17] = false; muteMask[7][17] = false;
muteMask[7][18] = false; muteMask[7][18] = false;
// set all tracks to play, do it for one beat and then switch to // set all tracks to play
// mute array zero
// hack for jet bug on pan and mutes
for (int xx = 0; xx < 32; xx++) { for (int xx = 0; xx < 32; xx++) {
muteMask[8][xx] = false; muteMask[8][xx] = false;
} }
@@ -425,29 +416,36 @@ public class JetBoyView extends SurfaceView implements SurfaceHolder.Callback {
*/ */
private void initializeJetPlayer() { private void initializeJetPlayer() {
// if (mJet!=null) // JET info: this is what we do to undesirable instances: we release them!
// { if (mJet != null)
// mJet.release(); {
// mJet = null; mJet.release();
// } mJet = null;
}
// JET info: let's create our JetPlayer instance using the factory
mJet = JetPlayer.getJetPlayer(); mJet = JetPlayer.getJetPlayer();
mJetPlaying = false; mJetPlaying = false;
// make sure we flush the queue // JET info: make sure we flush the queue,
// otherwise left over events from previous gameplay // JET info: otherwise left over events from previous gameplay can hang around.
// can hang around. // JET info: ok, here we don't really need that but if you ever reuse a JetPlayer
// JET info: instance, clear the queue before reusing it, this will also clear any
// JET info: trigger clips that have been triggered but not played yet.
mJet.clearQueue(); mJet.clearQueue();
// mJet.setStatusUpdateListener(this); // JET info: we are going to receive in this example all the JET callbacks
// JET info: inthis animation thread object.
mJet.setEventListener(this); mJet.setEventListener(this);
Log.d(TAG, "opening jet file"); Log.d(TAG, "opening jet file");
// mJet.loadJetFile(m_PathToJetFile); // JET info: load the actual JET content the game will be playing,
// JET info: it's stored as a raw resource in our APK, and is labeled "level1"
mJet.loadJetFile(mContext.getResources().openRawResourceFd(R.raw.level1)); mJet.loadJetFile(mContext.getResources().openRawResourceFd(R.raw.level1));
// JET info: if our JET file was stored on the sdcard for instance, we would have used
// JET info: mJet.loadJetFile("/sdcard/level1.jet");
Log.d(TAG, "opening jet file DONE"); Log.d(TAG, "opening jet file DONE");
@@ -455,26 +453,34 @@ public class JetBoyView extends SurfaceView implements SurfaceHolder.Callback {
byte sSegmentID = 0; byte sSegmentID = 0;
Log.d(TAG, " start queuing jet file"); Log.d(TAG, " start queuing jet file");
// JET info: now we're all set to prepare queuing the JET audio segments for the game.
// JET info: in this example, the game uses segment 0 for the duration of the game play,
// JET info: and plays segment 1 several times as the "outro" music, so we're going to
// JET info: queue everything upfront, but with more complex JET compositions, we could
// JET info: also queue the segments during the game play.
// this is the main game play music // JET info: this is the main game play music
// it is located at segment 0 // JET info: it is located at segment 0
// it uses lib #0 this allows DLS to play // JET info: it uses the first DLS lib in the .jet resource, which is at index 0
// -1 would mean no DLS // JET info: index -1 means no DLS
// higher numbers untested
mJet.queueJetSegment(0, 0, 0, 0, 0, sSegmentID); mJet.queueJetSegment(0, 0, 0, 0, 0, sSegmentID);
// end game music, loop 4 times normal pitch // JET info: end game music, loop 4 times normal pitch
mJet.queueJetSegment(1, 0, 4, 0, 0, sSegmentID); mJet.queueJetSegment(1, 0, 4, 0, 0, sSegmentID);
// end game music loop 4 times up an octave // JET info: end game music loop 4 times up an octave
mJet.queueJetSegment(1, 0, 4, 1, 0, sSegmentID); mJet.queueJetSegment(1, 0, 4, 1, 0, sSegmentID);
mJet.setMuteArray(muteMask[8], true); // JET info: set the mute mask as designed for the beginning of the game, when the
// JET info: the player hasn't scored yet.
mJet.setMuteArray(muteMask[0], true);
Log.d(TAG, " start queuing jet file DONE"); Log.d(TAG, " start queuing jet file DONE");
} }
private void doDraw(Canvas canvas) { private void doDraw(Canvas canvas) {
if (mState == STATE_RUNNING) { if (mState == STATE_RUNNING) {
@@ -482,18 +488,14 @@ public class JetBoyView extends SurfaceView implements SurfaceHolder.Callback {
} else if (mState == STATE_START) { } else if (mState == STATE_START) {
doDrawReady(canvas); doDrawReady(canvas);
} else if (mState == STATE_PLAY || mState == STATE_LOSE) { } else if (mState == STATE_PLAY || mState == STATE_LOSE) {
if (mTitleBG2 == null) { if (mTitleBG2 == null) {
mTitleBG2 = BitmapFactory.decodeResource(mRes, R.drawable.title_bg_hori); mTitleBG2 = BitmapFactory.decodeResource(mRes, R.drawable.title_bg_hori);
} }
doDrawPlay(canvas); doDrawPlay(canvas);
}// end state play block }// end state play block
} }
/** /**
* Draws current state of the game Canvas. * Draws current state of the game Canvas.
*/ */
@@ -542,8 +544,7 @@ public class JetBoyView extends SurfaceView implements SurfaceHolder.Callback {
if (mShipIndex == 4) if (mShipIndex == 4)
mShipIndex = 0; mShipIndex = 0;
// draw the space ship. // draw the space ship in the same lane as the next asteroid
// This will have code to match asteroid lane
canvas.drawBitmap(mShipFlying[mShipIndex], mJetBoyX, mJetBoyY, null); canvas.drawBitmap(mShipFlying[mShipIndex], mJetBoyX, mJetBoyY, null);
if (mLaserOn) { if (mLaserOn) {
@@ -561,8 +562,6 @@ public class JetBoyView extends SurfaceView implements SurfaceHolder.Callback {
mJetBoyY = mJetBoyYMin; mJetBoyY = mJetBoyYMin;
mMuteArrayHack = false;
// set up jet stuff // set up jet stuff
initializeJetPlayer(); initializeJetPlayer();
@@ -576,7 +575,6 @@ public class JetBoyView extends SurfaceView implements SurfaceHolder.Callback {
mHitStreak = 0; mHitStreak = 0;
mHitTotal = 0; mHitTotal = 0;
// mTimerTotal="1:20";
} }
private void doAsteroidAnimation(Canvas canvas) { private void doAsteroidAnimation(Canvas canvas) {
@@ -585,20 +583,10 @@ public class JetBoyView extends SurfaceView implements SurfaceHolder.Callback {
return; return;
// Compute what percentage through a beat we are and adjust // Compute what percentage through a beat we are and adjust
// animation and postion // animation and position based on that. This assumes 140bpm(428ms/beat).
// based on that. This assumes 140bpm(428ms/beat), we really should // This is just inter-beat interpolation, no game state is updated
// compute this
// based on properties of the music file under ideal circumstances.
// This is just
// interbeat interpolation, no game state is updated
long frameDelta = System.currentTimeMillis() - mLastBeatTime; long frameDelta = System.currentTimeMillis() - mLastBeatTime;
// mPixelMoveX per beat
// This hid the feeling of the asteroids moving to the beat and
// caused some issues with
// explosions not aligned with asteroids last position, so fix that
// if we use this again.
// int asteroidDrawOffset = (int)(mPixelMoveX * frameDelta/428L);
// animation frames per beat
int animOffset = (int)(ANIMATION_FRAMES_PER_BEAT * frameDelta / 428); int animOffset = (int)(ANIMATION_FRAMES_PER_BEAT * frameDelta / 428);
for (int i = (mDangerWillRobinson.size() - 1); i >= 0; i--) { for (int i = (mDangerWillRobinson.size() - 1); i >= 0; i--) {
@@ -631,10 +619,10 @@ public class JetBoyView extends SurfaceView implements SurfaceHolder.Callback {
canvas.drawBitmap(mTitleBG2, 0, 0, null); canvas.drawBitmap(mTitleBG2, 0, 0, null);
} }
/** /**
* the heart of the worker bee * the heart of the worker bee
*/ */
public void run() { public void run() {
// while running do stuff in this loop...bzzz! // while running do stuff in this loop...bzzz!
while (mRun) { while (mRun) {
@@ -671,13 +659,10 @@ public class JetBoyView extends SurfaceView implements SurfaceHolder.Callback {
}// end of STATE_RUNNING block }// end of STATE_RUNNING block
else if (mState == STATE_PLAY && !mInitialized) else if (mState == STATE_PLAY && !mInitialized)
{ {
setInitialGameState(); setInitialGameState();
} else if (mState == STATE_LOSE) { } else if (mState == STATE_LOSE) {
mInitialized = false; mInitialized = false;
} }
try { try {
@@ -696,6 +681,7 @@ public class JetBoyView extends SurfaceView implements SurfaceHolder.Callback {
}// end while mrun block }// end while mrun block
} }
/** /**
* This method handles updating the model of the game state. No * This method handles updating the model of the game state. No
* rendering is done here only processing of inputs and update of state. * rendering is done here only processing of inputs and update of state.
@@ -719,7 +705,7 @@ public class JetBoyView extends SurfaceView implements SurfaceHolder.Callback {
mKeyContext = processKeyEvent((KeyGameEvent)event, mKeyContext); mKeyContext = processKeyEvent((KeyGameEvent)event, mKeyContext);
// Update laser state. Having this here allows the laser to // Update laser state. Having this here allows the laser to
// be trigered right when the key is // be triggered right when the key is
// pressed. If we comment this out the laser will only be // pressed. If we comment this out the laser will only be
// turned on when updateLaser is called // turned on when updateLaser is called
// when processing a timer event below. // when processing a timer event below.
@@ -731,7 +717,7 @@ public class JetBoyView extends SurfaceView implements SurfaceHolder.Callback {
JetGameEvent jetEvent = (JetGameEvent)event; JetGameEvent jetEvent = (JetGameEvent)event;
// Only update state on a timer event // Only update state on a timer event
if (jetEvent.value == 82) { if (jetEvent.value == TIMER_EVENT) {
// Note the time of the last beat // Note the time of the last beat
mLastBeatTime = System.currentTimeMillis(); mLastBeatTime = System.currentTimeMillis();
@@ -740,7 +726,7 @@ public class JetBoyView extends SurfaceView implements SurfaceHolder.Callback {
// on for too long. // on for too long.
updateLaser(mKeyContext); updateLaser(mKeyContext);
// Update explosions before we updated asteroids because // Update explosions before we update asteroids because
// updateAsteroids may add // updateAsteroids may add
// new explosions that we do not want updated until next // new explosions that we do not want updated until next
// frame // frame
@@ -756,13 +742,14 @@ public class JetBoyView extends SurfaceView implements SurfaceHolder.Callback {
} }
} }
/** /**
* This method handles the state updates that can be caused by key press * This method handles the state updates that can be caused by key press
* events. Key events may mean different things depending on what has * events. Key events may mean different things depending on what has
* come before, to support this concept this method takes an opaque * come before, to support this concept this method takes an opaque
* context object as a parameter and returns an updated version. This * context object as a parameter and returns an updated version. This
* context should be set to null for the first event then should be set * context should be set to null for the first event then should be set
* to the last value returned for subsiquent events. * to the last value returned for subsequent events.
*/ */
protected Object processKeyEvent(KeyGameEvent event, Object context) { protected Object processKeyEvent(KeyGameEvent event, Object context) {
// Log.d(TAG, "key code is " + event.keyCode + " " + (event.up ? // Log.d(TAG, "key code is " + event.keyCode + " " + (event.up ?
@@ -789,6 +776,7 @@ public class JetBoyView extends SurfaceView implements SurfaceHolder.Callback {
return context; return context;
} }
/** /**
* This method updates the laser status based on user input and shot * This method updates the laser status based on user input and shot
* duration * duration
@@ -803,17 +791,14 @@ public class JetBoyView extends SurfaceView implements SurfaceHolder.Callback {
// If the laser has been on too long shut it down // If the laser has been on too long shut it down
if (mLaserOn && System.currentTimeMillis() - mLaserFireTime > 400) { if (mLaserOn && System.currentTimeMillis() - mLaserFireTime > 400) {
mLaserOn = false; mLaserOn = false;
} }
// trying to tune the laser hit timing // trying to tune the laser hit timing
else if (System.currentTimeMillis() - mLaserFireTime > 300) { else if (System.currentTimeMillis() - mLaserFireTime > 300) {
// if (mJet!=null) // JET info: the laser sound is on track 23, we mute it (true) right away (false)
// {
mJet.setMuteFlag(23, true, false); mJet.setMuteFlag(23, true, false);
// }
} }
// Now check to see if we should turn the laser on. We do this after // Now check to see if we should turn the laser on. We do this after
@@ -826,7 +811,7 @@ public class JetBoyView extends SurfaceView implements SurfaceHolder.Callback {
mLaserOn = true; mLaserOn = true;
mLaserFireTime = keyTime; mLaserFireTime = keyTime;
// Log.d(TAG, "*** LASER ON ***"); // JET info: unmute the laser track (false) right away (false)
mJet.setMuteFlag(23, false, false); mJet.setMuteFlag(23, false, false);
} }
} }
@@ -841,14 +826,9 @@ public class JetBoyView extends SurfaceView implements SurfaceHolder.Callback {
for (int i = (mDangerWillRobinson.size() - 1); i >= 0; i--) { for (int i = (mDangerWillRobinson.size() - 1); i >= 0; i--) {
Asteroid asteroid = mDangerWillRobinson.elementAt(i); Asteroid asteroid = mDangerWillRobinson.elementAt(i);
// If the asteroid is within laser ranged but not already missed // If the asteroid is within laser range but not already missed
// check if the // check if the key was pressed close enough to the beat to make a hit
// key was pressed close enough to the beat to make a hit
// there isnt any real logic here. just played with it until the
// game "felt right"
if (asteroid.mDrawX <= mAsteroidMoveLimitX + 20 && !asteroid.mMissed) if (asteroid.mDrawX <= mAsteroidMoveLimitX + 20 && !asteroid.mMissed)
{ {
// If the laser was fired on the beat destroy the asteroid // If the laser was fired on the beat destroy the asteroid
if (mLaserOn) { if (mLaserOn) {
@@ -870,9 +850,8 @@ public class JetBoyView extends SurfaceView implements SurfaceHolder.Callback {
// This asteroid has been removed process the next one // This asteroid has been removed process the next one
continue; continue;
} else { } else {
// Sorry, timing was not good enough, marke the asteroid // Sorry, timing was not good enough, mark the asteroid
// as missed so // as missed so on next frame it cannot be hit even if it is still
// on next frame it cannot be hit even if it is still
// within range // within range
asteroid.mMissed = true; asteroid.mMissed = true;
@@ -928,27 +907,17 @@ public class JetBoyView extends SurfaceView implements SurfaceHolder.Callback {
protected void processJetEvent(JetPlayer player, short segment, byte track, byte channel, protected void processJetEvent(JetPlayer player, short segment, byte track, byte channel,
byte controller, byte value) { byte controller, byte value) {
Log.d(TAG, "onJetEvent(): seg=" + segment + " track=" + track + " chan=" + channel //Log.d(TAG, "onJetEvent(): seg=" + segment + " track=" + track + " chan=" + channel
+ " cntrlr=" + controller + " val=" + value); // + " cntrlr=" + controller + " val=" + value);
String eventID = "" + value;
// Check for an event that triggers a new asteroid // Check for an event that triggers a new asteroid
if (eventID.equalsIgnoreCase(mSendEvent)) { if (value == NEW_ASTEROID_EVENT) {
// Log.d(TAG, "~~~~ setting create to true");
doAsteroidCreation(); doAsteroidCreation();
} }
mBeatCount++; mBeatCount++;
if (!mMuteArrayHack) {
mMuteArrayHack = true;
mJet.setMuteArray(muteMask[0], false);
}
if (mBeatCount > 4) { if (mBeatCount > 4) {
mBeatCount = 1; mBeatCount = 1;
@@ -958,11 +927,10 @@ public class JetBoyView extends SurfaceView implements SurfaceHolder.Callback {
// it was a game requirement to change the mute array on 1st beat of // it was a game requirement to change the mute array on 1st beat of
// the next measure when needed // the next measure when needed
// and so we track beat count, after than we track hitStreak to // and so we track beat count, after that we track hitStreak to
// determine music level // determine the music "intensity"
// if the level has go gone up, call trigger clip otherwise just // if the intensity has go gone up, call a corresponding trigger clip, otherwise just
// execute rest of change music bed logic. // execute the rest of the music bed change logic.
// could probably be a method call here.
if (mBeatCount == 1) { if (mBeatCount == 1) {
// do it back wards so you fall into the correct one // do it back wards so you fall into the correct one
@@ -976,18 +944,21 @@ public class JetBoyView extends SurfaceView implements SurfaceHolder.Callback {
} }
mCurrentBed = 7; mCurrentBed = 7;
// JET info: change the mute mask to update the way the music plays based
// JET info: on the player's skills.
mJet.setMuteArray(muteMask[7], false); mJet.setMuteArray(muteMask[7], false);
} }
} else if (mHitStreak > 24) { } else if (mHitStreak > 24) {
if (mCurrentBed != 6) { if (mCurrentBed != 6) {
if (mCurrentBed < 6) { if (mCurrentBed < 6) {
// JET info: quite a few asteroids hit, trigger the clip with the guy's
// JET info: voice that encourages the player.
mJet.triggerClip(6); mJet.triggerClip(6);
} }
mCurrentBed = 6; mCurrentBed = 6;
mJet.setMuteArray(muteMask[6], false); mJet.setMuteArray(muteMask[6], false);
// mJet.triggerClip(6);
} }
} else if (mHitStreak > 20) { } else if (mHitStreak > 20) {
if (mCurrentBed != 5) { if (mCurrentBed != 5) {
@@ -997,7 +968,6 @@ public class JetBoyView extends SurfaceView implements SurfaceHolder.Callback {
mCurrentBed = 5; mCurrentBed = 5;
mJet.setMuteArray(muteMask[5], false); mJet.setMuteArray(muteMask[5], false);
// mJet.triggerClip(5);
} }
} else if (mHitStreak > 16) { } else if (mHitStreak > 16) {
if (mCurrentBed != 4) { if (mCurrentBed != 4) {
@@ -1007,7 +977,6 @@ public class JetBoyView extends SurfaceView implements SurfaceHolder.Callback {
} }
mCurrentBed = 4; mCurrentBed = 4;
mJet.setMuteArray(muteMask[4], false); mJet.setMuteArray(muteMask[4], false);
// mJet.triggerClip(4);
} }
} else if (mHitStreak > 12) { } else if (mHitStreak > 12) {
if (mCurrentBed != 3) { if (mCurrentBed != 3) {
@@ -1016,7 +985,6 @@ public class JetBoyView extends SurfaceView implements SurfaceHolder.Callback {
} }
mCurrentBed = 3; mCurrentBed = 3;
mJet.setMuteArray(muteMask[3], false); mJet.setMuteArray(muteMask[3], false);
// mJet.triggerClip(3);
} }
} else if (mHitStreak > 8) { } else if (mHitStreak > 8) {
if (mCurrentBed != 2) { if (mCurrentBed != 2) {
@@ -1026,7 +994,6 @@ public class JetBoyView extends SurfaceView implements SurfaceHolder.Callback {
mCurrentBed = 2; mCurrentBed = 2;
mJet.setMuteArray(muteMask[2], false); mJet.setMuteArray(muteMask[2], false);
// mJet.triggerClip(2);
} }
} else if (mHitStreak > 4) { } else if (mHitStreak > 4) {
if (mCurrentBed != 1) { if (mCurrentBed != 1) {
@@ -1036,23 +1003,14 @@ public class JetBoyView extends SurfaceView implements SurfaceHolder.Callback {
} }
mJet.setMuteArray(muteMask[1], false); mJet.setMuteArray(muteMask[1], false);
// mJet.triggerClip(1);
mCurrentBed = 1; mCurrentBed = 1;
} }
} }
} }
/*
* try { Log.d(TAG,"onJetEvent: segment =" + segment);
* Log.d(TAG,"onJetEvent(): track =" + track);
* Log.d(TAG,"onJetEvent(): channel =" + channel);
* Log.d(TAG,"onJetEvent(): controller =" + controller);
* Log.d(TAG,"onJetEvent(): value =" + value); } catch(Exception e1) {
* Log.e(TAG,"on Jet Event caught " + e1.toString()); }
*/
} }
private void doAsteroidCreation() { private void doAsteroidCreation() {
// Log.d(TAG, "asteroid created"); // Log.d(TAG, "asteroid created");
@@ -1070,6 +1028,7 @@ public class JetBoyView extends SurfaceView implements SurfaceHolder.Callback {
mDangerWillRobinson.add(_as); mDangerWillRobinson.add(_as);
} }
/** /**
* Used to signal the thread whether it should be running or not. * Used to signal the thread whether it should be running or not.
* Passing true allows the thread to run; passing false will shut it * Passing true allows the thread to run; passing false will shut it
@@ -1087,6 +1046,7 @@ public class JetBoyView extends SurfaceView implements SurfaceHolder.Callback {
} }
} }
/** /**
* returns the current int value of game state as defined by state * returns the current int value of game state as defined by state
* tracking constants * tracking constants
@@ -1099,6 +1059,7 @@ public class JetBoyView extends SurfaceView implements SurfaceHolder.Callback {
} }
} }
/** /**
* Sets the game mode. That is, whether we are running, paused, in the * Sets the game mode. That is, whether we are running, paused, in the
* failure state, in the victory state, etc. * failure state, in the victory state, etc.
@@ -1112,13 +1073,13 @@ public class JetBoyView extends SurfaceView implements SurfaceHolder.Callback {
} }
} }
/** /**
* Sets state based on input, optionally also passing in a text message. * Sets state based on input, optionally also passing in a text message.
* *
* @param state * @param state
* @param message * @param message
*/ */
// TODO - Modeled from lunar lander Determine if best way to do this.
public void setGameState(int state, CharSequence message) { public void setGameState(int state, CharSequence message) {
synchronized (mSurfaceHolder) { synchronized (mSurfaceHolder) {
@@ -1149,23 +1110,24 @@ public class JetBoyView extends SurfaceView implements SurfaceHolder.Callback {
// events in the queue // events in the queue
mEventQueue.clear(); mEventQueue.clear();
// And reset the ket state so we dont think a button is pressed that isn't // And reset the key state so we don't think a button is pressed when it isn't
mKeyContext = null; mKeyContext = null;
} }
} }
} }
/** /**
* Add key press input to the GameEvent queue * Add key press input to the GameEvent queue
*/ */
public boolean doKeyDown(int keyCode, KeyEvent msg) { public boolean doKeyDown(int keyCode, KeyEvent msg) {
mEventQueue.add(new KeyGameEvent(keyCode, false, msg)); mEventQueue.add(new KeyGameEvent(keyCode, false, msg));
return true; return true;
} }
/** /**
* Add key press input to the GameEvent queue * Add key press input to the GameEvent queue
*/ */
@@ -1175,6 +1137,7 @@ public class JetBoyView extends SurfaceView implements SurfaceHolder.Callback {
return true; return true;
} }
/* Callback invoked when the surface dimensions change. */ /* Callback invoked when the surface dimensions change. */
public void setSurfaceSize(int width, int height) { public void setSurfaceSize(int width, int height) {
// synchronized to make sure these all change atomically // synchronized to make sure these all change atomically
@@ -1192,10 +1155,10 @@ public class JetBoyView extends SurfaceView implements SurfaceHolder.Callback {
} }
} }
/** /**
* Pauses the physics update & animation. * Pauses the physics update & animation.
*/ */
//TODO should probably add a pause to the menu button
public void pause() { public void pause() {
synchronized (mSurfaceHolder) { synchronized (mSurfaceHolder) {
if (mState == STATE_RUNNING) if (mState == STATE_RUNNING)
@@ -1206,11 +1169,11 @@ public class JetBoyView extends SurfaceView implements SurfaceHolder.Callback {
if (mJet != null) { if (mJet != null) {
mJet.pause(); mJet.pause();
mJet.release();
} }
} }
} }
/** /**
* Does the work of updating timer * Does the work of updating timer
* *
@@ -1276,27 +1239,21 @@ public class JetBoyView extends SurfaceView implements SurfaceHolder.Callback {
} }
/**
* required JetPlayer method. Informs listener of when a queue segement
* event has been generated.
*
* @param nbSegments
*/
public void onJetNumQueuedSegmentUpdate(int nbSegments) {
Log.i(TAG, "onJetNumQueuedSegmentUpdate(): nbSegments =" + nbSegments);
}
// JET info: JET event listener interface implementation:
/** /**
* required JetPlayer method. A more specific handler. * required OnJetEventListener method. Notifications for queue updates
* *
* @param player * @param player
* @param nbSegments * @param nbSegments
*/ */
public void onJetNumQueuedSegmentUpdate(JetPlayer player, int nbSegments) { public void onJetNumQueuedSegmentUpdate(JetPlayer player, int nbSegments) {
Log.i(TAG, "onJetNumQueuedUpdate(): nbSegs =" + nbSegments); //Log.i(TAG, "onJetNumQueuedUpdate(): nbSegs =" + nbSegments);
} }
// JET info: JET event listener interface implementation:
/** /**
* The method which receives notification from event listener. * The method which receives notification from event listener.
* This is where we queue up events 80 and 82. * This is where we queue up events 80 and 82.
@@ -1314,20 +1271,23 @@ public class JetBoyView extends SurfaceView implements SurfaceHolder.Callback {
public void onJetEvent(JetPlayer player, short segment, byte track, byte channel, public void onJetEvent(JetPlayer player, short segment, byte track, byte channel,
byte controller, byte value) { byte controller, byte value) {
Log.d(TAG, "jet got event " + value); //Log.d(TAG, "jet got event " + value);
//events fire outside the animation thread. This can cause timing issues. //events fire outside the animation thread. This can cause timing issues.
//put in queue for processing by animation thread. //put in queue for processing by animation thread.
mEventQueue.add(new JetGameEvent(player, segment, track, channel, controller, value)); mEventQueue.add(new JetGameEvent(player, segment, track, channel, controller, value));
} }
// JET info: JET event listener interface implementation:
public void onJetPauseUpdate(JetPlayer player, int paused) { public void onJetPauseUpdate(JetPlayer player, int paused) {
Log.i(TAG, "onJetPauseUpdate(): paused =" + paused); //Log.i(TAG, "onJetPauseUpdate(): paused =" + paused);
} }
// JET info: JET event listener interface implementation:
public void onJetUserIdUpdate(JetPlayer player, int userId, int repeatCount) { public void onJetUserIdUpdate(JetPlayer player, int userId, int repeatCount) {
Log.i(TAG, "onJetUserIdUpdate(): userId =" + userId + " repeatCount=" + repeatCount); //Log.i(TAG, "onJetUserIdUpdate(): userId =" + userId + " repeatCount=" + repeatCount);
} }
@@ -1367,9 +1327,6 @@ public class JetBoyView extends SurfaceView implements SurfaceHolder.Callback {
mTimerView.setText(m.getData().getString("text")); mTimerView.setText(m.getData().getString("text"));
//ok so maybe it isn't really a "lose"
//this bit was borrowed from lunar lander and then evolved.
//too close to deadline to mess with now.
if (m.getData().getString("STATE_LOSE") != null) { if (m.getData().getString("STATE_LOSE") != null) {
//mButtonRestart.setVisibility(View.VISIBLE); //mButtonRestart.setVisibility(View.VISIBLE);
mButtonRetry.setVisibility(View.VISIBLE); mButtonRetry.setVisibility(View.VISIBLE);
@@ -1400,6 +1357,7 @@ public class JetBoyView extends SurfaceView implements SurfaceHolder.Callback {
Log.d(TAG, "@@@ done creating view!"); Log.d(TAG, "@@@ done creating view!");
} }
/** /**
* Pass in a reference to the timer view widget so we can update it from here. * Pass in a reference to the timer view widget so we can update it from here.
* *
@@ -1409,15 +1367,13 @@ public class JetBoyView extends SurfaceView implements SurfaceHolder.Callback {
mTimerView = tv; mTimerView = tv;
} }
/** /**
* Standard window-focus override. Notice focus lost so we can pause on * Standard window-focus override. Notice focus lost so we can pause on
* focus lost. e.g. user switches to take a call. * focus lost. e.g. user switches to take a call.
*/ */
@Override @Override
public void onWindowFocusChanged(boolean hasWindowFocus) { public void onWindowFocusChanged(boolean hasWindowFocus) {
Log.d(TAG, "@@@FOCUS CHANGED!");
if (!hasWindowFocus) { if (!hasWindowFocus) {
if (thread != null) if (thread != null)
thread.pause(); thread.pause();
@@ -1425,6 +1381,7 @@ public class JetBoyView extends SurfaceView implements SurfaceHolder.Callback {
} }
} }
/** /**
* Fetches the animation thread corresponding to this LunarView. * Fetches the animation thread corresponding to this LunarView.
* *
@@ -1434,11 +1391,13 @@ public class JetBoyView extends SurfaceView implements SurfaceHolder.Callback {
return thread; return thread;
} }
/* Callback invoked when the surface dimensions change. */ /* Callback invoked when the surface dimensions change. */
public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) { public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
thread.setSurfaceSize(width, height); thread.setSurfaceSize(width, height);
} }
public void surfaceCreated(SurfaceHolder arg0) { public void surfaceCreated(SurfaceHolder arg0) {
// start the thread here so that we don't busy-wait in run() // start the thread here so that we don't busy-wait in run()
// waiting for the surface to be created // waiting for the surface to be created
@@ -1446,6 +1405,7 @@ public class JetBoyView extends SurfaceView implements SurfaceHolder.Callback {
thread.start(); thread.start();
} }
public void surfaceDestroyed(SurfaceHolder arg0) { public void surfaceDestroyed(SurfaceHolder arg0) {
boolean retry = true; boolean retry = true;
thread.setRunning(false); thread.setRunning(false);
@@ -1459,6 +1419,7 @@ public class JetBoyView extends SurfaceView implements SurfaceHolder.Callback {
} }
} }
/** /**
* A reference to the button to start game over. * A reference to the button to start game over.
* *
@@ -1470,6 +1431,7 @@ public class JetBoyView extends SurfaceView implements SurfaceHolder.Callback {
// mButtonRestart = _buttonRestart; // mButtonRestart = _buttonRestart;
} }
//we reuse the help screen from the end game screen. //we reuse the help screen from the end game screen.
public void SetTextView(TextView textView) { public void SetTextView(TextView textView) {
mTextView = textView; mTextView = textView;