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;
|
||||
|
||||
public abstract class AbstractGui : IGameObject
|
||||
public abstract class AbstractGui : IDrawableObject
|
||||
{
|
||||
protected UIManager Manager = new();
|
||||
protected List<DrawableUIElement> Elements = new();
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
|
@ -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)
|
||||
{
|
||||
}
|
||||
}
|
|
@ -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)
|
||||
{
|
||||
}
|
||||
}
|
|
@ -8,7 +8,7 @@ using System.Text;
|
|||
|
||||
namespace DangerousD.GameCore.Graphics
|
||||
{
|
||||
class GraphicsComponent
|
||||
public class GraphicsComponent
|
||||
{
|
||||
private List<AnimationContainer> animations;
|
||||
private List<Texture2D> textures;
|
||||
|
|
|
@ -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
|
||||
{
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue