Compare commits
No commits in common. "8720896e87c2061863412eb41d2e60f5bdb9a09b" and "bb910fbe58431074468b5afdc6229abef6f46519" have entirely different histories.
8720896e87
...
bb910fbe58
@ -4,7 +4,7 @@ using System;
|
|||||||
// Good background reading, eventually:
|
// Good background reading, eventually:
|
||||||
// https://gamasutra.com/blogs/ItayKeren/20150511/243083/Scroll_Back_The_Theory_and_Practice_of_Cameras_in_SideScrollers.php
|
// https://gamasutra.com/blogs/ItayKeren/20150511/243083/Scroll_Back_The_Theory_and_Practice_of_Cameras_in_SideScrollers.php
|
||||||
namespace SemiColinGames {
|
namespace SemiColinGames {
|
||||||
public class Camera {
|
class Camera {
|
||||||
// Screen size in pixels is 1920x1080 divided by 4.
|
// Screen size in pixels is 1920x1080 divided by 4.
|
||||||
private Rectangle bbox = new Rectangle(0, 0, 480, 270);
|
private Rectangle bbox = new Rectangle(0, 0, 480, 270);
|
||||||
public int Width { get => bbox.Width; }
|
public int Width { get => bbox.Width; }
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
using System;
|
using System;
|
||||||
|
|
||||||
namespace SemiColinGames {
|
namespace SemiColinGames {
|
||||||
public class Clock {
|
class Clock {
|
||||||
public static void AddModelTime(double seconds) {
|
public static void AddModelTime(double seconds) {
|
||||||
ModelTime += TimeSpan.FromSeconds(seconds);
|
ModelTime += TimeSpan.FromSeconds(seconds);
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,7 @@ using Microsoft.Xna.Framework.Graphics;
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
|
||||||
namespace SemiColinGames {
|
namespace SemiColinGames {
|
||||||
public static class Debug {
|
static class Debug {
|
||||||
struct DebugRect {
|
struct DebugRect {
|
||||||
public Rectangle Rect;
|
public Rectangle Rect;
|
||||||
public Color Color;
|
public Color Color;
|
||||||
|
@ -7,7 +7,7 @@ using System.IO;
|
|||||||
// Methods are ordered alphabetically by type name.
|
// Methods are ordered alphabetically by type name.
|
||||||
|
|
||||||
namespace SemiColinGames {
|
namespace SemiColinGames {
|
||||||
public static class ExtensionMethods {
|
static class ExtensionMethods {
|
||||||
// ContentManager
|
// ContentManager
|
||||||
public static string LoadString(this ContentManager content, string path) {
|
public static string LoadString(this ContentManager content, string path) {
|
||||||
string fullPath = Path.Combine(content.RootDirectory, path);
|
string fullPath = Path.Combine(content.RootDirectory, path);
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
using System.Collections.Generic;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
namespace SemiColinGames {
|
namespace SemiColinGames {
|
||||||
public interface IState<T> {
|
public interface IState<T> {
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
using System;
|
using System;
|
||||||
|
|
||||||
namespace SemiColinGames {
|
namespace SemiColinGames {
|
||||||
public class FpsCounter {
|
class FpsCounter {
|
||||||
private readonly int[] frameTimes = new int[60];
|
private readonly int[] frameTimes = new int[60];
|
||||||
private double fps = 0;
|
private double fps = 0;
|
||||||
private int idx = 0;
|
private int idx = 0;
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
using System;
|
using System;
|
||||||
|
|
||||||
namespace SemiColinGames {
|
namespace SemiColinGames {
|
||||||
public class Line {
|
class Line {
|
||||||
public static Point[] Rasterize(Point p1, Point p2) {
|
public static Point[] Rasterize(Point p1, Point p2) {
|
||||||
return Line.Rasterize(p1.X, p1.Y, p2.X, p2.Y);
|
return Line.Rasterize(p1.X, p1.Y, p2.X, p2.Y);
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,7 @@ using Microsoft.Xna.Framework.Graphics;
|
|||||||
using System;
|
using System;
|
||||||
|
|
||||||
namespace SemiColinGames {
|
namespace SemiColinGames {
|
||||||
public sealed class LinesOfSight : IDisposable {
|
class LinesOfSight : IDisposable {
|
||||||
|
|
||||||
const int NUM_EDGE_VERTICES = 60;
|
const int NUM_EDGE_VERTICES = 60;
|
||||||
|
|
||||||
|
@ -4,7 +4,7 @@ using Microsoft.Xna.Framework.Graphics;
|
|||||||
using System;
|
using System;
|
||||||
|
|
||||||
namespace SemiColinGames {
|
namespace SemiColinGames {
|
||||||
public sealed class Scene : IDisposable {
|
class Scene : IDisposable {
|
||||||
const float DESIRED_ASPECT_RATIO = 1920.0f / 1080.0f;
|
const float DESIRED_ASPECT_RATIO = 1920.0f / 1080.0f;
|
||||||
|
|
||||||
Color backgroundColor = Color.CornflowerBlue;
|
Color backgroundColor = Color.CornflowerBlue;
|
||||||
@ -56,7 +56,7 @@ namespace SemiColinGames {
|
|||||||
GC.SuppressFinalize(this);
|
GC.SuppressFinalize(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Draw(bool isRunningSlowly, World world, bool paused) {
|
public void Draw(bool isRunningSlowly, World world, LinesOfSight linesOfSight, bool paused) {
|
||||||
graphics.SetRenderTarget(null);
|
graphics.SetRenderTarget(null);
|
||||||
graphics.Clear(backgroundColor);
|
graphics.Clear(backgroundColor);
|
||||||
|
|
||||||
@ -87,7 +87,7 @@ namespace SemiColinGames {
|
|||||||
// Draw lines of sight.
|
// Draw lines of sight.
|
||||||
basicEffect.Projection = camera.Projection;
|
basicEffect.Projection = camera.Projection;
|
||||||
if (Debug.Enabled) {
|
if (Debug.Enabled) {
|
||||||
world.LinesOfSight.Draw(graphics, basicEffect);
|
linesOfSight.Draw(graphics, basicEffect);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set up transformation matrix for drawing world objects.
|
// Set up transformation matrix for drawing world objects.
|
||||||
|
@ -23,6 +23,7 @@ namespace SemiColinGames {
|
|||||||
|
|
||||||
Scene scene;
|
Scene scene;
|
||||||
World world;
|
World world;
|
||||||
|
LinesOfSight linesOfSight;
|
||||||
Camera camera = new Camera();
|
Camera camera = new Camera();
|
||||||
|
|
||||||
public SneakGame() {
|
public SneakGame() {
|
||||||
@ -60,13 +61,14 @@ namespace SemiColinGames {
|
|||||||
SoundEffects.Load(Content);
|
SoundEffects.Load(Content);
|
||||||
Textures.Load(Content);
|
Textures.Load(Content);
|
||||||
Sprites.Load(Content);
|
Sprites.Load(Content);
|
||||||
|
// TODO: move this into World.
|
||||||
|
linesOfSight = new LinesOfSight(GraphicsDevice);
|
||||||
LoadLevel();
|
LoadLevel();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void LoadLevel() {
|
private void LoadLevel() {
|
||||||
camera = new Camera();
|
camera = new Camera();
|
||||||
world?.Dispose();
|
world = new World(Content.LoadString("levels/demo.json"));
|
||||||
world = new World(GraphicsDevice, Content.LoadString("levels/demo.json"));
|
|
||||||
scene?.Dispose();
|
scene?.Dispose();
|
||||||
scene = new Scene(GraphicsDevice, camera);
|
scene = new Scene(GraphicsDevice, camera);
|
||||||
|
|
||||||
@ -112,6 +114,7 @@ namespace SemiColinGames {
|
|||||||
float modelTime = (float) gameTime.ElapsedGameTime.TotalSeconds;
|
float modelTime = (float) gameTime.ElapsedGameTime.TotalSeconds;
|
||||||
Clock.AddModelTime(modelTime);
|
Clock.AddModelTime(modelTime);
|
||||||
world.Update(modelTime, input);
|
world.Update(modelTime, input);
|
||||||
|
linesOfSight.Update(world.Player, world.CollisionTargets);
|
||||||
camera.Update(world.Player.Position, world.Width);
|
camera.Update(world.Player.Position, world.Width);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -134,7 +137,7 @@ namespace SemiColinGames {
|
|||||||
|
|
||||||
Debug.SetFpsText(fpsText);
|
Debug.SetFpsText(fpsText);
|
||||||
|
|
||||||
scene.Draw(gameTime.IsRunningSlowly, world, paused);
|
scene.Draw(gameTime.IsRunningSlowly, world, linesOfSight, paused);
|
||||||
|
|
||||||
base.Draw(gameTime);
|
base.Draw(gameTime);
|
||||||
drawTimer.Stop();
|
drawTimer.Stop();
|
||||||
|
@ -4,7 +4,7 @@ using Newtonsoft.Json.Linq;
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
|
||||||
namespace SemiColinGames {
|
namespace SemiColinGames {
|
||||||
public static class Sprites {
|
static class Sprites {
|
||||||
public static Sprite Executioner;
|
public static Sprite Executioner;
|
||||||
public static Sprite Ninja;
|
public static Sprite Ninja;
|
||||||
|
|
||||||
@ -45,7 +45,7 @@ namespace SemiColinGames {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public class Sprite {
|
class Sprite {
|
||||||
public readonly TextureRef Texture;
|
public readonly TextureRef Texture;
|
||||||
|
|
||||||
private readonly Dictionary<string, SpriteAnimation> animations;
|
private readonly Dictionary<string, SpriteAnimation> animations;
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
using Microsoft.Xna.Framework.Graphics;
|
using Microsoft.Xna.Framework.Graphics;
|
||||||
|
|
||||||
namespace SemiColinGames {
|
namespace SemiColinGames {
|
||||||
public static class Text {
|
static class Text {
|
||||||
// Outlined text in black.
|
// Outlined text in black.
|
||||||
public static void DrawOutlined(
|
public static void DrawOutlined(
|
||||||
SpriteBatch spriteBatch, SpriteFont font, string text, Vector2 position, Color color) {
|
SpriteBatch spriteBatch, SpriteFont font, string text, Vector2 position, Color color) {
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
|
|
||||||
namespace SemiColinGames {
|
namespace SemiColinGames {
|
||||||
public class Timer {
|
class Timer {
|
||||||
|
|
||||||
private readonly Stopwatch stopwatch = new Stopwatch();
|
private readonly Stopwatch stopwatch = new Stopwatch();
|
||||||
private readonly double targetTime;
|
private readonly double targetTime;
|
||||||
|
@ -3,10 +3,35 @@ using Microsoft.Xna.Framework.Graphics;
|
|||||||
using Newtonsoft.Json.Linq;
|
using Newtonsoft.Json.Linq;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
|
||||||
namespace SemiColinGames {
|
namespace SemiColinGames {
|
||||||
|
|
||||||
public sealed class World : IDisposable {
|
public class Tile {
|
||||||
|
public static int CompareByX(Tile t1, Tile t2) {
|
||||||
|
return t1.Position.X.CompareTo(t2.Position.X);
|
||||||
|
}
|
||||||
|
|
||||||
|
private TextureRef texture;
|
||||||
|
private Rectangle textureSource;
|
||||||
|
|
||||||
|
public Tile(TextureRef texture, Rectangle textureSource, Rectangle position, bool isHazard) {
|
||||||
|
Position = position;
|
||||||
|
this.texture = texture;
|
||||||
|
this.textureSource = textureSource;
|
||||||
|
IsHazard = isHazard;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Rectangle Position { get; private set; }
|
||||||
|
public bool IsHazard = false;
|
||||||
|
|
||||||
|
public void Draw(SpriteBatch spriteBatch) {
|
||||||
|
spriteBatch.Draw(
|
||||||
|
texture.Get, Position.Location.ToVector2(), textureSource, Color.White);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public class World {
|
||||||
|
|
||||||
public const int TileSize = 16;
|
public const int TileSize = 16;
|
||||||
|
|
||||||
@ -21,7 +46,6 @@ namespace SemiColinGames {
|
|||||||
|
|
||||||
public Player Player { get; private set; }
|
public Player Player { get; private set; }
|
||||||
public AABB[] CollisionTargets { get; }
|
public AABB[] CollisionTargets { get; }
|
||||||
public LinesOfSight LinesOfSight { get; private set; }
|
|
||||||
|
|
||||||
// Size of World in pixels.
|
// Size of World in pixels.
|
||||||
public int Width {
|
public int Width {
|
||||||
@ -32,9 +56,7 @@ namespace SemiColinGames {
|
|||||||
get { return gridHeight * TileSize; }
|
get { return gridHeight * TileSize; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public World(GraphicsDevice graphics, string json) {
|
public World(string json) {
|
||||||
LinesOfSight = new LinesOfSight(graphics);
|
|
||||||
|
|
||||||
JObject root = JObject.Parse(json);
|
JObject root = JObject.Parse(json);
|
||||||
|
|
||||||
List<Tile> hazardTiles = new List<Tile>();
|
List<Tile> hazardTiles = new List<Tile>();
|
||||||
@ -89,15 +111,6 @@ namespace SemiColinGames {
|
|||||||
new Vector2(Width + 1, 0), new Vector2(1, float.MaxValue));
|
new Vector2(Width + 1, 0), new Vector2(1, float.MaxValue));
|
||||||
}
|
}
|
||||||
|
|
||||||
~World() {
|
|
||||||
Dispose();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Dispose() {
|
|
||||||
LinesOfSight.Dispose();
|
|
||||||
GC.SuppressFinalize(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
private List<Tile> ParseLayer(JToken layer) {
|
private List<Tile> ParseLayer(JToken layer) {
|
||||||
string layerName = layer.SelectToken("name").Value<string>();
|
string layerName = layer.SelectToken("name").Value<string>();
|
||||||
|
|
||||||
@ -161,7 +174,6 @@ namespace SemiColinGames {
|
|||||||
if (Player.Health <= 0) {
|
if (Player.Health <= 0) {
|
||||||
Reset();
|
Reset();
|
||||||
}
|
}
|
||||||
LinesOfSight.Update(Player, CollisionTargets);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Draws everything that's behind the player, from back to front.
|
// Draws everything that's behind the player, from back to front.
|
||||||
@ -181,28 +193,4 @@ namespace SemiColinGames {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public class Tile {
|
|
||||||
public static int CompareByX(Tile t1, Tile t2) {
|
|
||||||
return t1.Position.X.CompareTo(t2.Position.X);
|
|
||||||
}
|
|
||||||
|
|
||||||
private readonly TextureRef texture;
|
|
||||||
private readonly Rectangle textureSource;
|
|
||||||
|
|
||||||
public Tile(TextureRef texture, Rectangle textureSource, Rectangle position, bool isHazard) {
|
|
||||||
Position = position;
|
|
||||||
this.texture = texture;
|
|
||||||
this.textureSource = textureSource;
|
|
||||||
IsHazard = isHazard;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Rectangle Position { get; private set; }
|
|
||||||
public bool IsHazard = false;
|
|
||||||
|
|
||||||
public void Draw(SpriteBatch spriteBatch) {
|
|
||||||
spriteBatch.Draw(
|
|
||||||
texture.Get, Position.Location.ToVector2(), textureSource, Color.White);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user