Advertisement
Vchavauty

Animation.cpp

Jul 26th, 2013
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.34 KB | None | 0 0
  1. #include "Animation.h"
  2.  
  3. Animation::Animation()
  4. {
  5.     FrameRate = 70;
  6.     MaxFrames = 8;
  7.     CurrentFrame = 0;
  8.     FrameTA = 1;
  9.     OldTime = 0;
  10.     Direction = 1;
  11.     MAX_X = 1000;
  12.     MAX_Y = 700;
  13.  
  14. }
  15. void Animation::SetCurrentFrame(int Frame)
  16. {
  17.     CurrentFrame = Frame;
  18. }
  19. void Animation::SetFrameRate(int Rate)
  20. {
  21.     FrameRate = Rate;
  22. }
  23. int Animation::GetCurrentFrame()
  24. {
  25.     return CurrentFrame;
  26. }
  27.  
  28. void Animation::Anima()
  29. {
  30.     if(Working)
  31.     {
  32.         if(OldTime + FrameRate > SDL_GetTicks())
  33.             return;
  34.         OldTime = SDL_GetTicks();
  35.  
  36.         if(Direction == 0)
  37.         {
  38.             if(CurrentFrame > MaxFrames)
  39.                 CurrentFrame = 0;
  40.             else
  41.                 CurrentFrame = CurrentFrame + FrameTA;
  42.  
  43.             if(PosX > MAX_X)
  44.             {
  45.                 PosX = 0;
  46.             }
  47.             else
  48.                 PosX = PosX + 5;
  49.  
  50.  
  51.         }
  52.         else if(Direction == 1)
  53.         {
  54.             if(CurrentFrame < 0)
  55.                 CurrentFrame = MaxFrames;
  56.             else
  57.                 CurrentFrame = CurrentFrame + FrameTA;
  58.  
  59.             if(PosX < 0)
  60.                 PosX = MAX_X;
  61.             else
  62.                 PosX = PosX - 3;
  63.         }
  64.  
  65.     }
  66.  
  67. }
  68.  
  69. int Animation::retrievePosX()
  70. {
  71.     return PosX;
  72. }
  73. int Animation::retrievePosY()
  74. {
  75.     return PosY;
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement