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.dialogBoxBackground.toStringz());
  17. if (WindowShouldClose()) {
  18. currentGameState = GameState.Exit;
  19. } else {
  20. debugWriteln("Game initializing.");
  21. luaExec = systemSettings.scriptPath;
  22. }
  23. }
  24. void texturesLogic(TextureEngine[] textures) {
  25. for (int i = 0; i < textures.length; i++) {
  26. if (textures[i].drawTexture) {
  27. if (textures[i].alpha < 1.0f) {
  28. textures[i].alpha += GetFrameTime() * textures[i].fadeSpeed;
  29. if (textures[i].alpha > 1.0f) textures[i].alpha = 1.0f;
  30. }
  31. } else {
  32. if (textures[i].alpha > 0.0f) {
  33. textures[i].alpha -= GetFrameTime() * textures[i].fadeSpeed;
  34. if (textures[i].alpha < 0.0f) textures[i].alpha = 0.0f;
  35. }
  36. }
  37. if (textures[i].alpha > 0.0f) {
  38. float centeredX = textures[i].x - (textures[i].width * textures[i].scale / 2);
  39. float centeredY = textures[i].y - (textures[i].height * textures[i].scale / 2);
  40. Color tint = textures[i].color;
  41. tint.a = cast(ubyte)(255 * textures[i].alpha);
  42. DrawTextureEx(textures[i].texture,
  43. Vector2(centeredX, centeredY),
  44. 0.0,
  45. textures[i].scale,
  46. tint
  47. );
  48. }
  49. }
  50. }
  51. void effectsLogic() {
  52. UpdateMusicStream(music);
  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, animationAlpha);
  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, scale);
  76. }
  77. }