Minor bug fixes.

This commit is contained in:
2026-09-06 20:08:23 -04:00
parent ebcfd9cd39
commit 6e88a9e9e2
24 changed files with 126 additions and 43 deletions

View File

@@ -17,6 +17,7 @@ public class Game1 : Game
SpriteBatch _sb = null!;
SpriteFont _font12 = null!;
SpriteFont _font20 = null!;
RenderTarget2D _virtualScreen = null!; // fixed 800x600 scene, stretched to the window
bool _paused;
string _enteredName = "";
@@ -44,6 +45,18 @@ public class Game1 : Game
IsFixedTimeStep = true;
TargetElapsedTime = TimeSpan.FromSeconds(1 / 120.0);
Window.Title = "Freedom Fighter";
Window.AllowUserResizing = true;
Window.ClientSizeChanged += (_, _) =>
{
int w = Window.ClientBounds.Width, h = Window.ClientBounds.Height;
if (w > 0 && h > 0 &&
(w != _graphics.PreferredBackBufferWidth || h != _graphics.PreferredBackBufferHeight))
{
_graphics.PreferredBackBufferWidth = w;
_graphics.PreferredBackBufferHeight = h;
_graphics.ApplyChanges();
}
};
}
protected override void LoadContent()
@@ -51,6 +64,13 @@ public class Game1 : Game
_sb = new SpriteBatch(GraphicsDevice);
_font12 = Content.Load<SpriteFont>("Verdana12");
_font20 = Content.Load<SpriteFont>("Verdana20");
_virtualScreen = new RenderTarget2D(GraphicsDevice, G.ScreenWidth, G.ScreenHeight);
// the Delphi form's Width/Height were the OUTER window size (800x600, sizeable border);
// as a DPI-unaware app it was also stretched by Windows, so scale by the current DPI
if (System.Windows.Forms.Control.FromHandle(Window.Handle) is System.Windows.Forms.Form form)
form.Size = new System.Drawing.Size(
G.ScreenWidth * form.DeviceDpi / 96, G.ScreenHeight * form.DeviceDpi / 96);
string contentDir = Path.Combine(AppContext.BaseDirectory, "Content");
@@ -109,36 +129,45 @@ public class Game1 : Game
if (G.Input.PauseClicked)
_paused = !_paused;
if (_paused)
if (!_paused)
{
base.Draw(gameTime);
return;
GraphicsDevice.SetRenderTarget(_virtualScreen);
GraphicsDevice.Clear(Color.Black);
_sb.Begin(SpriteSortMode.Deferred, BlendState.NonPremultiplied, SamplerState.PointClamp);
G.Sprites.Move(0);
switch (G.State)
{
case GameState.Intro: DoIntro(); break;
case GameState.Idle: DrawMenu(); break;
case GameState.Intermission: DoIntermission(); break;
case GameState.Playing: GameLoop(); break;
case GameState.Stats: DoStats(); break;
case GameState.Shop: DoShop(); break;
case GameState.GameOver: DoGameOver(); break;
case GameState.Credits: DoCredits(); break;
case GameState.HighScore: DoHighScore(); break;
case GameState.EnterName: DoEnterName(); break;
}
G.Sprites.Collision();
G.Sprites.RemoveDead();
G.Sprites.Draw(_sb);
_sb.End();
GraphicsDevice.SetRenderTarget(null);
}
// stretch the 800x600 scene to the window, as DirectX presentation did
GraphicsDevice.Clear(Color.Black);
_sb.Begin(SpriteSortMode.Deferred, BlendState.NonPremultiplied, SamplerState.PointClamp);
G.Sprites.Move(0);
switch (G.State)
{
case GameState.Intro: DoIntro(); break;
case GameState.Idle: DrawMenu(); break;
case GameState.Intermission: DoIntermission(); break;
case GameState.Playing: GameLoop(); break;
case GameState.Stats: DoStats(); break;
case GameState.Shop: DoShop(); break;
case GameState.GameOver: DoGameOver(); break;
case GameState.Credits: DoCredits(); break;
case GameState.HighScore: DoHighScore(); break;
case GameState.EnterName: DoEnterName(); break;
}
G.Sprites.Collision();
G.Sprites.RemoveDead();
G.Sprites.Draw(_sb);
_sb.Begin(SpriteSortMode.Deferred, BlendState.Opaque, SamplerState.LinearClamp);
_sb.Draw(_virtualScreen, new Rectangle(0, 0,
GraphicsDevice.PresentationParameters.BackBufferWidth,
GraphicsDevice.PresentationParameters.BackBufferHeight), Color.White);
_sb.End();
base.Draw(gameTime);
if (ShotFile != null && --ShotFrames <= 0)
@@ -151,14 +180,9 @@ public class Game1 : Game
void SaveScreenshot(string file)
{
int w = GraphicsDevice.PresentationParameters.BackBufferWidth;
int h = GraphicsDevice.PresentationParameters.BackBufferHeight;
var data = new Color[w * h];
GraphicsDevice.GetBackBufferData(data);
using var tex = new Texture2D(GraphicsDevice, w, h);
tex.SetData(data);
// capture the virtual screen so debug shots are always 800x600
using var fs = File.Create(file);
tex.SaveAsPng(fs, w, h);
_virtualScreen.SaveAsPng(fs, _virtualScreen.Width, _virtualScreen.Height);
}
// ================================================================ helpers