Recent Posts
PHP | 14 sec ago
PHP | 19 sec ago
None | 26 sec ago
XML | 1 min ago
XML | 1 min ago
XML | 1 min ago
None | 1 min ago
None | 1 min ago
Ada | 1 min ago
None | 2 min ago
Sitereport
Find cool info about any domain on the internet?
visit sitereport
Free Subdomains
Want a pastebin.com sub-domain for your community?
learn more...
What is pastebin?
Pastebin is a website that hosts all your text & code on dedicated servers for easy sharing.
learn more...
Learn a little bit about the new Pastebin.com on our help page. hide message
By Gabor Szauer on the 4th of Jul 2009 05:22:33 AM Download | Raw | Embed | Report
  1. // Author: Gabor Szauer
  2. //         http://gaborszauer.com
  3. // Last Updated: July 3, 2009
  4. // Changelog:
  5. //         http://pastebin.com/f125cefeb
  6. //         http://pastebin.com/f5f35c041
  7. // Dependencies:
  8. //         http://pastebin.com/f19b4b3d8
  9. //         http://pastebin.com/f23b75420
  10.  
  11. #ifndef H_SPRITE
  12. #define H_SPRITE
  13.  
  14. #include "Bitmap.h"
  15. #include "Vector.h"
  16.  
  17. #define _SECONDS(x) (x*1000)
  18.  
  19. class Sprite : public Bitmap {
  20. private:
  21.         Sprite(const Sprite& rSprite) {}
  22. protected:
  23.         int nWidth; // Width of view window
  24.         int nHeight; // Height of view window
  25.         unsigned int nTickUpdateCount; // Update every x milliseconds
  26.         int nAnim; // What animation group to display
  27.         int nFrame; // Current Frame
  28.         POINT pPos; // Position of the view window
  29.         DWORD dwLastTick; // Keep track of the animation timer
  30.         Vector<Vector<RECT>*> vAnimation;
  31.  
  32.         void SetToNull() {
  33.                 Bitmap::SetToNull();
  34.                 nWidth = 0;
  35.                 nHeight = 0;
  36.                 pPos.x = 0;
  37.                 pPos.y = 0;
  38.                 nFrame = 0;
  39.                 nAnim = -1;
  40.                 nTickUpdateCount = 0;
  41.                 nFrame = 0;
  42.         }
  43.         bool IsNull() {
  44.                 return (
  45.                         Bitmap::IsNull() &&
  46.                         nWidth == 0 &&
  47.                         nHeight == 0 &&
  48.                         pPos.x == 0 &&
  49.                         pPos.y == 0 &&
  50.                         nFrame == 0 &&
  51.                         nAnim == -1 &&
  52.                         nTickUpdateCount == 0 &&
  53.                         nFrame == 0
  54.                         );
  55.         }
  56. public:
  57.         HWND hWnd;
  58.         void Destroy() {               
  59.                 for (int i = 0; i < vAnimation.Size(); ++i) {
  60.                         (*vAnimation[i]).Clear();
  61.                         delete vAnimation[i];
  62.                 }
  63.                 vAnimation.Clear();
  64.                 Bitmap::Destroy();
  65.                 SetToNull();
  66.         }
  67.  
  68.         ~Sprite() {
  69.                 if (!IsNull()) {
  70.                         this->Destroy();
  71.                 }
  72.         }
  73.  
  74.         Sprite() {
  75.                 SetToNull();
  76.                 Sync();
  77.         }
  78.  
  79.         void Sync() {
  80.                 dwLastTick = GetTickCount();
  81.         }
  82.  
  83.         void SetAnimation(int rnAnim = 0) {
  84.                 nAnim = rnAnim;
  85.                 nFrame = 0;
  86.         }
  87.  
  88.         void SetUpdateCount(int rnCount) {
  89.                 nTickUpdateCount = rnCount;
  90.         }
  91.  
  92.         void SetWidth(int rnWidth) {
  93.                 nWidth = rnWidth;
  94.         }
  95.  
  96.         void SetHeight(int rnHeight) {
  97.                 nHeight = rnHeight;
  98.         }
  99.  
  100.         void SetDimentions(int rnWidth, int rnHeight) {
  101.                 nWidth = rnWidth;
  102.                 nHeight = rnHeight;
  103.         }
  104.  
  105.         void SetPosition(int rnX, int rnY) {
  106.                 pPos.x = rnX;
  107.                 pPos.y = rnY;
  108.         }
  109.  
  110.         int CreateAnimation() {
  111.                 Vector<RECT>* vNewAnimation = new Vector<RECT>;
  112.                 vAnimation.Append(vNewAnimation);
  113.  
  114.                 return vAnimation.Size() - 1;
  115.         }
  116.  
  117.         void SetAnimatedRegion(int nAnimIndex, RECT &rRect) {
  118.                 (*vAnimation[nAnimIndex]).Append(rRect);
  119.         }
  120.  
  121.         void Flush(HDC hdcDisplay, int rnX, int rnY) {
  122.                 UpdateAnimation();
  123.                 BitBlt(hdcDisplay, rnX, rnY, nWidth, nHeight, hdcBitmap, pPos.x, pPos.y, SRCCOPY);
  124.         }
  125.  
  126.         void TransparentFlush(HDC hdcDisplay, int rnX, int rnY, UINT uiColorToExclude = RGB(255, 0, 255)) {
  127.                 UpdateAnimation();
  128.                 TransparentBlt(hdcDisplay, rnX, rnY, nWidth, nHeight, hdcBitmap, pPos.x, pPos.y, nWidth, nHeight, uiColorToExclude);
  129.         }
  130.  
  131.         void UpdateAnimation() {
  132.                 if (nAnim == -1)
  133.                         return;
  134.                 if (GetTickCount() - dwLastTick >= nTickUpdateCount) {
  135.                         if (++nFrame == (*vAnimation[nAnim]).Size()) {
  136.                                 nFrame = 0;
  137.                         }
  138.                         nWidth = (*vAnimation[nAnim])[nFrame].right - (*vAnimation[nAnim])[nFrame].left;
  139.                         nHeight = (*vAnimation[nAnim])[nFrame].bottom - (*vAnimation[nAnim])[nFrame].top;
  140.                         pPos.x = (*vAnimation[nAnim])[nFrame].left;
  141.                         pPos.y = (*vAnimation[nAnim])[nFrame].top;
  142.                         dwLastTick = GetTickCount();
  143.                 }
  144.         }
  145. };
  146.  
  147. #endif
Submit a correction or amendment below. Make A New Post
To highlight particular lines, prefix each line with @h@
Syntax highlighting:
Post expiration:
Post exposure:
Name / Title:
Email: