diff --git a/Shared/ShmupScene.cs b/Shared/ShmupScene.cs index e8371d6..30735b8 100644 --- a/Shared/ShmupScene.cs +++ b/Shared/ShmupScene.cs @@ -8,17 +8,17 @@ namespace SemiColinGames { const float DESIRED_ASPECT_RATIO = 1920.0f / 1080.0f; - private readonly Color backgroundColor = Color.DarkBlue; + private readonly Color backgroundColor = Color.Black; private readonly GraphicsDevice graphics; private readonly RenderTarget2D sceneTarget; private readonly SpriteBatch spriteBatch; - public ShmupScene(GraphicsDevice graphics) { + public ShmupScene(GraphicsDevice graphics, Point worldSize) { this.graphics = graphics; sceneTarget = new RenderTarget2D( - graphics, 1920 / 4, 1080 / 4, false /* mipmap */, + graphics, worldSize.X, worldSize.Y, false /* mipmap */, graphics.PresentationParameters.BackBufferFormat, DepthFormat.Depth24); spriteBatch = new SpriteBatch(graphics); } @@ -28,6 +28,8 @@ namespace SemiColinGames { } public void Dispose() { + sceneTarget.Dispose(); + spriteBatch.Dispose(); GC.SuppressFinalize(this); } @@ -43,7 +45,12 @@ namespace SemiColinGames { spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.PointClamp, DepthStencilState.Default, RasterizerState.CullNone); - spriteBatch.Draw(Textures.Yellow2.Get, Vector2.Floor(world.Player.Position), Color.White); + + // Draw player. + Texture2D playerTexture = world.Player.Texture.Get; + Vector2 spriteCenter = new Vector2(playerTexture.Width / 2, playerTexture.Height / 2); + Vector2 drawPos = Vector2.Floor(Vector2.Subtract(world.Player.Position, spriteCenter)); + spriteBatch.Draw(playerTexture, drawPos, Color.White); spriteBatch.End(); // Get ready to draw sceneTarget to screen. diff --git a/Shared/ShmupWorld.cs b/Shared/ShmupWorld.cs index b78bdb5..106b99c 100644 --- a/Shared/ShmupWorld.cs +++ b/Shared/ShmupWorld.cs @@ -5,14 +5,18 @@ using System.Collections.Generic; namespace SemiColinGames { public sealed class ShmupWorld : IWorld { - public struct ShmupPlayer { + public class ShmupPlayer { + public TextureRef Texture = Textures.Yellow2; // Center of player sprite. - public Vector2 Position; + public Vector2 Position = new Vector2(32, 1080 / 8); + public Vector2 HalfSize = new Vector2(16, 10); } - public ShmupPlayer Player; + public readonly Point Size; + public readonly ShmupPlayer Player; public ShmupWorld() { + Size = new Point(1920 / 4, 1080 / 4); Player = new ShmupPlayer(); } @@ -28,6 +32,11 @@ namespace SemiColinGames { float speed = 150f; Vector2 motion = Vector2.Multiply(input[0].Motion, modelTime * speed); Player.Position = Vector2.Add(Player.Position, motion); + Player.Position.X = Math.Max(Player.Position.X, Player.HalfSize.X); + Player.Position.X = Math.Min(Player.Position.X, Size.X - Player.HalfSize.X); + Player.Position.Y = Math.Max(Player.Position.Y, Player.HalfSize.Y); + Player.Position.Y = Math.Min(Player.Position.Y, Size.Y - Player.HalfSize.Y); + } } } diff --git a/Shared/SneakGame.cs b/Shared/SneakGame.cs index 87af97b..b084c15 100644 --- a/Shared/SneakGame.cs +++ b/Shared/SneakGame.cs @@ -70,7 +70,7 @@ namespace SemiColinGames { scene?.Dispose(); // scene = new SneakScene(GraphicsDevice, ((SneakWorld) world).Camera); // scene = new TreeScene(GraphicsDevice); - scene = new ShmupScene(GraphicsDevice); + scene = new ShmupScene(GraphicsDevice, ((ShmupWorld) world).Size); GC.Collect(); GC.WaitForPendingFinalizers();