GameApp.cpp
上传用户:zhj2929
上传日期:2022-07-23
资源大小:28772k
文件大小:2k
源码类别:

游戏引擎

开发平台:

Visual C++

  1. #include <stdio.h>
  2. #include "GameApp.h"
  3. #include "GameState.h"
  4. #include "MeshEffect.hpp"
  5. #include "GameStateLogo.hpp"
  6. #include "GameStateSplash.hpp"
  7. #include "GameStateHelp.hpp"
  8. #include "GameStateLoading.hpp"
  9. #include "GameStatePlay.hpp"
  10. #include "GameStateEnd.hpp"
  11. GameApp::GameApp(JGE *engine): JApp(engine)
  12. {
  13. for (int i=GAME_STATE_LOGO;i<=GAME_STATE_PLAY;i++)
  14. mGameStates[i] = NULL;
  15. }
  16. GameApp::~GameApp()
  17. {
  18. }
  19. void GameApp::Create()
  20. {
  21. mGameStates[GAME_STATE_LOGO] = new GameStateLogo(this);
  22. mGameStates[GAME_STATE_LOGO]->Create();
  23. mGameStates[GAME_STATE_SPLASH] = new GameStateSplash(this);
  24. mGameStates[GAME_STATE_SPLASH]->Create();
  25. mGameStates[GAME_STATE_HELP] = new GameStateHelp(this);
  26. //mGameStates[GAME_STATE_HELP]->Create();
  27. mGameStates[GAME_STATE_LOADING] = new GameStateLoading(this);
  28. mGameStates[GAME_STATE_PLAY] = new GameStatePlay(this);
  29. mGameStates[GAME_STATE_END] = new GameStateEnd(this);
  30.     //mGameStates[GAME_STATE_END]->Create();
  31. mCurrentState = NULL;
  32. mNextState = mGameStates[GAME_STATE_LOGO];
  33. //mNextState = mGameStates[GAME_STATE_LOADING];
  34. }
  35. void GameApp::LoadGameStates()
  36. {
  37. mGameStates[GAME_STATE_PLAY]->Create();
  38. }
  39. void GameApp::LoadGameStateHelp()
  40. {
  41. mGameStates[GAME_STATE_HELP]->Create();
  42. }
  43. void GameApp::LoadGameStateSplash()
  44. {
  45. mGameStates[GAME_STATE_SPLASH]->Create();
  46. }
  47. void GameApp::setI(int j)
  48. {
  49. mGameStates[GAME_STATE_END]->setI(j);
  50. }
  51. void GameApp::LoadGameStateEnd()
  52. {
  53. mGameStates[GAME_STATE_END]->Create();
  54. }
  55. void GameApp::Destroy()
  56. {
  57. for (int i=GAME_STATE_LOGO;i<=GAME_STATE_PLAY;i++)
  58. {
  59. if (mGameStates[i])
  60. {
  61. mGameStates[i]->Destroy();
  62. delete mGameStates[i];
  63. }
  64. }
  65. }
  66. void GameApp::Update()
  67. {
  68. if (mCurrentState != NULL)
  69. mCurrentState->Update();
  70. if (mNextState != NULL)
  71. {
  72. if (mCurrentState != NULL)
  73. mCurrentState->End();
  74. mCurrentState = mNextState;
  75. mCurrentState->Start();
  76. mNextState = NULL;
  77. }
  78. }
  79. void GameApp::Render()
  80. {
  81. if (mCurrentState != NULL)
  82. {
  83. mCurrentState->Render();
  84. }
  85. }
  86. void GameApp::SetNextState(int state)
  87. {
  88. mNextState = mGameStates[state];
  89. }