Merge branch 'Development' into Player
This commit is contained in:
commit
076dc73135
15 changed files with 134 additions and 79 deletions
|
@ -15,11 +15,16 @@ using System.Reflection;
|
|||
using ZoFo.GameCore.GameObjects.Entities;
|
||||
using ZoFo.GameCore.GameManagers;
|
||||
using ZoFo.GameCore.GameManagers.NetworkManager.Updates.ClientToServer;
|
||||
|
||||
using ZoFo.GameCore.GameObjects.Entities.LivingEntities.Player;
|
||||
using System.Linq;
|
||||
using System.Web;
|
||||
using ZoFo.GameCore.GUI;
|
||||
namespace ZoFo.GameCore
|
||||
{
|
||||
public class Client
|
||||
{
|
||||
#region Network part
|
||||
|
||||
ClientNetworkManager networkManager;
|
||||
|
||||
public bool IsConnected { get { return networkManager.IsConnected; } }
|
||||
|
@ -48,12 +53,13 @@ namespace ZoFo.GameCore
|
|||
}
|
||||
public void GameEndedUnexpectedly() { }
|
||||
|
||||
public void JoinRoom(string ip,int port)
|
||||
public void JoinRoom(string ip, int port)
|
||||
{
|
||||
networkManager.JoinRoom(ip,port);
|
||||
networkManager.JoinRoom(ip, port);
|
||||
}
|
||||
public void JoinYourself(int port) { networkManager.JoinYourself(port); }
|
||||
|
||||
#endregion
|
||||
|
||||
List<MapObject> mapObjects = new List<MapObject>();
|
||||
List<GameObject> gameObjects = new List<GameObject>();
|
||||
|
@ -94,20 +100,43 @@ namespace ZoFo.GameCore
|
|||
}
|
||||
else if (update is UpdateGameObjectCreated)
|
||||
{
|
||||
var a = Assembly.GetAssembly(typeof(GameObject));
|
||||
if ((update as UpdateGameObjectCreated).GameObjectType == "EntittyForAnimationTests")
|
||||
{
|
||||
gameObjects.Add(new EntittyForAnimationTests((update as UpdateGameObjectCreated).position));
|
||||
if ((update as UpdateGameObjectCreated).GameObjectType == "Player")
|
||||
gameObjects.Add(new Player((update as UpdateGameObjectCreated).position));
|
||||
|
||||
gameObjects.Add(
|
||||
new EntittyForAnimationTests(new Vector2(100,100))
|
||||
);
|
||||
}
|
||||
(gameObjects.Last() as Entity).SetIdByClient((update as UpdateGameObjectCreated).IdEntity);
|
||||
//var a = Assembly.GetAssembly(typeof(GameObject));
|
||||
//gameObjects.Add( TODO reflection
|
||||
//Activator.CreateInstance(Type.GetType("ZoFo.GameCore.GameObjects.Entities.EntittyForAnimationTests")
|
||||
///*(update as UpdateGameObjectCreated).GameObjectType*/, new []{ new Vector2(100, 100) })
|
||||
//as GameObject
|
||||
//);
|
||||
}
|
||||
else if (update is UpdatePosition)
|
||||
{
|
||||
var ent = FindEntityById(update.IdEntity);
|
||||
|
||||
ent.position = (update as UpdatePosition).NewPosition;
|
||||
DebugHUD.Instance.Log("newPosition " + ent.position);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public Entity FindEntityById(int id)
|
||||
{
|
||||
for (int i = 0; i < gameObjects.Count; i++)
|
||||
{
|
||||
if (gameObjects[i] is Entity)
|
||||
{
|
||||
if ((gameObjects[i] as Entity).Id == id)
|
||||
{
|
||||
return gameObjects[i] as Entity;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -13,9 +13,11 @@ public class DebugHUD
|
|||
private SpriteFont _spriteFont;
|
||||
private Dictionary<string, string> _text = new();
|
||||
private List<string> _log = new();
|
||||
public static DebugHUD Instance { get; private set; }
|
||||
|
||||
public void Initialize()
|
||||
{
|
||||
Instance = this;
|
||||
}
|
||||
|
||||
public void LoadContent()
|
||||
|
|
|
@ -12,6 +12,7 @@ using ZoFo.GameCore.GameManagers.ItemManager;
|
|||
using ZoFo.GameCore.GUI;
|
||||
using static System.Collections.Specialized.BitVector32;
|
||||
using MonogameLibrary.UI.Base;
|
||||
using ZoFo.GameCore.GameObjects;
|
||||
|
||||
namespace ZoFo.GameCore.GameManagers
|
||||
{
|
||||
|
@ -83,6 +84,8 @@ namespace ZoFo.GameCore.GameManagers
|
|||
currentGUI.LoadContent();
|
||||
animationBuilder = new AnimationBuilder();
|
||||
animationBuilder.LoadAnimations();
|
||||
GameObject.debugTexture = new Texture2D(GraphicsDevice, 1, 1);
|
||||
GameObject.debugTexture.SetData(new Color[] { Color.White });
|
||||
}
|
||||
|
||||
protected override void Update(GameTime gameTime)
|
||||
|
|
|
@ -1,6 +0,0 @@
|
|||
namespace ZoFo.GameCore.GameManagers.CollisionManager
|
||||
{
|
||||
public class CollectionComponent
|
||||
{
|
||||
}
|
||||
}
|
|
@ -12,20 +12,38 @@ using ZoFo.GameCore.GameObjects.Entities.LivingEntities.Player;
|
|||
namespace ZoFo.GameCore.GameManagers.CollisionManager
|
||||
{
|
||||
public class CollisionComponent
|
||||
{
|
||||
//==КОНСТРУКТОР==
|
||||
{
|
||||
//==КОНСТРУКТОР==
|
||||
public CollisionComponent(GameObject gameObject)
|
||||
{
|
||||
this.gameObject = gameObject;
|
||||
AppManager.Instance.server.collisionManager.Register(this);
|
||||
}
|
||||
|
||||
this.gameObject = gameObject;
|
||||
hasCollision = false;
|
||||
this.isTrigger = false;
|
||||
}
|
||||
|
||||
public CollisionComponent(GameObject gameObject, bool hasCollision = false, Rectangle? collisionRectangle = null, bool isTrigger = false, Rectangle? triggerRectangle = null)
|
||||
{
|
||||
this.gameObject = gameObject;
|
||||
|
||||
hasCollision = hasCollision;
|
||||
this.isTrigger = isTrigger;
|
||||
if (hasCollision)
|
||||
this.stopRectangle = collisionRectangle.Value;
|
||||
if (isTrigger)
|
||||
this.triggerRectangle = triggerRectangle.Value;
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
//==ПОЛЯ==
|
||||
|
||||
public GameObject gameObject { get; set; }
|
||||
|
||||
|
||||
bool doesStop;
|
||||
bool hasCollision;
|
||||
public Rectangle stopRectangle;
|
||||
|
||||
|
@ -46,30 +64,7 @@ namespace ZoFo.GameCore.GameManagers.CollisionManager
|
|||
|
||||
public event EventHandler<CollisionComponent> OnCollision;
|
||||
|
||||
|
||||
// methods-event
|
||||
|
||||
|
||||
public CollisionComponent(GameObject gameObject)
|
||||
{
|
||||
|
||||
this.gameObject = gameObject;
|
||||
doesStop = false;
|
||||
this.isTrigger = false;
|
||||
AppManager.Instance.server.collisionManager.Register(this);
|
||||
}
|
||||
public CollisionComponent(GameObject gameObject, bool hasCollision = false, Rectangle? collisionRectangle = null, bool isTrigger = false, Rectangle? triggerRectangle = null)
|
||||
{
|
||||
this.gameObject = gameObject;
|
||||
|
||||
doesStop = hasCollision;
|
||||
this.isTrigger = isTrigger;
|
||||
if (hasCollision)
|
||||
this.stopRectangle = collisionRectangle.Value;
|
||||
if (isTrigger)
|
||||
this.triggerRectanglee = triggerRectangle.Value;
|
||||
|
||||
AppManager.Instance.server.collisionManager.Register(this);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -31,8 +31,10 @@ namespace ZoFo.GameCore.GameManagers.CollisionManager
|
|||
//for (int i = 0; i < ObjectsWithCollisions.Count; i++)
|
||||
//{
|
||||
var currentRect = entity.collisionComponent.stopRectangle;//задаём РЕК
|
||||
var newRect = currentRect; // задаём значение старого РЕК новому РЕК
|
||||
bool flagRemovedObject = false; //флаг удаления
|
||||
currentRect.X+=(int)entity.position.X;
|
||||
currentRect.Y+=(int)entity.position.Y;
|
||||
|
||||
var newRect = currentRect; // задаём значение старого РЕК новому РЕК
|
||||
|
||||
|
||||
var collidedX = false; // соприкосновение
|
||||
|
@ -94,17 +96,15 @@ namespace ZoFo.GameCore.GameManagers.CollisionManager
|
|||
entity.position.X += entity.velocity.Y;
|
||||
newRect.Y = tryingRectY.Y;//значение по X для нового РЕК приравниваем к значению испытуемого РЕК
|
||||
}
|
||||
|
||||
entity.collisionComponent.stopRectangle = newRect;
|
||||
entity.graphicsComponent.ObjectDrawRectangle = newRect;
|
||||
|
||||
entity.graphicsComponent.ObjectDrawRectangle.X = (int)entity.position.X;
|
||||
entity.graphicsComponent.ObjectDrawRectangle.Y = (int)entity.position.Y;
|
||||
AppManager.Instance.server.AddData(new UpdatePosition() { NewPosition = entity.position, IdEntity = entity.Id });
|
||||
AppManager.Instance.debugHud.Set("testPos", entity.position.ToString()); //TODO remove
|
||||
entity.velocity = Vector2.Zero;
|
||||
}
|
||||
|
||||
//обновление позиции объекта
|
||||
public void UpdateObjectsPositions()
|
||||
{
|
||||
|
||||
}
|
||||
//обновление позиции объекта
|
||||
|
||||
public void UpdatePositions()
|
||||
{
|
||||
|
|
|
@ -7,7 +7,7 @@ using System.Threading.Tasks;
|
|||
|
||||
namespace ZoFo.GameCore.GameManagers.ItemManager
|
||||
{
|
||||
class ItemInfo
|
||||
public class ItemInfo
|
||||
{
|
||||
//поля
|
||||
string tag;
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
using System;
|
||||
using Microsoft.Xna.Framework;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
@ -14,5 +15,6 @@ namespace ZoFo.GameCore.GameManagers.NetworkManager.Updates.ServerToClient
|
|||
public UpdateGameObjectCreated() { UpdateType = "UpdateGameObjectCreated"; }
|
||||
public string GameObjectType;
|
||||
public string GameObjectId;
|
||||
public Vector2 position;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
using System;
|
||||
using Microsoft.Xna.Framework;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using ZoFo.GameCore.GameObjects.Entities.LivingEntities;
|
||||
|
@ -10,8 +11,10 @@ namespace ZoFo.GameCore.GameManagers.NetworkManager.Updates.ServerToClient
|
|||
/// <summary>
|
||||
/// Хранит новую позицию
|
||||
/// </summary>
|
||||
public class UpdatePosition : UpdateData
|
||||
public class UpdatePosition : UpdateData
|
||||
{
|
||||
public UpdatePosition() { UpdateType = "UpdatePosition"; }
|
||||
|
||||
public Vector2 NewPosition { get; set; }
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,10 +12,22 @@ namespace ZoFo.GameCore.GameObjects.Entities
|
|||
//public override GraphicsComponent graphicsComponent => null;
|
||||
public CollisionComponent collisionComponent { get; protected set; }
|
||||
public int Id { get; set; }
|
||||
static int totalEntitiesCreated = 0;
|
||||
protected Entity(Vector2 position) : base(position)
|
||||
{
|
||||
|
||||
Id = totalEntitiesCreated;
|
||||
totalEntitiesCreated++;
|
||||
collisionComponent = new CollisionComponent(this);
|
||||
}
|
||||
/// <summary>
|
||||
/// For initialisation on Client
|
||||
/// </summary>
|
||||
/// <param name="newId"></param>
|
||||
public void SetIdByClient(int newId)
|
||||
{
|
||||
Id = newId;
|
||||
}
|
||||
|
||||
public virtual void Update()
|
||||
{
|
||||
}
|
||||
|
|
|
@ -15,7 +15,7 @@ public class Interactable : Entity
|
|||
{
|
||||
collisionComponent.OnTriggerEnter += (sender, e) => ChangeInteraction(sender, e, true);
|
||||
collisionComponent.OnTriggerExit += (sender, e) => ChangeInteraction(sender, e, false);
|
||||
collisionComponent.OnTriggerInteract += OnInteraction;
|
||||
collisionComponent.OnTriggerZone += OnInteraction;
|
||||
}
|
||||
|
||||
private void ChangeInteraction(object sender, CollisionComponent e, bool isReady)
|
||||
|
|
|
@ -34,6 +34,7 @@ public class LivingEntity : Entity
|
|||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -26,20 +26,23 @@ public class Player : LivingEntity
|
|||
//InputWeaponRotation = new Vector2(0, 0);
|
||||
//InputPlayerRotation = new Vector2(0, 0);
|
||||
|
||||
collisionComponent = new CollisionComponent(this, true, new Rectangle(0, 0, 10, 10));
|
||||
collisionComponent.stopRectangle = new Rectangle(0, 0, 100, 100);
|
||||
graphicsComponent.ObjectDrawRectangle = new Rectangle(0,0,100,100);
|
||||
}
|
||||
|
||||
|
||||
public void Update(GameTime gameTime)
|
||||
public override void Update()
|
||||
{
|
||||
|
||||
MovementLogic();
|
||||
}
|
||||
float t;
|
||||
public void MovementLogic()
|
||||
{
|
||||
velocity.X = (float)Math.Sin(t);
|
||||
t++;
|
||||
if (InputPlayerRotation.X > 0.9)
|
||||
{
|
||||
velocity.X = 5;
|
||||
}
|
||||
}
|
||||
public void HandleNewInput(UpdateInput updateInput)
|
||||
|
|
|
@ -46,6 +46,7 @@ public abstract class GameObject
|
|||
|
||||
#region Client Side
|
||||
|
||||
public static Texture2D debugTexture;
|
||||
/// <summary>
|
||||
/// Для клиента
|
||||
/// Это вызывается в клиентской части игры
|
||||
|
@ -82,19 +83,21 @@ public abstract class GameObject
|
|||
{
|
||||
graphicsComponent.DrawAnimation(graphicsComponent.ObjectDrawRectangle, spriteBatch);
|
||||
//debug
|
||||
DrawDebugRectangle(spriteBatch, graphicsComponent.ObjectDrawRectangle);
|
||||
|
||||
if (AppManager.Instance.InputManager.CollisionsCheat)
|
||||
DrawDebugRectangle(spriteBatch, graphicsComponent.ObjectDrawRectangle);
|
||||
|
||||
}
|
||||
public void DrawDebugRectangle(SpriteBatch spriteBatch, Rectangle _rectangle, Nullable<Color> color = null)
|
||||
{
|
||||
if (color is null) color = new Color(1, 0, 0, 0.25f);
|
||||
if (color is null) color = new Color(1, 0, 0, 0.1f);
|
||||
if (color.Value.A == 255) color = new Color(color.Value, 0.25f);
|
||||
//spriteBatch.Draw(debugTexture,
|
||||
// new Rectangle((_rectangle.X - graphicsComponent.CameraPosition.X) * graphicsComponent.scaling,
|
||||
// (_rectangle.Y - graphicsComponent.CameraPosition.Y) * graphicsComponent.scaling,
|
||||
// _rectangle.Width * graphicsComponent.scaling,
|
||||
// _rectangle.Height * graphicsComponent.scaling), color.Value);
|
||||
spriteBatch.Draw(debugTexture,
|
||||
new Rectangle((_rectangle.X - GraphicsComponent.CameraPosition.X) * GraphicsComponent.scaling,
|
||||
(_rectangle.Y - GraphicsComponent.CameraPosition.Y) * GraphicsComponent.scaling,
|
||||
_rectangle.Width * GraphicsComponent.scaling,
|
||||
_rectangle.Height * GraphicsComponent.scaling), color.Value);
|
||||
|
||||
//TODO: debugTexture
|
||||
}
|
||||
|
|
|
@ -15,6 +15,7 @@ using ZoFo.GameCore.GameManagers.NetworkManager.Updates;
|
|||
using ZoFo.GameCore.GameManagers.NetworkManager.Updates.ServerToClient;
|
||||
using ZoFo.GameCore.GameObjects;
|
||||
using ZoFo.GameCore.GameObjects.Entities;
|
||||
using ZoFo.GameCore.GameObjects.Entities.LivingEntities.Enemies;
|
||||
using ZoFo.GameCore.GameObjects.Entities.LivingEntities.Player;
|
||||
using ZoFo.GameCore.GameObjects.MapObjects;
|
||||
|
||||
|
@ -25,9 +26,7 @@ namespace ZoFo.GameCore
|
|||
private ServerNetworkManager networkManager;
|
||||
private int ticks = 0;
|
||||
public IPEndPoint MyIp { get { return networkManager.InfoConnect; } }
|
||||
|
||||
public CollisionManager collisionManager;
|
||||
|
||||
|
||||
public Server()
|
||||
{
|
||||
networkManager = new ServerNetworkManager();
|
||||
|
@ -84,7 +83,7 @@ namespace ZoFo.GameCore
|
|||
#endregion
|
||||
|
||||
#region Game Methods
|
||||
|
||||
public CollisionManager collisionManager;
|
||||
/// <summary>
|
||||
/// Запуск игры в комнате
|
||||
/// </summary>
|
||||
|
@ -112,7 +111,6 @@ namespace ZoFo.GameCore
|
|||
networkManager.CloseConnection();
|
||||
}
|
||||
|
||||
public CollisionManager collisionManager;
|
||||
private List<GameObject> gameObjects = new List<GameObject>();
|
||||
private List<Entity> entities; //entity
|
||||
public void Update(GameTime gameTime)
|
||||
|
@ -151,10 +149,20 @@ namespace ZoFo.GameCore
|
|||
});//TODO
|
||||
return;
|
||||
}
|
||||
if (gameObject is Entity)
|
||||
{
|
||||
AddData(new UpdateGameObjectCreated() { GameObjectType = gameObject.GetType().Name, IdEntity = (gameObject as Entity).Id });
|
||||
collisionManager.Register((gameObject as Entity).collisionComponent);
|
||||
}
|
||||
else
|
||||
AddData(new UpdateGameObjectCreated() { GameObjectType = gameObject.GetType().Name });
|
||||
|
||||
AddData(new UpdateGameObjectCreated()
|
||||
{ GameObjectType = gameObject.GetType().Name }
|
||||
);
|
||||
|
||||
////var elems = gameObject.GetType().GetProperties(System.Reflection.BindingFlags.Public);
|
||||
////if (elems.Count()>0) TODO
|
||||
////{
|
||||
//// AppManager.Instance.server.collisionManager.Register((elems.First().GetValue(gameObject) as CollisionComponent));
|
||||
////}
|
||||
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue