SpriteManager.cpp
上传用户:sycq158
上传日期:2008-10-22
资源大小:15361k
文件大小:2k
- // SpriteManager.cpp: implementation of the CSpriteManager class.
- //
- //////////////////////////////////////////////////////////////////////
- #include <list>
- #include "DSUtil.h"
- #include "ddutil.h"
- #include "Sprite.h"
- #include "SpriteManager.h"
- //////////////////////////////////////////////////////////////////////
- // Construction/Destruction
- //////////////////////////////////////////////////////////////////////
- CSpriteManager::CSpriteManager()
- {
- }
- CSpriteManager::~CSpriteManager()
- {
- }
- void CSpriteManager::Update()
- {
- std::list<CSprite*>::iterator iSprite;
- for ( iSprite = m_pSpriteList.begin(); iSprite != m_pSpriteList.end(); iSprite++)
- (*iSprite)->Update();
- }
- void CSpriteManager::AddSprite(CSprite *pSprite)
- {
- pSprite->m_Movement.m_pfnCollision = m_pfnCollision;
- pSprite->m_Movement.m_pfnFindPath = m_pfnFindPath;
- m_pSpriteList.push_front(pSprite);
- }
- void CSpriteManager::Draw(LPDIRECTDRAWSURFACE7 pdds)
- {
- std::list<CSprite*>::iterator iSprite;
- for ( iSprite = m_pSpriteList.begin(); iSprite != m_pSpriteList.end(); iSprite++)
- (*iSprite)->Draw(pdds);
- }
- void CSpriteManager::RemoveSprite(CSprite *pSprite)
- {
- m_pSpriteList.remove(pSprite);
- }
- void CSpriteManager::SetCollAndPathFn(bool (__cdecl *pfnCollision)(RECT&), void (__cdecl *pfnFindPath)(CSprite *))
- {
- m_pfnCollision = pfnCollision;
- m_pfnFindPath = pfnFindPath;
- }
- bool CSpriteManager::IsHit(RECT &rc)
- {
- std::list<CSprite*>::iterator iSprite;
- for ( iSprite = m_pSpriteList.begin(); iSprite != m_pSpriteList.end(); iSprite++) {
- if ((*iSprite)->m_Movement.m_nInvulnerable==0 && (*iSprite)->IsHit(rc) == true) {
- return true;
- }
- }
- return false;
- }
- int CSpriteManager::KillSpritesColliWith(CSprite* pSprite)
- {
- std::list<CSprite*>::iterator iSprite;
- int nHit = 0;
- for ( iSprite = m_pSpriteList.begin(); iSprite != m_pSpriteList.end(); iSprite++) {
- if (pSprite->IsHit((*iSprite)->GetRect()) == true) {
- long nState = (*iSprite)->GetState();
- if (nState != ST_DEAD && nState !=ST_KILL) {
- (*iSprite)->SetState(ST_KILL);
- nHit++;
- }
- }
-
- }
- return nHit;
- }
- void CSpriteManager::Destroy()
- {
- m_pSpriteList.erase(m_pSpriteList.begin(),m_pSpriteList.end());
- }