Compare commits

..

2 Commits

Author SHA1 Message Date
5732d60047 add projectiles to Textures 2020-11-19 17:03:45 -05:00
7695f45cc0 clamp player movement to world 2020-11-19 16:36:21 -05:00
4 changed files with 29 additions and 8 deletions

View File

@ -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.

View File

@ -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);
}
}
}

View File

@ -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();

View File

@ -76,6 +76,11 @@ namespace SemiColinGames {
public static TextureRef Yellow3 = new TextureRef("sprites/dylestorm/Yellow-3");
public static TextureRef Yellow4 = new TextureRef("sprites/dylestorm/Yellow-4");
public static TextureRef Yellow5 = new TextureRef("sprites/dylestorm/Yellow-5");
public static TextureRef Projectile1 = new TextureRef("sprites/dylestorm/projectile02-1");
public static TextureRef Projectile2 = new TextureRef("sprites/dylestorm/projectile02-2");
public static TextureRef Projectile3 = new TextureRef("sprites/dylestorm/projectile02-3");
public static TextureRef Projectile4 = new TextureRef("sprites/dylestorm/projectile02-4");
public static TextureRef Projectile5 = new TextureRef("sprites/dylestorm/projectile02-5");
// Backgrounds are indexed by draw order; the first element should be drawn furthest back.
public static TextureRef[] Backgrounds = new TextureRef[] {