gamelogic.d 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. module graphics.gamelogic;
  2. import raylib;
  3. import bindbc.lua;
  4. import variables;
  5. import graphics.effects;
  6. import std.string;
  7. import std.math;
  8. import dialogs.dialogbox;
  9. import system.abstraction;
  10. /**
  11. * this module contains game logic, which was removed from engine.d for better readability.
  12. **/
  13. void gameInit()
  14. {
  15. circle = LoadTexture(systemSettings.dialogBoxEndIndicator.toStringz());
  16. dialogBackgroundTex = LoadTexture(systemSettings.dialogBoxImage.toStringz());
  17. choiceWindowTex = LoadTexture(systemSettings.choiceBoxImage.toStringz());
  18. if (WindowShouldClose()) {
  19. currentGameState = GameState.Exit;
  20. } else {
  21. debugWriteln("Game initializing.");
  22. luaExec = systemSettings.scriptPath;
  23. }
  24. }
  25. void texturesLogic(TextureEngine[] textures) {
  26. for (int i = 0; i < textures.length; i++) {
  27. if (textures[i].drawTexture) {
  28. if (textures[i].alpha < 1.0f) {
  29. textures[i].alpha += GetFrameTime() * textures[i].fadeSpeed;
  30. if (textures[i].alpha > 1.0f) textures[i].alpha = 1.0f;
  31. }
  32. } else {
  33. if (textures[i].alpha > 0.0f) {
  34. textures[i].alpha -= GetFrameTime() * textures[i].fadeSpeed;
  35. if (textures[i].alpha < 0.0f) textures[i].alpha = 0.0f;
  36. }
  37. }
  38. if (textures[i].alpha > 0.0f) {
  39. float centeredX = textures[i].x - (textures[i].width * textures[i].scale / 2);
  40. float centeredY = textures[i].y - (textures[i].height * textures[i].scale / 2);
  41. Color tint = Colors.WHITE;
  42. tint.a = cast(ubyte)(255 * textures[i].alpha);
  43. DrawTextureEx(textures[i].texture,
  44. Vector2(centeredX, centeredY),
  45. 0.0,
  46. textures[i].scale,
  47. tint
  48. );
  49. }
  50. }
  51. }
  52. void effectsLogic() {
  53. if (isCameraMoving) {
  54. float delta = GetFrameTime() * cameraMoveSpeed;
  55. camera.target.x += (cameraTargetX - camera.target.x) * delta;
  56. camera.target.y += (cameraTargetY - camera.target.y) * delta;
  57. camera.zoom += (cameraTargetZoom - camera.zoom) * delta;
  58. if (fabs(camera.target.x - cameraTargetX) < 5.0f &&
  59. fabs(camera.target.y - cameraTargetY) < 5.0f &&
  60. fabs(camera.zoom - cameraTargetZoom) < 0.5f) {
  61. isCameraMoving = false;
  62. }
  63. }
  64. playUIAnimation(framesUI);
  65. }
  66. void backgroundLogic() {
  67. texturesLogic(backgroundTextures);
  68. }
  69. void characterLogic() {
  70. texturesLogic(characterTextures);
  71. }
  72. void dialogLogic() {
  73. if (showDialog) {
  74. displayDialog(messageGlobal, choices, selectedChoice, choicePage, textFont, &showDialog, typingSpeed,
  75. circle, dialogBackgroundTex, choiceWindowTex);
  76. }
  77. }