Isotest.cpp
上传用户:pfmy85
上传日期:2007-01-07
资源大小:22k
文件大小:8k
源码类别:

DirextX编程

开发平台:

Visual C++

  1. // Isotest.cpp : Defines the class behaviors for the application.
  2. #include "stdafx.h"
  3. #include "Isotest.h"
  4. #include "DSMusicBuffer.h"
  5. #ifdef _DEBUG
  6. #define new DEBUG_NEW
  7. #undef THIS_FILE
  8. static char THIS_FILE[] = __FILE__;
  9. #endif
  10. const bool g_bFullScreen
  11. #ifdef _DEBUG
  12. = false; // true;
  13. #else
  14. = true; // false;
  15. #endif // _DEBUG
  16. const DWORD g_dwWidth = 640; // 800; // 1024;
  17. const DWORD g_dwHeight = 480; // 600; // 768;
  18. const DWORD g_dwBPP = 8; // 16; // 24; // 32;
  19. CIsotestApp::CIsotestApp(void)
  20. {
  21. SetFullScreen(g_bFullScreen);
  22. SetPackFileName(_T("data"), _T("data"));
  23. // Called during initial app startup, this function
  24. // performs all the permanent initialization.
  25. m_pDDDevice = NULL;
  26. m_pRenderSurface = NULL;
  27. // add your permanent init code here !
  28. m_pDDDevice = NULL;
  29. m_pRenderSurface = NULL;
  30. m_pMouseState = NULL;
  31. m_pCursor = NULL;
  32. m_pKeyState = NULL;
  33. m_pTextSurface = NULL;
  34. m_pDSBackGround = NULL;
  35. m_pLevel = NULL;
  36. m_pSelector = NULL;
  37. }
  38. // Called before the app exits, this function gives the app
  39. // the chance to cleanup after itself.
  40. CIsotestApp::~CIsotestApp()
  41. {
  42. // add your cleaup code here !
  43. }
  44. bool CIsotestApp::GetDXInitSettings(void)
  45. {
  46. if (m_pDirectSound != NULL)
  47. {
  48. if (m_pDirectSound->SelectDSDriver(0) == false)
  49. return  false;
  50. }
  51. if (m_pDirectMusic != NULL)
  52. {
  53. if (m_pDirectMusic->SelectDefaultDMusPort() == false)
  54. return  false;
  55. }
  56. if (m_pDirectDraw->SelectDDDevice(0) == false)
  57. return  false;
  58. if (GetFirstDDDevice()->SelectDisplayMode(
  59. IsFullScreen(), g_dwWidth, g_dwHeight, g_dwBPP) == false)
  60. return  false;
  61. return  true;
  62. }
  63. // Called during device intialization, this code checks the device
  64. // for some minimum set of capabilities, Initialize scene objects.
  65. bool CIsotestApp::InitDXObjects(void)
  66. {
  67. m_pDDDevice = GetFirstDDDevice();
  68. m_pRenderSurface = m_pDDDevice->GetRenderSurface();
  69. // add your init code here !
  70. ASSERT(m_pGUIManager != NULL);
  71. m_pMouseState = m_pGUIManager->GetMouseState();
  72. m_pKeyState = m_pGUIManager->GetKeyState();
  73. ASSERT(m_pKeyState != NULL);
  74. m_pCursor = new CDXSprite;
  75. if (m_pCursor->Create(m_pDDDevice, "cursor01.bmp", 20, 20, m_pPackFileManager) == false)
  76. return false;
  77. // m_pTextSurface = new  CDDTextSurface;
  78. // if (m_pTextSurface->Create(m_pDDDevice, "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA") == false)
  79. // return  false;
  80. m_pLevel = new CLevel;
  81. bool bRet = m_pLevel->LoadLevel(m_pDDDevice, "Level001.dat", m_pPackFileManager);
  82. // m_pLevel->SetViewRect(&m_rcView);
  83. CRect rc(0,0, 32, 480);
  84. m_pSelector = new CTileSelector;
  85. m_pSelector->Create(m_pDDDevice, m_pLevel->m_pMapTile, 5, 4, m_rcScreen,
  86. "sb_arrow.bmp", m_pPackFileManager);
  87. if (m_pDirectMusic != NULL)
  88. {
  89. m_pDSBackGround = new  CDSMusicBuffer;
  90. if (m_pDSBackGround->Create(m_pDirectSound,
  91. _T("back.mid"), m_pPackFileManager) == false)
  92. return  false;
  93. }
  94. if (m_pDSBackGround != NULL)
  95. {
  96. m_pDSBackGround->SetLoop(true);
  97. m_pDSBackGround->Play();
  98. }
  99. return  true;
  100. }
  101. // Called when the app is exitting, or the device is being changed,
  102. // this function deletes any device dependant objects.
  103. bool CIsotestApp::DestroyDXObjects(void)
  104. {
  105. // add your destroy code here !
  106. if (m_pCursor != NULL)
  107. {
  108. delete m_pCursor;
  109. m_pCursor = NULL;
  110. }
  111. if (m_pLevel != NULL)
  112. {
  113. delete m_pLevel;
  114. m_pLevel = NULL;
  115. }
  116. if (m_pTextSurface != NULL)
  117. {
  118. delete m_pTextSurface;
  119. m_pTextSurface = NULL;
  120. }
  121. if (m_pSelector != NULL)
  122. {
  123. delete m_pSelector;
  124. m_pSelector = NULL;
  125. }
  126. if (m_pDSBackGround != NULL)
  127. {
  128. delete m_pDSBackGround;
  129. m_pDSBackGround = NULL;
  130. }
  131. m_pMouseState = NULL;
  132. m_pKeyState = NULL;
  133. m_pRenderSurface = NULL;
  134. m_pDDDevice = NULL;
  135. return  CDirectXApp::DestroyDXObjects();
  136. }
  137. // Called once per frame, the call is the entry point for
  138. // animating the scene. This function sets up render states,
  139. // clears the viewport, and renders the scene.
  140. bool CIsotestApp::UpdateFrame(void)
  141. {
  142. // add your code here !
  143. // m_pRenderSurface->Fill(0);
  144. m_pLevel->Render(m_pRenderSurface, m_pGUIManager->GetCurrentTime()/*, &m_rcView*/);
  145. // m_pSelector->Draw(m_pRenderSurface);
  146. // CString strOut;
  147. // int nTx, nTy;
  148. // m_pLevel->m_pMap->AbsoluteCell(m_pMouseState->GetMouseX(),
  149. // m_pMouseState->GetMouseY(),
  150. // nTx, nTy, false);
  151. // strOut.Format("Mouse Pos: X=%d, Y=%d, %d",
  152. // nTx, nTy, 
  153. // m_pKeyState->GetKeyTimeStamp());
  154. // m_pTextSurface->SetText(strOut);
  155. // m_pTextSurface->Draw(m_pRenderSurface, 32, 0);
  156. m_pCursor->MoveTo(m_pMouseState->GetMouseX(), m_pMouseState->GetMouseY());
  157. m_pCursor->Draw(m_pRenderSurface, &m_rcScreen);
  158. m_pCursor->NextFrame();
  159. ProcessInput();
  160. return  CDirectXApp::UpdateFrame();
  161. }
  162. // ---- add your functions ! ----
  163. void CIsotestApp::ProcessInput()
  164. {
  165. static nTileNo = 0;
  166. CELL* pCell;
  167. static BOOL bKeyDown = FALSE;
  168. switch (m_pKeyState->GetKeyState())
  169. {
  170. case CDIKeyState::KEY_DOWN:
  171. bKeyDown = TRUE;
  172. if (m_pKeyState->GetKeyCode() == DIK_SPACE)
  173. m_pLevel->m_pHero->SetAction(CHero::ACTION_AT);
  174. //m_pLevel->m_pMap->Save("map01.dat");
  175. break;
  176. case CDIKeyState::KEY_UP:
  177. bKeyDown = FALSE;
  178. break;
  179. }
  180. if (bKeyDown)
  181. {
  182. switch (m_pKeyState->GetKeyCode())
  183. {
  184. /* case DIK_SUBTRACT:
  185. nTileNo--;
  186. break;
  187. case DIK_ADD:
  188. nTileNo++;
  189. break;
  190. */ case DIK_NUMPAD6:
  191. case DIK_RIGHT:
  192. m_pLevel->m_pHero->Move(m_pLevel->m_pMap, RIGHT_DOWN);
  193. m_pLevel->m_pHero->SetDirection(RIGHT_DOWN);
  194. m_pLevel->m_pHero->SetAction(CHero::ACTION_WL);
  195. break;
  196. case DIK_NUMPAD4:
  197. case DIK_LEFT:
  198. m_pLevel->m_pHero->Move(m_pLevel->m_pMap, LEFT_UP);
  199. m_pLevel->m_pHero->SetDirection(LEFT_UP);
  200. m_pLevel->m_pHero->SetAction(CHero::ACTION_WL);
  201. break;
  202. case DIK_NUMPAD2:
  203. case DIK_DOWN:
  204. m_pLevel->m_pHero->Move(m_pLevel->m_pMap, LEFT_DOWN);
  205. m_pLevel->m_pHero->SetDirection(LEFT_DOWN);
  206. m_pLevel->m_pHero->SetAction(CHero::ACTION_WL);
  207. break;
  208. case DIK_NUMPAD8:
  209. case DIK_UP:
  210. m_pLevel->m_pHero->Move(m_pLevel->m_pMap, RIGHT_UP);
  211. m_pLevel->m_pHero->SetDirection(RIGHT_UP);
  212. m_pLevel->m_pHero->SetAction(CHero::ACTION_WL);
  213. break;
  214. }
  215. }
  216. else
  217. m_pLevel->m_pHero->SetAction(CHero::ACTION_ST);
  218. int nTx, nTy;
  219. POINT pt;
  220. pt.x = m_pMouseState->GetMouseX();
  221. pt.y = m_pMouseState->GetMouseY();
  222. CDIMouseState::MOUSE_BUTTON_STATE eMouseState = 
  223. m_pMouseState->GetButtonState();
  224. /*
  225. if (eMouseState == CDIMouseState::MOUSE_BUTTON_0_DOWN)
  226. {
  227. if (m_rcView.PtInRect(pt))
  228. {
  229. m_pLevel->m_pMap->AbsoluteCell(m_pMouseState->GetMouseX(),
  230. m_pMouseState->GetMouseY(),
  231. nTx, nTy, FALSE);
  232. pCell = m_pLevel->m_pMap->GetCell(nTx, nTy);
  233. if (m_pKeyState->IsShiftPressed())
  234. {
  235. pCell->fringe.index = (BYTE)nTileNo;
  236. if (nTileNo > 255)
  237. pCell->fringe.flag |= CDXIsoMap::m_CellIdxFlg;
  238. else
  239. pCell->fringe.flag &=
  240. (CDXIsoMap::m_CellIdxFlg ^ 0xFF);
  241. }
  242. else
  243. {
  244. pCell->base.index = (BYTE)nTileNo;
  245. if (nTileNo > 255)
  246. pCell->base.flag |= CDXIsoMap::m_CellIdxFlg;
  247. else
  248. pCell->base.flag &=
  249. (CDXIsoMap::m_CellIdxFlg ^ 0xFF);
  250. }
  251. }
  252. else
  253. {
  254. m_pSelector->ProcessMouse(pt.x, pt.y, eMouseState);
  255. nTileNo = m_pSelector->GetCurTile();
  256. }
  257. }
  258. */
  259. // m_pKeyState->Update();
  260. }
  261. // ----
  262. #if _MSC_VER >= 1200 && _MSC_VER < 1400
  263. #ifdef _DEBUG
  264. #pragma comment(lib, "DXGuideD_VC6.lib")
  265. #else
  266. #pragma comment(lib, "DXGuide_VC6.lib")
  267. #endif // _DEBUG
  268. #endif // _MSC_VER
  269. #if _MSC_VER >= 1000 && _MSC_VER < 1200
  270. #ifdef _DEBUG
  271. #pragma comment(lib, "DXGuideD_VC5.lib")
  272. #else
  273. #pragma comment(lib, "DXGuide_VC5.lib")
  274. #endif // _DEBUG
  275. #endif // _MSC_VER
  276. BEGIN_MESSAGE_MAP(CIsotestApp, CDirectXApp)
  277. //{{AFX_MSG_MAP(CIsotestApp)
  278. //}}AFX_MSG_MAP
  279. END_MESSAGE_MAP()
  280. CIsotestApp theApp;