// Animation.cpp: implementation of the CAnimation class. // ////////////////////////////////////////////////////////////////////// #include "stdafx.h" #include "Fantan.h" #include "Animation.h" #include "MyBitmap.h" #ifdef _DEBUG #undef THIS_FILE static char THIS_FILE[]=__FILE__; #define new DEBUG_NEW #endif ////////////////////////////////////////////////////////////////////// // Construction/Destruction ////////////////////////////////////////////////////////////////////// CAnimation::CAnimation(int nBitmaps, char *filePrefix, int positions[][2], CWnd *pWnd, COLORREF transColor) : m_nBitmaps(nBitmaps), m_state(0), m_pWnd(pWnd), m_transColor(transColor) { int i; CString filename; CMyBitmap *ptr; BITMAP bm; m_positions = new CRect[nBitmaps]; for (i=0; iLoadBitmapFromFile(filename)) { m_bitmaps.push_back(ptr); ptr->GetBitmap(&bm); m_positions[i] = CRect(positions[i][0], positions[i][1], positions[i][0]+bm.bmWidth, positions[i][1]+bm.bmHeight); } else delete ptr; } } CAnimation::~CAnimation() { int i; delete m_positions; for (i=0; iDrawSprite(pDC, m_transColor, m_positions[m_state].left, m_positions[m_state].top); } void CAnimation::step(bool reset) { m_pWnd->InvalidateRect(m_positions[m_state], FALSE); if (reset) m_state = 0; else m_state = (m_state+1) % m_nBitmaps; m_pWnd->InvalidateRect(m_positions[m_state], FALSE); }