effects.d 1.9 KB

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