GameObject Fixes

This commit is contained in:
SergoDobro 2024-08-16 15:21:45 +03:00
parent 54aded7c1d
commit 12a464bea6
12 changed files with 69 additions and 35 deletions

View file

@ -13,25 +13,11 @@ namespace ZoFo.GameCore.GameObjects.Entities
protected override GraphicsComponent graphicsComponent => null; protected override GraphicsComponent graphicsComponent => null;
public CollisionComponent collisionComponent { get; protected set; } public CollisionComponent collisionComponent { get; protected set; }
public int Id { get; set; } public int Id { get; set; }
public void CollisionComponent() protected Entity(Vector2 position) : base(position)
{ {
} }
public void AnimationComponent()
{
}
public void UpdateLogic()
{
}
} }
} }
//вектор
//вилосити
//поситион
//текстура

View file

@ -1,7 +1,10 @@
using System; using Microsoft.Xna.Framework;
using System;
namespace ZoFo.GameCore.GameObjects.Entities.Interactables.Collectables; namespace ZoFo.GameCore.GameObjects.Entities.Interactables.Collectables;
public class Collectable : Entity public class Collectable : Entity
{ {
public Collectable(Vector2 position) : base(position)
{
}
} }

View file

@ -2,10 +2,13 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Net.Mime; using System.Net.Mime;
using System.Reflection; using System.Reflection;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content; using Microsoft.Xna.Framework.Content;
namespace ZoFo.GameCore.GameObjects.Entities.LivingEntities.Enemies; namespace ZoFo.GameCore.GameObjects.Entities.LivingEntities.Enemies;
public class Enemy : LivingEntity public class Enemy : LivingEntity
{ {
public Enemy(Vector2 position) : base(position)
{
}
} }

View file

@ -9,6 +9,9 @@ public class LivingEntity : Entity
{ {
public Vector2 velocity; public Vector2 velocity;
public LivingEntity(Vector2 position) : base(position)
{
}
public void TextureLoad(SpriteBatch spriteBatch) public void TextureLoad(SpriteBatch spriteBatch)
{ {

View file

@ -9,6 +9,10 @@ public class Player : LivingEntity
private int health; private int health;
Server server = new Server(); Server server = new Server();
public Player(Vector2 position) : base(position)
{
}
public void Update(GameTime gameTime) public void Update(GameTime gameTime)
{ {
// server.AddData(); // server.AddData();

View file

@ -1,7 +1,10 @@
using System; using Microsoft.Xna.Framework;
using System;
namespace ZoFo.GameCore.GameObjects.Entities.LivingEntities.Projectiles; namespace ZoFo.GameCore.GameObjects.Entities.LivingEntities.Projectiles;
public class Bullet : Projectile public class Bullet : Projectile
{ {
public Bullet(Vector2 position) : base(position)
{
}
} }

View file

@ -1,7 +1,10 @@
using System; using Microsoft.Xna.Framework;
using System;
namespace ZoFo.GameCore.GameObjects.Entities.LivingEntities.Projectiles; namespace ZoFo.GameCore.GameObjects.Entities.LivingEntities.Projectiles;
public class Projectile : LivingEntity public class Projectile : LivingEntity
{ {
public Projectile(Vector2 position) : base(position)
{
}
} }

View file

@ -1,7 +1,10 @@
using System; using Microsoft.Xna.Framework;
using System;
namespace ZoFo.GameCore.GameObjects.Entities.LivingEntities.Projectiles; namespace ZoFo.GameCore.GameObjects.Entities.LivingEntities.Projectiles;
public class Rock : Projectile public class Rock : Projectile
{ {
public Rock(Vector2 position) : base(position)
{
}
} }

View file

@ -18,6 +18,10 @@ public abstract class GameObject
{ {
this.position = position; this.position = position;
} }
public virtual void UpdateLogic(GameTime gameTime)
{
PlayAnimation_OnServer();
}
/// <summary> /// <summary>
@ -25,7 +29,7 @@ public abstract class GameObject
/// </summary> /// </summary>
public void PlayAnimation_OnServer() public void PlayAnimation_OnServer()
{ {
//TODO graphicsComponent.Update();
} }
#endregion #endregion
@ -34,22 +38,35 @@ public abstract class GameObject
#region Client Side #region Client Side
/// <summary> /// <summary>
/// Для клиента
/// Это вызывается в клиентской части игры /// Это вызывается в клиентской части игры
/// </summary> /// </summary>
public void PlayAnimation_OnClient() public void PlayAnimation_OnClient()
{ {
graphicsComponent.Update(); graphicsComponent.Update();
} }
/// <summary>
/// Для клиента
/// Загрузка графического компонента
/// </summary>
public void LoadContent() public void LoadContent()
{ {
graphicsComponent.LoadContent(); graphicsComponent.LoadContent();
} }
public virtual void Update(GameTime gameTime) /// <summary>
/// Для клиента
/// Обновление, которое вызывается у клиента, для просмотра анимаций
/// </summary>
public virtual void UpdateAnimations(GameTime gameTime)
{ {
//PlayAnimation(); PlayAnimation_OnClient();
} }
/// <summary>
/// Для клиента
/// </summary>
public virtual void Draw(SpriteBatch spriteBatch) public virtual void Draw(SpriteBatch spriteBatch)
{ {
graphicsComponent.DrawAnimation(graphicsComponent.ObjectDrawRectangle, spriteBatch); graphicsComponent.DrawAnimation(graphicsComponent.ObjectDrawRectangle, spriteBatch);

View file

@ -21,6 +21,10 @@ namespace ZoFo.GameCore.GameObjects.MapObjects
_sourceRectangle = sourceRectangle; _sourceRectangle = sourceRectangle;
graphicsComponent.ObjectDrawRectangle = new Rectangle(0,0, (int)size.X, (int)size.Y); graphicsComponent.ObjectDrawRectangle = new Rectangle(0,0, (int)size.X, (int)size.Y);
} }
public override void Draw(SpriteBatch spriteBatch)
{
graphicsComponent.DrawAnimation(graphicsComponent.ObjectDrawRectangle, spriteBatch, _sourceRectangle);
}
} }
} }

View file

@ -9,7 +9,7 @@ public class StopObject : MapObject
{ {
CollisionComponent collisionComponent; CollisionComponent collisionComponent;
protected StopObject(Vector2 position, Vector2 size, Rectangle sourceRectangle) : base(position, size, sourceRectangle) protected StopObject(Vector2 position, Vector2 size, Rectangle sourceRectangle, string textureName) : base(position, size, sourceRectangle, textureName)
{ {
} }
} }

View file

@ -15,9 +15,7 @@ namespace ZoFo.GameCore
{ {
public class Server public class Server
{ {
private List<GameObject> gameObjects;
private ServerNetworkManager networkManager; private ServerNetworkManager networkManager;
private List<Entity> entity; //entity
public Server() public Server()
{ {
networkManager = new ServerNetworkManager(); networkManager = new ServerNetworkManager();
@ -58,8 +56,15 @@ namespace ZoFo.GameCore
networkManager.AddData(gameEnded); networkManager.AddData(gameEnded);
networkManager.CloseConnection(); networkManager.CloseConnection();
} }
private List<GameObject> gameObjects;
private List<Entity> entities; //entity
public void Update(GameTime gameTime) public void Update(GameTime gameTime)
{ {
foreach (var go in gameObjects)
{
go.UpdateLogic(gameTime);
}
} }
/// <summary> /// <summary>