diff --git a/DangerousD/GameCore/GUI/AbstractGui.cs b/DangerousD/GameCore/GUI/AbstractGui.cs index 91926cb..802981e 100644 --- a/DangerousD/GameCore/GUI/AbstractGui.cs +++ b/DangerousD/GameCore/GUI/AbstractGui.cs @@ -6,7 +6,7 @@ using MonogameLibrary.UI.Base; namespace DangerousD.GameCore.GUI; -public abstract class AbstractGui : IGameObject +public abstract class AbstractGui : IDrawableObject { protected UIManager Manager = new(); protected List Elements = new(); diff --git a/DangerousD/GameCore/GameObjects/Entity.cs b/DangerousD/GameCore/GameObjects/Entity.cs index a4305fa..dfbbf7e 100644 --- a/DangerousD/GameCore/GameObjects/Entity.cs +++ b/DangerousD/GameCore/GameObjects/Entity.cs @@ -1,10 +1,29 @@ using System; using System.Collections.Generic; using System.Text; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; namespace DangerousD.GameCore.GameObjects { - class Entity - { + abstract class Entity : GameObject + { + private Vector2 targetPosition; + public float speed; + + public Entity(Vector2 position) : base(position) {} + + + public void SetPosition(Vector2 position) { targetPosition = position; } + + public override void Update(GameTime gameTime) + { + if (Vector2.Distance(Pos, targetPosition) > 0.5f) + { + Vector2 dir = targetPosition - Pos; + dir.Normalize(); + Pos += dir * speed; + } + } } } diff --git a/DangerousD/GameCore/GameObjects/GameObject.cs b/DangerousD/GameCore/GameObjects/GameObject.cs index 183e0d2..4ff4ae8 100644 --- a/DangerousD/GameCore/GameObjects/GameObject.cs +++ b/DangerousD/GameCore/GameObjects/GameObject.cs @@ -2,15 +2,43 @@ using System; using System.Collections.Generic; using System.Text; +using DangerousD.GameCore.GUI; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Content; +using Microsoft.Xna.Framework.Graphics; namespace DangerousD.GameCore { - class GameObject + public abstract class GameObject : IDrawableObject { - GraphicsComponent graphicsComponent; - public GameObject() + public Vector2 Pos { get; protected set; } + public int Width { get; protected set; } + public int Height { get; protected set; } + public Rectangle Rectangle => new Rectangle((int)Pos.X, (int)Pos.Y, Width, Height); + protected GraphicsComponent Animator; + + public GameObject(Vector2 pos) { + Pos = pos; + Width = 500; + Height = 100; + Animator = new GraphicsComponent(new() { "playerIdle" }); GameManager.Register(this); } + + public virtual void OnCollision() + { + } + + public abstract void Initialize(GraphicsDevice graphicsDevice); + + public abstract void LoadContent(ContentManager content); + + public abstract void Update(GameTime gameTime); + + public virtual void Draw(SpriteBatch spriteBatch) + { + Animator.DrawAnimation(Rectangle, "playerIdle", spriteBatch); + } } } diff --git a/DangerousD/GameCore/GameObjects/IGameObject.cs b/DangerousD/GameCore/GameObjects/IDrawableObject.cs similarity index 92% rename from DangerousD/GameCore/GameObjects/IGameObject.cs rename to DangerousD/GameCore/GameObjects/IDrawableObject.cs index 9037a10..4c25e3f 100644 --- a/DangerousD/GameCore/GameObjects/IGameObject.cs +++ b/DangerousD/GameCore/GameObjects/IDrawableObject.cs @@ -4,7 +4,7 @@ using Microsoft.Xna.Framework.Graphics; namespace DangerousD.GameCore.GUI { - interface IGameObject + interface IDrawableObject { void Initialize(GraphicsDevice graphicsDevice); void LoadContent(ContentManager content); diff --git a/DangerousD/GameCore/GameObjects/LivingEntity.cs b/DangerousD/GameCore/GameObjects/LivingEntity.cs index f5625c9..f1f5cd2 100644 --- a/DangerousD/GameCore/GameObjects/LivingEntity.cs +++ b/DangerousD/GameCore/GameObjects/LivingEntity.cs @@ -1,10 +1,10 @@ -using System; -using System.Collections.Generic; -using System.Text; +using Microsoft.Xna.Framework; -namespace DangerousD.GameCore.GameObjects +namespace DangerousD.GameCore.GameObjects; + +internal abstract class LivingEntity : Entity { - class LivingEntity : GameObject + public LivingEntity(Vector2 position) : base(position) { } -} +} \ No newline at end of file diff --git a/DangerousD/GameCore/GameObjects/MapObject.cs b/DangerousD/GameCore/GameObjects/MapObject.cs index db4beab..65befa6 100644 --- a/DangerousD/GameCore/GameObjects/MapObject.cs +++ b/DangerousD/GameCore/GameObjects/MapObject.cs @@ -1,10 +1,10 @@ -using System; -using System.Collections.Generic; -using System.Text; +using Microsoft.Xna.Framework; -namespace DangerousD.GameCore.GameObjects +namespace DangerousD.GameCore.GameObjects; + +internal abstract class MapObject : GameObject { - class MapObject : GameObject + public MapObject(Vector2 position) : base(position) { } -} +} \ No newline at end of file diff --git a/DangerousD/GameCore/Graphics/GraphicsComponent.cs b/DangerousD/GameCore/Graphics/GraphicsComponent.cs index 1a7606a..6db5dbb 100644 --- a/DangerousD/GameCore/Graphics/GraphicsComponent.cs +++ b/DangerousD/GameCore/Graphics/GraphicsComponent.cs @@ -8,7 +8,7 @@ using System.Text; namespace DangerousD.GameCore.Graphics { - class GraphicsComponent + public class GraphicsComponent { private List animations; private List textures; diff --git a/DangerousD/GameCore/InputManager.cs b/DangerousD/GameCore/InputManager.cs index a3efc29..83e224f 100644 --- a/DangerousD/GameCore/InputManager.cs +++ b/DangerousD/GameCore/InputManager.cs @@ -5,7 +5,7 @@ using System.Collections.Generic; using System.Diagnostics; using System.Text; using System.Xml.Serialization; -using System.Runtime.InteropServices.WindowsRuntime; +using System.Runtime.InteropServices; namespace DangerousD.GameCore { diff --git a/DangerousD/GameCore/Managers/AppManager.cs b/DangerousD/GameCore/Managers/AppManager.cs index 0df51f6..213f053 100644 --- a/DangerousD/GameCore/Managers/AppManager.cs +++ b/DangerousD/GameCore/Managers/AppManager.cs @@ -15,9 +15,9 @@ namespace DangerousD.GameCore private GraphicsDeviceManager _graphics; private SpriteBatch _spriteBatch; GameState gameState; - IGameObject MenuGUI; - IGameObject OptionsGUI; - IGameObject LobbyGUI; + IDrawableObject MenuGUI; + IDrawableObject OptionsGUI; + IDrawableObject LobbyGUI; public AppManager() { _graphics = new GraphicsDeviceManager(this); diff --git a/DangerousD/GameCore/Network/NetworkManager.cs b/DangerousD/GameCore/Network/NetworkManager.cs index a619e33..436d15b 100644 --- a/DangerousD/GameCore/Network/NetworkManager.cs +++ b/DangerousD/GameCore/Network/NetworkManager.cs @@ -9,9 +9,9 @@ namespace DangerousD.GameCore.Network { public class NetworkManagerTest { - public delegate void ReceivingHandler(string msg); + public delegate void ReceivingHandler(string jsonMessage); - public event ReceivingHandler GetMsg; + public event ReceivingHandler GetReceivingMessages; Socket socket; IPEndPoint endPoint; @@ -68,9 +68,9 @@ namespace DangerousD.GameCore.Network Thread ReceivingThread = new Thread(ReceiveMsgFromHost); ReceivingThread.Start(); } - public void SendMsg(string msg) + public void SendMsg(string jsonMessage) { - byte[] Data = Encoding.Unicode.GetBytes(msg); + byte[] Data = Encoding.Unicode.GetBytes(jsonMessage); int count = Data.Length; if (state == "Host") { @@ -86,7 +86,7 @@ namespace DangerousD.GameCore.Network socket.Send(Data); } } - public void ReceiveMsgFromHost() + private void ReceiveMsgFromHost() { while (true) { @@ -98,7 +98,7 @@ namespace DangerousD.GameCore.Network } } - public void AsyncReceiveCallback(IAsyncResult ar) + private void AsyncReceiveCallback(IAsyncResult ar) { StateObject so = ar.AsyncState as StateObject; Socket clientSocket = so.workSocket; @@ -111,7 +111,7 @@ namespace DangerousD.GameCore.Network } else { - GetMsg(so.sb.ToString()); + GetReceivingMessages(so.sb.ToString()); } } }