engine.d 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. // quantumde1 developed software, licensed under MIT license.
  2. module graphics.engine;
  3. import raylib;
  4. import graphics.playback;
  5. import std.stdio;
  6. import std.math;
  7. import std.file;
  8. import graphics.gamelogic;
  9. import std.string;
  10. import std.conv;
  11. import variables;
  12. import std.random;
  13. import std.datetime;
  14. import ui.menu;
  15. import std.typecons;
  16. import system.abstraction;
  17. import system.config;
  18. import dialogs.dialogbox;
  19. import scripts.lua;
  20. import std.array;
  21. import system.abstraction;
  22. import system.cleanup;
  23. void engine_loader(string window_name, int screenWidth, int screenHeight)
  24. {
  25. // Initialization
  26. debug debugWriteln("Engine version: ", ver);
  27. SetExitKey(0);
  28. // Window and Audio Initialization
  29. InitWindow(screenWidth, screenHeight, cast(char*) window_name);
  30. DisableCursor();
  31. ToggleFullscreen();
  32. SetTargetFPS(60);
  33. textFont = LoadFont("res/font_en.png");
  34. // Fade In and Out Effects
  35. InitAudioDevice();
  36. audioEnabled = systemSettings.sound_state.to!bool;
  37. helloScreen();
  38. ClearBackground(Colors.BLACK);
  39. EndDrawing();
  40. camera.target = Vector2(screenWidth/2.0f, screenHeight/2.0f);
  41. camera.offset = Vector2(screenWidth/2.0f, screenHeight/2.0f);
  42. camera.rotation = 0.0f;
  43. camera.zoom = 1.0f;
  44. while (true)
  45. {
  46. switch (currentGameState)
  47. {
  48. case GameState.MainMenu:
  49. debugWriteln("Showing menu.");
  50. showMainMenu(currentGameState);
  51. break;
  52. case GameState.InGame:
  53. import core.stdc.stdlib;
  54. import core.stdc.time;
  55. gameInit();
  56. while (!WindowShouldClose())
  57. {
  58. SetExitKey(0);
  59. if (luaReload)
  60. {
  61. int luaExecutionCode = luaInit(luaExec);
  62. if (luaExecutionCode != EngineExitCodes.EXIT_OK) {
  63. debugWriteln("Engine stops execution according to error code: ", luaExecutionCode);
  64. currentGameState = GameState.Exit;
  65. break;
  66. }
  67. luaReload = false;
  68. }
  69. luaEventLoop();
  70. BeginDrawing();
  71. ClearBackground(Colors.BLACK);
  72. // main logic
  73. // effects logic
  74. BeginMode2D(camera);
  75. backgroundLogic();
  76. effectsLogic();
  77. EndMode2D();
  78. dialogLogic();
  79. EndDrawing();
  80. }
  81. break;
  82. case GameState.Exit:
  83. EndDrawing();
  84. unloadResourcesLogic();
  85. return;
  86. default:
  87. break;
  88. }
  89. }
  90. }