Isotest.cpp
上传用户:pfmy85
上传日期:2007-01-07
资源大小:22k
文件大小:8k
- // Isotest.cpp : Defines the class behaviors for the application.
- #include "stdafx.h"
- #include "Isotest.h"
- #include "DSMusicBuffer.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- const bool g_bFullScreen
- #ifdef _DEBUG
- = false; // true;
- #else
- = true; // false;
- #endif // _DEBUG
- const DWORD g_dwWidth = 640; // 800; // 1024;
- const DWORD g_dwHeight = 480; // 600; // 768;
- const DWORD g_dwBPP = 8; // 16; // 24; // 32;
- CIsotestApp::CIsotestApp(void)
- {
- SetFullScreen(g_bFullScreen);
- SetPackFileName(_T("data"), _T("data"));
- // Called during initial app startup, this function
- // performs all the permanent initialization.
- m_pDDDevice = NULL;
- m_pRenderSurface = NULL;
- // add your permanent init code here !
- m_pDDDevice = NULL;
- m_pRenderSurface = NULL;
- m_pMouseState = NULL;
- m_pCursor = NULL;
- m_pKeyState = NULL;
- m_pTextSurface = NULL;
- m_pDSBackGround = NULL;
- m_pLevel = NULL;
- m_pSelector = NULL;
- }
- // Called before the app exits, this function gives the app
- // the chance to cleanup after itself.
- CIsotestApp::~CIsotestApp()
- {
- // add your cleaup code here !
- }
- bool CIsotestApp::GetDXInitSettings(void)
- {
- if (m_pDirectSound != NULL)
- {
- if (m_pDirectSound->SelectDSDriver(0) == false)
- return false;
- }
- if (m_pDirectMusic != NULL)
- {
- if (m_pDirectMusic->SelectDefaultDMusPort() == false)
- return false;
- }
- if (m_pDirectDraw->SelectDDDevice(0) == false)
- return false;
- if (GetFirstDDDevice()->SelectDisplayMode(
- IsFullScreen(), g_dwWidth, g_dwHeight, g_dwBPP) == false)
- return false;
- return true;
- }
- // Called during device intialization, this code checks the device
- // for some minimum set of capabilities, Initialize scene objects.
- bool CIsotestApp::InitDXObjects(void)
- {
- m_pDDDevice = GetFirstDDDevice();
- m_pRenderSurface = m_pDDDevice->GetRenderSurface();
- // add your init code here !
- ASSERT(m_pGUIManager != NULL);
- m_pMouseState = m_pGUIManager->GetMouseState();
- m_pKeyState = m_pGUIManager->GetKeyState();
- ASSERT(m_pKeyState != NULL);
- m_pCursor = new CDXSprite;
- if (m_pCursor->Create(m_pDDDevice, "cursor01.bmp", 20, 20, m_pPackFileManager) == false)
- return false;
- // m_pTextSurface = new CDDTextSurface;
- // if (m_pTextSurface->Create(m_pDDDevice, "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA") == false)
- // return false;
- m_pLevel = new CLevel;
- bool bRet = m_pLevel->LoadLevel(m_pDDDevice, "Level001.dat", m_pPackFileManager);
- // m_pLevel->SetViewRect(&m_rcView);
- CRect rc(0,0, 32, 480);
- m_pSelector = new CTileSelector;
- m_pSelector->Create(m_pDDDevice, m_pLevel->m_pMapTile, 5, 4, m_rcScreen,
- "sb_arrow.bmp", m_pPackFileManager);
- if (m_pDirectMusic != NULL)
- {
- m_pDSBackGround = new CDSMusicBuffer;
- if (m_pDSBackGround->Create(m_pDirectSound,
- _T("back.mid"), m_pPackFileManager) == false)
- return false;
- }
- if (m_pDSBackGround != NULL)
- {
- m_pDSBackGround->SetLoop(true);
- m_pDSBackGround->Play();
- }
- return true;
- }
- // Called when the app is exitting, or the device is being changed,
- // this function deletes any device dependant objects.
- bool CIsotestApp::DestroyDXObjects(void)
- {
- // add your destroy code here !
- if (m_pCursor != NULL)
- {
- delete m_pCursor;
- m_pCursor = NULL;
- }
- if (m_pLevel != NULL)
- {
- delete m_pLevel;
- m_pLevel = NULL;
- }
- if (m_pTextSurface != NULL)
- {
- delete m_pTextSurface;
- m_pTextSurface = NULL;
- }
- if (m_pSelector != NULL)
- {
- delete m_pSelector;
- m_pSelector = NULL;
- }
- if (m_pDSBackGround != NULL)
- {
- delete m_pDSBackGround;
- m_pDSBackGround = NULL;
- }
- m_pMouseState = NULL;
- m_pKeyState = NULL;
- m_pRenderSurface = NULL;
- m_pDDDevice = NULL;
- return CDirectXApp::DestroyDXObjects();
- }
- // Called once per frame, the call is the entry point for
- // animating the scene. This function sets up render states,
- // clears the viewport, and renders the scene.
- bool CIsotestApp::UpdateFrame(void)
- {
- // add your code here !
- // m_pRenderSurface->Fill(0);
- m_pLevel->Render(m_pRenderSurface, m_pGUIManager->GetCurrentTime()/*, &m_rcView*/);
-
- // m_pSelector->Draw(m_pRenderSurface);
- // CString strOut;
- // int nTx, nTy;
- // m_pLevel->m_pMap->AbsoluteCell(m_pMouseState->GetMouseX(),
- // m_pMouseState->GetMouseY(),
- // nTx, nTy, false);
- // strOut.Format("Mouse Pos: X=%d, Y=%d, %d",
- // nTx, nTy,
- // m_pKeyState->GetKeyTimeStamp());
- // m_pTextSurface->SetText(strOut);
- // m_pTextSurface->Draw(m_pRenderSurface, 32, 0);
- m_pCursor->MoveTo(m_pMouseState->GetMouseX(), m_pMouseState->GetMouseY());
- m_pCursor->Draw(m_pRenderSurface, &m_rcScreen);
- m_pCursor->NextFrame();
- ProcessInput();
- return CDirectXApp::UpdateFrame();
- }
- // ---- add your functions ! ----
- void CIsotestApp::ProcessInput()
- {
- static nTileNo = 0;
- CELL* pCell;
- static BOOL bKeyDown = FALSE;
- switch (m_pKeyState->GetKeyState())
- {
- case CDIKeyState::KEY_DOWN:
- bKeyDown = TRUE;
- if (m_pKeyState->GetKeyCode() == DIK_SPACE)
- m_pLevel->m_pHero->SetAction(CHero::ACTION_AT);
- //m_pLevel->m_pMap->Save("map01.dat");
- break;
- case CDIKeyState::KEY_UP:
- bKeyDown = FALSE;
- break;
- }
- if (bKeyDown)
- {
- switch (m_pKeyState->GetKeyCode())
- {
- /* case DIK_SUBTRACT:
- nTileNo--;
- break;
- case DIK_ADD:
- nTileNo++;
- break;
- */ case DIK_NUMPAD6:
- case DIK_RIGHT:
- m_pLevel->m_pHero->Move(m_pLevel->m_pMap, RIGHT_DOWN);
- m_pLevel->m_pHero->SetDirection(RIGHT_DOWN);
- m_pLevel->m_pHero->SetAction(CHero::ACTION_WL);
- break;
- case DIK_NUMPAD4:
- case DIK_LEFT:
- m_pLevel->m_pHero->Move(m_pLevel->m_pMap, LEFT_UP);
- m_pLevel->m_pHero->SetDirection(LEFT_UP);
- m_pLevel->m_pHero->SetAction(CHero::ACTION_WL);
- break;
- case DIK_NUMPAD2:
- case DIK_DOWN:
- m_pLevel->m_pHero->Move(m_pLevel->m_pMap, LEFT_DOWN);
- m_pLevel->m_pHero->SetDirection(LEFT_DOWN);
- m_pLevel->m_pHero->SetAction(CHero::ACTION_WL);
- break;
- case DIK_NUMPAD8:
- case DIK_UP:
- m_pLevel->m_pHero->Move(m_pLevel->m_pMap, RIGHT_UP);
- m_pLevel->m_pHero->SetDirection(RIGHT_UP);
- m_pLevel->m_pHero->SetAction(CHero::ACTION_WL);
- break;
- }
- }
- else
- m_pLevel->m_pHero->SetAction(CHero::ACTION_ST);
- int nTx, nTy;
- POINT pt;
- pt.x = m_pMouseState->GetMouseX();
- pt.y = m_pMouseState->GetMouseY();
- CDIMouseState::MOUSE_BUTTON_STATE eMouseState =
- m_pMouseState->GetButtonState();
- /*
- if (eMouseState == CDIMouseState::MOUSE_BUTTON_0_DOWN)
- {
- if (m_rcView.PtInRect(pt))
- {
- m_pLevel->m_pMap->AbsoluteCell(m_pMouseState->GetMouseX(),
- m_pMouseState->GetMouseY(),
- nTx, nTy, FALSE);
- pCell = m_pLevel->m_pMap->GetCell(nTx, nTy);
- if (m_pKeyState->IsShiftPressed())
- {
- pCell->fringe.index = (BYTE)nTileNo;
- if (nTileNo > 255)
- pCell->fringe.flag |= CDXIsoMap::m_CellIdxFlg;
- else
- pCell->fringe.flag &=
- (CDXIsoMap::m_CellIdxFlg ^ 0xFF);
- }
- else
- {
- pCell->base.index = (BYTE)nTileNo;
- if (nTileNo > 255)
- pCell->base.flag |= CDXIsoMap::m_CellIdxFlg;
- else
- pCell->base.flag &=
- (CDXIsoMap::m_CellIdxFlg ^ 0xFF);
- }
- }
- else
- {
- m_pSelector->ProcessMouse(pt.x, pt.y, eMouseState);
- nTileNo = m_pSelector->GetCurTile();
- }
- }
- */
- // m_pKeyState->Update();
- }
- // ----
- #if _MSC_VER >= 1200 && _MSC_VER < 1400
- #ifdef _DEBUG
- #pragma comment(lib, "DXGuideD_VC6.lib")
- #else
- #pragma comment(lib, "DXGuide_VC6.lib")
- #endif // _DEBUG
- #endif // _MSC_VER
- #if _MSC_VER >= 1000 && _MSC_VER < 1200
- #ifdef _DEBUG
- #pragma comment(lib, "DXGuideD_VC5.lib")
- #else
- #pragma comment(lib, "DXGuide_VC5.lib")
- #endif // _DEBUG
- #endif // _MSC_VER
- BEGIN_MESSAGE_MAP(CIsotestApp, CDirectXApp)
- //{{AFX_MSG_MAP(CIsotestApp)
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- CIsotestApp theApp;