gamelogic.d 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. playUIAnimation(framesUI, animationAlpha);
  54. }
  55. void backgroundLogic() {
  56. texturesLogic(backgroundTextures);
  57. }
  58. void characterLogic() {
  59. texturesLogic(characterTextures);
  60. }
  61. void dialogLogic() {
  62. if (showDialog) {
  63. displayDialog(messageGlobal, choices, selectedChoice, choicePage, textFont, &showDialog, typingSpeed,
  64. circle, dialogBackgroundTex, scale);
  65. }
  66. }