Advertisement
shout1232131

Untitled

Jul 8th, 2017
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.62 KB | None | 0 0
  1. /*Written 2017 by Michał Przekota.
  2. To the extent possible under law, the author(s) have dedicated all copyright to men who want to help with the problem.
  3. */
  4. #pragma once
  5. #include "Animation.h"
  6.  
  7. class SpriteSheetAnimation : public Animation
  8. {
  9. public:
  10.     SpriteSheetAnimation();
  11.     ~SpriteSheetAnimation();
  12.  
  13.     void Draw(Animation &a,SDL_Renderer *renderer);
  14.     void Update(Animation &a);
  15.  
  16. private:
  17.     Uint32 ticks, sprite;
  18.  
  19.     int frameCounter, switchFrame;
  20. };
  21.  
  22. /*Written 2017 by Michał Przekota.
  23. To the extent possible under law, the author(s) have dedicated all copyright to men who want to help with the problem.
  24. */
  25. #ifndef DEBUG
  26. #define DEBUG
  27.  
  28. #include "SpriteSheetAnimation.h"
  29.  
  30. SpriteSheetAnimation::SpriteSheetAnimation()
  31. {
  32.     frameCounter = 0;
  33.     switchFrame = 100;
  34. }
  35. SpriteSheetAnimation::~SpriteSheetAnimation()
  36. {
  37. }
  38.  
  39. void SpriteSheetAnimation::Draw(Animation &a, SDL_Renderer *renderer)
  40. {
  41.    
  42. }
  43.  
  44. void SpriteSheetAnimation::Update(Animation &a)
  45. {
  46.     if (a.getActive())
  47.     {
  48.         frameCounter++;
  49.  
  50.         ticks = SDL_GetTicks();
  51.         sprite = (ticks*6/1000) % 4;
  52.  
  53.         if (frameCounter >= switchFrame)
  54.         {
  55.             frameCounter = 0;
  56.             a.CurrentFrame().first++;
  57.  
  58.             if (a.CurrentFrame().first * a.FrameDimentions().first >= a.Image().getWidth())
  59.             {
  60.                 a.CurrentFrame().first = 0;
  61.             }
  62.         }
  63.     }
  64.     else
  65.     {
  66.         frameCounter = 0;
  67.         a.CurrentFrame().first = 1;
  68.         sprite = 1;
  69.     }
  70.  
  71.     a.GetSourceRect().x = a.FrameDimentions().first * sprite;
  72.     a.GetSourceRect().y = a.CurrentFrame().second *a.FrameDimentions().second;
  73.     a.GetSourceRect().w = a.FrameDimentions().first;
  74.     a.GetSourceRect().h = a.FrameDimentions().second;
  75. }
  76.  
  77. #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement