gamelogic.d 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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_01b.PNG");
  25. choiceWindowTex = LoadTexture("res/misc/TEX#win_00b.PNG");
  26. if (WindowShouldClose()) {
  27. currentGameState = GameState.Exit;
  28. } else {
  29. debugWriteln("Game initializing.");
  30. systemSettings = loadSettingsFromConfigFile();
  31. luaExec = systemSettings.script_path;
  32. }
  33. }
  34. void texturesLogic(TextureEngine[] textures) {
  35. for (int i = 0; i < textures.length; i++) {
  36. if (textures[i].drawTexture) {
  37. if (textures[i].alpha < 1.0f) {
  38. textures[i].alpha += GetFrameTime() * textures[i].fadeSpeed;
  39. if (textures[i].alpha > 1.0f) textures[i].alpha = 1.0f;
  40. }
  41. } else {
  42. if (textures[i].alpha > 0.0f) {
  43. textures[i].alpha -= GetFrameTime() * textures[i].fadeSpeed;
  44. if (textures[i].alpha < 0.0f) textures[i].alpha = 0.0f;
  45. }
  46. }
  47. if (textures[i].alpha > 0.0f) {
  48. float centeredX = textures[i].x - (textures[i].width * textures[i].scale / 2);
  49. float centeredY = textures[i].y - (textures[i].height * textures[i].scale / 2);
  50. Color tint = Colors.WHITE;
  51. tint.a = cast(ubyte)(255 * textures[i].alpha);
  52. DrawTextureEx(textures[i].texture,
  53. Vector2(centeredX, centeredY),
  54. 0.0,
  55. textures[i].scale,
  56. tint
  57. );
  58. }
  59. }
  60. }
  61. void effectsLogic()
  62. {
  63. UpdateMusicStream(music);
  64. if (isCameraMoving) {
  65. float delta = GetFrameTime() * cameraMoveSpeed;
  66. camera.target.x += (cameraTargetX - camera.target.x) * delta;
  67. camera.target.y += (cameraTargetY - camera.target.y) * delta;
  68. camera.zoom += (cameraTargetZoom - camera.zoom) * delta;
  69. if (fabs(camera.target.x - cameraTargetX) < 5.0f &&
  70. fabs(camera.target.y - cameraTargetY) < 5.0f &&
  71. fabs(camera.zoom - cameraTargetZoom) < 0.5f) {
  72. isCameraMoving = false;
  73. }
  74. }
  75. playUIAnimation(framesUI);
  76. }
  77. void backgroundLogic() {
  78. texturesLogic(backgroundTextures);
  79. }
  80. void characterLogic() {
  81. texturesLogic(characterTextures);
  82. }
  83. void dialogLogic() {
  84. if (showDialog) {
  85. displayDialog(messageGlobal, choices, selectedChoice, choicePage, textFont, &showDialog, typingSpeed,
  86. circle, dialogBackgroundTex, choiceWindowTex);
  87. }
  88. }