gamelogic.d 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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. if (WindowShouldClose()) {
  24. currentGameState = GameState.Exit;
  25. } else {
  26. debugWriteln("Game initializing.");
  27. systemSettings = loadSettingsFromConfigFile();
  28. if (sfxEnabled == false) {
  29. UnloadSound(audio.menuMoveSound);
  30. UnloadSound(audio.acceptSound);
  31. UnloadSound(audio.menuChangeSound);
  32. UnloadSound(audio.declineSound);
  33. UnloadSound(audio.nonSound);
  34. }
  35. }
  36. }
  37. void effectsLogic()
  38. {
  39. UpdateMusicStream(music);
  40. if (isCameraMoving) {
  41. float delta = GetFrameTime() * cameraMoveSpeed;
  42. camera.target.x += (cameraTargetX - camera.target.x) * delta;
  43. camera.target.y += (cameraTargetY - camera.target.y) * delta;
  44. camera.zoom += (cameraTargetZoom - camera.zoom) * delta;
  45. if (fabs(camera.target.x - cameraTargetX) < 5.0f &&
  46. fabs(camera.target.y - cameraTargetY) < 5.0f &&
  47. fabs(camera.zoom - cameraTargetZoom) < 0.5f) {
  48. isCameraMoving = false;
  49. }
  50. }
  51. playUIAnimation(framesUI);
  52. }
  53. void backgroundLogic() {
  54. for (int i = 0; i < backgroundTextures.length; i++) {
  55. if (backgroundTextures[i].drawTexture == true) {
  56. float centeredX = backgroundTextures[i].x - (backgroundTextures[i].width * backgroundTextures[i].scale / 2);
  57. float centeredY = backgroundTextures[i].y - (backgroundTextures[i].height * backgroundTextures[i].scale / 2);
  58. DrawTextureEx(backgroundTextures[i].texture,
  59. Vector2(centeredX, centeredY),
  60. 0.0,
  61. backgroundTextures[i].scale,
  62. Colors.WHITE
  63. );
  64. }
  65. }
  66. for (int i = 0; i < characterTextures.length; i++) {
  67. if (characterTextures[i].drawTexture == true) {
  68. float centeredX = characterTextures[i].x - (characterTextures[i].width * characterTextures[i].scale / 2);
  69. float centeredY = characterTextures[i].y - (characterTextures[i].height * characterTextures[i].scale / 2);
  70. DrawTextureEx(characterTextures[i].texture,
  71. Vector2(centeredX, centeredY),
  72. 0.0,
  73. characterTextures[i].scale,
  74. Colors.WHITE);
  75. }
  76. }
  77. }
  78. void dialogLogic() {
  79. if (showDialog) {
  80. displayDialog(messageGlobal, choices, selectedChoice, choicePage, textFont, &showDialog, typingSpeed);
  81. }
  82. }