class Black { Vector2D m_Position; Vector2D m_OffsetVector; float m_Width; float m_Height; float m_Offset; void Initialize() { m_Height = m_Width = random( BLACK_MIN_SIZE, BLACK_MAX_SIZE ); m_Position = new Vector2D(); m_OffsetVector = new Vector2D(); Reset(); } void Reset() { m_OffsetVector.x = random( -1.f, 1.f ); m_OffsetVector.y = random( -1.f, 1.f ); m_OffsetVector.Normalize(); m_Offset = ((m_Width - BLACK_MIN_SIZE) / (BLACK_MAX_SIZE - BLACK_MIN_SIZE)) * BLACK_SPACING; m_Position.x = SCREEN_HALF_WIDTH + m_OffsetVector.x * (m_Offset + HUD.gameTimer); m_Position.y = SCREEN_HALF_HEIGHT + m_OffsetVector.y * (m_Offset + HUD.gameTimer); } void Update() { //update position m_Position.x = SCREEN_HALF_WIDTH + m_OffsetVector.x * (m_Offset + HUD.gameTimer); m_Position.y = SCREEN_HALF_HEIGHT + m_OffsetVector.y * (m_Offset + HUD.gameTimer); } void Draw() { stroke( 0, 0, 0 ); fill( 0, 0, 0 ); rect( m_Position.x, m_Position.y, m_Width, m_Height ); } }; class Color { Vector2D m_Position; Vector2D m_Direction; Vector2D m_Forces; float m_Width; float m_Height; float m_HalfWidth; float m_HalfHeight; boolean m_Used; int m_ColorIndex; int m_UniqueID; float m_SizeScale; boolean m_Selected; int m_SelectedFrame; boolean m_HoverSelected; boolean m_Changed; void Initialize() { float minSize = 20.f; float maxSize = 30.f; m_Height = m_Width = random( minSize, maxSize ); m_HalfHeight = m_HalfWidth = m_Width * .5f; m_Forces = new Vector2D( 0.f, 0.f ); m_Position = new Vector2D(); m_Direction = new Vector2D(); Reset(); } void Reset() { m_Used = false; m_Selected = false; m_HoverSelected = false; m_Changed = false; m_Position.x = random( 0.f, SCREEN_WIDTH - m_Width ); m_Position.y = random( 0.f, SCREEN_HEIGHT - m_Height ); m_Direction.x = SCREEN_WIDTH*.5f - m_Position.x; m_Direction.y = SCREEN_HEIGHT*.5f - m_Position.y; m_Direction.Normalize(); m_Direction.Multiply( .25f ); m_SizeScale = 1.f; GetRandomColor(); } void Update() { if( m_Used ) { //if we're the same color as the background, destroy us if( m_ColorIndex == HUD.colorQueue[5] ) { TurnOff(); HUD.AddForce( 5.f ); return; } m_Position.Add( m_Forces ); m_Position.Add( m_Direction ); m_Position.x = CapFloat( m_Position.x, 0.f, (float)SCREEN_WIDTH ); m_Position.y = CapFloat( m_Position.y, 0.f, (float)SCREEN_HEIGHT ); m_Forces.Zero(); m_SizeScale += .02f; if( m_SizeScale >= 1.f ) { m_SizeScale = 1.f; } if( m_Selected || m_HoverSelected ) { ++m_SelectedFrame; if( m_SelectedFrame > 30 ) { m_SelectedFrame = 0; } } } } void Draw() { if( m_Used ) { stroke( GAME_COLORS[ m_ColorIndex ] ); fill( GAME_COLORS[ m_ColorIndex ] ); rect( m_Position.x, m_Position.y, m_Width*m_SizeScale, m_Height*m_SizeScale ); if( m_Selected || m_HoverSelected || m_Changed ) { stroke( BACKGROUND_COLOR ); fill( BACKGROUND_COLOR ); float offset = 5.f + (float)m_SelectedFrame / 30.f; float doubleOffset = offset * 2.f; rect( m_Position.x + offset, m_Position.y + offset, (m_Width-doubleOffset)*m_SizeScale, (m_Height-doubleOffset)*m_SizeScale ); //turn off every frame m_HoverSelected = false; } } } void AddToForces( float X, float Y ) { if( m_UniqueID == 0 ) { return; } m_Forces.x += X; m_Forces.y += Y; } void TurnOff() { m_Used = false; m_Selected = false; m_HoverSelected = false; m_Changed = false; } void TurnOn() { Reset(); m_Used = true; m_SizeScale = 0.f; GetRandomColor(); } void GetRandomColor() { int newIndex = int( random( 1, 5 ) ); while( newIndex == 3 || newIndex == 5 ) { newIndex = int( random( 1, 5 ) ); } m_ColorIndex = newIndex; } }; void AddNewSquare() { int i; for( i = 0; i < NUM_COLORS; ++i ) { if( COLORS[i].m_Used == false ) { COLORS[i].TurnOn(); return; } } } int CombineColors( int colorA, int colorB ) { if( colorA == 3 || colorB == 3 || colorA > 4 || colorB > 4 ) { return( -1 ); } int returnIndex = colorA; returnIndex |= colorB; return( returnIndex ); }