Game1.cs 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. using Microsoft.Xna.Framework;
  2. using Microsoft.Xna.Framework.Graphics;
  3. using Microsoft.Xna.Framework.Input;
  4. using System;
  5. using System.IO;
  6. using System.Linq;
  7. namespace FF8
  8. {
  9. public class Game1 : Game
  10. {
  11. GraphicsDeviceManager graphics;
  12. SpriteBatch spriteBatch;
  13. public Game1()
  14. {
  15. graphics = new GraphicsDeviceManager(this);
  16. Content.RootDirectory = "Content";
  17. graphics.PreferredBackBufferWidth = Memory.PreferredViewportWidth;
  18. graphics.PreferredBackBufferHeight = Memory.PreferredViewportHeight;
  19. Window.AllowUserResizing = true;
  20. }
  21. protected override void Initialize()
  22. {
  23. FFmpeg.AutoGen.Example.FFmpegBinariesHelper.RegisterFFmpegBinaries();
  24. Input.Init();
  25. Memory.Init(graphics, spriteBatch, Content);
  26. init_debugger_Audio.Init(); //this initializes the DirectAudio, it's true that it gets loaded AFTER logo, but we will do the opposite
  27. init_debugger_Audio.Init_SoundAudio(); //this initalizes the WAVE format audio.dat
  28. FieldInitializer.Init(); //this initializes the field module, it's worth to have this at the beginning
  29. Init_debugger_battle.Init(); //this initializes the encounters
  30. Module_movie_test.Init();
  31. Memory.random = new Random(); //creates global random class for all sort of things
  32. base.Initialize();
  33. //ArchiveSearch s = new ArchiveSearch(new byte[] { 0xc8,0xc9,0xca,0xcb,0xcc,0xcd,0xce,0xcf });//used to find file a string is in. disable if not using.
  34. }
  35. protected override void LoadContent()
  36. {
  37. spriteBatch = new SpriteBatch(GraphicsDevice);
  38. Memory.spriteBatch = spriteBatch;
  39. Memory.shadowTexture = Content.Load<Texture2D>("Shadow");
  40. GenerateShadowModel();
  41. }
  42. private void GenerateShadowModel()
  43. {
  44. /*
  45. * X-X
  46. * X-X
  47. * X-X
  48. */
  49. Vector3[] vertices = new Vector3[] //3x3
  50. {
  51. new Vector3(-10,0,10),
  52. new Vector3(0,0,10),
  53. new Vector3(0,0,0),
  54. new Vector3(-10,0,0),
  55. new Vector3(10,0,10),
  56. new Vector3(10,0,0),
  57. new Vector3(0,0,-10),
  58. new Vector3(-10,0,-10),
  59. new Vector3(10,0,-10),
  60. };
  61. Vector2[] textureCoordinates = new Vector2[]
  62. {
  63. new Vector2(0.0099f, 0.9950f),
  64. new Vector2(0.0099f, 0.0189f),
  65. new Vector2(0.9777f, 0.0189f),
  66. new Vector2(0.9777f, 0.9950f),
  67. new Vector2(0.9821f, 0.9995f),
  68. new Vector2(0.0143f, 0.9995f),
  69. new Vector2(0.0143f, 0.0144f),
  70. new Vector2(0.9821f, 0.0144f)
  71. };
  72. VertexPositionTexture[] vpt = new VertexPositionTexture[]
  73. {
  74. //righttop (should be bottom left)
  75. new VertexPositionTexture(vertices[0], textureCoordinates[6]),
  76. new VertexPositionTexture(vertices[1], textureCoordinates[7]),
  77. new VertexPositionTexture(vertices[2], textureCoordinates[4]),
  78. new VertexPositionTexture(vertices[2], textureCoordinates[4]),
  79. new VertexPositionTexture(vertices[3], textureCoordinates[5]),
  80. new VertexPositionTexture(vertices[0], textureCoordinates[6]),
  81. //top left
  82. new VertexPositionTexture(vertices[1], textureCoordinates[0]),
  83. new VertexPositionTexture(vertices[4], textureCoordinates[1]),
  84. new VertexPositionTexture(vertices[5], textureCoordinates[2]),
  85. new VertexPositionTexture(vertices[5], textureCoordinates[2]),
  86. new VertexPositionTexture(vertices[2], textureCoordinates[3]),
  87. new VertexPositionTexture(vertices[1], textureCoordinates[0]),
  88. //bottom right should be top right
  89. new VertexPositionTexture(vertices[3], textureCoordinates[7]),
  90. new VertexPositionTexture(vertices[2], textureCoordinates[4]),
  91. new VertexPositionTexture(vertices[6], textureCoordinates[5]),
  92. new VertexPositionTexture(vertices[6], textureCoordinates[5]),
  93. new VertexPositionTexture(vertices[7], textureCoordinates[6]),
  94. new VertexPositionTexture(vertices[3], textureCoordinates[7]),
  95. //bottom left should be bottom right
  96. new VertexPositionTexture(vertices[2], textureCoordinates[4]),
  97. new VertexPositionTexture(vertices[5], textureCoordinates[5]),
  98. new VertexPositionTexture(vertices[8], textureCoordinates[6]),
  99. new VertexPositionTexture(vertices[8], textureCoordinates[6]),
  100. new VertexPositionTexture(vertices[6], textureCoordinates[7]),
  101. new VertexPositionTexture(vertices[2], textureCoordinates[4]),
  102. };
  103. Memory.shadowGeometry = vpt;
  104. }
  105. protected override void UnloadContent()
  106. {
  107. }
  108. protected override void Update(GameTime gameTime)
  109. {
  110. Memory.gameTime = gameTime;
  111. Memory.IsActive = IsActive;
  112. //it breaks the Font
  113. //Memory.PreferredViewportWidth = graphics.GraphicsDevice.Viewport.Width;
  114. //Memory.PreferredViewportHeight = graphics.GraphicsDevice.Viewport.Height;
  115. Input.Update();
  116. if (Input.Button(Buttons.Exit))
  117. GracefullyExit();
  118. init_debugger_Audio.Update();
  119. ModuleHandler.Update(gameTime);
  120. base.Update(gameTime);
  121. if (Memory.SuppressDraw)
  122. {
  123. SuppressDraw();
  124. Memory.SuppressDraw = false;
  125. }
  126. IsMouseVisible = Memory.IsMouseVisible;
  127. }
  128. protected override void Draw(GameTime gameTime)
  129. {
  130. ModuleHandler.Draw(gameTime);
  131. base.Draw(gameTime);
  132. //if (Input.GetInputDelayed(Keys.F1)) //SCREENSHOT CAPABILITIES WIP; I'm leaving it as-is for now. I'll be probably using that for battle transitions (or not)
  133. //{
  134. //Texture2D tex = new Texture2D(graphics.GraphicsDevice, graphics.GraphicsDevice.Viewport.Width, graphics.GraphicsDevice.Viewport.Height, false, SurfaceFormat.Color);
  135. //byte[] b = new byte[tex.Width * tex.Height * 4];
  136. //graphics.GraphicsDevice.GetBackBufferData<byte>(b);
  137. //tex.SetData(b);
  138. // tex.SaveAsJpeg(new System.IO.FileStream("D:/test.jpg", System.IO.FileMode.OpenOrCreate, System.IO.FileAccess.ReadWrite), tex.Width, tex.Height);
  139. //}
  140. }
  141. private void GracefullyExit()
  142. {
  143. //step1. dispose DirectMusic as it's unmanaged
  144. init_debugger_Audio.KillAudio();
  145. Exit();
  146. }
  147. }
  148. }