BIG MapManager commit
This commit is contained in:
parent
e7e18468f4
commit
368d08cb41
11 changed files with 63 additions and 41 deletions
|
@ -17,9 +17,9 @@ public abstract class AbstractGui : IDrawableObject
|
||||||
|
|
||||||
protected abstract void CreateUI();
|
protected abstract void CreateUI();
|
||||||
private GraphicsDevice graphicsDevice;
|
private GraphicsDevice graphicsDevice;
|
||||||
public virtual void Initialize(GraphicsDevice graphicsDevice)
|
public virtual void Initialize()
|
||||||
{
|
{
|
||||||
Manager.Initialize(graphicsDevice);
|
Manager.Initialize(AppManager.Instance.GraphicsDevice);
|
||||||
this.graphicsDevice = graphicsDevice;
|
this.graphicsDevice = graphicsDevice;
|
||||||
CreateUI();
|
CreateUI();
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,12 +7,8 @@ using Microsoft.Xna.Framework.Graphics;
|
||||||
namespace DangerousD.GameCore.GameObjects
|
namespace DangerousD.GameCore.GameObjects
|
||||||
{
|
{
|
||||||
public abstract class Entity : GameObject
|
public abstract class Entity : GameObject
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
public Entity(Vector2 position) : base(position) {}
|
public Entity(Vector2 position) : base(position) {}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,10 +22,12 @@ namespace DangerousD.GameCore
|
||||||
protected abstract GraphicsComponent GraphicsComponent { get; }
|
protected abstract GraphicsComponent GraphicsComponent { get; }
|
||||||
public GameObject(Vector2 pos)
|
public GameObject(Vector2 pos)
|
||||||
{
|
{
|
||||||
|
Initialize();
|
||||||
_pos = pos;
|
_pos = pos;
|
||||||
Width = 500;
|
Width = 500;
|
||||||
Height = 101;
|
Height = 101;
|
||||||
//Animator = new GraphicsComponent(new() { "playerIdle" });
|
//Animator = new GraphicsComponent(new() { "playerIdle" });
|
||||||
|
|
||||||
LoadContent();
|
LoadContent();
|
||||||
AppManager.Instance.GameManager.Register(this);
|
AppManager.Instance.GameManager.Register(this);
|
||||||
}
|
}
|
||||||
|
@ -34,7 +36,7 @@ namespace DangerousD.GameCore
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual void Initialize(GraphicsDevice graphicsDevice)
|
public virtual void Initialize()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,7 +6,7 @@ namespace DangerousD.GameCore.GUI
|
||||||
{
|
{
|
||||||
interface IDrawableObject
|
interface IDrawableObject
|
||||||
{
|
{
|
||||||
void Initialize(GraphicsDevice graphicsDevice);
|
void Initialize();
|
||||||
void LoadContent();
|
void LoadContent();
|
||||||
void Update(GameTime gameTime);
|
void Update(GameTime gameTime);
|
||||||
void Draw(SpriteBatch spriteBatch);
|
void Draw(SpriteBatch spriteBatch);
|
||||||
|
|
|
@ -1,13 +1,29 @@
|
||||||
using Microsoft.Xna.Framework;
|
using System.Collections.Generic;
|
||||||
|
using Microsoft.Xna.Framework;
|
||||||
using System.Security.Cryptography.X509Certificates;
|
using System.Security.Cryptography.X509Certificates;
|
||||||
|
using DangerousD.GameCore.Graphics;
|
||||||
|
using Microsoft.Xna.Framework.Graphics;
|
||||||
|
using MonoGame.Extended.Sprites;
|
||||||
|
|
||||||
namespace DangerousD.GameCore.GameObjects;
|
namespace DangerousD.GameCore.GameObjects;
|
||||||
|
|
||||||
public abstract class MapObject : GameObject
|
public abstract class MapObject : GameObject
|
||||||
{
|
{
|
||||||
public bool IsColliderOn;
|
public bool IsColliderOn;
|
||||||
public MapObject(Vector2 position) : base(position)
|
private Rectangle _sourceRectangle;
|
||||||
|
protected override GraphicsComponent GraphicsComponent { get; } = new("map");
|
||||||
|
public MapObject(Vector2 position, Rectangle sourceRectangle) : base(position)
|
||||||
|
{
|
||||||
|
_sourceRectangle = sourceRectangle;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void Initialize()
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void Draw(SpriteBatch spriteBatch)
|
||||||
|
{
|
||||||
|
GraphicsComponent.DrawAnimation(Rectangle, spriteBatch, _sourceRectangle);
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -5,7 +5,7 @@ namespace DangerousD.GameCore.GameObjects.MapObjects;
|
||||||
|
|
||||||
public class Platform : MapObject
|
public class Platform : MapObject
|
||||||
{
|
{
|
||||||
public Platform(Vector2 position, string texture) : base(position)
|
public Platform(Vector2 position, Rectangle sourceRectangle) : base(position, sourceRectangle)
|
||||||
{
|
{
|
||||||
IsColliderOn = true;
|
IsColliderOn = true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,7 @@ namespace DangerousD.GameCore.GameObjects.MapObjects;
|
||||||
|
|
||||||
public class StopTile : MapObject
|
public class StopTile : MapObject
|
||||||
{
|
{
|
||||||
public StopTile(Vector2 position) : base(position)
|
public StopTile(Vector2 position, Rectangle sourceRectangle) : base(position, sourceRectangle)
|
||||||
{
|
{
|
||||||
IsColliderOn = true;
|
IsColliderOn = true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,7 @@ namespace DangerousD.GameCore.GameObjects.MapObjects;
|
||||||
|
|
||||||
public class Tile : MapObject
|
public class Tile : MapObject
|
||||||
{
|
{
|
||||||
public Tile(Vector2 position) : base(position)
|
public Tile(Vector2 position, Rectangle sourceRectangle) : base(position, sourceRectangle)
|
||||||
{
|
{
|
||||||
IsColliderOn = false;
|
IsColliderOn = false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -45,9 +45,9 @@ namespace DangerousD.GameCore
|
||||||
protected override void Initialize()
|
protected override void Initialize()
|
||||||
{
|
{
|
||||||
AnimationBuilder.LoadAnimations();
|
AnimationBuilder.LoadAnimations();
|
||||||
MenuGUI.Initialize(GraphicsDevice);
|
MenuGUI.Initialize();
|
||||||
LoginGUI.Initialize(GraphicsDevice);
|
LoginGUI.Initialize();
|
||||||
LobbyGUI.Initialize(GraphicsDevice);
|
LobbyGUI.Initialize();
|
||||||
base.Initialize();
|
base.Initialize();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -28,7 +28,6 @@ namespace DangerousD.GameCore
|
||||||
players = new List<Player>();
|
players = new List<Player>();
|
||||||
mapManager = new MapManager();
|
mapManager = new MapManager();
|
||||||
physicsManager = new PhysicsManager();
|
physicsManager = new PhysicsManager();
|
||||||
mapManager.Init();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
internal void Register(GameObject gameObject)
|
internal void Register(GameObject gameObject)
|
||||||
|
|
|
@ -1,51 +1,60 @@
|
||||||
using DangerousD.GameCore.GameObjects;
|
using System.Collections.Generic;
|
||||||
using DangerousD.GameCore.Graphics;
|
|
||||||
using DangerousD.GameCore.Levels;
|
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Net.Security;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using System.Xml;
|
using System.Xml;
|
||||||
using DangerousD.GameCore.GameObjects.MapObjects;
|
using DangerousD.GameCore.GameObjects.MapObjects;
|
||||||
using Microsoft.Xna.Framework;
|
using Microsoft.Xna.Framework;
|
||||||
using Microsoft.Xna.Framework.Graphics;
|
using Microsoft.Xna.Framework.Graphics;
|
||||||
|
|
||||||
namespace DangerousD.GameCore.Managers
|
namespace DangerousD.GameCore.Managers
|
||||||
{
|
{
|
||||||
public class MapManager
|
public class MapManager
|
||||||
{
|
{
|
||||||
private Texture2D _texture;
|
|
||||||
public void Init()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
//Level
|
//Level
|
||||||
public void LoadLevel(string level)
|
public void LoadLevel(string level)
|
||||||
{
|
{
|
||||||
XmlDocument xml = new();
|
XmlDocument xml = new();
|
||||||
xml.Load($"{level}.tmx");
|
xml.Load($"{level}.tmx");
|
||||||
XmlNode mapNode = xml.DocumentElement[].SelectSingleNode("//layer[@type='collidable']");
|
|
||||||
Vector2 tileSize = new(int.Parse(xml.DocumentElement.Attributes["tilewidth"].Value),
|
Vector2 tileSize = new(int.Parse(xml.DocumentElement.Attributes["tilewidth"].Value),
|
||||||
int.Parse(xml.DocumentElement.Attributes["tileheight"].Value));
|
int.Parse(xml.DocumentElement.Attributes["tileheight"].Value));
|
||||||
|
|
||||||
foreach (XmlNode chunk in mapNode.ChildNodes)
|
XmlNodeList layers = xml.DocumentElement.SelectNodes("//layer");
|
||||||
|
|
||||||
|
foreach (XmlNode layer in layers)
|
||||||
{
|
{
|
||||||
Vector2 chunkSize = new(int.Parse(chunk.Attributes["width"].Value), int.Parse(chunk.Attributes["height"].Value))
|
InstantiateTiles(layer, tileSize);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void InstantiateTiles(XmlNode layer, Vector2 tileSize)
|
||||||
|
{
|
||||||
|
string tileType = layer.Attributes["class"].Value;
|
||||||
|
|
||||||
|
foreach (XmlNode chunk in layer.ChildNodes)
|
||||||
|
{
|
||||||
|
Vector2 chunkSize = new(int.Parse(chunk.Attributes["width"].Value),
|
||||||
|
int.Parse(chunk.Attributes["height"].Value));
|
||||||
Vector2 chunkPos = new(int.Parse(chunk.Attributes["x"].Value), int.Parse(chunk.Attributes["y"].Value));
|
Vector2 chunkPos = new(int.Parse(chunk.Attributes["x"].Value), int.Parse(chunk.Attributes["y"].Value));
|
||||||
|
|
||||||
|
|
||||||
List<int> tiles = chunk.Value.Split(',').Select(int.Parse).ToList();
|
List<int> tiles = chunk.Value.Split(',').Select(int.Parse).ToList();
|
||||||
for (int i = 0; i < tiles.Count; i++)
|
for (int i = 0; i < tiles.Count; i++)
|
||||||
{
|
{
|
||||||
new StopTile(chunk)
|
Vector2 pos = new((chunkPos.Y + i % chunkSize.X) * tileSize.Y,
|
||||||
}
|
(chunkPos.Y + i / chunkSize.X) * tileSize.Y);
|
||||||
}
|
Rectangle sourceRect = new(pos.ToPoint(), tileSize.ToPoint());
|
||||||
}
|
|
||||||
|
|
||||||
private void CreateTiles(T d)
|
switch (tileType)
|
||||||
{
|
{
|
||||||
|
case "collidable":
|
||||||
|
new StopTile(pos, sourceRect);
|
||||||
|
break;
|
||||||
|
case "platform":
|
||||||
|
new Platform(pos, sourceRect);
|
||||||
|
break;
|
||||||
|
case "non_collidable":
|
||||||
|
new Tile(pos, sourceRect);
|
||||||
|
break;
|
||||||
|
}}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue