debug better stats added
Classes moved around methods renamed Minor overall
This commit is contained in:
parent
29acff1b6d
commit
0aa9adc2a1
18 changed files with 396 additions and 163 deletions
|
@ -130,6 +130,7 @@ namespace ZoFo.GameCore
|
||||||
/// <param name="gameTime"></param>
|
/// <param name="gameTime"></param>
|
||||||
internal void Update(GameTime gameTime)
|
internal void Update(GameTime gameTime)
|
||||||
{
|
{
|
||||||
|
DebugHUD.AddGOData(particles.Count, "particles");
|
||||||
UpdateShaking();
|
UpdateShaking();
|
||||||
for (int i = 0; i < gameObjects.Count; i++)
|
for (int i = 0; i < gameObjects.Count; i++)
|
||||||
{
|
{
|
||||||
|
@ -153,24 +154,30 @@ namespace ZoFo.GameCore
|
||||||
{
|
{
|
||||||
networkManager.SendData();
|
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++)
|
for (int i = 0; i < mapObjects.Count; i++)
|
||||||
{
|
{
|
||||||
mapObjects[i].Draw(spriteBatch);
|
mapObjects[i].Draw(_spriteBatch);
|
||||||
}
|
}
|
||||||
for (int i = 0; i < stopObjects.Count; i++)
|
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++)
|
for (int i = 0; i < gameObjects.Count; i++)
|
||||||
{
|
{
|
||||||
gameObjects[i].Draw(spriteBatch);
|
gameObjects[i].Draw(_spriteBatch);
|
||||||
}
|
}
|
||||||
for (int i = 0; i < particles.Count; i++)
|
for (int i = 0; i < particles.Count; i++)
|
||||||
{
|
{
|
||||||
particles[i].Draw(spriteBatch);
|
particles[i].Draw(_spriteBatch);
|
||||||
}
|
}
|
||||||
|
_spriteBatch.End();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -5,6 +5,10 @@ using Microsoft.Xna.Framework.Graphics;
|
||||||
using MonogameLibrary.UI.Elements;
|
using MonogameLibrary.UI.Elements;
|
||||||
using static System.String;
|
using static System.String;
|
||||||
using ZoFo.GameCore.GameManagers;
|
using ZoFo.GameCore.GameManagers;
|
||||||
|
using static System.Net.Mime.MediaTypeNames;
|
||||||
|
using System;
|
||||||
|
using System.Diagnostics;
|
||||||
|
using Microsoft.Xna.Framework.Input;
|
||||||
|
|
||||||
namespace ZoFo.GameCore.GUI;
|
namespace ZoFo.GameCore.GUI;
|
||||||
|
|
||||||
|
@ -14,10 +18,12 @@ public class DebugHUD
|
||||||
private Dictionary<string, string> _text = new();
|
private Dictionary<string, string> _text = new();
|
||||||
private List<string> _log = new();
|
private List<string> _log = new();
|
||||||
public static DebugHUD Instance { get; private set; }
|
public static DebugHUD Instance { get; private set; }
|
||||||
|
public Texture2D noTexture;
|
||||||
|
public static bool IsActivated = true;
|
||||||
public void Initialize()
|
public void Initialize()
|
||||||
{
|
{
|
||||||
Instance = this;
|
Instance = this;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void LoadContent()
|
public void LoadContent()
|
||||||
|
@ -25,12 +31,18 @@ public class DebugHUD
|
||||||
_spriteFont = AppManager.Instance.Content.Load<SpriteFont>("Fonts/Font2");
|
_spriteFont = AppManager.Instance.Content.Load<SpriteFont>("Fonts/Font2");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool prev_KeyState;//SHould move this logic and deneralize to main input manager
|
||||||
public void Update(GameTime gameTime)
|
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)
|
public void Draw(SpriteBatch spriteBatch)
|
||||||
{
|
{
|
||||||
|
if (!IsActivated) return;
|
||||||
//return;//TODO delete
|
//return;//TODO delete
|
||||||
var keysString = Join("\n", _text.Select(el => el.Key + ": " + el.Value).ToList());
|
var keysString = Join("\n", _text.Select(el => el.Key + ": " + el.Value).ToList());
|
||||||
spriteBatch.Begin();
|
spriteBatch.Begin();
|
||||||
|
@ -56,7 +68,11 @@ public class DebugHUD
|
||||||
SpriteEffects.None,
|
SpriteEffects.None,
|
||||||
0
|
0
|
||||||
);
|
);
|
||||||
|
|
||||||
|
DrawGameObjecctsCounter(spriteBatch);
|
||||||
|
|
||||||
spriteBatch.End();
|
spriteBatch.End();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Set(string key, string value)
|
public void Set(string key, string value)
|
||||||
|
@ -76,12 +92,120 @@ public class DebugHUD
|
||||||
_log.RemoveAt(0);
|
_log.RemoveAt(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int totalSavedStatistics = 100;
|
||||||
public static void DebugLog(string value)
|
public static void DebugLog(string value)
|
||||||
{
|
{
|
||||||
Instance._log.Add(value);
|
Instance._log.Add(value);
|
||||||
if (Instance._log.Count > 30)
|
if (Instance._log.Count > totalSavedStatistics)
|
||||||
{
|
{
|
||||||
Instance._log.RemoveAt(0);
|
Instance._log.RemoveAt(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static Dictionary<string, List<int>> 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<int>());
|
||||||
|
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<int>());
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -99,8 +99,14 @@ namespace ZoFo.GameCore.GameManagers
|
||||||
|
|
||||||
animationBuilder = new AnimationBuilder();
|
animationBuilder = new AnimationBuilder();
|
||||||
animationBuilder.LoadAnimations();
|
animationBuilder.LoadAnimations();
|
||||||
|
|
||||||
GameObject.debugTexture = new Texture2D(GraphicsDevice, 1, 1);
|
GameObject.debugTexture = new Texture2D(GraphicsDevice, 1, 1);
|
||||||
GameObject.debugTexture.SetData(new Color[] { Color.White });
|
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)
|
protected override void Update(GameTime gameTime)
|
||||||
|
@ -110,9 +116,9 @@ namespace ZoFo.GameCore.GameManagers
|
||||||
|
|
||||||
|
|
||||||
// debugHud.Set("key", "value");
|
// debugHud.Set("key", "value");
|
||||||
|
|
||||||
CheckGUI();
|
CheckGUI();
|
||||||
InputManager.Update();
|
InputManager.Update();
|
||||||
|
debugHud.Update(gameTime);
|
||||||
currentGUI.Update(gameTime);
|
currentGUI.Update(gameTime);
|
||||||
switch (gamestate)
|
switch (gamestate)
|
||||||
{
|
{
|
||||||
|
@ -137,7 +143,6 @@ namespace ZoFo.GameCore.GameManagers
|
||||||
|
|
||||||
|
|
||||||
// Pointwrap
|
// Pointwrap
|
||||||
_spriteBatch.Begin(samplerState: SamplerState.PointWrap);
|
|
||||||
switch (gamestate)
|
switch (gamestate)
|
||||||
{
|
{
|
||||||
case GameState.ClientPlaying:
|
case GameState.ClientPlaying:
|
||||||
|
@ -151,7 +156,6 @@ namespace ZoFo.GameCore.GameManagers
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
_spriteBatch.End();
|
|
||||||
currentGUI.Draw(_spriteBatch);
|
currentGUI.Draw(_spriteBatch);
|
||||||
debugHud.Draw(_spriteBatch);
|
debugHud.Draw(_spriteBatch);
|
||||||
|
|
||||||
|
|
|
@ -14,7 +14,9 @@ using ZoFo.GameCore.GameObjects.Entities.LivingEntities;
|
||||||
using ZoFo.GameCore.GameManagers.NetworkManager.Updates.ServerToClient;
|
using ZoFo.GameCore.GameManagers.NetworkManager.Updates.ServerToClient;
|
||||||
using ZoFo.GameCore.Graphics;
|
using ZoFo.GameCore.Graphics;
|
||||||
using ZoFo.GameCore.GameManagers.NetworkManager.SerializableDTO;
|
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
|
namespace ZoFo.GameCore.GameManagers.CollisionManager
|
||||||
{
|
{
|
||||||
|
@ -56,6 +58,13 @@ namespace ZoFo.GameCore.GameManagers.CollisionManager
|
||||||
{
|
{
|
||||||
//ADD CHECKSPEED TODO
|
//ADD CHECKSPEED TODO
|
||||||
var entity = componentOfEntity.gameObject as LivingEntity;
|
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++)
|
//for (int i = 0; i < ObjectsWithCollisions.Count; i++)
|
||||||
//{
|
//{
|
||||||
var currentRect = entity.collisionComponent.stopRectangle;//задаём РЕК
|
var currentRect = entity.collisionComponent.stopRectangle;//задаём РЕК
|
||||||
|
|
|
@ -39,7 +39,7 @@ namespace ZoFo.GameCore.GameManagers.NetworkManager
|
||||||
public delegate void OnDataSend(string data);
|
public delegate void OnDataSend(string data);
|
||||||
public event OnDataSend GetDataSend; // event
|
public event OnDataSend GetDataSend; // event
|
||||||
Thread serverThread;
|
Thread serverThread;
|
||||||
int datapackSize = 150;
|
int datapackSize = 150+50;
|
||||||
public ServerNetworkManager() { Init(); }
|
public ServerNetworkManager() { Init(); }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -132,9 +132,12 @@ namespace ZoFo.GameCore.GameManagers.NetworkManager
|
||||||
importantUpdates.RemoveAt(0);
|
importantUpdates.RemoveAt(0);
|
||||||
currentDatagrammId++;
|
currentDatagrammId++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
DebugHUD.AddGOData(sendedData.Count, "server gameobjects");
|
||||||
|
|
||||||
if (sendedData.Count != 0)
|
if (sendedData.Count != 0)
|
||||||
{
|
{
|
||||||
|
|
||||||
for (int i = 0; i < clientsEP.Count; i++)
|
for (int i = 0; i < clientsEP.Count; i++)
|
||||||
{
|
{
|
||||||
foreach (Datagramm Dgramm in sendedData.Where(x => x.PlayerId == i+1))
|
foreach (Datagramm Dgramm in sendedData.Where(x => x.PlayerId == i+1))
|
||||||
|
|
|
@ -14,6 +14,8 @@ namespace ZoFo.GameCore.GameManagers
|
||||||
{
|
{
|
||||||
public class SettingsManager //нужно что-то менять с разрешением
|
public class SettingsManager //нужно что-то менять с разрешением
|
||||||
{
|
{
|
||||||
|
public SettingsManager() { Instance = this; }
|
||||||
|
public static SettingsManager Instance { get; private set; }
|
||||||
private SettingsContainer settingsContainer = new SettingsContainer();
|
private SettingsContainer settingsContainer = new SettingsContainer();
|
||||||
public bool IsFullScreen { get => settingsContainer.IsFullScreen; }
|
public bool IsFullScreen { get => settingsContainer.IsFullScreen; }
|
||||||
public float MainVolume { get => settingsContainer.MainVolume; }
|
public float MainVolume { get => settingsContainer.MainVolume; }
|
||||||
|
|
|
@ -61,7 +61,7 @@ namespace ZoFo.GameCore.GameObjects
|
||||||
{
|
{
|
||||||
if (AppManager.Instance.gamestate == GameState.HostPlaying)
|
if (AppManager.Instance.gamestate == GameState.HostPlaying)
|
||||||
{
|
{
|
||||||
AppManager.Instance.server.DeleteObject(this);
|
AppManager.Instance.server.DeleteEntity(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,7 +32,7 @@ public class Collectable : Interactable
|
||||||
DebugHUD.DebugLog("collected");
|
DebugHUD.DebugLog("collected");
|
||||||
string lootname = this.GetType().ToString().ToLower().Split('.').Last();
|
string lootname = this.GetType().ToString().ToLower().Split('.').Last();
|
||||||
(sender as Player).lootData.AddLoot(lootname, 1, (sender as Player).Id);
|
(sender as Player).lootData.AddLoot(lootname, 1, (sender as Player).Id);
|
||||||
AppManager.Instance.server.DeleteObject(this);
|
AppManager.Instance.server.DeleteEntity(this);
|
||||||
base.OnInteraction(sender);
|
base.OnInteraction(sender);
|
||||||
}
|
}
|
||||||
public override void Draw(SpriteBatch spriteBatch)
|
public override void Draw(SpriteBatch spriteBatch)
|
||||||
|
|
|
@ -6,6 +6,7 @@ using Microsoft.Xna.Framework;
|
||||||
using Microsoft.Xna.Framework.Content;
|
using Microsoft.Xna.Framework.Content;
|
||||||
using ZoFo.GameCore.GameManagers;
|
using ZoFo.GameCore.GameManagers;
|
||||||
using ZoFo.GameCore.Graphics;
|
using ZoFo.GameCore.Graphics;
|
||||||
|
using ZoFo.GameCore.GUI;
|
||||||
|
|
||||||
namespace ZoFo.GameCore.GameObjects;
|
namespace ZoFo.GameCore.GameObjects;
|
||||||
public class Enemy : LivingEntity
|
public class Enemy : LivingEntity
|
||||||
|
@ -25,6 +26,8 @@ public class Enemy : LivingEntity
|
||||||
public virtual void TakeDamage(float damage)
|
public virtual void TakeDamage(float damage)
|
||||||
{
|
{
|
||||||
if (isDying) return;
|
if (isDying) return;
|
||||||
|
DebugHUD.AddAdditionalDataToGraph((int)damage, "damage");
|
||||||
|
|
||||||
health -= damage;
|
health -= damage;
|
||||||
if (health < 0)
|
if (health < 0)
|
||||||
Die();
|
Die();
|
||||||
|
|
|
@ -39,6 +39,9 @@ namespace ZoFo.GameCore.GameObjects
|
||||||
{
|
{
|
||||||
if (str == "zombie_death")
|
if (str == "zombie_death")
|
||||||
DeathEnd();
|
DeathEnd();
|
||||||
|
if (str != "zombie_attack"){
|
||||||
|
|
||||||
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -252,6 +252,8 @@ public class Player : LivingEntity
|
||||||
reloading = 5;
|
reloading = 5;
|
||||||
IsTryingToShoot = true;
|
IsTryingToShoot = true;
|
||||||
|
|
||||||
|
DebugHUD.AddGOData(0, "damage");
|
||||||
|
|
||||||
StartAnimation("player_shoot_1");
|
StartAnimation("player_shoot_1");
|
||||||
|
|
||||||
List<Entity> entities = AppManager.Instance.server.collisionManager.GetEntities(GetDamageArea(InputWeaponRotation), this).ToList();
|
List<Entity> entities = AppManager.Instance.server.collisionManager.GetEntities(GetDamageArea(InputWeaponRotation), this).ToList();
|
||||||
|
|
35
ZoFo/GameCore/GameObjects/Entities/Particles/Explosion.cs
Normal file
35
ZoFo/GameCore/GameObjects/Entities/Particles/Explosion.cs
Normal file
|
@ -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
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 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
|
||||||
|
/// </summary>
|
||||||
|
public class Explosion : Particle
|
||||||
|
{
|
||||||
|
public override GraphicsComponent graphicsComponent { get; } = new AnimatedGraphicsComponent(new List<string> { "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);
|
||||||
|
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
132
ZoFo/GameCore/GameObjects/Entities/Particles/Granade.cs
Normal file
132
ZoFo/GameCore/GameObjects/Entities/Particles/Granade.cs
Normal file
|
@ -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
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// TODO: change from particle to throwable, it is not a particle anymore
|
||||||
|
/// </summary>
|
||||||
|
public class Granade : GameObject
|
||||||
|
{
|
||||||
|
public override GraphicsComponent graphicsComponent { get; } = new AnimatedGraphicsComponent(new List<string> { "explosion_1" }, "explosion_1");
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// TODO updates with directed effect
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="positionTo"></param>
|
||||||
|
/// <param name="positionFrom"></param>
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,12 +1,7 @@
|
||||||
using Microsoft.Xna.Framework;
|
using Microsoft.Xna.Framework;
|
||||||
using Microsoft.Xna.Framework.Graphics;
|
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using ZoFo.GameCore.GameManagers;
|
|
||||||
using ZoFo.GameCore.GameManagers.CollisionManager;
|
|
||||||
using ZoFo.GameCore.Graphics;
|
using ZoFo.GameCore.Graphics;
|
||||||
|
|
||||||
namespace ZoFo.GameCore.GameObjects
|
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<string> { "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);
|
|
||||||
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
/// <summary>
|
|
||||||
/// TODO: change from particle to throwable, it is not a particle anymore
|
|
||||||
/// </summary>
|
|
||||||
public class Granade : GameObject
|
|
||||||
{
|
|
||||||
public override GraphicsComponent graphicsComponent { get; } = new AnimatedGraphicsComponent(new List<string> { "explosion_1" }, "explosion_1");
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// TODO updates with directed effect
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="positionTo"></param>
|
|
||||||
/// <param name="positionFrom"></param>
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -49,6 +49,12 @@ public abstract class GameObject
|
||||||
AppManager.Instance.server.RegisterGameObject(gameObject);
|
AppManager.Instance.server.RegisterGameObject(gameObject);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
public void Delete_OnServer()
|
||||||
|
{
|
||||||
|
AppManager.Instance.server.DeleteGameObject(this);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
using Microsoft.Xna.Framework.Graphics;
|
using Microsoft.Xna.Framework.Graphics;
|
||||||
using System;
|
using System;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
|
using System.Linq;
|
||||||
using System.Security.Cryptography.X509Certificates;
|
using System.Security.Cryptography.X509Certificates;
|
||||||
using ZoFo.GameCore.GameManagers.CollisionManager;
|
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)
|
public StopObject(Vector2 position, Vector2 size, Rectangle sourceRectangle, string textureName, Rectangle[] collisions) : base(position, size, sourceRectangle, textureName)
|
||||||
{
|
{
|
||||||
|
var cols = collisions.ToList();
|
||||||
collisionComponents = new CollisionComponent[collisions.Length];
|
for (int i = 0; i < cols.Count; i++)
|
||||||
for (int i = 0; i < collisionComponents.Length; 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)
|
public override void Draw(SpriteBatch spriteBatch)
|
||||||
{
|
{
|
||||||
base.Draw(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));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -56,4 +56,13 @@ public abstract class GraphicsComponent
|
||||||
*/
|
*/
|
||||||
}
|
}
|
||||||
public static Point CameraPosition = new Point(0, 0);
|
public static Point CameraPosition = new Point(0, 0);
|
||||||
|
|
||||||
|
///////// <summary>
|
||||||
|
///////// Нужно для поиска порядка для отрисовки и нормализации
|
||||||
|
///////// </summary>
|
||||||
|
//////public static Rectangle MapBoundries = new Rectangle(0,0,1000,1000);
|
||||||
|
//////public static void SetMapBoundries(Rectangle rectangle)
|
||||||
|
//////{
|
||||||
|
////// MapBoundries = rectangle;
|
||||||
|
//////}
|
||||||
}
|
}
|
|
@ -97,7 +97,7 @@ namespace ZoFo.GameCore
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}//Поспать
|
}//Поспать - хорошая идея!
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -263,7 +263,7 @@ namespace ZoFo.GameCore
|
||||||
/// Удаляет игровой объект
|
/// Удаляет игровой объект
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="gameObject"></param>
|
/// <param name="gameObject"></param>
|
||||||
public void DeleteObject(Entity entity)
|
public void DeleteEntity(Entity entity)
|
||||||
{
|
{
|
||||||
if (gameObjects.Contains(entity))
|
if (gameObjects.Contains(entity))
|
||||||
gameObjects.Remove(entity);
|
gameObjects.Remove(entity);
|
||||||
|
@ -276,6 +276,28 @@ namespace ZoFo.GameCore
|
||||||
);
|
);
|
||||||
collisionManager.Deregister(entity.collisionComponent);
|
collisionManager.Deregister(entity.collisionComponent);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Be careful
|
||||||
|
/// GameObjects are not synced, if you need deletion on Client that gameObject should be an entity!
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="gameObject"></param>
|
||||||
|
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
|
#endregion
|
||||||
|
|
Loading…
Add table
Reference in a new issue