Merge branch 'main' of https://github.com/progtime-net/DangerousD
This commit is contained in:
commit
95e466fe74
10 changed files with 78 additions and 31 deletions
|
@ -6,7 +6,7 @@ using MonogameLibrary.UI.Base;
|
||||||
|
|
||||||
namespace DangerousD.GameCore.GUI;
|
namespace DangerousD.GameCore.GUI;
|
||||||
|
|
||||||
public abstract class AbstractGui : IGameObject
|
public abstract class AbstractGui : IDrawableObject
|
||||||
{
|
{
|
||||||
protected UIManager Manager = new();
|
protected UIManager Manager = new();
|
||||||
protected List<DrawableUIElement> Elements = new();
|
protected List<DrawableUIElement> Elements = new();
|
||||||
|
|
|
@ -1,10 +1,29 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
using Microsoft.Xna.Framework;
|
||||||
|
using Microsoft.Xna.Framework.Graphics;
|
||||||
|
|
||||||
namespace DangerousD.GameCore.GameObjects
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,15 +2,43 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
using DangerousD.GameCore.GUI;
|
||||||
|
using Microsoft.Xna.Framework;
|
||||||
|
using Microsoft.Xna.Framework.Content;
|
||||||
|
using Microsoft.Xna.Framework.Graphics;
|
||||||
|
|
||||||
namespace DangerousD.GameCore
|
namespace DangerousD.GameCore
|
||||||
{
|
{
|
||||||
class GameObject
|
public abstract class GameObject : IDrawableObject
|
||||||
{
|
{
|
||||||
GraphicsComponent graphicsComponent;
|
public Vector2 Pos { get; protected set; }
|
||||||
public GameObject()
|
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);
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,7 @@ using Microsoft.Xna.Framework.Graphics;
|
||||||
|
|
||||||
namespace DangerousD.GameCore.GUI
|
namespace DangerousD.GameCore.GUI
|
||||||
{
|
{
|
||||||
interface IGameObject
|
interface IDrawableObject
|
||||||
{
|
{
|
||||||
void Initialize(GraphicsDevice graphicsDevice);
|
void Initialize(GraphicsDevice graphicsDevice);
|
||||||
void LoadContent(ContentManager content);
|
void LoadContent(ContentManager content);
|
|
@ -1,10 +1,10 @@
|
||||||
using System;
|
using Microsoft.Xna.Framework;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Text;
|
|
||||||
|
|
||||||
namespace DangerousD.GameCore.GameObjects
|
namespace DangerousD.GameCore.GameObjects;
|
||||||
|
|
||||||
|
internal abstract class LivingEntity : Entity
|
||||||
{
|
{
|
||||||
class LivingEntity : GameObject
|
public LivingEntity(Vector2 position) : base(position)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,10 +1,10 @@
|
||||||
using System;
|
using Microsoft.Xna.Framework;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Text;
|
|
||||||
|
|
||||||
namespace DangerousD.GameCore.GameObjects
|
namespace DangerousD.GameCore.GameObjects;
|
||||||
|
|
||||||
|
internal abstract class MapObject : GameObject
|
||||||
{
|
{
|
||||||
class MapObject : GameObject
|
public MapObject(Vector2 position) : base(position)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -8,7 +8,7 @@ using System.Text;
|
||||||
|
|
||||||
namespace DangerousD.GameCore.Graphics
|
namespace DangerousD.GameCore.Graphics
|
||||||
{
|
{
|
||||||
class GraphicsComponent
|
public class GraphicsComponent
|
||||||
{
|
{
|
||||||
private List<AnimationContainer> animations;
|
private List<AnimationContainer> animations;
|
||||||
private List<Texture2D> textures;
|
private List<Texture2D> textures;
|
||||||
|
|
|
@ -5,7 +5,7 @@ using System.Collections.Generic;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Xml.Serialization;
|
using System.Xml.Serialization;
|
||||||
using System.Runtime.InteropServices.WindowsRuntime;
|
using System.Runtime.InteropServices;
|
||||||
|
|
||||||
namespace DangerousD.GameCore
|
namespace DangerousD.GameCore
|
||||||
{
|
{
|
||||||
|
|
|
@ -15,9 +15,9 @@ namespace DangerousD.GameCore
|
||||||
private GraphicsDeviceManager _graphics;
|
private GraphicsDeviceManager _graphics;
|
||||||
private SpriteBatch _spriteBatch;
|
private SpriteBatch _spriteBatch;
|
||||||
GameState gameState;
|
GameState gameState;
|
||||||
IGameObject MenuGUI;
|
IDrawableObject MenuGUI;
|
||||||
IGameObject OptionsGUI;
|
IDrawableObject OptionsGUI;
|
||||||
IGameObject LobbyGUI;
|
IDrawableObject LobbyGUI;
|
||||||
public AppManager()
|
public AppManager()
|
||||||
{
|
{
|
||||||
_graphics = new GraphicsDeviceManager(this);
|
_graphics = new GraphicsDeviceManager(this);
|
||||||
|
|
|
@ -9,9 +9,9 @@ namespace DangerousD.GameCore.Network
|
||||||
{
|
{
|
||||||
public class NetworkManagerTest
|
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;
|
Socket socket;
|
||||||
IPEndPoint endPoint;
|
IPEndPoint endPoint;
|
||||||
|
@ -68,9 +68,9 @@ namespace DangerousD.GameCore.Network
|
||||||
Thread ReceivingThread = new Thread(ReceiveMsgFromHost);
|
Thread ReceivingThread = new Thread(ReceiveMsgFromHost);
|
||||||
ReceivingThread.Start();
|
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;
|
int count = Data.Length;
|
||||||
if (state == "Host")
|
if (state == "Host")
|
||||||
{
|
{
|
||||||
|
@ -86,7 +86,7 @@ namespace DangerousD.GameCore.Network
|
||||||
socket.Send(Data);
|
socket.Send(Data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public void ReceiveMsgFromHost()
|
private void ReceiveMsgFromHost()
|
||||||
{
|
{
|
||||||
while (true)
|
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;
|
StateObject so = ar.AsyncState as StateObject;
|
||||||
Socket clientSocket = so.workSocket;
|
Socket clientSocket = so.workSocket;
|
||||||
|
@ -111,7 +111,7 @@ namespace DangerousD.GameCore.Network
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
GetMsg(so.sb.ToString());
|
GetReceivingMessages(so.sb.ToString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue