engine.d 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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()
  31. {
  32. int screenWidth = 1344;
  33. int screenHeight = 1008;
  34. // Initialization
  35. debug debugWriteln("Engine version: ", ver);
  36. SetExitKey(0);
  37. Image icon = LoadImage("res/icon.png");
  38. // Window and Audio Initialization
  39. InitWindow(screenWidth, screenHeight, "Remember11 - Self Chapter");
  40. SetWindowIcon(icon);
  41. UnloadImage(icon);
  42. //ToggleFullscreen();
  43. SetTargetFPS(60);
  44. textFont = LoadFont("res/font_en.png");
  45. // Fade In and Out Effects
  46. InitAudioDevice();
  47. audioEnabled = systemSettings.sound_state.to!bool;
  48. helloScreen();
  49. ClearBackground(Colors.BLACK);
  50. EndDrawing();
  51. camera.target = Vector2(screenWidth/2.0f, screenHeight/2.0f);
  52. camera.offset = Vector2(screenWidth/2.0f, screenHeight/2.0f);
  53. camera.rotation = 0.0f;
  54. camera.zoom = 1.0f;
  55. while (true)
  56. {
  57. switch (currentGameState)
  58. {
  59. case GameState.MainMenu:
  60. debugWriteln("Showing menu.");
  61. showMainMenu();
  62. break;
  63. case GameState.InGame:
  64. gameInit();
  65. luaExec = systemSettings.script_path;
  66. while (!WindowShouldClose())
  67. {
  68. SetExitKey(0);
  69. if (luaReload) {
  70. int luaExecutionCode = luaInit(luaExec);
  71. if (luaExecutionCode != EngineExitCodes.EXIT_OK) {
  72. writeln("[ERROR] Engine stops execution according to error code: ",
  73. luaExecutionCode.to!EngineExitCodes);
  74. currentGameState = GameState.Exit;
  75. break;
  76. }
  77. luaReload = false;
  78. }
  79. if (IsKeyPressed(KeyboardKey.KEY_F11)) {
  80. ToggleFullscreen();
  81. }
  82. BeginDrawing();
  83. ClearBackground(Colors.BLACK);
  84. // main logic
  85. BeginMode2D(camera);
  86. backgroundLogic();
  87. characterLogic();
  88. // effects logic
  89. effectsLogic();
  90. EndMode2D();
  91. //drawing dialogs
  92. dialogLogic();
  93. luaEventLoop();
  94. EndDrawing();
  95. }
  96. break;
  97. case GameState.Exit:
  98. EndDrawing();
  99. unloadResourcesLogic();
  100. CloseAudioDevice();
  101. CloseWindow();
  102. return;
  103. default:
  104. break;
  105. }
  106. }
  107. }