class HeadsUpDisplay { int [] colorQueue; int queueSpeed; int timeUntilNextColor; float blackSpeed; float blackForce; float gameTimer; void Initialize() { int i; colorQueue = new int[10]; for( i = 0; i < 10; ++i ) { GetNewColorIndex( i ); } Reset(); } void Reset() { blackSpeed = .5f; blackForce = 0.f; gameTimer = GAME_TIMER_LENGTH; queueSpeed = 120; timeUntilNextColor = queueSpeed; } void Update() { //update color queue --timeUntilNextColor; if( timeUntilNextColor <= 0 ) { timeUntilNextColor = queueSpeed; int i; //shift all colors down the line for( i = 1; i < 10; ++i ) { colorQueue[i-1] = colorQueue[i]; } //add a new color at the end of the line GetNewColorIndex( 9 ); } //update game timer gameTimer -= blackSpeed; gameTimer += blackForce; if( gameTimer < 0 ) { RESET(); } else if( gameTimer > GAME_TIMER_LENGTH ) { blackForce = 0.f; gameTimer = GAME_TIMER_LENGTH; } //decay black force applied to game timer blackForce *= .9f; if( blackForce < .05f ) { blackForce = 0.f; } } void Draw() { float halfWidth = SCREEN_WIDTH * .5f; //draw border stroke( 0 ); fill( 0, 0, 0 ); rect( 0.f, 0.f, SCREEN_WIDTH, 40.f ); rect( 0.f, SCREEN_HEIGHT - 40.f, SCREEN_WIDTH, 40.f ); rect( 0.f, 0.f, 40.f, SCREEN_HEIGHT ); rect( SCREEN_WIDTH - 40.f, 0.f, 40.f, SCREEN_HEIGHT ); //draw beam float currentColorRatio = 1.f - (float)timeUntilNextColor / (float)queueSpeed; float currentColorPosX = halfWidth - (currentColorRatio*200.f); stroke( GAME_COLORS[ colorQueue[3] ] ); fill( GAME_COLORS[ colorQueue[3] ] ); rect( currentColorPosX - 400.f, SCREEN_HEIGHT - 35.f, 200.f, 20.f ); stroke( GAME_COLORS[ colorQueue[4] ] ); fill( GAME_COLORS[ colorQueue[4] ] ); rect( currentColorPosX - 200.f, SCREEN_HEIGHT - 35.f, 200.f, 20.f ); stroke( GAME_COLORS[ colorQueue[5] ] ); fill( GAME_COLORS[ colorQueue[5] ] ); rect( currentColorPosX, SCREEN_HEIGHT - 35.f, 200.f, 20.f ); stroke( GAME_COLORS[ colorQueue[6] ] ); fill( GAME_COLORS[ colorQueue[6] ] ); rect( currentColorPosX + 200.f, SCREEN_HEIGHT - 35.f, 200.f, 20.f ); stroke( GAME_COLORS[ colorQueue[7] ] ); fill( GAME_COLORS[ colorQueue[7] ] ); rect( currentColorPosX + 400.f, SCREEN_HEIGHT - 35.f, 200.f, 20.f ); //draw beam locks float beamLockWidth = 10.f; float beamLockHeight = 10.f; stroke( GAME_COLORS[ colorQueue[3] ] ); fill( GAME_COLORS[ colorQueue[3] ] ); rect( currentColorPosX - 200.f, SCREEN_HEIGHT - 30.f, beamLockWidth, beamLockHeight ); stroke( GAME_COLORS[ colorQueue[4] ] ); fill( GAME_COLORS[ colorQueue[4] ] ); rect( currentColorPosX - 210.f, SCREEN_HEIGHT - 30.f, beamLockWidth, beamLockHeight ); rect( currentColorPosX + 0.f, SCREEN_HEIGHT - 30.f, beamLockWidth, beamLockHeight ); stroke( GAME_COLORS[ colorQueue[5] ] ); fill( GAME_COLORS[ colorQueue[5] ] ); rect( currentColorPosX - 10.f, SCREEN_HEIGHT - 30.f, beamLockWidth, beamLockHeight ); rect( currentColorPosX + 200.f, SCREEN_HEIGHT - 30.f, beamLockWidth, beamLockHeight ); stroke( GAME_COLORS[ colorQueue[6] ] ); fill( GAME_COLORS[ colorQueue[6] ] ); rect( currentColorPosX + 190.f, SCREEN_HEIGHT - 30.f, beamLockWidth, beamLockHeight ); rect( currentColorPosX + 400.f, SCREEN_HEIGHT - 30.f, beamLockWidth, beamLockHeight ); stroke( GAME_COLORS[ colorQueue[7] ] ); fill( GAME_COLORS[ colorQueue[7] ] ); rect( currentColorPosX + 390.f, SCREEN_HEIGHT - 30.f, beamLockWidth, beamLockHeight ); //draw triangle stroke( 100 ); fill( 100 ); triangle( halfWidth - 30.f, SCREEN_HEIGHT - 5.f, halfWidth + 30.f, SCREEN_HEIGHT - 5.f, halfWidth , SCREEN_HEIGHT - 55.f ); stroke( GAME_COLORS[ colorQueue[5] ] ); fill( GAME_COLORS[ colorQueue[5] ] ); triangle( halfWidth - 21.5f, SCREEN_HEIGHT - 9.f, halfWidth + 21.5f, SCREEN_HEIGHT - 9.f, halfWidth , SCREEN_HEIGHT - 45.f ); } void GetNewColorIndex( int queueIndex ) { if( queueIndex == 0 ) { int newIndex = int( random( 3, 7 ) ); while( newIndex == 4 || newIndex == 7 ) { newIndex = int( random( 3, 7 ) ); } colorQueue[0] = newIndex; } else { int newIndex = int( random( 3, 7 ) ); while( newIndex == 4 || newIndex == 7 || newIndex == colorQueue[queueIndex-1] ) { newIndex = int( random( 3, 7 ) ); } colorQueue[queueIndex] = newIndex; } } void AddForce( float Force ) { blackForce = Force; } }