Colin McMillen
3 years ago
5 changed files with 118 additions and 2 deletions
-
2Shared/Shared.projitems
-
76Shared/ShmupScene.cs
-
33Shared/ShmupWorld.cs
-
6Shared/SneakGame.cs
-
3Shared/Textures.cs
@ -0,0 +1,76 @@ |
|||||
|
using Microsoft.Xna.Framework; |
||||
|
using Microsoft.Xna.Framework.Graphics; |
||||
|
using System; |
||||
|
using System.Collections.Generic; |
||||
|
|
||||
|
namespace SemiColinGames { |
||||
|
public sealed class ShmupScene : IScene { |
||||
|
|
||||
|
const float DESIRED_ASPECT_RATIO = 1920.0f / 1080.0f; |
||||
|
|
||||
|
private readonly Color backgroundColor = Color.DarkBlue; |
||||
|
|
||||
|
private readonly GraphicsDevice graphics; |
||||
|
private readonly RenderTarget2D sceneTarget; |
||||
|
private readonly SpriteBatch spriteBatch; |
||||
|
|
||||
|
public ShmupScene(GraphicsDevice graphics) { |
||||
|
this.graphics = graphics; |
||||
|
|
||||
|
sceneTarget = new RenderTarget2D( |
||||
|
graphics, 1920 / 4, 1080 / 4, false /* mipmap */, |
||||
|
graphics.PresentationParameters.BackBufferFormat, DepthFormat.Depth24); |
||||
|
spriteBatch = new SpriteBatch(graphics); |
||||
|
} |
||||
|
|
||||
|
~ShmupScene() { |
||||
|
Dispose(); |
||||
|
} |
||||
|
|
||||
|
public void Dispose() { |
||||
|
GC.SuppressFinalize(this); |
||||
|
} |
||||
|
|
||||
|
public void Draw(bool isRunningSlowly, IWorld iworld, bool paused) { |
||||
|
ShmupWorld world = (ShmupWorld) iworld; |
||||
|
graphics.SetRenderTarget(null); |
||||
|
graphics.Clear(backgroundColor); |
||||
|
|
||||
|
// Draw scene to sceneTarget.
|
||||
|
graphics.SetRenderTarget(sceneTarget); |
||||
|
graphics.Clear(backgroundColor); |
||||
|
|
||||
|
spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, |
||||
|
SamplerState.PointClamp, DepthStencilState.Default, |
||||
|
RasterizerState.CullNone); |
||||
|
spriteBatch.Draw(Textures.SilverBlue1.Get, Vector2.Floor(world.Player.Position), Color.White); |
||||
|
spriteBatch.End(); |
||||
|
|
||||
|
// Get ready to draw sceneTarget to screen.
|
||||
|
graphics.SetRenderTarget(null); |
||||
|
|
||||
|
|
||||
|
// Letterbox the scene if needed.
|
||||
|
float aspectRatio = 1.0f * graphics.Viewport.Width / graphics.Viewport.Height; |
||||
|
Rectangle drawRect; |
||||
|
if (aspectRatio > DESIRED_ASPECT_RATIO) { |
||||
|
// Need to letterbox the sides.
|
||||
|
int desiredWidth = (int) (graphics.Viewport.Height * DESIRED_ASPECT_RATIO); |
||||
|
int padding = (graphics.Viewport.Width - desiredWidth) / 2; |
||||
|
drawRect = new Rectangle(padding, 0, desiredWidth, graphics.Viewport.Height); |
||||
|
} else { |
||||
|
// Need to letterbox the top / bottom.
|
||||
|
int desiredHeight = (int) (graphics.Viewport.Width / DESIRED_ASPECT_RATIO); |
||||
|
int padding = (graphics.Viewport.Height - desiredHeight) / 2; |
||||
|
drawRect = new Rectangle(0, padding, graphics.Viewport.Width, desiredHeight); |
||||
|
} |
||||
|
|
||||
|
// Actually draw to screen.
|
||||
|
spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, |
||||
|
SamplerState.PointClamp, DepthStencilState.Default, |
||||
|
RasterizerState.CullNone); |
||||
|
spriteBatch.Draw(sceneTarget, drawRect, Color.White); |
||||
|
spriteBatch.End(); |
||||
|
} |
||||
|
} |
||||
|
} |
@ -0,0 +1,33 @@ |
|||||
|
using Microsoft.Xna.Framework; |
||||
|
using Microsoft.Xna.Framework.Graphics; |
||||
|
using System; |
||||
|
using System.Collections.Generic; |
||||
|
|
||||
|
namespace SemiColinGames { |
||||
|
public sealed class ShmupWorld : IWorld { |
||||
|
public struct ShmupPlayer { |
||||
|
// Center of player sprite.
|
||||
|
public Vector2 Position; |
||||
|
} |
||||
|
|
||||
|
public ShmupPlayer Player; |
||||
|
|
||||
|
public ShmupWorld() { |
||||
|
Player = new ShmupPlayer(); |
||||
|
} |
||||
|
|
||||
|
~ShmupWorld() { |
||||
|
Dispose(); |
||||
|
} |
||||
|
|
||||
|
public void Dispose() { |
||||
|
GC.SuppressFinalize(this); |
||||
|
} |
||||
|
|
||||
|
public void Update(float modelTime, History<Input> input) { |
||||
|
float speed = 150f; |
||||
|
Vector2 motion = Vector2.Multiply(input[0].Motion, modelTime * speed); |
||||
|
Player.Position = Vector2.Add(Player.Position, motion); |
||||
|
} |
||||
|
} |
||||
|
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue