GameObject Almost Finished

This commit is contained in:
SergoDobro 2024-08-16 13:07:27 +03:00
parent 2187bc4466
commit 866f87c0d0
5 changed files with 113 additions and 3 deletions

View file

@ -1,5 +1,8 @@

using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using System;
using ZoFo.GameCore.GameManagers;
using ZoFo.GameCore.ZoFo_graphics;
namespace ZoFo.GameCore.GameObjects;
@ -7,9 +10,65 @@ namespace ZoFo.GameCore.GameObjects;
public abstract class GameObject
{
public Vector2 position;
public Vector2 rotation;
public Vector2 rotation; //вектор направления объекта
protected abstract GraphicsComponent graphicsComponent { get; }
public void Draw() { }
#region ServerSide
public GameObject(Vector2 position)
{
this.position = position;
}
/// <summary>
/// Это вызывается в логике игры, которая на сервере, здесь будет вызываться уведомление об анимации
/// </summary>
public void PlayAnimation_OnServer()
{
//TODO
}
#endregion
#region Client Side
/// <summary>
/// Это вызывается в клиентской части игры
/// </summary>
public void PlayAnimation_OnClient()
{
graphicsComponent.Update();
}
public void LoadContent()
{
graphicsComponent.LoadContent();
}
public virtual void Update(GameTime gameTime)
{
//PlayAnimation();
}
public virtual void Draw(SpriteBatch spriteBatch)
{
graphicsComponent.DrawAnimation(graphicsComponent.ObjectDrawRectangle, spriteBatch);
//debug
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.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
}

View file

@ -0,0 +1,26 @@
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ZoFo.GameCore.GameManagers;
using ZoFo.GameCore.ZoFo_graphics;
namespace ZoFo.GameCore.GameObjects.MapObjects
{
internal class MapObject : GameObject
{
public virtual bool IsColliderOn { get; protected set; } = true;
private Rectangle _sourceRectangle;
protected override GraphicsComponent graphicsComponent => new("tiles");
public MapObject(Vector2 position, Vector2 size, Rectangle sourceRectangle) : base(position)
{
_sourceRectangle = sourceRectangle;
graphicsComponent.ObjectDrawRectangle = new Rectangle(0,0, (int)size.X, (int)size.Y);
}
}
}

View file

@ -0,0 +1,13 @@
using Microsoft.Xna.Framework;
using System;
using ZoFo.GameCore.ZoFo_graphics;
namespace ZoFo.GameCore.GameObjects.MapObjects.StopObjects;
public abstract class StopObject : GameObject
{
protected StopObject(Vector2 position) : base(position)
{
//TODO
}
}

View file

@ -0,0 +1,8 @@
using System;
namespace ZoFo.GameCore.GameObjects.MapObjects.Tiles;
public class Tile
{
}

View file

@ -15,6 +15,10 @@ namespace ZoFo.GameCore.ZoFo_graphics
public class GraphicsComponent
{
public Rectangle ObjectDrawRectangle { get; set; }
public event Action<string> actionOfAnimationEnd;
private List<AnimationContainer> animations;
private List<Texture2D> textures;