A stealth-based 2D platformer where you don't have to kill anyone unless you want to. https://www.semicolin.games
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

76 lines
2.6 KiB

  1. using Microsoft.Xna.Framework;
  2. using Microsoft.Xna.Framework.Graphics;
  3. using System;
  4. using System.Collections.Generic;
  5. namespace SemiColinGames {
  6. public sealed class ShmupScene : IScene {
  7. const float DESIRED_ASPECT_RATIO = 1920.0f / 1080.0f;
  8. private readonly Color backgroundColor = Color.DarkBlue;
  9. private readonly GraphicsDevice graphics;
  10. private readonly RenderTarget2D sceneTarget;
  11. private readonly SpriteBatch spriteBatch;
  12. public ShmupScene(GraphicsDevice graphics) {
  13. this.graphics = graphics;
  14. sceneTarget = new RenderTarget2D(
  15. graphics, 1920 / 4, 1080 / 4, false /* mipmap */,
  16. graphics.PresentationParameters.BackBufferFormat, DepthFormat.Depth24);
  17. spriteBatch = new SpriteBatch(graphics);
  18. }
  19. ~ShmupScene() {
  20. Dispose();
  21. }
  22. public void Dispose() {
  23. GC.SuppressFinalize(this);
  24. }
  25. public void Draw(bool isRunningSlowly, IWorld iworld, bool paused) {
  26. ShmupWorld world = (ShmupWorld) iworld;
  27. graphics.SetRenderTarget(null);
  28. graphics.Clear(backgroundColor);
  29. // Draw scene to sceneTarget.
  30. graphics.SetRenderTarget(sceneTarget);
  31. graphics.Clear(backgroundColor);
  32. spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend,
  33. SamplerState.PointClamp, DepthStencilState.Default,
  34. RasterizerState.CullNone);
  35. spriteBatch.Draw(Textures.SilverBlue1.Get, Vector2.Floor(world.Player.Position), Color.White);
  36. spriteBatch.End();
  37. // Get ready to draw sceneTarget to screen.
  38. graphics.SetRenderTarget(null);
  39. // Letterbox the scene if needed.
  40. float aspectRatio = 1.0f * graphics.Viewport.Width / graphics.Viewport.Height;
  41. Rectangle drawRect;
  42. if (aspectRatio > DESIRED_ASPECT_RATIO) {
  43. // Need to letterbox the sides.
  44. int desiredWidth = (int) (graphics.Viewport.Height * DESIRED_ASPECT_RATIO);
  45. int padding = (graphics.Viewport.Width - desiredWidth) / 2;
  46. drawRect = new Rectangle(padding, 0, desiredWidth, graphics.Viewport.Height);
  47. } else {
  48. // Need to letterbox the top / bottom.
  49. int desiredHeight = (int) (graphics.Viewport.Width / DESIRED_ASPECT_RATIO);
  50. int padding = (graphics.Viewport.Height - desiredHeight) / 2;
  51. drawRect = new Rectangle(0, padding, graphics.Viewport.Width, desiredHeight);
  52. }
  53. // Actually draw to screen.
  54. spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend,
  55. SamplerState.PointClamp, DepthStencilState.Default,
  56. RasterizerState.CullNone);
  57. spriteBatch.Draw(sceneTarget, drawRect, Color.White);
  58. spriteBatch.End();
  59. }
  60. }
  61. }