Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Old UpdateGameState() function with movement functions inside.
- // Trying to replace below function using the arbitray keys (IsKeyDown A ) with the functions in the struct - entire question at http://pastebin.com/C329ueqM
- void UpdateGameState()
- {
- //\==================================================================================
- //\ Player movement handling code
- //\==================================================================================
- if( IsKeyDown( 'A' ) )
- {
- fPlayerX -= 2.f;
- if( fPlayerX < (fPlayerWidth*.5f) )
- {
- fPlayerX = (fPlayerWidth*.5f);
- }
- }
- if( IsKeyDown( 'D' ) )
- {
- fPlayerX += 2.f;
- if( fPlayerX > (iScreenWidth - (fPlayerWidth*.5f)) )
- {
- fPlayerX = iScreenWidth - (fPlayerWidth*.5f);
- }
- }
- MoveSprite( iPlayerCannon, player.fWidth, player.fHeight); //rk020414 have updated gamestate mostly to reflect struct implmntnt
- DrawSprite( iPlayerCannon );
- for( int i = 0; i < 15; ++i )
- {
- DrawSprite(alienShips[i]);
- }
- DrawLine( 0, 40, iScreenWidth, 40, SColour( 0x00, 0xFC, 0x00, 0xFF ));
- SetFont( pInvadersFont );
- DrawString( pkScore1, iScreenWidth * 0.025f, iScreenHeight - 2 );
- DrawString( pkHiScore, iScreenWidth * 0.425f, iScreenHeight - 2 );
- DrawString( pkScore2, iScreenWidth * 0.8f, iScreenHeight - 2 );
- DrawString( pkCredit, iScreenWidth * 0.7f, 38 );
- }
- // existing main loop
- int main( int argc, char* argv[] )
- {
- //\ Lets initialise the AIE Framework and give the window it creates an appropriate title
- Initialise( iScreenWidth, iScreenHeight, false, "Space Invaders" );
- SetBackgroundColour( SColour( 0x00, 0x00, 0x00, 0xFF ) );
- AddFont( pInvadersFont );
- iArcadeMarquee = CreateSprite( "./images/Space-Invaders-Marquee.png", iScreenWidth, iScreenHeight, true );
- MoveSprite( iArcadeMarquee, iScreenWidth * 0.5f, iScreenHeight * 0.5f );
- //\Below calls for the player strcture. That's right in space invaders we control a cannon
- //\Referencing player attributes from player strcture
- iPlayerCannon = CreateSprite( "./images/cannon.png", fPlayerWidth, fPlayerHeight, true ); //need this to create the cannon
- //not showing the cannon on the right Y axis or responding to move but need to upate the gamestateupdate for that to happen rk020414
- player.SetSize( 64.f, 32.f ); // calliung function with this code
- player.SetMovementKeys( 'A', 'D' );
- player.iSpriteID = CreateSprite( "./images/cannon.png", player.fWidth, player.fHeight, true );
- player.x = iScreenWidth * 0.5f;
- player.y = 80.f;
- float fEnemyX = iScreenWidth * 0.2f;
- float fEnemyY = iScreenHeight * 0.7f;
- for( int i = 0; i < 15; ++i )
- {
- alienShips[i] = CreateSprite( "./images/invaders/invaders_1_00.png", fPlayerWidth, fPlayerHeight, true );
- MoveSprite( alienShips[i], fEnemyX, fEnemyY );
- fEnemyX += 0.12 * iScreenWidth;
- if( fEnemyX > iScreenWidth * 0.8f)
- {
- fEnemyX = iScreenWidth * 0.2f;;
- fEnemyY -= 0.08 * iScreenHeight;
- }
- }
- GAMESTATES eCurrentState = eMAIN_MENU;
- do
- {
- ClearScreen();
- float fDeltaT = GetDeltaTime();
- switch (eCurrentState )
- {
- case eMAIN_MENU:
- UpdateMainMenu();
- if( IsKeyDown( KEY_ENTER ) )
- {
- eCurrentState = eGAMEPLAY;
- }
- break;
- case eGAMEPLAY:
- UpdateGameState();
- if( IsKeyDown( KEY_ESCAPE ) )
- {
- eCurrentState = eMAIN_MENU;
- }
- break;
- default:
- break;
- }
- } while ( FrameworkUpdate() == false );
- DestroySprite(iPlayerCannon);
- DestroySprite(iArcadeMarquee);
- Shutdown();
- return 0;
- }
- /// Entire main (they have not introduced project splitting yet in this tutorial)
- http://pastebin.com/YCHHrgV2
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement