diff --git a/ZoFo/GameCore/Client.cs b/ZoFo/GameCore/Client.cs
index da79f1d..cc46668 100644
--- a/ZoFo/GameCore/Client.cs
+++ b/ZoFo/GameCore/Client.cs
@@ -130,6 +130,7 @@ namespace ZoFo.GameCore
///
internal void Update(GameTime gameTime)
{
+ DebugHUD.AddGOData(particles.Count, "particles");
UpdateShaking();
for (int i = 0; i < gameObjects.Count; i++)
{
@@ -153,24 +154,30 @@ namespace ZoFo.GameCore
{
networkManager.SendData();
}
- internal void Draw(SpriteBatch spriteBatch)
+ internal void Draw(SpriteBatch _spriteBatch)
{
+ _spriteBatch.Begin(samplerState: SamplerState.PointWrap);//no layering
for (int i = 0; i < mapObjects.Count; i++)
{
- mapObjects[i].Draw(spriteBatch);
+ mapObjects[i].Draw(_spriteBatch);
}
for (int i = 0; i < stopObjects.Count; i++)
{
- stopObjects[i].Draw(spriteBatch);
+ stopObjects[i].Draw(_spriteBatch);
}
+ _spriteBatch.End();
+
+
+ _spriteBatch.Begin(sortMode: SpriteSortMode.FrontToBack, samplerState: SamplerState.PointWrap);
for (int i = 0; i < gameObjects.Count; i++)
{
- gameObjects[i].Draw(spriteBatch);
+ gameObjects[i].Draw(_spriteBatch);
}
for (int i = 0; i < particles.Count; i++)
{
- particles[i].Draw(spriteBatch);
+ particles[i].Draw(_spriteBatch);
}
+ _spriteBatch.End();
}
diff --git a/ZoFo/GameCore/GUI/DebugHUD.cs b/ZoFo/GameCore/GUI/DebugHUD.cs
index d728ada..d3e6332 100644
--- a/ZoFo/GameCore/GUI/DebugHUD.cs
+++ b/ZoFo/GameCore/GUI/DebugHUD.cs
@@ -5,6 +5,10 @@ using Microsoft.Xna.Framework.Graphics;
using MonogameLibrary.UI.Elements;
using static System.String;
using ZoFo.GameCore.GameManagers;
+using static System.Net.Mime.MediaTypeNames;
+using System;
+using System.Diagnostics;
+using Microsoft.Xna.Framework.Input;
namespace ZoFo.GameCore.GUI;
@@ -14,10 +18,12 @@ public class DebugHUD
private Dictionary _text = new();
private List _log = new();
public static DebugHUD Instance { get; private set; }
-
+ public Texture2D noTexture;
+ public static bool IsActivated = true;
public void Initialize()
{
Instance = this;
+
}
public void LoadContent()
@@ -25,12 +31,18 @@ public class DebugHUD
_spriteFont = AppManager.Instance.Content.Load("Fonts/Font2");
}
+ bool prev_KeyState;//SHould move this logic and deneralize to main input manager
public void Update(GameTime gameTime)
{
+ if (Keyboard.GetState().IsKeyDown(Keys.D1) && !prev_KeyState)
+ ChangeStatLayer();
+
+ prev_KeyState = Keyboard.GetState().IsKeyDown(Keys.D1);
}
public void Draw(SpriteBatch spriteBatch)
{
+ if (!IsActivated) return;
//return;//TODO delete
var keysString = Join("\n", _text.Select(el => el.Key + ": " + el.Value).ToList());
spriteBatch.Begin();
@@ -56,7 +68,11 @@ public class DebugHUD
SpriteEffects.None,
0
);
+
+ DrawGameObjecctsCounter(spriteBatch);
+
spriteBatch.End();
+
}
public void Set(string key, string value)
@@ -76,12 +92,120 @@ public class DebugHUD
_log.RemoveAt(0);
}
}
+
+ static int totalSavedStatistics = 100;
public static void DebugLog(string value)
{
Instance._log.Add(value);
- if (Instance._log.Count > 30)
+ if (Instance._log.Count > totalSavedStatistics)
{
Instance._log.RemoveAt(0);
}
}
+
+ public static Dictionary> gameObjectsStatistics = new();
+ public static string currentListName = "";
+ private static int colorDelta = 0;
+ private static int statLayer = 0;
+ public static void ChangeStatLayer()
+ {
+ if (gameObjectsStatistics.Count == 0) return;
+
+ statLayer = (statLayer + 1) % gameObjectsStatistics.Count;
+ currentListName = gameObjectsStatistics.ToArray()[statLayer].Key;
+ DebugSet("statistics list name:", currentListName);
+
+ }
+ public static void AddGOData(int data, string listName)
+ {
+ if (!gameObjectsStatistics.ContainsKey(listName))
+ {
+
+ gameObjectsStatistics.Add(listName, new List());
+ DebugSet("statistics list name:", currentListName);
+
+ }
+ if (currentListName == "")
+ currentListName = listName;
+ DebugSet("statistics list current parametr:", data.ToString());
+ gameObjectsStatistics[listName].Add(data);
+ if (gameObjectsStatistics[listName].Count > totalSavedStatistics)
+ {
+ gameObjectsStatistics[listName].RemoveAt(0);
+ if (currentListName == listName)
+ colorDelta++;
+
+
+
+ }
+
+ }
+ public static void AddAdditionalDataToGraph(int data, string listName)
+ {
+ if (!gameObjectsStatistics.ContainsKey(listName))
+ {
+ gameObjectsStatistics.Add(listName, new List());
+ DebugSet("statistics list name:", currentListName);
+
+ }
+ if (currentListName == "")
+ currentListName = listName;
+ if (gameObjectsStatistics[listName].Count() == 0)
+ gameObjectsStatistics[listName].Add(0);
+
+ gameObjectsStatistics[listName][gameObjectsStatistics[listName].Count() - 1] += data;
+ DebugSet("statistics list current parametr:", gameObjectsStatistics[listName][gameObjectsStatistics[listName].Count() - 1].ToString());
+
+ if (gameObjectsStatistics[listName].Count > totalSavedStatistics)
+ {
+ gameObjectsStatistics[listName].RemoveAt(0);
+ if (currentListName == listName)
+ colorDelta++;
+
+
+
+ }
+
+ }
+ static Color[] colorsForGraphic = new Color[] {
+ new Color(255,0,0),
+ new Color(250,0,0),
+ new Color(245,0,0),
+ new Color(240,0,0),
+ new Color(235,0,0),
+ new Color(240,0,0),
+ new Color(245,0,0),
+ };
+ public void DrawGameObjecctsCounter(SpriteBatch spriteBatch)
+ {
+ if (gameObjectsStatistics.Count == 0) return;
+ if (gameObjectsStatistics[currentListName].Count == 0) return;
+
+ Point leftTopPoint = (SettingsManager.Instance.Resolution.ToVector2() * new Vector2(0.8f, 0.8f)).ToPoint();
+ Point rightBottomPoint = (SettingsManager.Instance.Resolution.ToVector2() * new Vector2(0.99f, 0.95f)).ToPoint();
+
+ Point leftBottomPoint = new Point(leftTopPoint.X, rightBottomPoint.Y);
+ Point rightTopPoint = new Point(rightBottomPoint.X, leftTopPoint.Y);
+ int max = gameObjectsStatistics[currentListName].Max();
+
+ spriteBatch.Draw(noTexture, new Rectangle(leftTopPoint, rightBottomPoint - leftTopPoint
+ ), new Color(Color.Gray, 0.4f));
+ for (int i = 0; i < gameObjectsStatistics[currentListName].Count; i++)
+ {
+ int val = gameObjectsStatistics[currentListName][i];
+ int needToMax = (int)((1 - ((float)val)/max) * (leftBottomPoint.Y - leftTopPoint.Y));
+ float sizeOfBar = (rightBottomPoint.X - leftBottomPoint.X)/ (float)totalSavedStatistics;
+ int dX = (int)(i * sizeOfBar);
+
+ Color col = colorsForGraphic[Math.Abs(colorDelta + i) % colorsForGraphic.Count()];
+
+
+ spriteBatch.Draw(noTexture, new Rectangle(
+ leftBottomPoint.X + dX,
+ leftTopPoint.Y + (needToMax),
+ (int)Math.Ceiling(sizeOfBar),
+ (leftBottomPoint.Y - leftTopPoint.Y) - needToMax
+ ), col);
+ }
+ }
}
\ No newline at end of file
diff --git a/ZoFo/GameCore/GameManagers/AppManager.cs b/ZoFo/GameCore/GameManagers/AppManager.cs
index 0a07719..ef6f242 100644
--- a/ZoFo/GameCore/GameManagers/AppManager.cs
+++ b/ZoFo/GameCore/GameManagers/AppManager.cs
@@ -99,8 +99,14 @@ namespace ZoFo.GameCore.GameManagers
animationBuilder = new AnimationBuilder();
animationBuilder.LoadAnimations();
+
GameObject.debugTexture = new Texture2D(GraphicsDevice, 1, 1);
GameObject.debugTexture.SetData(new Color[] { Color.White });
+
+
+ DebugHUD.Instance.noTexture = new Texture2D(GraphicsDevice, 1, 1);
+ DebugHUD.Instance.noTexture.SetData(new Color[] { Color.White });
+
}
protected override void Update(GameTime gameTime)
@@ -110,9 +116,9 @@ namespace ZoFo.GameCore.GameManagers
// debugHud.Set("key", "value");
-
CheckGUI();
InputManager.Update();
+ debugHud.Update(gameTime);
currentGUI.Update(gameTime);
switch (gamestate)
{
@@ -137,7 +143,6 @@ namespace ZoFo.GameCore.GameManagers
// Pointwrap
- _spriteBatch.Begin(samplerState: SamplerState.PointWrap);
switch (gamestate)
{
case GameState.ClientPlaying:
@@ -151,7 +156,6 @@ namespace ZoFo.GameCore.GameManagers
break;
}
- _spriteBatch.End();
currentGUI.Draw(_spriteBatch);
debugHud.Draw(_spriteBatch);
diff --git a/ZoFo/GameCore/GameManagers/CollisionManager/CollisionManager.cs b/ZoFo/GameCore/GameManagers/CollisionManager/CollisionManager.cs
index 7faaca4..3cdb171 100644
--- a/ZoFo/GameCore/GameManagers/CollisionManager/CollisionManager.cs
+++ b/ZoFo/GameCore/GameManagers/CollisionManager/CollisionManager.cs
@@ -14,7 +14,9 @@ using ZoFo.GameCore.GameObjects.Entities.LivingEntities;
using ZoFo.GameCore.GameManagers.NetworkManager.Updates.ServerToClient;
using ZoFo.GameCore.Graphics;
using ZoFo.GameCore.GameManagers.NetworkManager.SerializableDTO;
-using ZoFo.GameCore.GameObjects.Entities.LivingEntities.Player;
+using ZoFo.GameCore.GameObjects.Entities.LivingEntities.Player;
+using System.Diagnostics;
+using ZoFo.GameCore.GUI;
namespace ZoFo.GameCore.GameManagers.CollisionManager
{
@@ -56,6 +58,13 @@ namespace ZoFo.GameCore.GameManagers.CollisionManager
{
//ADD CHECKSPEED TODO
var entity = componentOfEntity.gameObject as LivingEntity;
+
+ if (float.IsNaN(entity.velocity.X) || float.IsNaN(entity.velocity.Y))
+ {
+ DebugHUD.DebugLog("ENTITY HAS ODD velocity!");
+ entity.velocity = new Vector2();
+ return;
+ }
//for (int i = 0; i < ObjectsWithCollisions.Count; i++)
//{
var currentRect = entity.collisionComponent.stopRectangle;//задаём РЕК
diff --git a/ZoFo/GameCore/GameManagers/NetworkManager/ServerNetworkManager.cs b/ZoFo/GameCore/GameManagers/NetworkManager/ServerNetworkManager.cs
index 313a154..b05b093 100644
--- a/ZoFo/GameCore/GameManagers/NetworkManager/ServerNetworkManager.cs
+++ b/ZoFo/GameCore/GameManagers/NetworkManager/ServerNetworkManager.cs
@@ -39,7 +39,7 @@ namespace ZoFo.GameCore.GameManagers.NetworkManager
public delegate void OnDataSend(string data);
public event OnDataSend GetDataSend; // event
Thread serverThread;
- int datapackSize = 150;
+ int datapackSize = 150+50;
public ServerNetworkManager() { Init(); }
///
@@ -132,9 +132,12 @@ namespace ZoFo.GameCore.GameManagers.NetworkManager
importantUpdates.RemoveAt(0);
currentDatagrammId++;
}
-
+
+ DebugHUD.AddGOData(sendedData.Count, "server gameobjects");
+
if (sendedData.Count != 0)
{
+
for (int i = 0; i < clientsEP.Count; i++)
{
foreach (Datagramm Dgramm in sendedData.Where(x => x.PlayerId == i+1))
diff --git a/ZoFo/GameCore/GameManagers/SettingsManager.cs b/ZoFo/GameCore/GameManagers/SettingsManager.cs
index 13d870a..fc39d9d 100644
--- a/ZoFo/GameCore/GameManagers/SettingsManager.cs
+++ b/ZoFo/GameCore/GameManagers/SettingsManager.cs
@@ -14,6 +14,8 @@ namespace ZoFo.GameCore.GameManagers
{
public class SettingsManager //нужно что-то менять с разрешением
{
+ public SettingsManager() { Instance = this; }
+ public static SettingsManager Instance { get; private set; }
private SettingsContainer settingsContainer = new SettingsContainer();
public bool IsFullScreen { get => settingsContainer.IsFullScreen; }
public float MainVolume { get => settingsContainer.MainVolume; }
diff --git a/ZoFo/GameCore/GameObjects/Entities/Entity.cs b/ZoFo/GameCore/GameObjects/Entities/Entity.cs
index 3a97d3b..46cbc61 100644
--- a/ZoFo/GameCore/GameObjects/Entities/Entity.cs
+++ b/ZoFo/GameCore/GameObjects/Entities/Entity.cs
@@ -61,7 +61,7 @@ namespace ZoFo.GameCore.GameObjects
{
if (AppManager.Instance.gamestate == GameState.HostPlaying)
{
- AppManager.Instance.server.DeleteObject(this);
+ AppManager.Instance.server.DeleteEntity(this);
}
}
}
diff --git a/ZoFo/GameCore/GameObjects/Entities/Interactables/Collectables/Collectable.cs b/ZoFo/GameCore/GameObjects/Entities/Interactables/Collectables/Collectable.cs
index ec5d4af..ce1bea4 100644
--- a/ZoFo/GameCore/GameObjects/Entities/Interactables/Collectables/Collectable.cs
+++ b/ZoFo/GameCore/GameObjects/Entities/Interactables/Collectables/Collectable.cs
@@ -32,7 +32,7 @@ public class Collectable : Interactable
DebugHUD.DebugLog("collected");
string lootname = this.GetType().ToString().ToLower().Split('.').Last();
(sender as Player).lootData.AddLoot(lootname, 1, (sender as Player).Id);
- AppManager.Instance.server.DeleteObject(this);
+ AppManager.Instance.server.DeleteEntity(this);
base.OnInteraction(sender);
}
public override void Draw(SpriteBatch spriteBatch)
diff --git a/ZoFo/GameCore/GameObjects/Entities/LivingEntities/Enemies/Enemy.cs b/ZoFo/GameCore/GameObjects/Entities/LivingEntities/Enemies/Enemy.cs
index 22e4a35..8fd944b 100644
--- a/ZoFo/GameCore/GameObjects/Entities/LivingEntities/Enemies/Enemy.cs
+++ b/ZoFo/GameCore/GameObjects/Entities/LivingEntities/Enemies/Enemy.cs
@@ -6,6 +6,7 @@ using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using ZoFo.GameCore.GameManagers;
using ZoFo.GameCore.Graphics;
+using ZoFo.GameCore.GUI;
namespace ZoFo.GameCore.GameObjects;
public class Enemy : LivingEntity
@@ -25,6 +26,8 @@ public class Enemy : LivingEntity
public virtual void TakeDamage(float damage)
{
if (isDying) return;
+ DebugHUD.AddAdditionalDataToGraph((int)damage, "damage");
+
health -= damage;
if (health < 0)
Die();
diff --git a/ZoFo/GameCore/GameObjects/Entities/LivingEntities/Enemies/Zombie.cs b/ZoFo/GameCore/GameObjects/Entities/LivingEntities/Enemies/Zombie.cs
index 31c22a8..a8eca18 100644
--- a/ZoFo/GameCore/GameObjects/Entities/LivingEntities/Enemies/Zombie.cs
+++ b/ZoFo/GameCore/GameObjects/Entities/LivingEntities/Enemies/Zombie.cs
@@ -39,6 +39,9 @@ namespace ZoFo.GameCore.GameObjects
{
if (str == "zombie_death")
DeathEnd();
+ if (str != "zombie_attack"){
+
+ }
};
}
diff --git a/ZoFo/GameCore/GameObjects/Entities/LivingEntities/Player/Player.cs b/ZoFo/GameCore/GameObjects/Entities/LivingEntities/Player/Player.cs
index b1d873b..a99cdd9 100644
--- a/ZoFo/GameCore/GameObjects/Entities/LivingEntities/Player/Player.cs
+++ b/ZoFo/GameCore/GameObjects/Entities/LivingEntities/Player/Player.cs
@@ -252,6 +252,8 @@ public class Player : LivingEntity
reloading = 5;
IsTryingToShoot = true;
+ DebugHUD.AddGOData(0, "damage");
+
StartAnimation("player_shoot_1");
List entities = AppManager.Instance.server.collisionManager.GetEntities(GetDamageArea(InputWeaponRotation), this).ToList();
diff --git a/ZoFo/GameCore/GameObjects/Entities/Particles/Explosion.cs b/ZoFo/GameCore/GameObjects/Entities/Particles/Explosion.cs
new file mode 100644
index 0000000..5b4d48f
--- /dev/null
+++ b/ZoFo/GameCore/GameObjects/Entities/Particles/Explosion.cs
@@ -0,0 +1,35 @@
+using Microsoft.Xna.Framework;
+using System;
+using System.Collections.Generic;
+using ZoFo.GameCore.GameManagers;
+using ZoFo.GameCore.GameManagers.CollisionManager;
+using ZoFo.GameCore.Graphics;
+
+namespace ZoFo.GameCore.GameObjects
+{
+ ///
+ /// It is a particle. It is not stored on the server.
+ ///
+ /// We need to understand: should we create it on client, or on server and send it
+ ///
+ public class Explosion : Particle
+ {
+ public override GraphicsComponent graphicsComponent { get; } = new AnimatedGraphicsComponent(new List { "explosion_1" }, "explosion_1");
+
+ public Explosion(Vector2 position) : base(position)
+ {
+ if (AppManager.Instance.client != null)//remove
+ {
+ AppManager.Instance.client.AddShaking(0.05f);
+ }
+ graphicsComponent.ObjectDrawRectangle = new Rectangle(-30, -30, 60, 60).SetOrigin(position);
+ AppManager.Instance.SoundManager.StartSound("gun-gunshot-01", Vector2.Zero, Vector2.Zero, 0.5f, (float)(Random.Shared.NextDouble() * 2 - 1));
+ (graphicsComponent as AnimatedGraphicsComponent).actionOfAnimationEnd += _ =>
+ {
+
+ Delete_OnClient(this);
+
+ };
+ }
+ }
+}
diff --git a/ZoFo/GameCore/GameObjects/Entities/Particles/Granade.cs b/ZoFo/GameCore/GameObjects/Entities/Particles/Granade.cs
new file mode 100644
index 0000000..9add728
--- /dev/null
+++ b/ZoFo/GameCore/GameObjects/Entities/Particles/Granade.cs
@@ -0,0 +1,132 @@
+using Microsoft.Xna.Framework;
+using Microsoft.Xna.Framework.Graphics;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using ZoFo.GameCore.GameManagers;
+using ZoFo.GameCore.GameManagers.CollisionManager;
+using ZoFo.GameCore.Graphics;
+
+namespace ZoFo.GameCore.GameObjects
+{
+ ///
+ /// TODO: change from particle to throwable, it is not a particle anymore
+ ///
+ public class Granade : GameObject
+ {
+ public override GraphicsComponent graphicsComponent { get; } = new AnimatedGraphicsComponent(new List { "explosion_1" }, "explosion_1");
+
+ ///
+ /// TODO updates with directed effect
+ ///
+ ///
+ ///
+ public Granade(Vector2 positionTo) : base(positionTo)
+ {
+ if (AppManager.Instance.client.myPlayer != null)
+ this.positionFrom = AppManager.Instance.client.myPlayer.position;
+ this.positionTo = positionTo;
+ graphicsComponent.ObjectDrawRectangle = new Rectangle(-30, -30, 60, 60).SetOrigin(position);
+ AppManager.Instance.SoundManager.StartSound("gun-gunshot-01", Vector2.Zero, Vector2.Zero, 0.5f, (float)(Random.Shared.NextDouble() * 2 - 1));
+ (graphicsComponent as AnimatedGraphicsComponent).actionOfAnimationEnd += _ =>
+ {
+
+ //Delete_OnClient(this);
+
+ };
+ }
+ Vector2 positionFrom;
+ Vector2 positionTo;
+ float dt = 0;
+ public override void UpdateLogic_OnServer()
+ {
+
+ float m = Math.Min(positionFrom.Y, positionTo.Y) - 40;
+ position.X = (1 - dt) * positionFrom.X + dt * positionTo.X;
+ position.Y = (2 * positionTo.Y + 2 * positionFrom.Y - 4 * m) * dt * dt +
+ (4 * m - positionTo.Y - 3 * positionFrom.Y) * dt + positionFrom.Y;
+
+ if (dt >= 0.9)
+ {
+ FlightEndedOnServer();
+ return;
+ }
+ dt += 0.05f;
+ base.UpdateLogic_OnServer();
+ }
+ private void FlightEndedOnServer()
+ {
+
+ var rect = GetDamageRectangle();
+
+ var entities = (AppManager.Instance.server.collisionManager.GetEntities(rect).ToList());
+ foreach (var item in entities)
+ {
+ if (item is Enemy)
+ {
+ (item as Enemy).TakeDamage(1);
+ }
+ }
+ Delete_OnServer();
+
+ }
+ public override void Update_OnClient()
+ {
+ if (dt >= 1)
+ {
+ //Granade Finished the flight
+ Instantiate_OnClient(new Explosion(position + ExtentionClass.RandomVector()*10));
+ Delete_OnClient(this);
+ base.Update_OnClient();
+
+ for (int i = 0; i < 10; i++)
+ {
+ if (Random.Shared.NextDouble() < 0.1) continue;
+ float angl = i / 10f * (float)Math.PI * 2;
+ Instantiate_OnClient(new Explosion(position +
+ new Vector2((float)Math.Cos(angl), (float)Math.Sin(angl)
+ ) * 30));
+
+ }
+
+
+ var rect = GetDamageRectangle();
+
+ return;
+ }
+ float m = Math.Min(positionFrom.Y, positionTo.Y)-40;
+ position.X = (1 - dt) * positionFrom.X + dt * positionTo.X;
+ position.Y = (2 * positionTo.Y + 2 * positionFrom.Y - 4 * m) * dt * dt +
+ (4 * m - positionTo.Y - 3 * positionFrom.Y) * dt + positionFrom.Y;
+
+ dt += 0.05f;
+
+ //position =
+ //base.Update_OnClient();
+ graphicsComponent.ObjectDrawRectangle.X = (int)position.X; //Move To place where Updates Sets your position
+ graphicsComponent.ObjectDrawRectangle.Y = (int)position.Y;
+ PlayAnimation_OnClient();
+ }
+ public override void Draw(SpriteBatch spriteBatch)
+ {
+
+
+
+ DrawDebugRectangle(spriteBatch, GetDamageRectangle(), Color.Red);
+ base.Draw(spriteBatch);
+ }
+ public Rectangle GetDamageRectangle()
+ {
+
+ var rect = graphicsComponent.ObjectDrawRectangle;
+ rect.X = (int)position.X;
+ rect.Y = (int)position.Y;
+ int size = 10;
+ rect.X -= size;
+ rect.Y -= size;
+ rect.Width += 2 * size;
+ rect.Height += 2 * size;
+ return rect;
+ }
+ }
+}
diff --git a/ZoFo/GameCore/GameObjects/Entities/Particles/Particle.cs b/ZoFo/GameCore/GameObjects/Entities/Particles/Particle.cs
index 5cf4de5..9a9cf6a 100644
--- a/ZoFo/GameCore/GameObjects/Entities/Particles/Particle.cs
+++ b/ZoFo/GameCore/GameObjects/Entities/Particles/Particle.cs
@@ -1,12 +1,7 @@
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.GameManagers.CollisionManager;
using ZoFo.GameCore.Graphics;
namespace ZoFo.GameCore.GameObjects
@@ -19,140 +14,4 @@ namespace ZoFo.GameCore.GameObjects
{
}
}
- public class Explosion : Particle
- {
- public override GraphicsComponent graphicsComponent { get; } = new AnimatedGraphicsComponent(new List { "explosion_1" }, "explosion_1");
-
- public Explosion(Vector2 position) : base(position)
- {
- if (AppManager.Instance.client != null)//remove
- {
- AppManager.Instance.client.AddShaking(0.05f);
- }
- graphicsComponent.ObjectDrawRectangle = new Rectangle(-30, -30, 60, 60).SetOrigin(position);
- AppManager.Instance.SoundManager.StartSound("gun-gunshot-01", Vector2.Zero, Vector2.Zero, 0.5f, (float)(Random.Shared.NextDouble() * 2 - 1));
- (graphicsComponent as AnimatedGraphicsComponent).actionOfAnimationEnd += _ =>
- {
-
- Delete_OnClient(this);
-
- };
- }
- }
- ///
- /// TODO: change from particle to throwable, it is not a particle anymore
- ///
- public class Granade : GameObject
- {
- public override GraphicsComponent graphicsComponent { get; } = new AnimatedGraphicsComponent(new List { "explosion_1" }, "explosion_1");
-
- ///
- /// TODO updates with directed effect
- ///
- ///
- ///
- public Granade(Vector2 positionTo) : base(positionTo)
- {
- if (AppManager.Instance.client.myPlayer != null)
- this.positionFrom = AppManager.Instance.client.myPlayer.position;
- this.positionTo = positionTo;
- graphicsComponent.ObjectDrawRectangle = new Rectangle(-30, -30, 60, 60).SetOrigin(position);
- AppManager.Instance.SoundManager.StartSound("gun-gunshot-01", Vector2.Zero, Vector2.Zero, 0.5f, (float)(Random.Shared.NextDouble() * 2 - 1));
- (graphicsComponent as AnimatedGraphicsComponent).actionOfAnimationEnd += _ =>
- {
-
- //Delete_OnClient(this);
-
- };
- }
- Vector2 positionFrom;
- Vector2 positionTo;
- float dt = 0;
- public override void UpdateLogic_OnServer()
- {
-
- if (dt >= 1)
- {
- FlightEndedOnServer();
- return;
- }
- float m = Math.Min(positionFrom.Y, positionTo.Y) - 40;
- position.X = (1 - dt) * positionFrom.X + dt * positionTo.X;
- position.Y = (2 * positionTo.Y + 2 * positionFrom.Y - 4 * m) * dt * dt +
- (4 * m - positionTo.Y - 3 * positionFrom.Y) * dt + positionFrom.Y;
-
- dt += 0.05f;
- base.UpdateLogic_OnServer();
- }
- private void FlightEndedOnServer()
- {
-
- var rect = GetDamageRectangle();
-
- var entities = (AppManager.Instance.server.collisionManager.GetEntities(rect).ToList());
- foreach (var item in entities)
- {
- if (item is Enemy)
- {
- (item as Enemy).TakeDamage(1);
- }
- }
- }
- public override void Update_OnClient()
- {
- if (dt >= 1)
- {
- //Granade Finished the flight
- Instantiate_OnClient(new Explosion(position + ExtentionClass.RandomVector()*10));
- Delete_OnClient(this);
- base.Update_OnClient();
-
- for (int i = 0; i < 10; i++)
- {
- if (Random.Shared.NextDouble() < 0.1) continue;
- float angl = i / 10f * (float)Math.PI * 2;
- Instantiate_OnClient(new Explosion(position +
- new Vector2((float)Math.Cos(angl), (float)Math.Sin(angl)
- ) * 30));
-
- }
-
-
- var rect = GetDamageRectangle();
-
- return;
- }
- float m = Math.Min(positionFrom.Y, positionTo.Y)-40;
- position.X = (1 - dt) * positionFrom.X + dt * positionTo.X;
- position.Y = (2 * positionTo.Y + 2 * positionFrom.Y - 4 * m) * dt * dt +
- (4 * m - positionTo.Y - 3 * positionFrom.Y) * dt + positionFrom.Y;
-
- dt += 0.05f;
-
- //position =
- //base.Update_OnClient();
- graphicsComponent.ObjectDrawRectangle.X = (int)position.X; //Move To place where Updates Sets your position
- graphicsComponent.ObjectDrawRectangle.Y = (int)position.Y;
- PlayAnimation_OnClient();
- }
- public override void Draw(SpriteBatch spriteBatch)
- {
-
-
-
- DrawDebugRectangle(spriteBatch, GetDamageRectangle(), Color.Red);
- base.Draw(spriteBatch);
- }
- public Rectangle GetDamageRectangle()
- {
-
- var rect = graphicsComponent.ObjectDrawRectangle;
- int size = 10;
- rect.X -= size;
- rect.Y -= size;
- rect.Width += 2 * size;
- rect.Height += 2 * size;
- return rect;
- }
- }
}
diff --git a/ZoFo/GameCore/GameObjects/GameObject.cs b/ZoFo/GameCore/GameObjects/GameObject.cs
index 4c977d2..bf40b3a 100644
--- a/ZoFo/GameCore/GameObjects/GameObject.cs
+++ b/ZoFo/GameCore/GameObjects/GameObject.cs
@@ -49,6 +49,12 @@ public abstract class GameObject
AppManager.Instance.server.RegisterGameObject(gameObject);
}
}
+ public void Delete_OnServer()
+ {
+ AppManager.Instance.server.DeleteGameObject(this);
+
+ }
+
#endregion
diff --git a/ZoFo/GameCore/GameObjects/MapObjects/StopObjects/StopObject.cs b/ZoFo/GameCore/GameObjects/MapObjects/StopObjects/StopObject.cs
index 392cf6f..1bd3010 100644
--- a/ZoFo/GameCore/GameObjects/MapObjects/StopObjects/StopObject.cs
+++ b/ZoFo/GameCore/GameObjects/MapObjects/StopObjects/StopObject.cs
@@ -2,6 +2,7 @@
using Microsoft.Xna.Framework.Graphics;
using System;
using System.Diagnostics;
+using System.Linq;
using System.Security.Cryptography.X509Certificates;
using ZoFo.GameCore.GameManagers.CollisionManager;
@@ -14,16 +15,28 @@ public class StopObject : MapObject
public StopObject(Vector2 position, Vector2 size, Rectangle sourceRectangle, string textureName, Rectangle[] collisions) : base(position, size, sourceRectangle, textureName)
{
-
- collisionComponents = new CollisionComponent[collisions.Length];
- for (int i = 0; i < collisionComponents.Length; i++)
+ var cols = collisions.ToList();
+ for (int i = 0; i < cols.Count; i++)
{
- collisionComponents[i] = new CollisionComponent(this, true, new Rectangle(0,0, (int)size.X, (int)size.Y)/*collisions[i]*/);
+ if (cols[i].Width<1)
+ {
+ cols.RemoveAt(i);
+ i--;
+ }
+ }
+ collisionComponents = new CollisionComponent[cols.Count];
+
+ for (int i = 0; i < cols.Count; i++)
+ {
+ collisionComponents[i] = new CollisionComponent(this, true, cols[i]);
}
}
public override void Draw(SpriteBatch spriteBatch)
{
base.Draw(spriteBatch);
- DrawDebugRectangle(spriteBatch, new Rectangle((int)position.X, (int)position.Y, collisionComponents[0].stopRectangle.Width, collisionComponents[0].stopRectangle.Height));
+ foreach (var item in collisionComponents)
+ {
+ DrawDebugRectangle(spriteBatch, new Rectangle((int)position.X, (int)position.Y, item.stopRectangle.Width, item.stopRectangle.Height));
+ }
}
}
diff --git a/ZoFo/GameCore/Graphics/GraphicsComponent.cs b/ZoFo/GameCore/Graphics/GraphicsComponent.cs
index b4580ab..e46886d 100644
--- a/ZoFo/GameCore/Graphics/GraphicsComponent.cs
+++ b/ZoFo/GameCore/Graphics/GraphicsComponent.cs
@@ -56,4 +56,13 @@ public abstract class GraphicsComponent
*/
}
public static Point CameraPosition = new Point(0, 0);
+
+ /////////
+ ///////// Нужно для поиска порядка для отрисовки и нормализации
+ /////////
+ //////public static Rectangle MapBoundries = new Rectangle(0,0,1000,1000);
+ //////public static void SetMapBoundries(Rectangle rectangle)
+ //////{
+ ////// MapBoundries = rectangle;
+ //////}
}
\ No newline at end of file
diff --git a/ZoFo/GameCore/Server.cs b/ZoFo/GameCore/Server.cs
index 853eadf..0d49bcc 100644
--- a/ZoFo/GameCore/Server.cs
+++ b/ZoFo/GameCore/Server.cs
@@ -97,7 +97,7 @@ namespace ZoFo.GameCore
}
break;
}
- }//Поспать
+ }//Поспать - хорошая идея!
///
@@ -263,7 +263,7 @@ namespace ZoFo.GameCore
/// Удаляет игровой объект
///
///
- public void DeleteObject(Entity entity)
+ public void DeleteEntity(Entity entity)
{
if (gameObjects.Contains(entity))
gameObjects.Remove(entity);
@@ -276,6 +276,28 @@ namespace ZoFo.GameCore
);
collisionManager.Deregister(entity.collisionComponent);
}
+
+
+ ///
+ /// Be careful
+ /// GameObjects are not synced, if you need deletion on Client that gameObject should be an entity!
+ ///
+ ///
+ public void DeleteGameObject(GameObject gameObject)
+ {
+ if (gameObjects.Contains(gameObject))
+ gameObjects.Remove(gameObject);
+ if (entities.Contains(gameObject))
+ {
+
+ entities.Remove(gameObject as Entity);
+ AddData(new UpdateGameObjectDeleted()
+ { GameObjectType = (gameObject as Entity).GetType().Name, IdEntity = (gameObject as Entity).Id }
+ );
+ }
+ if (players.Contains(gameObject))
+ players.Remove(gameObject as Player);
+ }
}
#endregion