using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using System;
using ZoFo.GameCore.GameManagers;
using ZoFo.GameCore;
using ZoFo.GameCore.Graphics;
namespace ZoFo.GameCore.GameObjects;
public abstract class GameObject
{
public Vector2 position;
public Vector2 rotation; //вектор направления объекта
public abstract GraphicsComponent graphicsComponent { get; }
#region ServerSide
public GameObject(Vector2 position)
{
this.position = position;
graphicsComponent.LoadContent();
graphicsComponent.ObjectDrawRectangle.X = (int)position.X;
graphicsComponent.ObjectDrawRectangle.Y = (int)position.Y;
}
public virtual void UpdateLogic()
{
PlayAnimation_OnServer();
}
///
/// Это вызывается в логике игры, которая на сервере, здесь будет вызываться уведомление об анимации
///
public void PlayAnimation_OnServer()
{
graphicsComponent.Update();
}
#endregion
#region Client Side
public static Texture2D debugTexture;
///
/// Для клиента
/// Это вызывается в клиентской части игры
///
public void PlayAnimation_OnClient()
{
graphicsComponent.Update();
}
///
/// Для клиента
/// Загрузка графического компонента
///
public void LoadContent()
{
graphicsComponent.LoadContent();
}
///
/// Для клиента
/// Обновление, которое вызывается у клиента, для просмотра анимаций
///
public virtual void UpdateAnimations()
{
graphicsComponent.ObjectDrawRectangle.X = (int)position.X; //Move To place where Updates Sets your position
graphicsComponent.ObjectDrawRectangle.Y = (int)position.Y;
PlayAnimation_OnClient();
}
///
/// Для клиента
///
public virtual void Draw(SpriteBatch spriteBatch)
{
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 = null)
{
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);
//TODO: debugTexture
}
#endregion
}