gamelogic.d 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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. if (neededDraw2D)
  55. {
  56. DrawTexturePro(backgroundTexture, Rectangle(0, 0, cast(float) backgroundTexture.width, cast(
  57. float) backgroundTexture.height), Rectangle(0, 0, cast(float) GetScreenWidth(), cast(
  58. float) GetScreenHeight()), Vector2(0, 0), 0.0, Colors.WHITE);
  59. }
  60. for (int i = 0; i < characterTextures.length; i++)
  61. {
  62. if (characterTextures[i].drawTexture == true) {
  63. float centeredX = characterTextures[i].x - (characterTextures[i].width * characterTextures[i].scale / 2);
  64. float centeredY = characterTextures[i].y - (characterTextures[i].height * characterTextures[i].scale / 2);
  65. DrawTextureEx(characterTextures[i].texture,
  66. Vector2(centeredX, centeredY),
  67. 0.0,
  68. characterTextures[i].scale,
  69. Colors.WHITE);
  70. }
  71. }
  72. }
  73. void dialogLogic() {
  74. if (showDialog) {
  75. displayDialog(messageGlobal, choices, selectedChoice, choicePage, textFont, &showDialog, typingSpeed);
  76. }
  77. }