effects.d 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. module graphics.effects;
  2. import raylib;
  3. import std.stdio;
  4. import variables;
  5. import std.string;
  6. import system.abstraction;
  7. import system.config;
  8. import std.algorithm;
  9. import system.abstraction;
  10. import std.file;
  11. int screenWidth;
  12. int screenHeight;
  13. Texture2D[] loadAnimationFramesUI(const string fileDir, const string animationFileName)
  14. {
  15. screenWidth = GetScreenWidth();
  16. screenHeight = GetScreenHeight();
  17. Texture2D[] frames;
  18. uint frameIndex = 1;
  19. while (true)
  20. {
  21. string frameFileName = format("%s-%03d.png", animationFileName, frameIndex);
  22. if (std.file.exists(fileDir~"/"~frameFileName) == false) break;
  23. debug debugWriteln(frameFileName);
  24. Texture2D texture = LoadTexture((fileDir~"/"~frameFileName).toStringz());
  25. frames ~= texture;
  26. debug debugWriteln("Loaded frame for UI ", frameIndex, " - ", frameFileName);
  27. frameIndex++;
  28. }
  29. debug debugWriteln("Frames for ui animations length: ", frames.length);
  30. return frames;
  31. }
  32. void playUIAnimation(Texture2D[] frames)
  33. {
  34. static float frameTime = 0.0f;
  35. if (playAnimation) {
  36. frameTime += GetFrameTime();
  37. while (frameTime >= frameDuration && frameDuration > 0) {
  38. frameTime -= frameDuration;
  39. currentFrame = cast(int)((currentFrame + 1) % frames.length);
  40. }
  41. int frameWidth = frames[currentFrame].width;
  42. int frameHeight = frames[currentFrame].height;
  43. DrawTexturePro(
  44. frames[currentFrame],
  45. Rectangle(0, 0, frameWidth, frameHeight),
  46. Rectangle(0, 0, screenWidth, screenHeight),
  47. Vector2(0, 0),
  48. 0,
  49. Color(255, 255, 255, 127)
  50. );
  51. } else {
  52. frameTime = 0.0f;
  53. currentFrame = 0;
  54. }
  55. }
  56. Sound sfx;
  57. void playSfx(string filename) {
  58. debug debugWriteln("Loading & playing SFX");
  59. sfx = LoadSound(filename.toStringz());
  60. PlaySound(sfx);
  61. }