class Player { Vector2D m_LastPosition; Vector2D m_Position; int m_GridSquareX; int m_GridSquareY; float m_Sight; float m_Hearing; float m_Width; float m_Height; float m_HalfWidth; float m_HalfHeight; float m_DistanceTravelled; int m_TravelledCounter; int m_Type; // 0 - look // 1 - listen // 2 - scream void Initialize() { m_Position = new Vector2D(); m_Position.x = 10.f; m_Position.y = (float)SCREEN_HEIGHT - 10.f; m_LastPosition = new Vector2D(); m_LastPosition.Set( m_Position.x, m_Position.y ); m_Width = 12.f; m_Height = 12.f; m_HalfWidth = m_Width / 2.f; m_HalfHeight = m_Height / 2.f; m_Type = 0; m_Sight = 14400.f; //400 for 1 tile sight (20*20) --14400 is 6 tile sight m_Hearing = -10.f; m_DistanceTravelled = 0.f; m_TravelledCounter = 0; } void Update() { //compute current grid square int curCellIndexX = (int)(m_Position.x / GRID.m_CellWidth); int curCellIndexY = (int)(m_Position.y / GRID.m_CellWidth); m_GridSquareX = CapInt( curCellIndexX, 0, GRID.m_NumCellsX - 1 ); m_GridSquareY = CapInt( curCellIndexY, 0, GRID.m_NumCellsY - 1 ); if( GRID.m_Cells[ m_GridSquareY * GRID.m_NumCellsX + m_GridSquareX ].m_Spikey ) { if( GRID.m_Cells[ m_GridSquareY * GRID.m_NumCellsX + m_GridSquareX ].m_SpikesUp ) { ResetToHome(); } } --m_TravelledCounter; if( m_TravelledCounter < 0 ) { m_TravelledCounter = 30; m_DistanceTravelled = 0.f; } } void Draw() { if( m_Type != CURRENT_PLAYER ) { //only draw if we're in viewing distance //Vector2D thisPlayerToCurrent = new Vector2D( PLAYER[CURRENT_PLAYER].m_Position.x - m_Position.x, // PLAYER[CURRENT_PLAYER].m_Position.y - m_Position.y ); //if( !DRAW_ALL && thisPlayerToCurrent.MagnitudeSquared() > PLAYER[CURRENT_PLAYER].m_Sight ) Vector2D thisPlayerToCurrent = new Vector2D( PLAYER[0].m_Position.x - m_Position.x, PLAYER[0].m_Position.y - m_Position.y ); if( !DRAW_ALL && thisPlayerToCurrent.MagnitudeSquared() > PLAYER[0].m_Sight ) { return; } } int redComponent = 0; if( CURRENT_PLAYER == 2 ) { redComponent = 128; } stroke( 255, 255 - redComponent, 255 - redComponent ); fill( 255, 255 - redComponent, 255 - redComponent ); ellipse( m_Position.x, m_Position.y, m_Width, m_Height ); switch( m_Type ) { case 0: { fill( redComponent, 0, 0 ); ellipse( m_Position.x, m_Position.y, m_Width - 2.f, m_Height - 2.f ); break; } case 1: { break; } case 2: { stroke( 255, 0, 0 ); line( m_Position.x - m_HalfWidth, m_Position.y - m_HalfHeight, m_Position.x + m_HalfWidth, m_Position.y + m_HalfHeight ); line( m_Position.x - m_HalfWidth, m_Position.y + m_HalfHeight, m_Position.x + m_HalfWidth, m_Position.y - m_HalfHeight ); break; } } } void Move( float moveX, float moveY ) { m_LastPosition.x = m_Position.x; m_LastPosition.y = m_Position.y; float tempPosX = m_Position.x + moveX; float tempPosY = m_Position.y + moveY; //cap if( tempPosX < 0.f ) { tempPosX = 0.f; } else if( tempPosX > (float)SCREEN_WIDTH ) { tempPosX = (float)SCREEN_WIDTH; } if( tempPosY < 0.f ) { tempPosY = 0.f; } else if( tempPosY > (float)SCREEN_HEIGHT ) { tempPosY = (float)SCREEN_HEIGHT; } //compute projected grid square int curCellIndexX = (int)(tempPosX / GRID.m_CellWidth); int curCellIndexY = (int)(tempPosY / GRID.m_CellWidth); curCellIndexX = CapInt( curCellIndexX, 0, GRID.m_NumCellsX - 1 ); curCellIndexY = CapInt( curCellIndexY, 0, GRID.m_NumCellsY - 1 ); if( GRID.m_Cells[ curCellIndexY * GRID.m_NumCellsX + curCellIndexX ].m_Wall == false ) { m_Position.x = tempPosX; m_Position.y = tempPosY; } //if we've travelled farther than our magic number to create a new sound, do so Vector2D travelled = new Vector2D( m_LastPosition.x - m_Position.x, m_LastPosition.y - m_Position.y ); m_DistanceTravelled += travelled.MagnitudeSquared(); if( m_DistanceTravelled > 40.f && m_TravelledCounter > 0 ) { m_TravelledCounter = 30; m_DistanceTravelled = 0.f; SOUND_MANAGER.AddSoundBurst( m_Position.x, m_Position.y, 100, 1 ); } } void Action() { if( m_Type == 2 ) { SOUND_MANAGER.AddSoundBurst( m_Position.x, m_Position.y, 100, 2 ); } } void ResetToHome() { m_Position.Set( 10.f, (float)SCREEN_HEIGHT - 10.f ); } };