Advertisement
Anaryl

ancillary 1

Apr 2nd, 2014
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.12 KB | None | 0 0
  1. //So let's modify our Player Cannon structure a little bit more. Add the following into our PlayerCannon structure.
  2. unsigned int iLeftMovementExtreme;
  3. unsigned int iRightMovementExtreme;
  4. void SetMovementExtremes( unsigned int a_leftExtreme, unsigned int a_RightExtreme )
  5. {
  6. iLeftMovementExtreme = a_leftExtreme;
  7. iRightMovementExtreme = a_RightExtreme;
  8. }
  9.  
  10. void Move( float a_fTimeStep, float a_fSpeed )
  11. {
  12. if( IsKeyDown( iMoveLeftKey ) )
  13. {
  14. x -= a_fTimeStep * a_fSpeed;
  15. if( x < (iLeftMovementExtreme + fWidth*.5f) )
  16. {
  17. x = (iLeftMovementExtreme + fWidth*.5f);
  18. }
  19. }
  20. if( IsKeyDown( iMoveRightKey ) )
  21. {
  22. x -= a_fTimeStep * a_fSpeed;
  23. if( x > (iRightMovementExtreme - fWidth*.5f) )
  24. {
  25. x = (iRightMovementExtreme - fWidth*.5f);
  26. }
  27. }
  28. MoveSprite( iSpriteID, x, y );
  29. }
  30.  
  31.  
  32. /* Ok so we should now have a version of our Space Invaders game that has some functions and a player structure in place of all the global player variables that we previously had. Go ahead and insert these functions in the location we previously had our player movement code, do not forget to set your movement Extreme values. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement