class GridCell { boolean m_Goal; boolean m_InSight; boolean m_Wall; boolean m_FakeWall; boolean m_Breakable; boolean m_Spikey; boolean m_SpikesUp; float m_SpikeCountdown; void Initialize() { m_InSight = false; m_Wall = false; m_FakeWall = false; m_Breakable = false; m_Spikey = false; m_SpikesUp = false; m_SpikeCountdown = random( 30.f, 120.f ); } }; class Grid { int m_ExtentX; int m_ExtentY; int m_NumCellsX; int m_NumCellsY; int m_NumCellsTotal; int m_CellWidth; int m_CellHeight; GridCell [] m_Cells; void Initialize() { m_ExtentX = SCREEN_WIDTH; m_ExtentY = SCREEN_HEIGHT; m_NumCellsX = 20; m_NumCellsY = 20; m_NumCellsTotal = m_NumCellsX * m_NumCellsY; m_CellWidth = m_ExtentX / m_NumCellsX; m_CellHeight = m_ExtentY / m_NumCellsY; m_Cells = new GridCell[m_NumCellsTotal]; int i; for( i = 0; i < m_NumCellsTotal; ++i ) { m_Cells[i] = new GridCell(); m_Cells[i].Initialize(); } //hard set walls int x, y; for( x = 3; x < 5; ++x ) { for( y = 0; y < 3; ++y ) { m_Cells[ y * m_NumCellsX + x ].m_Wall = true; } } for( x = 15; x < 20; ++x ) { for( y = 0; y < 2; ++y ) { m_Cells[ y * m_NumCellsX + x ].m_Wall = true; } } for( x = 7; x < 13; ++x ) { for( y = 2; y < 3; ++y ) { m_Cells[ y * m_NumCellsX + x ].m_Wall = true; } } for( x = 11; x < 13; ++x ) { for( y = 3; y < 8; ++y ) { m_Cells[ y * m_NumCellsX + x ].m_Wall = true; } } for( x = 0; x < 8; ++x ) { for( y = 5; y < 7; ++y ) { m_Cells[ y * m_NumCellsX + x ].m_Wall = true; } } for( x = 15; x < 20; ++x ) { for( y = 4; y < 6; ++y ) { m_Cells[ y * m_NumCellsX + x ].m_Wall = true; } } for( x = 6; x < 8; ++x ) { for( y = 7; y < 12; ++y ) { m_Cells[ y * m_NumCellsX + x ].m_Wall = true; } } for( x = 15; x < 17; ++x ) { for( y = 6; y < 11; ++y ) { m_Cells[ y * m_NumCellsX + x ].m_Wall = true; } } for( x = 15; x < 17; ++x ) { for( y = 13; y < 20; ++y ) { m_Cells[ y * m_NumCellsX + x ].m_Wall = true; } } for( x = 0; x < 2; ++x ) { for( y = 14; y < 16; ++y ) { m_Cells[ y * m_NumCellsX + x ].m_Wall = true; } } for( x = 2; x < 4; ++x ) { for( y = 9; y < 16; ++y ) { m_Cells[ y * m_NumCellsX + x ].m_Wall = true; } } for( x = 6; x < 8; ++x ) { for( y = 15; y < 20; ++y ) { m_Cells[ y * m_NumCellsX + x ].m_Wall = true; } } for( x = 8; x < 13; ++x ) { for( y = 15; y < 17; ++y ) { m_Cells[ y * m_NumCellsX + x ].m_Wall = true; } } for( x = 11; x < 13; ++x ) { for( y = 10; y < 15; ++y ) { m_Cells[ y * m_NumCellsX + x ].m_Wall = true; } } for( x = 1; x < 3; ++x ) { for( y = 5; y < 7; ++y ) { m_Cells[ y * m_NumCellsX + x ].m_FakeWall = true; m_Cells[ y * m_NumCellsX + x ].m_Wall = false; } } for( x = 18; x < 19; ++x ) { for( y = 4; y < 6; ++y ) { m_Cells[ y * m_NumCellsX + x ].m_FakeWall = true; m_Cells[ y * m_NumCellsX + x ].m_Wall = false; } } for( x = 8; x < 10; ++x ) { for( y = 15; y < 17; ++y ) { m_Cells[ y * m_NumCellsX + x ].m_Breakable = true; } } for( x = 15; x < 17; ++x ) { for( y = 6; y < 8; ++y ) { m_Cells[ y * m_NumCellsX + x ].m_Breakable = true; } } for( x = 7; x < 8; ++x ) { for( y = 0; y < 2; ++y ) { m_Cells[ y * m_NumCellsX + x ].m_Spikey = true; } } for( x = 9; x < 10; ++x ) { for( y = 0; y < 2; ++y ) { m_Cells[ y * m_NumCellsX + x ].m_Spikey = true; } } for( x = 11; x < 12; ++x ) { for( y = 0; y < 2; ++y ) { m_Cells[ y * m_NumCellsX + x ].m_Spikey = true; } } for( x = 15; x < 16; ++x ) { for( y = 11; y < 13; ++y ) { m_Cells[ y * m_NumCellsX + x ].m_Spikey = true; } } for( x = 12; x < 13; ++x ) { for( y = 8; y < 10; ++y ) { m_Cells[ y * m_NumCellsX + x ].m_Spikey = true; } } m_Cells[ 378 ].m_Goal = true; } void Update() { int i, j; for( i = 0; i < m_NumCellsX; ++i ) { for( j = 0; j < m_NumCellsY; ++j ) { if( m_Cells[ j * m_NumCellsX + i ].m_Spikey ) { //if the spikes are up, countdown until they need to drop back down if( m_Cells[ j * m_NumCellsX + i ].m_SpikesUp ) { m_Cells[ j * m_NumCellsX + i ].m_SpikeCountdown -= 1.f; if( m_Cells[ j * m_NumCellsX + i ].m_SpikeCountdown < 0.f ) { m_Cells[ j * m_NumCellsX + i ].m_SpikeCountdown = random( 30.f, 120.f ); m_Cells[ j * m_NumCellsX + i ].m_SpikesUp = false; float posX = i*m_CellWidth + m_CellWidth*.5f; float posY = j*m_CellHeight + m_CellHeight*.5f; SOUND_MANAGER.AddSoundBurst( posX, posY, 25, 0 ); } } //if the spikes are down, countdown until they need to pop up else { m_Cells[ j * m_NumCellsX + i ].m_SpikeCountdown -= 1.f; if( m_Cells[ j * m_NumCellsX + i ].m_SpikeCountdown < 0.f ) { m_Cells[ j * m_NumCellsX + i ].m_SpikeCountdown = random( 30.f, 60.f ); m_Cells[ j * m_NumCellsX + i ].m_SpikesUp = true; } } } } } } void Draw() { //save off current player's position //float currentPlayerX = PLAYER[CURRENT_PLAYER].m_Position.x; //float currentPlayerY = PLAYER[CURRENT_PLAYER].m_Position.y; float currentPlayerX = PLAYER[0].m_Position.x; float currentPlayerY = PLAYER[0].m_Position.y; int i, j; for( i = 0; i < m_NumCellsX; ++i ) { for( j = 0; j < m_NumCellsY; ++j ) { //compute distance to current player Vector2D playerToTile = new Vector2D( (i*m_CellWidth + m_CellWidth*.5f) - currentPlayerX, (j*m_CellHeight + m_CellHeight*.5f) - currentPlayerY ); //if the distance to the tile is within our sight, check to see if we should draw it //if( DRAW_ALL || playerToTile.MagnitudeSquared() < PLAYER[CURRENT_PLAYER].m_Sight ) if( DRAW_ALL || playerToTile.MagnitudeSquared() < PLAYER[0].m_Sight ) { //draw walls (even fake walls) if( m_Cells[ j * m_NumCellsX + i ].m_Wall || m_Cells[ j * m_NumCellsX + i ].m_FakeWall ) { int breakableInc = 0; if( m_Cells[ j * m_NumCellsX + i ].m_Breakable ) { breakableInc = 30; } //switch( CURRENT_PLAYER ) //{ // case 0: fill( 128, 128 + breakableInc, 128 ); stroke( 128, 128 + breakableInc, 128 ); break; // case 1: fill( 50, 50 + breakableInc, 50 ); stroke( 50, 50 + breakableInc, 50 ); break; // case 2: fill( 60, 0 + breakableInc, 0 ); stroke( 60, 0 + breakableInc, 0 ); break; //} fill( 128, 128 + breakableInc, 128 ); stroke( 128, 128 + breakableInc, 128 ); rect( i * m_CellWidth, j * m_CellHeight, m_CellWidth, m_CellHeight ); } //draw spikes if they're up else if( m_Cells[ j * m_NumCellsX + i ].m_Spikey && m_Cells[ j * m_NumCellsX + i ].m_SpikesUp ) { //switch( CURRENT_PLAYER ) //{ // case 0: fill( 128 ); stroke( 128 ); break; // case 1: fill( 50, 50, 50 ); stroke( 50, 50, 50 ); break; // case 2: fill( 60, 0, 0 ); stroke( 60, 0, 0 ); break; //} fill( 128 ); stroke( 128 ); ellipse( (i*m_CellWidth + m_CellWidth*.5f), (j*m_CellHeight + m_CellHeight*.5f), 6.f, 6.f ); } } if( m_Cells[ j * m_NumCellsX + i ].m_Goal ) { fill( 160, 160, 0 ); stroke( 160, 160, 0 ); rect( i * m_CellWidth, j * m_CellHeight, m_CellWidth, m_CellHeight ); } } } } };