#include "Presentation.h" BOOL GameInitialize(HINSTANCE hInstance){ _pGame=new GameEngine(hInstance,"Organic Chemistry","Organic Chemistry",IDI_PRESENTER,IDI_PRESENTER_SM,800,600); if(!_pGame) return false; _pGame->SetFrameRate(20); iMouseMoveFlag=0; _hInstance=hInstance; return true; } void GameStart(HWND hWindow){ // Create the offscreen device context and bitmap HDC hDC=GetDC(hWindow); _hOffscreenDC = CreateCompatibleDC(hDC); _hOffscreenBitmap = CreateCompatibleBitmap(hDC,_pGame->GetWidth(), _pGame->GetHeight()); SelectObject(_hOffscreenDC, _hOffscreenBitmap); _pGame->setOffScreenDC(_hOffscreenDC); //doing all initialization _pMainSideBar=new CSideBar(20,20,200,560,400,_pGame->GetHeight()*5,IDB_TREE_BG_LEFTTOP); _pAnswers=new CAnswers(580,20,200,560,800,1560,IDB_TREE_BG_LEFTTOP); //_pWelcome->ShowPanel(true); //_pMainSideBar->ShowPanel(false); pContent=_pMainSideBar->GetContent(); pContent->SetAnswerPanel(_pAnswers); _pGame->SetSleep(TRUE); btHideShowPanel=new CButton(); btHideShowPanel->SetImage(IDB_SCROLL_BUT_NOR); btHideShowPanel->SetPlace(16,300-35,true); _pWelcome=new CWelcome(20,20,760,560,760,560,IDB_TREE_BG_LEFTTOP,_pMainSideBar,pContent,btHideShowPanel); //btHideShowPanel->SetReady(false); ShowHome(); _pGame->SetHiding(true); _pGame->SetExercise(false); iCountDelay=0; bCaptured=false; ReleaseDC(hWindow,hDC); } void GameEnd(){ // Cleanup the offscreen device context and bitmap DeleteObject(_hOffscreenBitmap); DeleteDC(_hOffscreenDC); //delete[] pGrid; //delete _pMainSideBar; //delete pContent; //delete _pGame; } void GamePaint(HDC hDC) { HBRUSH hWhiteBrush = CreateSolidBrush(RGB(255, 255, 255)); HBRUSH hBrush = (HBRUSH)SelectObject(_hOffscreenDC, hWhiteBrush); Rectangle(_hOffscreenDC,0,0,_pGame->GetWidth(),_pGame->GetHeight()); SelectObject(_hOffscreenDC,hBrush); DeleteObject(hWhiteBrush); //_pWelcome->DrawScreen(_hOffscreenDC); _pMainSideBar->DrawScreen(_hOffscreenDC); pContent->DrawScreen(_hOffscreenDC); _pAnswers->DrawScreen(_hOffscreenDC); btHideShowPanel->DrawScreen(_hOffscreenDC); _pWelcome->DrawScreen(_hOffscreenDC); BitBlt(hDC, 0, 0, _pGame->GetWidth(), _pGame->GetHeight(), _hOffscreenDC, 0, 0, SRCCOPY); //ReleaseDC(_pGame->GetWindow(),hDC); } void GameCycle(){ HWND hWindow = _pGame->GetWindow(); HDC hDC = GetDC(hWindow); GamePaint(hDC); ReleaseDC(hWindow, hDC); } void MouseButtonDown(int x, int y, BOOL bLeft){ _pGame->SetSleep(false); _pWelcome->MouseButtonDown(x,y,bLeft); _pMainSideBar->MouseButtonDown(x,y,bLeft); if(btHideShowPanel->MouseButtonDown(x,y,bLeft)){ if(_pGame->IsHiding()){ //_pMainSideBar->SetX(-205); Expand(); } else{ //_pMainSideBar->SetX(20); Contract(); } } hwndPreviousCaptured=SetCapture(GameEngine::GetEngine()->GetWindow()); bCaptured=true; HWND hWindow=GameEngine::GetEngine()->GetWindow(); HDC hDC=GetDC(hWindow); GamePaint(hDC); ReleaseDC(hWindow,hDC); } void Expand(){ if(!btHideShowPanel->IsReady()) return; _pMainSideBar->ShowPanel(false); _pGame->SetHiding(false); if(_pGame->IsExercise()){ _pAnswers->ShowPanel(true); pContent->SetX_Width(20,530); } else{ _pAnswers->ShowPanel(false); pContent->SetX_Width(20,760); } pContent->Update(); } void Contract(){ if(!btHideShowPanel->IsReady()) return; _pMainSideBar->ShowPanel(true); _pGame->SetHiding(true); pContent->SetX_Width(250,530); pContent->Update(); _pAnswers->ShowPanel(false); } void MouseButtonUp(int x, int y, BOOL bLeft){ btHideShowPanel->MouseButtonUp(x,y,bLeft); _pGame->SetSleep(false); _pMainSideBar->MouseButtonUp(x,y,bLeft); _pWelcome->MouseButtonUp(x,y,bLeft); if(bCaptured){ SetCapture(hwndPreviousCaptured); } HWND hWindow=GameEngine::GetEngine()->GetWindow(); HDC hDC=GetDC(hWindow); GamePaint(hDC); ReleaseDC(hWindow,hDC); } void MouseMove(int x, int y){ if(iMouseMoveFlagGetFrameDelay(); _pGame->SetSleep(false); _pMainSideBar->MouseMove(x,y); btHideShowPanel->MouseMove(x,y); _pWelcome->MouseMove(x,y); } } void GameActivate(HWND hWindow){ //_pGame->SetSleep(FALSE); } void GameDeactivate(HWND hWindow){ //_pGame->SetSleep(TRUE); } void HandleKeys(){} void ShowHome(){ _pWelcome->ShowPanel(true); pContent->ShowPanel(false); _pMainSideBar->ShowPanel(false); btHideShowPanel->SetReady(false); //_pAnswers->ShowPanel(false); }