BattleSwirl.cs 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. using Microsoft.Xna.Framework;
  2. using Microsoft.Xna.Framework.Graphics;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. namespace OpenVIII
  9. {
  10. /// <summary>
  11. /// it's currently in mess, but I will clean it after I got everything working and comment things
  12. /// </summary>
  13. public static class BattleSwirl
  14. {
  15. static Texture2D backBufferTexture;
  16. private static bool bInitialized = false;
  17. private static bool bFirstClear = true;
  18. private static int swirlMode = 0;
  19. private static int swirlStage = 0;
  20. private static double sequenceTimer = 0.0;
  21. private static double activeFrameTimer = 0.0;
  22. static Texture2D blackLines;
  23. public static void Init()
  24. {
  25. bInitialized = false;
  26. //Memory.Encounters.Current().BattleFlags. //which flags is about the boss or normal swirl?
  27. Memory.Module = Module.BattleSwirl;
  28. backBufferTexture = Extended.BackBufferTexture;
  29. bInitialized = true;
  30. bFirstClear = true;
  31. swirlStage = 0;
  32. sequenceTimer = 0.0;
  33. activeFrameTimer = 0.0;
  34. scaleModifier = 1.0f; //maybe create this swirl as non-static class?
  35. translateModifier = 0.0f;
  36. //let's now generate the black lines screen cleaning buffer
  37. blackLines = new Texture2D(Memory.Graphics.GraphicsDevice, 0xFF + 120, //ok, so 0xff to fade alpha and 120 for maximum delay
  38. Memory.Graphics.GraphicsDevice.Viewport.Height, false,
  39. SurfaceFormat.Color);
  40. var colors = new Color[blackLines.Height*blackLines.Width];
  41. for (var i = 0; i < blackLines.Height; i++)
  42. {
  43. //we are incrementing by line- full width is 0xff+120
  44. var lineBuffer = Memory.Random.Next(0, 120); //generate the delay
  45. var scanAlpha = 255;
  46. for(var n=0; n<blackLines.Width-lineBuffer; n++) //fill with black
  47. colors[i*blackLines.Width+n] = new Color(Color.Black, 0xFF);
  48. for (var n = lineBuffer; n < blackLines.Width; n++) //fill with fading black
  49. colors[i * blackLines.Width + n] = new Color(0, 0, 0, scanAlpha--); //debug for red
  50. }
  51. blackLines.SetData(colors);
  52. Extended.DumpTexture(blackLines, @"D:\out.png");
  53. }
  54. //because of the backBuffer;
  55. public static void ContinueStage()
  56. {
  57. backBufferTexture = Extended.BackBufferTexture;
  58. swirlStage++;
  59. }
  60. //private static void BossSwirl()
  61. //{
  62. // return;
  63. //}
  64. //private static void NormalSwirl()
  65. //{
  66. // return;
  67. //}
  68. public static void Draw()
  69. {
  70. if (!bInitialized)
  71. return;
  72. sequenceTimer += Memory.ElapsedGameTime.TotalMilliseconds/1000.0;
  73. activeFrameTimer += Memory.ElapsedGameTime.TotalMilliseconds;
  74. //Memory.graphics.GraphicsDevice.Clear(Color.Black);
  75. if (activeFrameTimer > 1000.0 / 500.0)
  76. {
  77. activeFrameTimer = 0.0;
  78. switch (swirlMode)
  79. {
  80. case 0:
  81. if (swirlStage == 0)
  82. NormalSwirlDraw_stage1();
  83. else
  84. NormalSwirlDraw_stage2();
  85. break;
  86. case 1:
  87. BossSwirlDraw();
  88. break;
  89. };
  90. }
  91. }
  92. static float scaleModifier = 1f;
  93. static float translateModifier = 0f;
  94. private static void NormalSwirlDraw_stage1()
  95. {
  96. if (sequenceTimer < 0.50) //frame repeat by scaling on un-cleaned buffer
  97. {
  98. scaleModifier += 0.003f;
  99. Memory.SpriteBatch.Begin(SpriteSortMode.BackToFront, BlendState.Additive);
  100. var resolution = new Vector2(backBufferTexture.Width, backBufferTexture.Height);
  101. var transformedScale = Vector2.Transform(resolution, Matrix.CreateScale(scaleModifier));
  102. Memory.SpriteBatch.Draw(backBufferTexture, new Rectangle((int)(transformedScale.X - resolution.X) / -3
  103. ,0 /*(int)(transformedScale.Y - resolution.Y) / -3*/
  104. , (int)transformedScale.X, (int)transformedScale.Y),
  105. Color.White * 0.15f);
  106. Memory.SpriteBatch.End();
  107. }
  108. if(sequenceTimer > 0.50) //black lines going from left (grayscale 127 transition mask-just like in RPG Maker)
  109. {
  110. Extended.postBackBufferDelegate = ContinueStage;
  111. Extended.RequestBackBuffer();
  112. }
  113. }
  114. //wip - there's actually no need to do the second stage- clean this afterward
  115. private static void NormalSwirlDraw_stage2()
  116. {
  117. //int x = (int)(Memory.graphics.GraphicsDevice.Viewport.Width * translateModifier);
  118. var x = (int)translateModifier;
  119. translateModifier += 2f;
  120. //translateModifier += 0.002f;
  121. //Memory.graphics.GraphicsDevice.Clear(Color.Black);
  122. Memory.SpriteBatch.Begin(SpriteSortMode.BackToFront, BlendState.AlphaBlend);
  123. //Memory.spriteBatch.Draw(backBufferTexture,
  124. // new Rectangle(0, 0, Memory.graphics.GraphicsDevice.Viewport.Width, Memory.graphics.GraphicsDevice.Viewport.Height),
  125. // Color.White * 1f);
  126. Memory.SpriteBatch.Draw(blackLines, new Rectangle(x-Memory.Graphics.GraphicsDevice.Viewport.Width
  127. , 0
  128. , Memory.Graphics.GraphicsDevice.Viewport.Width, Memory.Graphics.GraphicsDevice.Viewport.Height),
  129. Color.White * 1f);
  130. Memory.SpriteBatch.End();
  131. if (x > Memory.Graphics.GraphicsDevice.Viewport.Width+blackLines.Width+0xff)
  132. Memory.Module = Module.BattleDebug;
  133. }
  134. private static void BossSwirlDraw()
  135. {
  136. //here is two screens going with 0.50 scaling from x to y and back to x repeating themselves up to the point
  137. //where additive rendering creates white screen - probably rising color.White * n [where n>1]
  138. //this probably uses cleaned render target
  139. return;
  140. }
  141. }
  142. }