Fix indentation so it looks okay on GitHub

master
BraydonKains 3 years ago
parent ff84687bc9
commit 531ffbf531

@ -1,19 +0,0 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<IsPackable>false</IsPackable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="nunit" Version="3.12.0" />
<PackageReference Include="NUnit3TestAdapter" Version="3.15.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.4.0"/>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="../SeeNoEvil/SeeNoEvil.csproj" />
</ItemGroup>
</Project>

@ -1,18 +0,0 @@
using NUnit.Framework;
namespace SeeNoEvil.Tests
{
public class Tests
{
[SetUp]
public void Setup()
{
}
[Test]
public void Test1()
{
Assert.Pass();
}
}
}

@ -4,12 +4,12 @@ using System.Text.Json;
namespace SeeNoEvil.Character {
public static class AnimationParser {
public static AnimationSetModel ReadAnimationJson(string fileName) {
StreamReader streamReader = File.OpenText(fileName);
string text = streamReader.ReadToEnd();
var options = new JsonSerializerOptions {
PropertyNameCaseInsensitive = true,
};
return JsonSerializer.Deserialize<AnimationSetModel>(text, options);
StreamReader streamReader = File.OpenText(fileName);
string text = streamReader.ReadToEnd();
var options = new JsonSerializerOptions {
PropertyNameCaseInsensitive = true,
};
return JsonSerializer.Deserialize<AnimationSetModel>(text, options);
}
}
}

@ -1,5 +1,3 @@
using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
namespace SeeNoEvil.Character {

@ -2,26 +2,26 @@ using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
namespace SeeNoEvil.Level {
public class Camera {
public Matrix Transform {get; private set;}
public Viewport Viewport {get; private set;}
public Vector2 Centre {get; set;}
public class Camera {
public Matrix Transform {get; private set;}
public Viewport Viewport {get; private set;}
public Vector2 Centre {get; set;}
private Vector3 TranslationVector =>
new Vector3(-Centre.X + (Viewport.Width / 2),
-Centre.Y + (Viewport.Height / 2),
1);
private Vector3 TranslationVector =>
new Vector3(-Centre.X + (Viewport.Width / 2),
-Centre.Y + (Viewport.Height / 2),
1);
public Camera(Viewport _viewport) {
Viewport = _viewport;
//TODO This is to experiment
Centre = new Vector2(Viewport.Width / 2, Viewport.Height / 2);
}
public Camera(Viewport _viewport) {
Viewport = _viewport;
//TODO This is to experiment
Centre = new Vector2(Viewport.Width / 2, Viewport.Height / 2);
}
//FIXME Don't need velocity anymore?
//FIXME Don't need velocity anymore?
public void Update(Vector2 position) {
Centre = position;
Transform = Matrix.CreateTranslation(TranslationVector);
}
Centre = position;
Transform = Matrix.CreateTranslation(TranslationVector);
}
}
}

@ -11,52 +11,52 @@ namespace SeeNoEvil.Level {
public class TilemapLevel {
private readonly string MapName;
private TiledMap Map;
private Dictionary<string, Texture2D> TilesetTextures;
private Dictionary<string, Texture2D> TilesetTextures;
public TilemapLevel(string tilemapName) {
MapName = tilemapName;
}
public void LoadMap(ContentManager content) {
Map = new TiledMap(TiledParser.ReadMapJson(MapName));
Map.LoadView();
Map.LoadObjects();
TilesetTextures = Map.GetTilesetNames().Aggregate(new Dictionary<string, Texture2D>(),
(textures, contentName) => {
textures.Add(contentName, content.Load<Texture2D>(contentName));
return textures;
});
}
private IEnumerable<string> GetTilesetNames() => Map.GetTilesetNames();
public Vector2 GetPlayerPosition() {
//FIXME This fuckin sucks
Map.Objects.TryGetValue("Cat", out List<ObjectCoordinate> catCoords);
ObjectCoordinate catCoord = catCoords.First();
return new Vector2(catCoord.X, catCoord.Y);
}
public PlayField GetPlayField() {
Map.View.TryGetValue("Ground", out List<TileLocation> ground);
return new PlayField(ground);
}
public IEnumerable<ObjectCoordinate> GetGhostCoordinates() {
// FIXME this fuckin sucks too I think?
Map.Objects.TryGetValue("Ghosts", out List<ObjectCoordinate> ghosts);
return ghosts;
}
public void Draw(SpriteBatch spriteBatch, string layer) {
List<TileLocation> locations;
if(Map.View.TryGetValue(layer, out locations))
locations.ForEach(tile => {
Texture2D layerTexture;
if(tile.tile.gid > 0 && TilesetTextures.TryGetValue(tile.tile.setName, out layerTexture)) {
spriteBatch.Draw(layerTexture, tile.location, tile.tile.srcRectangle, Color.White);
}
});
}
Map = new TiledMap(TiledParser.ReadMapJson(MapName));
Map.LoadView();
Map.LoadObjects();
TilesetTextures = Map.GetTilesetNames().Aggregate(new Dictionary<string, Texture2D>(),
(textures, contentName) => {
textures.Add(contentName, content.Load<Texture2D>(contentName));
return textures;
});
}
private IEnumerable<string> GetTilesetNames() => Map.GetTilesetNames();
public Vector2 GetPlayerPosition() {
//FIXME This fuckin sucks
Map.Objects.TryGetValue("Cat", out List<ObjectCoordinate> catCoords);
ObjectCoordinate catCoord = catCoords.First();
return new Vector2(catCoord.X, catCoord.Y);
}
public PlayField GetPlayField() {
Map.View.TryGetValue("Ground", out List<TileLocation> ground);
return new PlayField(ground);
}
public IEnumerable<ObjectCoordinate> GetGhostCoordinates() {
// FIXME this fuckin sucks too I think?
Map.Objects.TryGetValue("Ghosts", out List<ObjectCoordinate> ghosts);
return ghosts;
}
public void Draw(SpriteBatch spriteBatch, string layer) {
List<TileLocation> locations;
if(Map.View.TryGetValue(layer, out locations))
locations.ForEach(tile => {
Texture2D layerTexture;
if(tile.tile.gid > 0 && TilesetTextures.TryGetValue(tile.tile.setName, out layerTexture)) {
spriteBatch.Draw(layerTexture, tile.location, tile.tile.srcRectangle, Color.White);
}
});
}
}
}

@ -1,23 +1,20 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using SeeNoEvil.Character;
using SeeNoEvil.Tiled;
namespace SeeNoEvil.Level {
public class PlayField {
private IEnumerable<TileLocation> Tiles {get; set;}
public PlayField(IEnumerable<TileLocation> tiles) {
Tiles = tiles;
}
private IEnumerable<TileLocation> Tiles {get; set;}
public PlayField(IEnumerable<TileLocation> tiles) {
Tiles = tiles;
}
public bool TryWalk(Vector2 newLocation) =>
Tiles.Any(tile => tile.location.Equals(newLocation) && tile.tile.gid != 0);
public bool TryWalk(Vector2 newLocation) =>
Tiles.Any(tile => tile.location.Equals(newLocation) && tile.tile.gid != 0);
private bool Between(float pos1, float pos2, float bound) =>
(bound - pos1) >= (pos2 - pos1);
private bool Between(float pos1, float pos2, float bound) =>
(bound - pos1) >= (pos2 - pos1);
}
}

@ -1,11 +1,7 @@
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using SeeNoEvil.Tiled;
using SeeNoEvil.Level;
using SeeNoEvil.Character;

@ -6,35 +6,35 @@ using SeeNoEvil.Level;
namespace SeeNoEvil.Tiled {
public class TileLayer {
public string Type {get; private set;}
public string Name {get; private set;}
public readonly List<DataCoordinate> DataCoordinates = new List<DataCoordinate>();
public string Type {get; private set;}
public string Name {get; private set;}
public readonly List<DataCoordinate> DataCoordinates = new List<DataCoordinate>();
private int Width;
private int Height;
private List<uint> Data;
private int Width;
private int Height;
private List<uint> Data;
public TileLayer(MapLayerModel model) {
Name = model.Name;
Width = model.Width;
Height = model.Height;
Type = model.Type;
if(model.Type == "tilelayer") {
Data = model.Data.ToList();
BuildCoordinates();
}
}
Name = model.Name;
Width = model.Width;
Height = model.Height;
Type = model.Type;
if(model.Type == "tilelayer") {
Data = model.Data.ToList();
BuildCoordinates();
}
}
private void BuildCoordinates() {
int row = 0;
int column = 0;
Data.ForEach(gid => {
DataCoordinates.Add(new DataCoordinate(column, row, gid));
if(column == Width-1) {
row++;
column = 0;
} else column++;
});
}
private void BuildCoordinates() {
int row = 0;
int column = 0;
Data.ForEach(gid => {
DataCoordinates.Add(new DataCoordinate(column, row, gid));
if(column == Width-1) {
row++;
column = 0;
} else column++;
});
}
}
}

@ -3,77 +3,75 @@ using Microsoft.Xna.Framework;
namespace SeeNoEvil.Tiled {
public class TileSet {
private string Image {get; set;}
private string Name {get; set;}
private int ImageHeight {get; set;}
private int ImageWidth {get; set;}
private int TileHeight {get; set;}
private int TileWidth {get; set;}
private int Spacing {get; set;}
private int Columns {get; set;}
private int FirstGid {get; set;}
private int TileCount {get; set;}
private Dictionary<uint, Tile> Tiles {get; set;}
private bool TilesLoaded {get; set;}
private string Name {get; set;}
private int ImageHeight {get; set;}
private int ImageWidth {get; set;}
private int TileHeight {get; set;}
private int TileWidth {get; set;}
private int Spacing {get; set;}
private int Columns {get; set;}
private int FirstGid {get; set;}
private int TileCount {get; set;}
private Dictionary<uint, Tile> Tiles {get; set;}
private bool TilesLoaded {get; set;}
public TileSet(TileSetModel model) {
Image = model.Image;
Name = model.Name;
ImageHeight = model.ImageHeight;
ImageWidth = model.ImageWidth;
TileHeight = model.TileHeight;
TileWidth = model.TileWidth;
Spacing = model.Spacing;
Columns = model.Columns;
FirstGid = model.FirstGid;
TileCount = model.TileCount;
Tiles = new Dictionary<uint, Tile>();
TilesLoaded = false;
}
public TileSet(TileSetModel model) {
Image = model.Image;
Name = model.Name;
ImageHeight = model.ImageHeight;
ImageWidth = model.ImageWidth;
TileHeight = model.TileHeight;
TileWidth = model.TileWidth;
Spacing = model.Spacing;
Columns = model.Columns;
FirstGid = model.FirstGid;
TileCount = model.TileCount;
Tiles = new Dictionary<uint, Tile>();
TilesLoaded = false;
}
public bool ContainsTile(uint gid) =>
!(gid < FirstGid ||
gid > (FirstGid + TileCount - 1));
!(gid < FirstGid || gid > (FirstGid + TileCount - 1));
public Tile GetTile(uint gid) {
if(!TilesLoaded) LoadTiles();
Tile result;
Tiles.TryGetValue(gid, out result);
return result;
}
public Tile GetTile(uint gid) {
if(!TilesLoaded) LoadTiles();
Tile result;
Tiles.TryGetValue(gid, out result);
return result;
}
public string GetContentName() {
return Name;
}
return Name;
}
private void LoadTiles() {
Tiles = new Dictionary<uint, Tile>();
int row = 0;
int rowPx = 0;
int column = 0;
int columnPx = 0;
for(int i = 0; i < TileCount; i++) {
Rectangle rectangle = new Rectangle(
columnPx,
rowPx,
private void LoadTiles() {
Tiles = new Dictionary<uint, Tile>();
int row = 0;
int rowPx = 0;
int column = 0;
int columnPx = 0;
for(int i = 0; i < TileCount; i++) {
Rectangle rectangle = new Rectangle(
columnPx,
rowPx,
TileWidth,
TileHeight
);
uint gid = (uint)(i + FirstGid);
Tiles.Add(gid, new Tile(gid, rectangle, Name));
if(column == Columns-1) {
row++;
rowPx += Spacing + TileHeight;
column = 0;
columnPx = 0;
} else {
column++;
columnPx += Spacing + TileWidth;
}
}
);
uint gid = (uint)(i + FirstGid);
Tiles.Add(gid, new Tile(gid, rectangle, Name));
if(column == Columns-1) {
row++;
rowPx += Spacing + TileHeight;
column = 0;
columnPx = 0;
} else {
column++;
columnPx += Spacing + TileWidth;
}
}
TilesLoaded = true;
}
}
TilesLoaded = true;
}
}
}

@ -5,102 +5,102 @@ using SeeNoEvil.Level;
namespace SeeNoEvil.Tiled {
public class TiledMap {
public Dictionary<string, List<TileLocation>> View {get; private set;}
public Dictionary<string, List<ObjectCoordinate>> Objects {get; private set;}
public Dictionary<string, List<TileLocation>> View {get; private set;}
public Dictionary<string, List<ObjectCoordinate>> Objects {get; private set;}
private bool Infinite;
private List<TileLayer> TileLayers;
private List<ObjectLayer> ObjectLayers;
private List<TileSet> TileSets;
private int TileHeight;
private int TileWidth;
private int Rows;
private int Columns;
// TODO Do I really need this?
private Dictionary<uint, Tile> TileCache;
private List<TileSet> TileSets;
private int TileHeight;
private int TileWidth;
private int Rows;
private int Columns;
// TODO Do I really need this?
private Dictionary<uint, Tile> TileCache;
public TiledMap(TiledModel model) {
Infinite = model.Infinite;
TileLayers = model.Layers.Where(model => model.Type == "tilelayer")
.Select(model => new TileLayer(model)).ToList();
ObjectLayers = model.Layers.Where(model => model.Type == "objectgroup")
.Select(model => new ObjectLayer(model)).ToList();
TileSets = model.TileSets.Select(model => new TileSet(model)).ToList();
TileHeight = model.TileHeight;
TileWidth = model.TileWidth;
Rows = model.Height;
Columns = model.Width;
TileCache = new Dictionary<uint, Tile>();
View = new Dictionary<string, List<TileLocation>>();
}
Infinite = model.Infinite;
TileLayers = model.Layers.Where(model => model.Type == "tilelayer")
.Select(model => new TileLayer(model)).ToList();
ObjectLayers = model.Layers.Where(model => model.Type == "objectgroup")
.Select(model => new ObjectLayer(model)).ToList();
TileSets = model.TileSets.Select(model => new TileSet(model)).ToList();
TileHeight = model.TileHeight;
TileWidth = model.TileWidth;
Rows = model.Height;
Columns = model.Width;
TileCache = new Dictionary<uint, Tile>();
View = new Dictionary<string, List<TileLocation>>();
}
public IEnumerable<string> GetTilesetNames() =>
TileSets.Select(tileset => tileset.GetContentName());
public IEnumerable<string> GetTilesetNames() =>
TileSets.Select(tileset => tileset.GetContentName());
// Load Tile Locations for each layer
public void LoadView() {
// Get all tilelayers
Dictionary<string, List<DataCoordinate>> layerData = new Dictionary<string, List<DataCoordinate>>();
TileLayers.Where(layer => layer.Type == "tilelayer").ToList()
.ForEach(layer => {
layerData.Add(layer.Name, layer.DataCoordinates);
});
// Load Tile Locations for each layer
public void LoadView() {
// Get all tilelayers
Dictionary<string, List<DataCoordinate>> layerData = new Dictionary<string, List<DataCoordinate>>();
TileLayers.Where(layer => layer.Type == "tilelayer").ToList()
.ForEach(layer => {
layerData.Add(layer.Name, layer.DataCoordinates);
});
// Get all required unique gids and load to cache
LoadTiles(layerData.Aggregate(new HashSet<uint>(),
(tiles, layer) => {
foreach(var tile in layer.Value) {
tiles.Add(tile.gid);
}
return tiles;
})
);
// Get all required unique gids and load to cache
LoadTiles(layerData.Aggregate(new HashSet<uint>(),
(tiles, layer) => {
foreach(var tile in layer.Value) {
tiles.Add(tile.gid);
}
return tiles;
})
);
// build resulting tile location collection for each layer
View = layerData.Aggregate(new Dictionary<string, List<TileLocation>>(),
(locations, layer) => {
int column = 0, row = 0, columnPx = 0, rowPx = 0;
var layerLocations = new List<TileLocation>();
layer.Value.ForEach(coord => {
Tile currTile = new Tile();
if(coord.gid > 0)
TileCache.TryGetValue(coord.gid, out currTile);
Vector2 pxLocation = new Vector2(columnPx, rowPx);
layerLocations.Add(new TileLocation(currTile, pxLocation));
if(column == (Columns-1)) {
row++;
rowPx += TileHeight;
column = columnPx = 0;
} else {
column++;
columnPx += TileWidth;
}
});
locations.Add(layer.Key, layerLocations);
return locations;
});
}
// build resulting tile location collection for each layer
View = layerData.Aggregate(new Dictionary<string, List<TileLocation>>(),
(locations, layer) => {
int column = 0, row = 0, columnPx = 0, rowPx = 0;
var layerLocations = new List<TileLocation>();
layer.Value.ForEach(coord => {
Tile currTile = new Tile();
if(coord.gid > 0)
TileCache.TryGetValue(coord.gid, out currTile);
Vector2 pxLocation = new Vector2(columnPx, rowPx);
layerLocations.Add(new TileLocation(currTile, pxLocation));
if(column == (Columns-1)) {
row++;
rowPx += TileHeight;
column = columnPx = 0;
} else {
column++;
columnPx += TileWidth;
}
});
locations.Add(layer.Key, layerLocations);
return locations;
});
}
// Load objects on the level
public void LoadObjects() {
Objects = ObjectLayers.Aggregate(new Dictionary<string, List<ObjectCoordinate>>(),
// FIXME This is stupid naming
(layers, objects) => {
layers.Add(objects.Name, objects.Objects.ToList());
return layers;
}
);
}
// Load objects on the level
public void LoadObjects() {
Objects = ObjectLayers.Aggregate(new Dictionary<string, List<ObjectCoordinate>>(),
// FIXME This is stupid naming
(layers, objects) => {
layers.Add(objects.Name, objects.Objects.ToList());
return layers;
}
);
}
// Load tiles into cache if they don't exist
// Load tiles into cache if they don't exist
private void LoadTiles(HashSet<uint> tiles) {
foreach(uint gid in tiles) {
if(!TileCache.ContainsKey(gid)) {
TileSet tileset = TileSets.FirstOrDefault(set => set.ContainsTile(gid));
Tile tile = tileset == null ? new Tile() : tileset.GetTile(gid);
TileCache.Add(gid, tile);
}
}
}
foreach(uint gid in tiles) {
if(!TileCache.ContainsKey(gid)) {
TileSet tileset = TileSets.FirstOrDefault(set => set.ContainsTile(gid));
Tile tile = tileset == null ? new Tile() : tileset.GetTile(gid);
TileCache.Add(gid, tile);
}
}
}
}
}

@ -4,38 +4,38 @@ namespace SeeNoEvil.Tiled {
public struct TiledModel {
public bool Infinite {get; set;}
public IEnumerable<MapLayerModel> Layers {get; set;}
public IEnumerable<TileSetModel> TileSets {get; set;}
public int TileHeight {get; set;}
public int TileWidth {get; set;}
public int Height {get; set;}
public int Width {get; set;}
public IEnumerable<TileSetModel> TileSets {get; set;}
public int TileHeight {get; set;}
public int TileWidth {get; set;}
public int Height {get; set;}
public int Width {get; set;}
}
public struct TileSetModel {
public struct TileSetModel {
public string Image {get; set;}
public string Name {get; set;}
public int ImageHeight {get; set;}
public int ImageWidth {get; set;}
public int TileHeight {get; set;}
public int TileWidth {get; set;}
public int Spacing {get; set;}
public int Columns {get; set;}
public int FirstGid {get; set;}
public int TileCount {get; set;}
public string Name {get; set;}
public int ImageHeight {get; set;}
public int ImageWidth {get; set;}
public int TileHeight {get; set;}
public int TileWidth {get; set;}
public int Spacing {get; set;}
public int Columns {get; set;}
public int FirstGid {get; set;}
public int TileCount {get; set;}
}
public struct MapLayerModel {
public string Name {get; set;}
public int Width {get; set;}
public int Height {get; set;}
public IEnumerable<uint> Data {get; set;}
public string Type {get; set;}
public IEnumerable<TiledObjectModel> Objects {get; set;}
public struct MapLayerModel {
public string Name {get; set;}
public int Width {get; set;}
public int Height {get; set;}
public IEnumerable<uint> Data {get; set;}
public string Type {get; set;}
public IEnumerable<TiledObjectModel> Objects {get; set;}
}
public struct TiledObjectModel {
public int Id {get; set;}
public float X {get; set;}
public float Y {get; set;}
public int Id {get; set;}
public float X {get; set;}
public float Y {get; set;}
}
}

@ -4,12 +4,12 @@ using System.Text.Json;
namespace SeeNoEvil.Tiled {
public static class TiledParser {
public static TiledModel ReadMapJson(string fileName) {
StreamReader streamReader = File.OpenText(fileName);
string text = streamReader.ReadToEnd();
var options = new JsonSerializerOptions {
PropertyNameCaseInsensitive = true,
};
return JsonSerializer.Deserialize<TiledModel>(text, options);
StreamReader streamReader = File.OpenText(fileName);
string text = streamReader.ReadToEnd();
var options = new JsonSerializerOptions {
PropertyNameCaseInsensitive = true,
};
return JsonSerializer.Deserialize<TiledModel>(text, options);
}
}
}

@ -1,36 +1,36 @@
using Microsoft.Xna.Framework;
namespace SeeNoEvil.Tiled {
public struct Tile {
public Tile(long _gid, Rectangle _srcRectangle, string _setName) {
gid = (uint)_gid;
srcRectangle = _srcRectangle;
setName = _setName;
}
public uint gid;
public Rectangle srcRectangle;
public string setName;
}
public struct Tile {
public Tile(long _gid, Rectangle _srcRectangle, string _setName) {
gid = (uint)_gid;
srcRectangle = _srcRectangle;
setName = _setName;
}
public uint gid;
public Rectangle srcRectangle;
public string setName;
}
public struct TileLocation {
public struct TileLocation {
public TileLocation(Tile tile, Vector2 location) {
this.tile = tile;
this.location = location;
}
public Tile tile;
public Vector2 location;
public Tile tile;
public Vector2 location;
}
public struct DataCoordinate {
public DataCoordinate(int _x, int _y, uint _gid) {
x = _x;
y = _y;
gid = _gid;
}
public struct DataCoordinate {
public DataCoordinate(int _x, int _y, uint _gid) {
x = _x;
y = _y;
gid = _gid;
}
public int x;
public int y;
public uint gid;
}
public int x;
public int y;
public uint gid;
}
}
Loading…
Cancel
Save