effects.d 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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. int screenWidth;
  11. int screenHeight;
  12. Texture2D[] loadAnimationFramesUI(const string archivePath, const string animationName)
  13. {
  14. screenWidth = GetScreenWidth();
  15. screenHeight = GetScreenHeight();
  16. Texture2D[] frames;
  17. uint frameIndex = 1;
  18. while (true)
  19. {
  20. string frameFileName = format("%s-%03d.png", animationName, frameIndex);
  21. uint image_size;
  22. debug debugWriteln(frameFileName);
  23. char* image_data = get_file_data_from_archive(toStringz(archivePath),
  24. toStringz(frameFileName), &image_size);
  25. if (image_data == null)
  26. {
  27. debug debugWriteln("exiting from load anim UI");
  28. break;
  29. }
  30. Image image = LoadImageFromMemory(".PNG", cast(const(ubyte)*) image_data, image_size);
  31. Texture2D texture = LoadTextureFromImage(image);
  32. UnloadImage(image);
  33. frames ~= texture;
  34. debug debugWriteln("Loaded frame for UI ", frameIndex, " - ", frameFileName);
  35. frameIndex++;
  36. }
  37. debug debugWriteln("Frames for ui animations length: ", frames.length);
  38. return frames;
  39. }
  40. void playUIAnimation(Texture2D[] frames)
  41. {
  42. static float frameTime = 0.0f;
  43. if (playAnimation) {
  44. frameTime += GetFrameTime();
  45. while (frameTime >= frameDuration && frameDuration > 0) {
  46. frameTime -= frameDuration;
  47. currentFrame = cast(int)((currentFrame + 1) % frames.length);
  48. }
  49. int frameWidth = frames[currentFrame].width;
  50. int frameHeight = frames[currentFrame].height;
  51. DrawTexturePro(
  52. frames[currentFrame],
  53. Rectangle(0, 0, frameWidth, frameHeight),
  54. Rectangle(0, 0, screenWidth, screenHeight),
  55. Vector2(0, 0),
  56. 0,
  57. Color(255, 255, 255, 127)
  58. );
  59. } else {
  60. frameTime = 0.0f;
  61. currentFrame = 0;
  62. }
  63. }
  64. Sound sfx;
  65. void playSfx(string filename) {
  66. debug debugWriteln("Loading & playing SFX");
  67. sfx = LoadSound(filename.toStringz());
  68. PlaySound(sfx);
  69. }