Advertisement
Anaryl

ancillery 3

Apr 2nd, 2014
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.61 KB | None | 0 0
  1. // Old UpdateGameState() function with movement functions inside.
  2.  
  3. // Trying to replace below function using the arbitray keys (IsKeyDown A ) with the functions in the struct -  entire question at http://pastebin.com/C329ueqM
  4.  
  5. void UpdateGameState()
  6. {
  7.     //\==================================================================================
  8.     //\ Player movement handling code
  9.     //\==================================================================================
  10.     if( IsKeyDown( 'A' ) )
  11.     {
  12.         fPlayerX -= 2.f;
  13.         if( fPlayerX < (fPlayerWidth*.5f) )
  14.         {
  15.             fPlayerX = (fPlayerWidth*.5f);
  16.         }
  17.     }
  18.  
  19.     if( IsKeyDown( 'D' ) )
  20.     {
  21.         fPlayerX += 2.f;
  22.         if( fPlayerX > (iScreenWidth - (fPlayerWidth*.5f)) )
  23.         {
  24.             fPlayerX = iScreenWidth - (fPlayerWidth*.5f);
  25.         }
  26.     }
  27.  
  28.  
  29.     MoveSprite( iPlayerCannon, player.fWidth, player.fHeight); //rk020414 have updated gamestate mostly to reflect struct implmntnt
  30.     DrawSprite( iPlayerCannon );
  31.        
  32.     for( int i = 0; i < 15; ++i )
  33.     {
  34.         DrawSprite(alienShips[i]);
  35.     }
  36.  
  37.     DrawLine( 0, 40, iScreenWidth, 40, SColour( 0x00, 0xFC, 0x00, 0xFF ));
  38.    
  39.  
  40.     SetFont( pInvadersFont );
  41.     DrawString( pkScore1,   iScreenWidth * 0.025f,  iScreenHeight - 2 );
  42.     DrawString( pkHiScore,  iScreenWidth * 0.425f,  iScreenHeight - 2 );
  43.     DrawString( pkScore2,   iScreenWidth * 0.8f,    iScreenHeight - 2 );
  44.     DrawString( pkCredit,   iScreenWidth * 0.7f,    38 );
  45.  
  46.    
  47. }
  48.  
  49.  
  50. // existing main loop
  51.  
  52.  
  53. int main( int argc, char* argv[] )
  54. {  
  55.     //\ Lets initialise the AIE Framework and give the window it creates an appropriate title
  56.     Initialise( iScreenWidth, iScreenHeight, false, "Space Invaders" );
  57.     SetBackgroundColour( SColour( 0x00, 0x00, 0x00, 0xFF ) );
  58.     AddFont( pInvadersFont );
  59.  
  60.     iArcadeMarquee = CreateSprite( "./images/Space-Invaders-Marquee.png", iScreenWidth, iScreenHeight, true );
  61.     MoveSprite( iArcadeMarquee, iScreenWidth * 0.5f, iScreenHeight * 0.5f );
  62.  
  63.     //\Below calls for the player strcture. That's right in space invaders we control a cannon
  64.     //\Referencing player attributes from player strcture
  65.  
  66.     iPlayerCannon = CreateSprite( "./images/cannon.png", fPlayerWidth, fPlayerHeight, true ); //need this to create the cannon
  67.     //not showing the cannon on the right Y axis or responding to move but need to upate the gamestateupdate for that to happen rk020414
  68.  
  69.  
  70.     player.SetSize( 64.f, 32.f ); // calliung function with this code
  71.     player.SetMovementKeys( 'A', 'D' );
  72.     player.iSpriteID = CreateSprite( "./images/cannon.png", player.fWidth, player.fHeight, true );
  73.     player.x =  iScreenWidth * 0.5f;
  74.     player.y =  80.f;
  75.    
  76.     float fEnemyX = iScreenWidth * 0.2f;
  77.     float fEnemyY = iScreenHeight * 0.7f;
  78.     for( int i = 0; i < 15; ++i )
  79.     {
  80.         alienShips[i] = CreateSprite( "./images/invaders/invaders_1_00.png",  fPlayerWidth, fPlayerHeight, true );
  81.         MoveSprite( alienShips[i], fEnemyX, fEnemyY );
  82.         fEnemyX += 0.12 * iScreenWidth;
  83.         if( fEnemyX > iScreenWidth * 0.8f)
  84.         {
  85.                 fEnemyX = iScreenWidth * 0.2f;;
  86.                 fEnemyY -= 0.08 * iScreenHeight;
  87.         }
  88.  
  89.     }
  90.  
  91.     GAMESTATES eCurrentState = eMAIN_MENU;
  92.     do
  93.     {
  94.         ClearScreen();
  95.         float fDeltaT = GetDeltaTime();
  96.         switch (eCurrentState )
  97.         {
  98.         case eMAIN_MENU:
  99.             UpdateMainMenu();
  100.             if( IsKeyDown( KEY_ENTER ) )
  101.             {
  102.                 eCurrentState = eGAMEPLAY;
  103.             }
  104.             break;
  105.         case eGAMEPLAY:
  106.             UpdateGameState();
  107.             if( IsKeyDown( KEY_ESCAPE ) )
  108.             {
  109.                 eCurrentState = eMAIN_MENU;
  110.             }
  111.             break;
  112.         default:
  113.             break;
  114.         }  
  115.     } while ( FrameworkUpdate() == false );
  116.    
  117.     DestroySprite(iPlayerCannon);
  118.     DestroySprite(iArcadeMarquee);
  119.     Shutdown();
  120.  
  121.     return 0;
  122. }
  123.  
  124.  
  125.  
  126. /// Entire main (they have not introduced project splitting yet in this tutorial)
  127.  
  128. http://pastebin.com/YCHHrgV2
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement