Merge pull request #48 from progtime-net/MinorFixesAndConnections
minor overall
This commit is contained in:
commit
d8a278d2e4
9 changed files with 146 additions and 43 deletions
|
@ -62,6 +62,26 @@ namespace ZoFo.GameCore.GameManagers.CollisionManager
|
|||
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,6 +10,8 @@ using Microsoft.Xna.Framework;
|
|||
using ZoFo.GameCore.GameManagers.MapManager.MapElements;
|
||||
using ZoFo.GameCore.GameObjects.Entities;
|
||||
using ZoFo.GameCore.GameObjects.Entities.LivingEntities;
|
||||
using ZoFo.GameCore.GameManagers.NetworkManager.Updates.ServerToClient;
|
||||
using ZoFo.GameCore.ZoFo_graphics;
|
||||
|
||||
namespace ZoFo.GameCore.GameManagers.CollisionManager
|
||||
{
|
||||
|
@ -21,46 +23,48 @@ namespace ZoFo.GameCore.GameManagers.CollisionManager
|
|||
public List<CollisionComponent> EntitiesWithMovements;
|
||||
public List<CollisionComponent> ObjectsWithTriggers;
|
||||
|
||||
|
||||
|
||||
//чекаем коллизии в листе
|
||||
public void CheckComponentCollision(LivingEntity entity)
|
||||
public void CheckComponentCollision(CollisionComponent componentOfEntity)
|
||||
{
|
||||
var entity = componentOfEntity.gameObject as LivingEntity;
|
||||
//for (int i = 0; i < ObjectsWithCollisions.Count; i++)
|
||||
//{
|
||||
var currentRect = entity.collisionComponent.stopRectangle;//задаём РЕК
|
||||
var newRect = currentRect; // задаём значение старого РЕК новому РЕК
|
||||
bool flagRemovedObject = false; //флаг удаления
|
||||
var currentRect = entity.collisionComponent.stopRectangle;//задаём РЕК
|
||||
var newRect = currentRect; // задаём значение старого РЕК новому РЕК
|
||||
bool flagRemovedObject = false; //флаг удаления
|
||||
|
||||
|
||||
var collidedX = false; // соприкосновение
|
||||
var tryingRectX = currentRect;//переменная для попытки перемещения по X
|
||||
var collidedX = false; // соприкосновение
|
||||
var tryingRectX = currentRect;//переменная для попытки перемещения по X
|
||||
|
||||
tryingRectX.Offset((int)(entity.velocity.X), 0);//задаём значения для tryingRectX по X и по Y
|
||||
tryingRectX.Offset((int)(entity.velocity.X), 0);//задаём значения для tryingRectX по X и по Y
|
||||
|
||||
foreach (var item in ObjectsWithCollisions)//фильтрация
|
||||
{
|
||||
if (Math.Abs(item.stopRectangle.X - entity.collisionComponent.stopRectangle.X) < 550
|
||||
&& Math.Abs(item.stopRectangle.Y - entity.collisionComponent.stopRectangle.Y) < 550
|
||||
&& tryingRectX.Intersects(item.stopRectangle))
|
||||
|
||||
foreach (var item in ObjectsWithCollisions)//фильтрация
|
||||
{
|
||||
if (Math.Abs(item.stopRectangle.X - entity.collisionComponent.stopRectangle.X) < 550
|
||||
&& Math.Abs(item.stopRectangle.Y - entity.collisionComponent.stopRectangle.Y) < 550
|
||||
&& tryingRectX.Intersects(item.stopRectangle))
|
||||
collidedX = true;// меняем значение соприкосновения на true
|
||||
entity.OnCollision(item);//подписываем entity на ивент коллизии
|
||||
|
||||
{
|
||||
collidedX = true;// меняем значение соприкосновения на true
|
||||
entity.OnCollision(item);//подписываем entity на ивент коллизии
|
||||
|
||||
break;// выход
|
||||
}
|
||||
}
|
||||
|
||||
if (collidedX)// срабатывает, если перемещение блокируется
|
||||
{
|
||||
entity.velocity.X = 0;// задаём значение смещения entity на 0
|
||||
}
|
||||
else
|
||||
{
|
||||
newRect.X = tryingRectX.X;//значение по X для нового РЕК приравниваем к значению испытуемого РЕК
|
||||
break;// выход
|
||||
}
|
||||
}
|
||||
|
||||
//==ПОВТОРЯЕМ ТОЖЕ САМОЕ ДЛЯ Y==
|
||||
if (collidedX)// срабатывает, если перемещение блокируется
|
||||
{
|
||||
entity.velocity.X = 0;// задаём значение смещения entity на 0
|
||||
}
|
||||
else
|
||||
{
|
||||
entity.position.X += entity.velocity.X; //update player position
|
||||
newRect.X = tryingRectX.X;//значение по X для нового РЕК приравниваем к значению испытуемого РЕК
|
||||
}
|
||||
|
||||
//==ПОВТОРЯЕМ ТОЖЕ САМОЕ ДЛЯ Y==
|
||||
|
||||
var collidedY = false; // соприкосновение
|
||||
var tryingRectY = currentRect;//переменная для попытки перемещения по X
|
||||
|
@ -78,7 +82,7 @@ namespace ZoFo.GameCore.GameManagers.CollisionManager
|
|||
entity.OnCollision(item);//подписываем entity на ивент коллизии
|
||||
|
||||
break;// выход
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (collidedY)// срабатывает, если перемещение блокируется
|
||||
|
@ -87,8 +91,13 @@ namespace ZoFo.GameCore.GameManagers.CollisionManager
|
|||
}
|
||||
else
|
||||
{
|
||||
entity.position.X += entity.velocity.Y;
|
||||
newRect.Y = tryingRectY.Y;//значение по X для нового РЕК приравниваем к значению испытуемого РЕК
|
||||
}
|
||||
|
||||
entity.collisionComponent.stopRectangle = newRect;
|
||||
entity.graphicsComponent.ObjectDrawRectangle = newRect;
|
||||
entity.velocity = Vector2.Zero;
|
||||
}
|
||||
|
||||
//обновление позиции объекта
|
||||
|
@ -97,17 +106,32 @@ namespace ZoFo.GameCore.GameManagers.CollisionManager
|
|||
|
||||
}
|
||||
|
||||
public void UpdatePositions()
|
||||
{
|
||||
foreach (var item in EntitiesWithMovements)
|
||||
{
|
||||
CheckComponentCollision(item);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public CollisionManager()
|
||||
{
|
||||
//graphicsComponent
|
||||
//.ObjectDrawRectangle = new Rectangle(0, 0, 16 * 12, 16 * 16);
|
||||
EntitiesWithMovements = new List<CollisionComponent>();
|
||||
ObjectsWithCollisions = new List<CollisionComponent>();
|
||||
}
|
||||
//регистрация компонента(его коллизии)
|
||||
public void Register(CollisionComponent component)
|
||||
{
|
||||
ObjectsWithCollisions.Add(component);
|
||||
if (component.gameObject is Entity)
|
||||
if (component.gameObject is LivingEntity)
|
||||
{
|
||||
EntitiesWithMovements.Add(component);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -20,5 +20,7 @@ namespace ZoFo.GameCore.GameObjects.Entities
|
|||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,10 +14,15 @@ namespace ZoFo.GameCore.GameObjects.Entities
|
|||
public int Id { get; set; }
|
||||
protected Entity(Vector2 position) : base(position)
|
||||
{
|
||||
|
||||
}
|
||||
public virtual void Update()
|
||||
{
|
||||
|
||||
}
|
||||
public override void UpdateLogic()
|
||||
{
|
||||
Update();
|
||||
base.UpdateLogic();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,6 +9,9 @@ using ZoFo.GameCore.Graphics;
|
|||
namespace ZoFo.GameCore.GameObjects.Entities.LivingEntities;
|
||||
public class LivingEntity : Entity
|
||||
{
|
||||
/// <summary>
|
||||
/// Переменная для заявки на передвижения, т.е. то, на сколько вы хотите, чтобы в этом кадре переместился объект
|
||||
/// </summary>
|
||||
public Vector2 velocity;
|
||||
|
||||
private InputManager inputManager;
|
||||
|
|
|
@ -1,27 +1,49 @@
|
|||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using ZoFo.GameCore.GameManagers;
|
||||
using ZoFo.GameCore.GameManagers.CollisionManager;
|
||||
using ZoFo.GameCore.GameManagers.NetworkManager.Updates.ClientToServer;
|
||||
using ZoFo.GameCore.GameManagers.NetworkManager.Updates.ServerToClient;
|
||||
using ZoFo.GameCore.ZoFo_graphics;
|
||||
|
||||
namespace ZoFo.GameCore.GameObjects.Entities.LivingEntities.Player;
|
||||
|
||||
public class Player : LivingEntity
|
||||
{
|
||||
public Vector2 InputWeaponRotation{ get; set; }
|
||||
public Vector2 InputPlayerRotation{ get; set;}
|
||||
public bool IsTryingToShoot{get;set;}
|
||||
Texture2D texture;
|
||||
public Vector2 InputWeaponRotation { get; set; }
|
||||
public Vector2 InputPlayerRotation { get; set; }
|
||||
/// <summary>
|
||||
/// Факт того, что плеер в этом апдейте пытается стрелять
|
||||
/// </summary>
|
||||
public bool IsTryingToShoot { get; set; }
|
||||
private float speed;
|
||||
private int health;
|
||||
public override GraphicsComponent graphicsComponent { get; } = new GraphicsComponent(new List<string> { "player_running_top_rotate" }, "player_running_top_rotate");
|
||||
public Player(Vector2 position) : base(position)
|
||||
{
|
||||
//InputWeaponRotation = new Vector2(0, 0);
|
||||
//InputPlayerRotation = new Vector2(0, 0);
|
||||
|
||||
collisionComponent = new CollisionComponent(this, true, new Rectangle(0, 0, 10, 10));
|
||||
}
|
||||
|
||||
|
||||
public void Update(GameTime gameTime)
|
||||
{
|
||||
|
||||
{
|
||||
|
||||
MovementLogic();
|
||||
}
|
||||
public void MovementLogic()
|
||||
{
|
||||
if (InputPlayerRotation.X > 0.9)
|
||||
{
|
||||
velocity.X = 5;
|
||||
}
|
||||
}
|
||||
public void HandleNewInput(UpdateInput updateInput)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,10 +20,16 @@ public abstract class GameObject
|
|||
{
|
||||
this.position = position;
|
||||
graphicsComponent.LoadContent();
|
||||
|
||||
graphicsComponent.ObjectDrawRectangle.X = (int)position.X;
|
||||
graphicsComponent.ObjectDrawRectangle.Y = (int)position.Y;
|
||||
|
||||
}
|
||||
public virtual void UpdateLogic(GameTime gameTime)
|
||||
public virtual void UpdateLogic()
|
||||
{
|
||||
PlayAnimation_OnServer();
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -1,15 +1,22 @@
|
|||
using Microsoft.Xna.Framework;
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using ZoFo.GameCore.GameManagers.CollisionManager;
|
||||
|
||||
namespace ZoFo.GameCore.GameObjects.MapObjects.StopObjects;
|
||||
|
||||
public class StopObject : MapObject
|
||||
{
|
||||
CollisionComponent collisionComponent;
|
||||
CollisionComponent[] collisionComponent;
|
||||
|
||||
public StopObject(Vector2 position, Vector2 size, Rectangle sourceRectangle, string textureName) : base(position, size, sourceRectangle, textureName)
|
||||
|
||||
protected StopObject(Vector2 position, Vector2 size, Rectangle sourceRectangle, string textureName, Rectangle[] collisions) : base(position, size, s
|
||||
{
|
||||
collisionComponent = new CollisionComponent[collisions.Length];
|
||||
for (int i = 0; i < collisionComponent.Length; i++)
|
||||
{
|
||||
collisionComponent[i] = new CollisionComponent(this, true, collisions[i]);
|
||||
}
|
||||
// TODO: Написать коллизию, пусть тразмер будет чисто таким же как и текстурка.
|
||||
// Поменяйте уровень защиты конструктора, после снимите в MapManager комментарий в методе LoadMap с создания StopObject-а
|
||||
}
|
||||
|
|
|
@ -8,12 +8,14 @@ using System.Text;
|
|||
using System.Text.Json;
|
||||
using System.Threading.Tasks;
|
||||
using ZoFo.GameCore.GameManagers;
|
||||
using ZoFo.GameCore.GameManagers.CollisionManager;
|
||||
using ZoFo.GameCore.GameManagers.MapManager;
|
||||
using ZoFo.GameCore.GameManagers.NetworkManager;
|
||||
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.Player;
|
||||
using ZoFo.GameCore.GameObjects.MapObjects;
|
||||
|
||||
namespace ZoFo.GameCore
|
||||
|
@ -30,6 +32,8 @@ namespace ZoFo.GameCore
|
|||
|
||||
}
|
||||
#region server logic as App
|
||||
|
||||
#region Net Methods
|
||||
//TODO Comment pls
|
||||
public void OnDataSend(string data)
|
||||
{
|
||||
|
@ -73,6 +77,10 @@ namespace ZoFo.GameCore
|
|||
networkManager.Start(players);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Game Methods
|
||||
|
||||
/// <summary>
|
||||
/// Запуск игры в комнате
|
||||
/// </summary>
|
||||
|
@ -81,12 +89,13 @@ namespace ZoFo.GameCore
|
|||
|
||||
//TODO начинает рассылку и обмен пакетами игры
|
||||
//Грузит карту
|
||||
|
||||
collisionManager = new CollisionManager();
|
||||
gameObjects = new List<GameObject>();
|
||||
entities = new List<Entity>();
|
||||
new MapManager().LoadMap();
|
||||
|
||||
AppManager.Instance.server.RegisterGameObject(new EntittyForAnimationTests(new Vector2(40, 40)));
|
||||
AppManager.Instance.server.RegisterGameObject(new Player(new Vector2(140, 140)));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -98,6 +107,8 @@ namespace ZoFo.GameCore
|
|||
networkManager.AddData(gameEnded);
|
||||
networkManager.CloseConnection();
|
||||
}
|
||||
|
||||
public CollisionManager collisionManager;
|
||||
private List<GameObject> gameObjects = new List<GameObject>();
|
||||
private List<Entity> entities; //entity
|
||||
public void Update(GameTime gameTime)
|
||||
|
@ -106,8 +117,9 @@ namespace ZoFo.GameCore
|
|||
{
|
||||
foreach (var go in gameObjects)
|
||||
{
|
||||
go.UpdateLogic(gameTime);
|
||||
go.UpdateLogic();
|
||||
}
|
||||
collisionManager.UpdatePositions();
|
||||
ticks = 0;
|
||||
networkManager.SendData();
|
||||
}
|
||||
|
@ -156,4 +168,6 @@ namespace ZoFo.GameCore
|
|||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue