engine.d 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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. resetAllScriptValues();
  71. int luaExecutionCode = luaInit(luaExec);
  72. if (luaExecutionCode != EngineExitCodes.EXIT_OK) {
  73. writeln("[ERROR] Engine stops execution according to error code: ",
  74. luaExecutionCode.to!EngineExitCodes);
  75. currentGameState = GameState.Exit;
  76. break;
  77. }
  78. luaReload = false;
  79. }
  80. if (IsKeyPressed(KeyboardKey.KEY_F11)) {
  81. ToggleFullscreen();
  82. }
  83. BeginDrawing();
  84. ClearBackground(Colors.BLACK);
  85. // main logic
  86. BeginMode2D(camera);
  87. backgroundLogic();
  88. characterLogic();
  89. // effects logic
  90. effectsLogic();
  91. EndMode2D();
  92. //drawing dialogs
  93. dialogLogic();
  94. luaEventLoop();
  95. EndDrawing();
  96. }
  97. break;
  98. case GameState.Exit:
  99. EndDrawing();
  100. unloadResourcesLogic();
  101. CloseAudioDevice();
  102. CloseWindow();
  103. return;
  104. default:
  105. break;
  106. }
  107. }
  108. }