engine.d 2.7 KB

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