GameObject Almost Finished
This commit is contained in:
parent
2187bc4466
commit
866f87c0d0
5 changed files with 113 additions and 3 deletions
|
@ -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
|
||||
}
|
26
ZoFo/GameCore/GameObjects/MapObjects/MapObject.cs
Normal file
26
ZoFo/GameCore/GameObjects/MapObjects/MapObject.cs
Normal 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);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -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
|
||||
}
|
||||
}
|
8
ZoFo/GameCore/GameObjects/MapObjects/Tiles/Tile.cs
Normal file
8
ZoFo/GameCore/GameObjects/MapObjects/Tiles/Tile.cs
Normal file
|
@ -0,0 +1,8 @@
|
|||
using System;
|
||||
|
||||
namespace ZoFo.GameCore.GameObjects.MapObjects.Tiles;
|
||||
|
||||
public class Tile
|
||||
{
|
||||
|
||||
}
|
|
@ -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;
|
||||
|
|
Loading…
Add table
Reference in a new issue