Level.cpp
上传用户:pfmy85
上传日期:2007-01-07
资源大小:22k
文件大小:4k
- // Level.cpp: implementation of the CLevel class.
- //
- //////////////////////////////////////////////////////////////////////
- #include "stdafx.h"
- #include "Isotest.h"
- #include "Level.h"
- #ifdef _DEBUG
- #undef THIS_FILE
- static char THIS_FILE[]=__FILE__;
- #define new DEBUG_NEW
- #endif
- //////////////////////////////////////////////////////////////////////
- // Construction/Destruction
- //////////////////////////////////////////////////////////////////////
- CLevel::CLevel()
- {
- m_pHero = NULL;
- m_pMapTile = NULL;
- m_pMap = NULL;
- m_pFrameWnd = NULL;
- }
- CLevel::~CLevel()
- {
- if (m_pHero!= NULL)
- {
- delete m_pHero;
- m_pHero = NULL;
- }
- if (m_pMapTile!=NULL)
- {
- delete m_pMapTile;
- m_pMapTile = NULL;
- }
- if (m_pMap != NULL)
- {
- delete m_pMap;
- m_pMap = NULL;
- }
- if (m_pFrameWnd != NULL)
- {
- delete m_pFrameWnd;
- m_pFrameWnd = NULL;
- }
- }
- bool CLevel::LoadLevel(CDDDevice* pDDDevice, LPCTSTR lpszFileName,
- CPackFileManager* pPackFileManager/* = NULL*/)
- {
- CProfile profile;
- profile.Open(lpszFileName, pPackFileManager);
- CString strName;
- int i;
- // Load map tile
- strName = profile.GetProfileString("MapInfo", "TileSrc");
- m_pMapTile = new CDDDIBSurface;
- if (m_pMapTile == NULL)
- goto ErrExit;
- if (!m_pMapTile->Create(pDDDevice, strName, pPackFileManager))
- goto ErrExit;
- m_pMapTile->SetRGBColorKey();
- // Load map
- strName = profile.GetProfileString("MapInfo", "MapData");
- m_pMap = new CDXIsoMap;
- if (m_pMap == NULL)
- goto ErrExit;
- if (!m_pMap->Create(m_pMapTile, strName, pPackFileManager))
- goto ErrExit;
- // Load Frame Window
- strName = profile.GetProfileString("FrameInfo", "FrameSrc");
- m_pFrameWnd = new CDDDIBSurface;
- if (m_pFrameWnd == NULL)
- goto ErrExit;
- if (!m_pFrameWnd->Create(pDDDevice, strName, pPackFileManager))
- goto ErrExit;
- // m_pFrameWnd->SetRGBColorKey(0x0);
- // Load Hero
- POINT ptHero[CHero::ACTION_CNT];
- for (i=0; i<CHero::ACTION_CNT; i++)
- {
- strName.Format("%s_W", CHero::m_szHeroAction[i]);
- strName.MakeUpper();
- ptHero[i].x = profile.GetProfileInt("HeroInfo", strName, 0);
- strName.Format("%s_H", CHero::m_szHeroAction[i]);
- strName.MakeUpper();
- ptHero[i].y = profile.GetProfileInt("HeroInfo", strName, 0);
- }
- strName = profile.GetProfileString("HeroInfo", "SpriteSrc");
- m_pHero = new CHero;
- if (m_pHero == NULL)
- goto ErrExit;
- if (!m_pHero->Create(pDDDevice, strName, ptHero, pPackFileManager))
- goto ErrExit;
- RECT rect;
- rect.left = profile.GetProfileInt("FrameInfo", "Right_Left", 0);
- rect.top = profile.GetProfileInt("FrameInfo", "Right_Top", 0);
- rect.right = profile.GetProfileInt("FrameInfo", "Right_Right", 0);
- rect.bottom = profile.GetProfileInt("FrameInfo", "Right_Bottom", 0);
- SetViewRect(&rect);
- // Load map's initialize position
- m_pMap->MoveTo(profile.GetProfileInt("MapInfo", "InitPosX",0),
- profile.GetProfileInt("MapInfo", "InitPosY", 0));
- return true;
- ErrExit:
- ASSERT(FALSE);
- if (m_pFrameWnd != NULL)
- {
- delete m_pFrameWnd;
- m_pFrameWnd = NULL;
- }
- if (m_pHero!= NULL)
- {
- delete m_pHero;
- m_pHero = NULL;
- }
- if (m_pMapTile!=NULL)
- {
- delete m_pMapTile;
- m_pMapTile = NULL;
- }
- if (m_pMap != NULL)
- {
- delete m_pMap;
- m_pMap = NULL;
- }
- return false;
- }
- void CLevel::Render(CDDSurface* pDestSurface, __int64 nTime, LPRECT rcView/*=NULL*/)
- {
- m_pFrameWnd->Draw(pDestSurface, 0, 0);
- if (rcView == NULL)
- {
- m_pMap->Draw(pDestSurface);
- m_pHero->Draw(pDestSurface);
- }
- else
- {
- m_pMap->Draw(pDestSurface, rcView);
- m_pHero->Draw(pDestSurface, rcView);
- }
- m_pMap->DrawAbove(pDestSurface, m_pHero->m_nPosX, m_pHero->m_nPosY);
- m_pHero->ServeIt(nTime);
- }
- void CLevel::SetViewRect(LPRECT lprcView)
- {
- ASSERT(lprcView != NULL);
- memcpy(&m_rcView, lprcView, sizeof(RECT));
- m_pMap->SetViewRect(lprcView);
- m_pHero->SetViewRect(lprcView);
- }