cSprite.cpp
上传用户:sycq158
上传日期:2008-10-22
资源大小:15361k
文件大小:2k
- // CMAIN LIB - APPLICATION AND DIRECT WRAPPER
- //
- // Written by Mauricio Teichmann Ritter
- //
- // Copyright (C) 2002, Brazil. All rights reserved.
- //
- //
- // cSprite.cpp: implementation of the cSprite class.
- //
- //////////////////////////////////////////////////////////////////////
- #include "stdafx.h"
- #include "cSprite.h"
- //////////////////////////////////////////////////////////////////////
- // Construction/Destruction
- //////////////////////////////////////////////////////////////////////
- cSprite::cSprite()
- {
- }
- cSprite::~cSprite()
- {
- }
- void cSprite::Destroy()
- {
- m_surfTile.Destroy();
- }
- BOOL cSprite::Draw(LPDIRECTDRAWSURFACE7 lpDest, int iDestX, int iDestY, BOOL bAdvance, int iSrcX, int iSrcY, int iWidth, int iHeight)
- {
- int iCol, iRow;
- iCol = m_iAbsolutePosition % m_iCols;
- iRow = m_iAbsolutePosition / m_iCols;
- if(bAdvance)
- Next();
-
- if(iWidth == -1)
- iWidth = m_iSpriteWidth;
- if(iHeight == -1)
- iHeight = m_iSpriteHeight;
- return m_surfTile.Draw(lpDest, iDestX, iDestY, (iCol * m_iSpriteWidth)+iSrcX, (iRow * m_iSpriteHeight)+iSrcY, iWidth, iHeight);
- }
- BOOL cSprite::Create(HINSTANCE hInst, UINT nResource, int iTileWidth, int iTileHeight, COLORREF dwColorKey, int iSpriteWidth,int iSpriteHeight)
- {
- Destroy();
- m_surfTile.Create(iTileWidth, iTileHeight, dwColorKey);
- m_surfTile.LoadBitmap(hInst, nResource);
- m_iCols = iTileWidth / iSpriteWidth;
- m_iRows = iTileHeight / iSpriteHeight;
- m_iSpriteWidth = iSpriteWidth;
- m_iSpriteHeight = iSpriteHeight;
- m_iAbsolutePosition = 0;
- return TRUE;
- }
- void cSprite::Next()
- {
- m_iAbsolutePosition++;
- if(m_iAbsolutePosition > (m_iCols * m_iRows - 1))
- m_iAbsolutePosition = 0;
- }
- void cSprite::Previous()
- {
- m_iAbsolutePosition--;
- if(m_iAbsolutePosition < 0)
- m_iAbsolutePosition = (m_iCols * m_iRows - 1);
- }
- BOOL cSprite::IsEnd()
- {
- if(m_iAbsolutePosition == (m_iCols * m_iRows - 1))
- return TRUE;
- else
- return FALSE;
- }
- BOOL cSprite::IsBegin()
- {
- if(m_iAbsolutePosition == 0)
- return TRUE;
- else
- return FALSE;
- }
- void cSprite::Rewind()
- {
- m_iAbsolutePosition = 0;
- }