GameFrame.cpp
上传用户:maxiaolivb
上传日期:2022-06-07
资源大小:915k
文件大小:2k
源码类别:

游戏引擎

开发平台:

Visual C++

  1. #include ".gameframe.h"
  2. #include "EditCtrl.h"
  3. GameFrame::GameFrame(void)
  4. {
  5. m_pGuiManager = NULL;
  6. }
  7. GameFrame::~GameFrame(void)
  8. {
  9. DELETE_OBJECT(m_pGuiManager);
  10. }
  11. //初始化游戏框架
  12. bool GameFrame::InitGameFrame()
  13. {
  14. m_pGuiManager = new GuiManager;
  15. if (!m_pGuiManager)
  16. {
  17. g_pHGE->System_Log("图形用户接口管理器创建失败!");
  18. return false;
  19. }
  20. if (!InitAllCtrl())
  21. return false;
  22. m_pGuiManager->SetNavMode(HGEGUI_UPDOWN | HGEGUI_CYCLED);
  23. m_pGuiManager->Enter();
  24. return true;
  25. }
  26. //退出游戏框架
  27. bool GameFrame::ExitGameFrame()
  28. {
  29. if (!DeleteAllCtrl())
  30. return false;
  31. return true;
  32. }
  33. //游戏控制循环
  34. bool GameFrame::GameFrameRun()
  35. {
  36. if (g_pHGE->Input_GetKeyState(HGEK_ESCAPE))
  37. {
  38. DestroyWindow(g_pHGE->System_GetState(HGE_HWND));
  39. }
  40. static bool m_bLLastPressed = false;
  41. static bool m_bLPressed = false;
  42. m_bLLastPressed = m_bLPressed;
  43. m_bLPressed = g_pHGE->Input_GetKeyState(VK_LBUTTON);
  44. if(!m_bLLastPressed && m_bLPressed) // 鼠标左键按下
  45. {
  46. }
  47. else if(m_bLLastPressed && !m_bLPressed) // 鼠标左键松开
  48. {
  49. }
  50. return false;
  51. }
  52. //游戏绘制循环
  53. bool GameFrame::GameRenderRun()
  54. {
  55. float _fDt = g_pHGE->Timer_GetDelta();
  56. float _fTime = g_pHGE->Timer_GetTime();
  57. int _nFPS = g_pHGE->Timer_GetFPS();
  58. float _fPosX,_fPosY;
  59. int _fFocusCtrl = m_pGuiManager->Update(_fDt);
  60. m_pGuiManager->Render();
  61. g_pHGE->Input_GetMousePos(&_fPosX,&_fPosY);
  62. g_pFont->printf(5,5,0,"123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ");
  63. g_pFontCN->SetColor(0xFFFFFFFF);
  64. g_pFontCN->printf(5,30,"Delte = %0.3fnTime = %fnFPS = %dn鼠标坐标 = %.f:%.f",_fDt,_fTime,_nFPS,_fPosX,_fPosY);
  65. return false;
  66. }
  67. //初始化所有控件
  68. bool GameFrame::InitAllCtrl()
  69. {
  70. //添加编辑控件
  71. m_pGuiManager->AddCtrl(new EditCtrl(SYSTEM_CTRLID_EDIT,100,300,500,16,0xffff0000,0xffff00ff));
  72. g_pEditCtrl = (EditCtrl*)m_pGuiManager->GetCtrl(SYSTEM_CTRLID_EDIT);
  73. return true;
  74. }
  75. //删除所有控件
  76. bool GameFrame::DeleteAllCtrl()
  77. {
  78. return true;
  79. }