gamelogic.d 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. module graphics.gamelogic;
  2. import raylib;
  3. import bindbc.lua;
  4. import variables;
  5. import core.stdc.stdlib;
  6. import core.stdc.time;
  7. import graphics.engine;
  8. import scripts.lua;
  9. import std.stdio;
  10. import std.conv;
  11. import graphics.effects;
  12. import std.string;
  13. import std.math;
  14. import dialogs.dialogbox;
  15. import system.abstraction;
  16. import system.config;
  17. import std.file;
  18. /**
  19. * this module contains game logic, which was removed from engine.d for better readability.
  20. */
  21. void gameInit()
  22. {
  23. circle = LoadTexture("res/misc/circle.png");
  24. dialogBackgroundTex = LoadTexture("res/misc/TEX#win_01d.PNG");
  25. choiceWindowTex = LoadTexture("res/misc/TEX#win_00d.PNG");
  26. if (WindowShouldClose()) {
  27. currentGameState = GameState.Exit;
  28. } else {
  29. debugWriteln("Game initializing.");
  30. systemSettings = loadSettingsFromConfigFile();
  31. }
  32. }
  33. void effectsLogic()
  34. {
  35. UpdateMusicStream(music);
  36. if (isCameraMoving) {
  37. float delta = GetFrameTime() * cameraMoveSpeed;
  38. camera.target.x += (cameraTargetX - camera.target.x) * delta;
  39. camera.target.y += (cameraTargetY - camera.target.y) * delta;
  40. camera.zoom += (cameraTargetZoom - camera.zoom) * delta;
  41. if (fabs(camera.target.x - cameraTargetX) < 5.0f &&
  42. fabs(camera.target.y - cameraTargetY) < 5.0f &&
  43. fabs(camera.zoom - cameraTargetZoom) < 0.5f) {
  44. isCameraMoving = false;
  45. }
  46. }
  47. playUIAnimation(framesUI);
  48. }
  49. void backgroundLogic() {
  50. if (backgroundFades.length < backgroundTextures.length) {
  51. backgroundFades.length = backgroundTextures.length;
  52. }
  53. for (int i = 0; i < backgroundTextures.length; i++) {
  54. if (backgroundTextures[i].drawTexture) {
  55. if (backgroundFades[i].alpha < 1.0f) {
  56. backgroundFades[i].alpha += GetFrameTime() * backgroundFades[i].fadeSpeed;
  57. if (backgroundFades[i].alpha > 1.0f) backgroundFades[i].alpha = 1.0f;
  58. }
  59. } else {
  60. if (backgroundFades[i].alpha > 0.0f) {
  61. backgroundFades[i].alpha -= GetFrameTime() * backgroundFades[i].fadeSpeed;
  62. if (backgroundFades[i].alpha < 0.0f) backgroundFades[i].alpha = 0.0f;
  63. }
  64. }
  65. if (backgroundFades[i].alpha > 0.0f) {
  66. float centeredX = backgroundTextures[i].x - (backgroundTextures[i].width * backgroundTextures[i].scale / 2);
  67. float centeredY = backgroundTextures[i].y - (backgroundTextures[i].height * backgroundTextures[i].scale / 2);
  68. Color tint = Colors.WHITE;
  69. tint.a = cast(ubyte)(255 * backgroundFades[i].alpha);
  70. DrawTextureEx(backgroundTextures[i].texture,
  71. Vector2(centeredX, centeredY),
  72. 0.0,
  73. backgroundTextures[i].scale,
  74. tint
  75. );
  76. }
  77. }
  78. }
  79. void characterLogic() {
  80. if (characterFades.length < characterTextures.length) {
  81. characterFades.length = characterTextures.length;
  82. }
  83. for (int i = 0; i < characterTextures.length; i++) {
  84. if (characterTextures[i].drawTexture) {
  85. if (characterTextures[i].justDrawn) {
  86. characterFades[i].alpha = 0.0f;
  87. characterTextures[i].justDrawn = false;
  88. }
  89. if (characterFades[i].alpha < 1.0f) {
  90. characterFades[i].alpha += GetFrameTime() * characterFades[i].fadeSpeed;
  91. if (characterFades[i].alpha > 1.0f) characterFades[i].alpha = 1.0f;
  92. }
  93. } else {
  94. if (characterFades[i].alpha > 0.0f) {
  95. characterFades[i].alpha -= GetFrameTime() * characterFades[i].fadeSpeed;
  96. if (characterFades[i].alpha < 0.0f) {
  97. characterFades[i].alpha = 0.0f;
  98. }
  99. }
  100. }
  101. if (characterFades[i].alpha > 0.0f) {
  102. float centeredX = characterTextures[i].x - (characterTextures[i].width * characterTextures[i].scale / 2);
  103. float centeredY = characterTextures[i].y - (characterTextures[i].height * characterTextures[i].scale / 2);
  104. characterColor.a = cast(ubyte)(255 * characterFades[i].alpha);
  105. DrawTextureEx(characterTextures[i].texture,
  106. Vector2(centeredX, centeredY),
  107. 0.0,
  108. characterTextures[i].scale,
  109. characterColor);
  110. }
  111. }
  112. }
  113. void dialogLogic() {
  114. if (showDialog) {
  115. displayDialog(messageGlobal, choices, selectedChoice, choicePage, textFont, &showDialog, typingSpeed,
  116. circle, dialogBackgroundTex, choiceWindowTex);
  117. }
  118. }