gamelogic.d 2.9 KB

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