Merge branch 'DevelopmentX' into MapDevelopment
This commit is contained in:
commit
15f92ad95b
49 changed files with 1579 additions and 243 deletions
|
@ -199,6 +199,21 @@
|
|||
#begin Textures/Animations/testAnimationExample.animation
|
||||
/copy:Textures/Animations/testAnimationExample.animation
|
||||
|
||||
#begin Textures/Animations/zombie_attack.animation
|
||||
/copy:Textures/Animations/zombie_attack.animation
|
||||
|
||||
#begin Textures/Animations/zombie_damaged.animation
|
||||
/copy:Textures/Animations/zombie_damaged.animation
|
||||
|
||||
#begin Textures/Animations/zombie_death.animation
|
||||
/copy:Textures/Animations/zombie_death.animation
|
||||
|
||||
#begin Textures/Animations/zombie_idle.animation
|
||||
/copy:Textures/Animations/zombie_idle.animation
|
||||
|
||||
#begin Textures/Animations/zombie_walk.animation
|
||||
/copy:Textures/Animations/zombie_walk.animation
|
||||
|
||||
#begin Textures/AnimationTextures/Character/hr-level1_idle.png
|
||||
/importer:TextureImporter
|
||||
/processor:TextureProcessor
|
||||
|
@ -283,6 +298,30 @@
|
|||
/processorParam:TextureFormat=Color
|
||||
/build:Textures/AnimationTextures/unicorn.png
|
||||
|
||||
#begin Textures/AnimationTextures/Zombie/zombie_spritesheet_v1.png
|
||||
/importer:TextureImporter
|
||||
/processor:TextureProcessor
|
||||
/processorParam:ColorKeyColor=255,0,255,255
|
||||
/processorParam:ColorKeyEnabled=True
|
||||
/processorParam:GenerateMipmaps=False
|
||||
/processorParam:PremultiplyAlpha=True
|
||||
/processorParam:ResizeToPowerOfTwo=False
|
||||
/processorParam:MakeSquare=False
|
||||
/processorParam:TextureFormat=Color
|
||||
/build:Textures/AnimationTextures/Zombie/zombie_spritesheet_v1.png
|
||||
|
||||
#begin Textures/AnimationTextures/Zombie/zombie_spritesheet_v2.png
|
||||
/importer:TextureImporter
|
||||
/processor:TextureProcessor
|
||||
/processorParam:ColorKeyColor=255,0,255,255
|
||||
/processorParam:ColorKeyEnabled=True
|
||||
/processorParam:GenerateMipmaps=False
|
||||
/processorParam:PremultiplyAlpha=True
|
||||
/processorParam:ResizeToPowerOfTwo=False
|
||||
/processorParam:MakeSquare=False
|
||||
/processorParam:TextureFormat=Color
|
||||
/build:Textures/AnimationTextures/Zombie/zombie_spritesheet_v2.png
|
||||
|
||||
#begin Textures/GUI/background/base.png
|
||||
/importer:TextureImporter
|
||||
/processor:TextureProcessor
|
||||
|
|
|
@ -5,9 +5,9 @@
|
|||
},
|
||||
"activeFile": "TileMaps/main.tmj",
|
||||
"expandedProjectPaths": [
|
||||
".",
|
||||
"TileSets",
|
||||
"TileMaps",
|
||||
"."
|
||||
"TileMaps"
|
||||
],
|
||||
"fileStates": {
|
||||
"": {
|
||||
|
@ -17,11 +17,11 @@
|
|||
"scaleInDock": 1
|
||||
},
|
||||
"TileMaps/main.tmj": {
|
||||
"scale": 0.5,
|
||||
"scale": 0.33,
|
||||
"selectedLayer": 1,
|
||||
"viewCenter": {
|
||||
"x": 895,
|
||||
"y": 270
|
||||
"x": 1010.6060606060606,
|
||||
"y": 553.0303030303031
|
||||
}
|
||||
},
|
||||
"TileMaps/main.tmj#IconSet": {
|
||||
|
@ -42,24 +42,27 @@
|
|||
},
|
||||
"TileSets/TilesetNature.tsj": {
|
||||
"dynamicWrapping": false
|
||||
"scaleInDock": 1
|
||||
},
|
||||
"TileSets/WallSet.tsj": {
|
||||
"scaleInDock": 1,
|
||||
"scaleInEditor": 1
|
||||
},
|
||||
"TileSets/tileset 1 collision.tsj": {
|
||||
"scaleInDock": 1
|
||||
}
|
||||
},
|
||||
"last.imagePath": "D:/C#/Я смотрел ваши ХАКАТОНЫ/ZoFo/ZoFo/Content/Textures/icons",
|
||||
"last.objectTemplatePath": "D:/C#/Я смотрел ваши ХАКАТОНЫ/ZoFo/ZoFo/Content/MapData/Templates",
|
||||
"openFiles": [
|
||||
"TileSets/TileSet 1.tsj",
|
||||
"TileMaps/main.tmj",
|
||||
"TileSets/CollisionTileSet.tsj"
|
||||
"TileMaps/main.tmj"
|
||||
],
|
||||
"project": "MapSession.tiled-project",
|
||||
"recentFiles": [
|
||||
"TileSets/TileSet 1.tsj",
|
||||
"TileMaps/main.tmj",
|
||||
"TileSets/CollisionTileSet.tsj",
|
||||
"TileSets/TileSet 1.tsj",
|
||||
"TileSets/WallSet.tsj"
|
||||
],
|
||||
"stampsFolder": "D:/C#/Я смотрел ваши ХАКАТОНЫ/ZoFo/ZoFo/Content/MapData/TileStamps",
|
||||
|
|
File diff suppressed because it is too large
Load diff
Binary file not shown.
After Width: | Height: | Size: 5 KiB |
Binary file not shown.
After Width: | Height: | Size: 16 KiB |
1
ZoFo/Content/Textures/Animations/zombie_attack.animation
Normal file
1
ZoFo/Content/Textures/Animations/zombie_attack.animation
Normal file
|
@ -0,0 +1 @@
|
|||
{"id":"zombie_attack","textureName":"Textures/AnimationTextures/Zombie/zombie_spritesheet_v1","startSpriteRectangle":{"X":0,"Y":64,"Width":32,"Height":32},"frameSecond":[{"Item1":0,"Item2":5}],"textureFrameInterval":0,"framesCount":3,"isCycle":true,"offset":"0, 0"}
|
|
@ -0,0 +1 @@
|
|||
{"id":"zombie_damaged","textureName":"Textures/AnimationTextures/Zombie/zombie_spritesheet_v1","startSpriteRectangle":{"X":0,"Y":128,"Width":32,"Height":32},"frameSecond":[{"Item1":0,"Item2":5}],"textureFrameInterval":0,"framesCount":1,"isCycle":true,"offset":"0, 0"}
|
1
ZoFo/Content/Textures/Animations/zombie_death.animation
Normal file
1
ZoFo/Content/Textures/Animations/zombie_death.animation
Normal file
|
@ -0,0 +1 @@
|
|||
{"id":"zombie_death","textureName":"Textures/AnimationTextures/Zombie/zombie_spritesheet_v1","startSpriteRectangle":{"X":0,"Y":96,"Width":32,"Height":32},"frameSecond":[{"Item1":0,"Item2":5}],"textureFrameInterval":0,"framesCount":9,"isCycle":true,"offset":"0, 0"}
|
1
ZoFo/Content/Textures/Animations/zombie_idle.animation
Normal file
1
ZoFo/Content/Textures/Animations/zombie_idle.animation
Normal file
|
@ -0,0 +1 @@
|
|||
{"id":"zombie_idle","textureName":"Textures/AnimationTextures/Zombie/zombie_spritesheet_v1","startSpriteRectangle":{"X":0,"Y":0,"Width":32,"Height":32},"frameSecond":[{"Item1":0,"Item2":60}],"textureFrameInterval":0,"framesCount":2,"isCycle":true,"offset":"0, 0"}
|
1
ZoFo/Content/Textures/Animations/zombie_walk.animation
Normal file
1
ZoFo/Content/Textures/Animations/zombie_walk.animation
Normal file
|
@ -0,0 +1 @@
|
|||
{"id":"zombie_walk","textureName":"Textures/AnimationTextures/Zombie/zombie_spritesheet_v1","startSpriteRectangle":{"X":0,"Y":32,"Width":32,"Height":32},"frameSecond":[{"Item1":0,"Item2":5}],"textureFrameInterval":0,"framesCount":8,"isCycle":true,"offset":"0, 0"}
|
|
@ -24,6 +24,9 @@ using ZoFo.GameCore.GUI;
|
|||
using ZoFo.GameCore.GameObjects.Entities.Interactables.Collectables;
|
||||
using ZoFo.GameCore.GameObjects.MapObjects.StopObjects;
|
||||
using ZoFo.GameCore.GameObjects.Entities.LivingEntities.Enemies;
|
||||
using ZoFo.GameCore.Graphics;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using Newtonsoft.Json;
|
||||
namespace ZoFo.GameCore
|
||||
{
|
||||
public class Client
|
||||
|
@ -49,18 +52,35 @@ namespace ZoFo.GameCore
|
|||
InputMovementDirection = AppManager.Instance.InputManager.InputMovementDirection,
|
||||
InputAttackDirection = AppManager.Instance.InputManager.InputAttackDirection
|
||||
});
|
||||
|
||||
};
|
||||
AppManager.Instance.InputManager.OnInteract += () =>
|
||||
{
|
||||
networkManager.AddData(new UpdateInputInteraction() { });
|
||||
};
|
||||
AppManager.Instance.InputManager.ShootEvent += () =>
|
||||
{
|
||||
networkManager.AddData(new UpdateInputShoot() { });
|
||||
};
|
||||
}
|
||||
|
||||
public void OnDataSend(string data)
|
||||
{
|
||||
List<UpdateData> updateDatas = JsonSerializer.Deserialize<List<UpdateData>>(data);
|
||||
//List<UpdateTileCreated> updateDatas = JsonSerializer.Deserialize<List<UpdateTileCreated>>(data);
|
||||
JArray jToken = JsonConvert.DeserializeObject(data) as JArray;
|
||||
|
||||
//string[] brands = jToken.SelectToken("")?.ToObject<string[]>();
|
||||
foreach (JToken update in jToken.Children())
|
||||
{
|
||||
string a = update.ToString();
|
||||
UpdateTileCreated u = System.Text.Json.JsonSerializer.Deserialize<UpdateTileCreated>(a);
|
||||
}
|
||||
// тут будет switch
|
||||
AppManager.Instance.debugHud.Log(data);
|
||||
foreach (var item in updateDatas)
|
||||
{
|
||||
GotData(item);
|
||||
}
|
||||
//foreach (var item in updateDatas)
|
||||
//{
|
||||
// GotData(item);
|
||||
//}
|
||||
|
||||
}
|
||||
public void GameEndedUnexpectedly() { }
|
||||
|
@ -77,6 +97,7 @@ namespace ZoFo.GameCore
|
|||
List<GameObject> gameObjects = new List<GameObject>();
|
||||
List<Player> players = new List<Player>();
|
||||
List<StopObject> stopObjects = new List<StopObject>();
|
||||
|
||||
/// <summary>
|
||||
/// Клиент должен обнговлять игру анимаций
|
||||
/// </summary>
|
||||
|
@ -88,6 +109,8 @@ namespace ZoFo.GameCore
|
|||
AppManager.Instance.debugHud.Set("GameTime", gameTime.TotalGameTime.ToString());
|
||||
gameObjects[i].UpdateAnimations();
|
||||
}
|
||||
|
||||
networkManager.SendData();//set to ticks
|
||||
}
|
||||
internal void Draw(SpriteBatch spriteBatch)
|
||||
{
|
||||
|
@ -112,22 +135,21 @@ namespace ZoFo.GameCore
|
|||
mapObjects.Add(
|
||||
new MapObject(
|
||||
(update as UpdateTileCreated).Position,
|
||||
(update as UpdateTileCreated).Size.ToVector2(),
|
||||
(update as UpdateTileCreated).sourceRectangle,
|
||||
(update as UpdateTileCreated).Size.GetPoint().ToVector2(),
|
||||
(update as UpdateTileCreated).sourceRectangle.GetRectangle(),
|
||||
(update as UpdateTileCreated).tileSetName
|
||||
));
|
||||
}
|
||||
else if (update is UpdateStopObjectCreated)
|
||||
{
|
||||
stopObjects.Add(
|
||||
new StopObject(
|
||||
(update as UpdateStopObjectCreated).Position,
|
||||
(update as UpdateStopObjectCreated).Size.ToVector2(),
|
||||
(update as UpdateStopObjectCreated).sourceRectangle,
|
||||
(update as UpdateStopObjectCreated).tileSetName,
|
||||
(update as UpdateStopObjectCreated).collisions
|
||||
));
|
||||
}
|
||||
//else if (update is UpdateStopObjectCreated)
|
||||
//{
|
||||
// stopObjects.Add(
|
||||
// new StopObject(
|
||||
// (update as UpdateStopObjectCreated).Position,
|
||||
// (update as UpdateStopObjectCreated).Size.ToVector2(),
|
||||
// (update as UpdateStopObjectCreated).sourceRectangle,
|
||||
// (update as UpdateStopObjectCreated).tileSetName
|
||||
// ));
|
||||
//}
|
||||
else if (update is UpdateGameObjectCreated)
|
||||
{
|
||||
GameObject created_gameObject;
|
||||
|
@ -158,7 +180,21 @@ namespace ZoFo.GameCore
|
|||
var ent = FindEntityById(update.IdEntity);
|
||||
|
||||
ent.position = (update as UpdatePosition).NewPosition;
|
||||
DebugHUD.Instance.Log("newPosition " + ent.position);
|
||||
}
|
||||
else if (update is UpdateAnimation)
|
||||
{
|
||||
var ent = FindEntityById(update.IdEntity);
|
||||
if (ent != null)
|
||||
((ent as Entity).graphicsComponent as AnimatedGraphicsComponent).StartAnimation((update as UpdateAnimation).animationId);
|
||||
//DebugHUD.Instance.Log("new Animation " + ent.position);
|
||||
}
|
||||
else if (update is UpdateGameObjectDeleted)
|
||||
{
|
||||
var ent = FindEntityById(update.IdEntity);
|
||||
|
||||
if (ent != null)
|
||||
DeleteObject(ent);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -177,6 +213,16 @@ namespace ZoFo.GameCore
|
|||
}
|
||||
return null;
|
||||
}
|
||||
public void DeleteObject(Entity entity)
|
||||
{
|
||||
|
||||
if (gameObjects.Contains(entity))
|
||||
gameObjects.Remove(entity);
|
||||
//if (entities.Contains(entity))
|
||||
// entities.Remove(entity);
|
||||
if (players.Contains(entity))
|
||||
players.Remove(entity as Player);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -62,6 +62,10 @@ public class DebugHUD
|
|||
{
|
||||
_text[key] = value;
|
||||
}
|
||||
public static void DebugSet(string key, string value)
|
||||
{
|
||||
Instance._text[key] = value;
|
||||
}
|
||||
|
||||
public void Log(string value)
|
||||
{
|
||||
|
@ -71,4 +75,12 @@ public class DebugHUD
|
|||
_log.RemoveAt(0);
|
||||
}
|
||||
}
|
||||
public static void DebugLog(string value)
|
||||
{
|
||||
Instance._log.Add(value);
|
||||
if (Instance._log.Count > 30)
|
||||
{
|
||||
Instance._log.RemoveAt(0);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -43,12 +43,11 @@ namespace ZoFo.GameCore.GameManagers.CollisionManager
|
|||
public GameObject gameObject { get; set; }
|
||||
|
||||
|
||||
bool doesStop;
|
||||
bool hasCollision;
|
||||
public bool hasCollision;
|
||||
public Rectangle stopRectangle;
|
||||
|
||||
// triggers for rectangle
|
||||
bool isTrigger;
|
||||
public bool isTrigger;
|
||||
public Rectangle triggerRectangle;
|
||||
|
||||
//delegate
|
||||
|
@ -58,13 +57,21 @@ namespace ZoFo.GameCore.GameManagers.CollisionManager
|
|||
|
||||
|
||||
//events DoorInteraction
|
||||
public event EventHandler<CollisionComponent> OnTriggerEnter;
|
||||
public event EventHandler<CollisionComponent> OnTriggerZone;
|
||||
public event EventHandler<CollisionComponent> OnTriggerExit;
|
||||
public delegate void CollisionAction(Player player);
|
||||
public event CollisionAction? OnTriggerEnter;
|
||||
public event CollisionAction? OnTriggerZone;
|
||||
public event CollisionAction? OnTriggerExit;
|
||||
|
||||
public event EventHandler<CollisionComponent> OnCollision;
|
||||
public delegate void CoollisionEvent(GameObject gameObject);
|
||||
public event CoollisionEvent? OnCollision;
|
||||
|
||||
|
||||
|
||||
public void PlayerInZone(Player player) => OnTriggerZone?.Invoke(player);
|
||||
public void PlayerEnter(Player player) => OnTriggerEnter?.Invoke(player);
|
||||
public void PlayerExit(Player player) => OnTriggerExit?.Invoke(player);
|
||||
public void OnCollisionWithObject(GameObject gameObject) => OnCollision?.Invoke(gameObject);
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,6 +12,7 @@ using ZoFo.GameCore.GameObjects.Entities;
|
|||
using ZoFo.GameCore.GameObjects.Entities.LivingEntities;
|
||||
using ZoFo.GameCore.GameManagers.NetworkManager.Updates.ServerToClient;
|
||||
using ZoFo.GameCore.Graphics;
|
||||
using ZoFo.GameCore.GameObjects.Entities.LivingEntities.Player;
|
||||
|
||||
namespace ZoFo.GameCore.GameManagers.CollisionManager
|
||||
{
|
||||
|
@ -25,18 +26,25 @@ namespace ZoFo.GameCore.GameManagers.CollisionManager
|
|||
|
||||
|
||||
//чекаем коллизии в листе
|
||||
|
||||
/// <summary>
|
||||
/// минимальный накоп изменения перед перевдижением
|
||||
/// </summary>
|
||||
const float minimalValueToChange = 4;
|
||||
public void CheckComponentCollision(CollisionComponent componentOfEntity)
|
||||
{
|
||||
var entity = componentOfEntity.gameObject as LivingEntity;
|
||||
//for (int i = 0; i < ObjectsWithCollisions.Count; i++)
|
||||
//{
|
||||
var currentRect = entity.collisionComponent.stopRectangle;//задаём РЕК
|
||||
currentRect.X+=(int)entity.position.X;
|
||||
currentRect.Y+=(int)entity.position.Y;
|
||||
currentRect.X += (int)entity.position.X;
|
||||
currentRect.Y += (int)entity.position.Y;
|
||||
|
||||
var newRect = currentRect; // задаём значение старого РЕК новому РЕК
|
||||
|
||||
|
||||
if (Math.Abs((int)entity.velocity.X) > minimalValueToChange ) //TODO
|
||||
{
|
||||
var collidedX = false; // соприкосновение
|
||||
var tryingRectX = currentRect;//переменная для попытки перемещения по X
|
||||
|
||||
|
@ -53,8 +61,9 @@ namespace ZoFo.GameCore.GameManagers.CollisionManager
|
|||
|
||||
{
|
||||
collidedX = true;// меняем значение соприкосновения на true
|
||||
entity.OnCollision(item);//подписываем entity на ивент коллизии
|
||||
|
||||
//entity.OnCollision(item);//подписываем entity на ивент коллизии
|
||||
item.OnCollisionWithObject(entity);
|
||||
entity.collisionComponent.OnCollisionWithObject(item.gameObject);
|
||||
break;// выход
|
||||
}
|
||||
}
|
||||
|
@ -69,11 +78,16 @@ namespace ZoFo.GameCore.GameManagers.CollisionManager
|
|||
newRect.X = tryingRectX.X;//значение по X для нового РЕК приравниваем к значению испытуемого РЕК
|
||||
}
|
||||
|
||||
entity.velocity.X = 0;
|
||||
}
|
||||
//==ПОВТОРЯЕМ ТОЖЕ САМОЕ ДЛЯ Y==
|
||||
|
||||
var collidedY = false; // соприкосновение
|
||||
var tryingRectY = currentRect;//переменная для попытки перемещения по X
|
||||
|
||||
if (Math.Abs((int)entity.velocity.Y)> minimalValueToChange) //TODO
|
||||
{
|
||||
|
||||
tryingRectY.Offset(new Point(0, (int)entity.velocity.Y));//задаём значения для tryingRectX по X и по Y
|
||||
|
||||
foreach (var item in ObjectsWithCollisions)//фильтрация
|
||||
|
@ -101,43 +115,96 @@ namespace ZoFo.GameCore.GameManagers.CollisionManager
|
|||
entity.position.Y += entity.velocity.Y;
|
||||
newRect.Y = tryingRectY.Y;//значение по X для нового РЕК приравниваем к значению испытуемого РЕК
|
||||
}
|
||||
entity.velocity.Y = 0;
|
||||
}
|
||||
|
||||
|
||||
entity.graphicsComponent.ObjectDrawRectangle.X = (int)entity.position.X;
|
||||
entity.graphicsComponent.ObjectDrawRectangle.Y = (int)entity.position.Y;
|
||||
AppManager.Instance.server.AddData(new UpdatePosition() { NewPosition = entity.position, IdEntity = entity.Id });
|
||||
AppManager.Instance.debugHud.Set("testPos", entity.position.ToString()); //TODO remove
|
||||
entity.velocity = Vector2.Zero;
|
||||
}
|
||||
|
||||
public void UpdateTriggerZones(Player player)
|
||||
{
|
||||
|
||||
var entity = player as LivingEntity;
|
||||
var currentRect = entity.collisionComponent.stopRectangle;//задаём РЕК
|
||||
currentRect.X += (int)entity.position.X;
|
||||
currentRect.Y += (int)entity.position.Y;
|
||||
|
||||
|
||||
for (int i = 0; i < ObjectsWithTriggers.Count; i++)
|
||||
{
|
||||
int c = ObjectsWithTriggers.Count;
|
||||
|
||||
if (ObjectsWithTriggers[i].triggerRectangle.SetOrigin(ObjectsWithTriggers[i].gameObject.position).Intersects(currentRect))
|
||||
{
|
||||
ObjectsWithTriggers[i].PlayerInZone(player);
|
||||
}
|
||||
i -= c - ObjectsWithTriggers.Count;
|
||||
}
|
||||
}
|
||||
|
||||
//обновление позиции объекта
|
||||
|
||||
public void UpdatePositions()
|
||||
public void ResolvePhysics()
|
||||
{
|
||||
foreach (var item in EntitiesWithMovements)
|
||||
{
|
||||
CheckComponentCollision(item);
|
||||
}
|
||||
foreach (var item in AppManager.Instance.server.players)
|
||||
{
|
||||
UpdateTriggerZones(item);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public CollisionManager()
|
||||
{
|
||||
//graphicsComponent
|
||||
//.ObjectDrawRectangle = new Rectangle(0, 0, 16 * 12, 16 * 16);
|
||||
EntitiesWithMovements = new List<CollisionComponent>();
|
||||
ObjectsWithCollisions = new List<CollisionComponent>();
|
||||
ObjectsWithTriggers = new List<CollisionComponent>();
|
||||
}
|
||||
//регистрация компонента(его коллизии)
|
||||
public void Register(CollisionComponent component)
|
||||
{
|
||||
if (component.hasCollision)
|
||||
ObjectsWithCollisions.Add(component);
|
||||
if (component.isTrigger)
|
||||
ObjectsWithTriggers.Add(component);
|
||||
if (component.gameObject is LivingEntity)
|
||||
{
|
||||
EntitiesWithMovements.Add(component);
|
||||
}
|
||||
}
|
||||
public void Deregister(CollisionComponent component)
|
||||
{
|
||||
if (ObjectsWithCollisions.Contains(component))
|
||||
ObjectsWithCollisions.Remove(component);
|
||||
if (ObjectsWithTriggers.Contains(component))
|
||||
ObjectsWithTriggers.Remove(component);
|
||||
if (component.gameObject is LivingEntity)
|
||||
{
|
||||
if (EntitiesWithMovements.Contains(component))
|
||||
EntitiesWithMovements.Remove(component);
|
||||
}
|
||||
}
|
||||
|
||||
public Player[] GetPlayersInZone(Rectangle rectangle)
|
||||
{
|
||||
|
||||
List<Player> players = new List<Player>();
|
||||
foreach (var item in AppManager.Instance.server.players)//фильтрация
|
||||
{
|
||||
if (item.collisionComponent.stopRectangle.SetOrigin(item.position).Intersects(rectangle))
|
||||
{
|
||||
players.Add(item);
|
||||
}
|
||||
}
|
||||
return players.ToArray();
|
||||
}
|
||||
|
||||
}
|
||||
public static class ExtentionClass
|
||||
|
|
|
@ -10,6 +10,7 @@ using System.Linq;
|
|||
using System.Reflection.Metadata.Ecma335;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using ZoFo.GameCore.GUI;
|
||||
|
||||
namespace ZoFo.GameCore.GameManagers
|
||||
{
|
||||
|
@ -27,9 +28,6 @@ namespace ZoFo.GameCore.GameManagers
|
|||
private Vector2 prevInputMovementDirection;
|
||||
public Vector2 InputAttackDirection;
|
||||
private Vector2 prevInputAttackDirection;
|
||||
|
||||
public event Action TalkEvent;
|
||||
|
||||
public ScopeState currentScopeState; // Положение оружия. Left, Right, Straight, Back, StraightLeft, StraightRight, BackLeft, BackRight.
|
||||
private ScopeState prevCurrentScopeState;
|
||||
private bool _cheatsEnabled = false;
|
||||
|
@ -48,6 +46,7 @@ namespace ZoFo.GameCore.GameManagers
|
|||
|
||||
public InputManager()
|
||||
{
|
||||
isInteract = true;
|
||||
InputMovementDirection = new Vector2(0, 0);
|
||||
InputAttackDirection = new Vector2(0, 0);
|
||||
this.isShoot = false;
|
||||
|
@ -173,38 +172,46 @@ namespace ZoFo.GameCore.GameManagers
|
|||
if (keyBoardState.IsKeyDown(Keys.Up) || keyBoardState.IsKeyDown(Keys.W))
|
||||
{
|
||||
currentScopeState = ScopeState.Straight;
|
||||
InputMovementDirection = new Vector2(0, -1);
|
||||
}
|
||||
else if (keyBoardState.IsKeyDown(Keys.Down) || keyBoardState.IsKeyDown(Keys.S))
|
||||
{
|
||||
currentScopeState = ScopeState.Back;
|
||||
InputMovementDirection = new Vector2(0, 1);
|
||||
}
|
||||
else if(keyBoardState.IsKeyDown(Keys.Left) || keyBoardState.IsKeyDown(Keys.A))
|
||||
{
|
||||
currentScopeState = ScopeState.Left;
|
||||
InputMovementDirection = new Vector2(-1, 0);
|
||||
}
|
||||
else if(keyBoardState.IsKeyDown(Keys.Right) || keyBoardState.IsKeyDown(Keys.D))
|
||||
{
|
||||
currentScopeState = ScopeState.Right;
|
||||
InputMovementDirection = new Vector2(1, 0);
|
||||
}
|
||||
else if(keyBoardState.IsKeyDown(Keys.Right) && keyBoardState.IsKeyDown(Keys.Up) ||
|
||||
keyBoardState.IsKeyDown(Keys.D) && keyBoardState.IsKeyDown(Keys.W))
|
||||
{
|
||||
currentScopeState = ScopeState.StraightRight;
|
||||
InputMovementDirection = new Vector2(1, 1);
|
||||
}
|
||||
else if(keyBoardState.IsKeyDown(Keys.Left) && keyBoardState.IsKeyDown(Keys.Up) ||
|
||||
keyBoardState.IsKeyDown(Keys.A) && keyBoardState.IsKeyDown(Keys.W))
|
||||
{
|
||||
currentScopeState = ScopeState.StraightLeft;
|
||||
InputMovementDirection = new Vector2(-1, 1);
|
||||
}
|
||||
else if(keyBoardState.IsKeyDown(Keys.Right) && keyBoardState.IsKeyDown(Keys.Down) ||
|
||||
keyBoardState.IsKeyDown(Keys.D) && keyBoardState.IsKeyDown(Keys.S))
|
||||
{
|
||||
currentScopeState = ScopeState.BackRight;
|
||||
InputMovementDirection = new Vector2(1, -1);
|
||||
}
|
||||
else if(keyBoardState.IsKeyDown(Keys.Left) && keyBoardState.IsKeyDown(Keys.Down) ||
|
||||
keyBoardState.IsKeyDown(Keys.A) && keyBoardState.IsKeyDown(Keys.S))
|
||||
{
|
||||
currentScopeState = ScopeState.BackLeft;
|
||||
InputMovementDirection = new Vector2(-1, -1);
|
||||
}
|
||||
#endregion
|
||||
|
||||
|
@ -247,6 +254,8 @@ namespace ZoFo.GameCore.GameManagers
|
|||
prevInputAttackDirection = InputAttackDirection;
|
||||
prevCurrentScopeState = currentScopeState;
|
||||
#endregion
|
||||
|
||||
DebugHUD.Instance.Set("controls", currentScopeState.ToString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -41,7 +41,7 @@ namespace ZoFo.GameCore.GameManagers.MapManager
|
|||
// Загрузка TileSet-ов по TileSetInfo
|
||||
foreach (TileSetInfo tileSetInfo in _tileMap.TileSets)
|
||||
{
|
||||
TileSet tileSet = LoadTileSet(Path.Combine("Content", "MapData", "TileMaps", tileSetInfo.Source));
|
||||
TileSet tileSet = LoadTileSet(Path.Combine(AppContext.BaseDirectory, "Content", "MapData", "TileMaps", tileSetInfo.Source));
|
||||
tileSet.FirstGid = tileSetInfo.FirstGid;
|
||||
_tileSets.Add(tileSet);
|
||||
}
|
||||
|
|
|
@ -42,6 +42,13 @@ namespace ZoFo.GameCore.GameManagers.NetworkManager
|
|||
|
||||
public void SendData()
|
||||
{
|
||||
for (int i = 0; i < updates.Count; i++)
|
||||
{
|
||||
|
||||
AppManager.Instance.server.ProcessIUpdateData(updates[i]);
|
||||
}
|
||||
updates.Clear();
|
||||
return;// TODO remove
|
||||
byte[] bytes = Encoding.UTF8.GetBytes(JsonSerializer.Serialize(updates)); //нужно сериализовать
|
||||
socket.Send(bytes);
|
||||
}
|
||||
|
@ -98,7 +105,7 @@ namespace ZoFo.GameCore.GameManagers.NetworkManager
|
|||
|
||||
public static IPAddress GetIp()
|
||||
{
|
||||
string hostName = Dns.GetHostName(); // Retrive the Name of HOST
|
||||
/*string hostName = Dns.GetHostName(); // Retrive the Name of HOST
|
||||
var ipList = Dns.GetHostByName(hostName).AddressList;
|
||||
|
||||
foreach (var ip in ipList)
|
||||
|
@ -107,8 +114,8 @@ namespace ZoFo.GameCore.GameManagers.NetworkManager
|
|||
{
|
||||
return ip;
|
||||
}
|
||||
}
|
||||
return IPAddress.Loopback;
|
||||
}*/
|
||||
return IPAddress.Parse("127.0.0.1");
|
||||
}
|
||||
|
||||
//поток 2
|
||||
|
@ -116,8 +123,8 @@ namespace ZoFo.GameCore.GameManagers.NetworkManager
|
|||
{
|
||||
while(socket.Connected)
|
||||
{
|
||||
byte[] bytes = new byte[2048];
|
||||
var countAnsw = socket.Receive(bytes); //Вылетает если кто то закрыл
|
||||
byte[] bytes = new byte[65535];
|
||||
var countAnsw = socket.Receive(bytes, SocketFlags.Partial); //Вылетает если кто то закрыл
|
||||
string update = Encoding.UTF8.GetString(bytes, 0, countAnsw); // обновление отосланные сервером
|
||||
GetDataSent(update);
|
||||
}
|
||||
|
|
|
@ -0,0 +1,18 @@
|
|||
using Microsoft.Xna.Framework;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ZoFo.GameCore.GameManagers.NetworkManager.SerializableDTO
|
||||
{
|
||||
public class SerializablePoint
|
||||
{
|
||||
public int X;
|
||||
public int Y;
|
||||
|
||||
public SerializablePoint(Point point) { X = point.X; Y = point.Y;}
|
||||
public Point GetPoint() { return new Point(X, Y);}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,33 @@
|
|||
using Microsoft.Xna.Framework;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Text.Json.Serialization;
|
||||
using System.Threading.Tasks;
|
||||
using ZoFo.GameCore.GameManagers.NetworkManager.SerializableDTO;
|
||||
|
||||
namespace ZoFo.GameCore.GameManagers.NetworkManager.SerializableDTO
|
||||
{
|
||||
[Serializable]
|
||||
[JsonSerializable(typeof(SerializableRectangle))]
|
||||
public class SerializableRectangle
|
||||
{
|
||||
public SerializablePoint Size { get; set; }
|
||||
public SerializablePoint Location { get; set; }
|
||||
public int X { get; set; }
|
||||
public int Y { get; set; }
|
||||
public SerializableRectangle()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public SerializableRectangle(Rectangle rectangle) { X = rectangle.X; Y = rectangle.Y;
|
||||
Size = new SerializablePoint(rectangle.Size); Location = new SerializablePoint(rectangle.Location); }
|
||||
|
||||
public Rectangle GetRectangle()
|
||||
{
|
||||
return new Rectangle() { X = X, Y = Y, Size = Size.GetPoint(), Location = Location.GetPoint() };
|
||||
}
|
||||
}
|
||||
}
|
|
@ -52,17 +52,16 @@ namespace ZoFo.GameCore.GameManagers.NetworkManager
|
|||
/// <returns></returns>
|
||||
public static IPAddress GetIp()
|
||||
{
|
||||
string hostName = Dns.GetHostName(); // Retrive the Name of HOST
|
||||
/*string hostName = Dns.GetHostName(); // Retrive the Name of HOST
|
||||
var ipList = Dns.GetHostByName(hostName).AddressList;
|
||||
|
||||
foreach (var ip in ipList)
|
||||
{
|
||||
if (ip.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork)
|
||||
{
|
||||
return ip;
|
||||
}
|
||||
}
|
||||
return IPAddress.Loopback;
|
||||
}*/
|
||||
return IPAddress.Parse("127.0.0.1");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -80,15 +79,15 @@ namespace ZoFo.GameCore.GameManagers.NetworkManager
|
|||
//Что это?
|
||||
//по 10 паков за раз TODO FIXITFIXITFIXITFIXITFIXITFIXITFIXITFIXITFIXITFIXITFIXITFIXIT
|
||||
List<UpdateData> datasToSend = new List<UpdateData>();
|
||||
for (int i = 0; i < 5 && i<updates.Count; i++)
|
||||
for (int i = 0; i < 200 && i<updates.Count; i++)
|
||||
datasToSend.Add(updates[i]);
|
||||
string data = JsonSerializer.Serialize(datasToSend);
|
||||
var databytes = Encoding.UTF8.GetBytes(data);
|
||||
foreach (var item in clients)
|
||||
foreach (Socket socket in clients)
|
||||
{
|
||||
item.SendAsync(databytes);
|
||||
clients[0].SendAsync(databytes, SocketFlags.Partial);
|
||||
}
|
||||
for (int i = 0; i < 5 && i< datasToSend.Count; i++)
|
||||
for (int i = 0; i < 200 && i< datasToSend.Count; i++)
|
||||
updates.RemoveAt(0);
|
||||
}
|
||||
|
||||
|
@ -171,8 +170,8 @@ namespace ZoFo.GameCore.GameManagers.NetworkManager
|
|||
Socket client = (Socket)socket;
|
||||
while (client.Connected)
|
||||
{
|
||||
var buff = new byte[1024];
|
||||
var answ = client.Receive(buff);
|
||||
var buff = new byte[65535];
|
||||
var answ = client.Receive(buff, SocketFlags.Partial);
|
||||
string response = Encoding.UTF8.GetString(buff, 0, answ);
|
||||
GetDataSend(response);
|
||||
}
|
||||
|
|
|
@ -0,0 +1,12 @@
|
|||
using System;
|
||||
using ZoFo.GameCore.GameManagers.NetworkManager;
|
||||
|
||||
namespace ZoFo.GameCore.GameManagers.NetworkManager.Updates.ClientToServer;
|
||||
|
||||
/// <summary>
|
||||
/// уведомляет сервер о том, что игрок взаимодействует
|
||||
/// </summary>
|
||||
public class UpdateInputInteraction : UpdateData
|
||||
{
|
||||
public UpdateInputInteraction() { UpdateType = "UpdateInputInteraction"; }
|
||||
}
|
|
@ -0,0 +1,9 @@
|
|||
using System;
|
||||
using ZoFo.GameCore.GameManagers.NetworkManager.Updates;
|
||||
|
||||
namespace ZoFo.GameCore.GameManagers.NetworkManager.Updates.ClientToServer;
|
||||
|
||||
public class UpdateInputShoot : UpdateData
|
||||
{
|
||||
public UpdateInputShoot() { UpdateType = "UpdateInputShoot"; }
|
||||
}
|
|
@ -12,5 +12,6 @@ namespace ZoFo.GameCore.GameManagers.NetworkManager.Updates.ServerToClient
|
|||
public class UpdateAnimation : UpdateData
|
||||
{
|
||||
public UpdateAnimation() { UpdateType = "UpdateAnimation"; }
|
||||
public string animationId { get; set; }
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,6 +2,8 @@ namespace ZoFo.GameCore.GameManagers.NetworkManager.Updates.ServerToClient;
|
|||
|
||||
/// <summary>
|
||||
/// При попытке взаимодействия с объектом
|
||||
/// отправляет пользователю разрешение на взаимодействие
|
||||
/// TODO: Вероятно убрать(обсудить)
|
||||
/// </summary>
|
||||
public class UpdateInteraction : UpdateData
|
||||
{
|
||||
|
|
|
@ -6,6 +6,7 @@ using System.Linq;
|
|||
using System.Text;
|
||||
using System.Text.Json.Serialization;
|
||||
using System.Threading.Tasks;
|
||||
using ZoFo.GameCore.GameManagers.NetworkManager.SerializableDTO;
|
||||
using ZoFo.GameCore.GameManagers.NetworkManager.Updates.ClientToServer;
|
||||
|
||||
namespace ZoFo.GameCore.GameManagers.NetworkManager.Updates.ServerToClient
|
||||
|
@ -19,21 +20,8 @@ namespace ZoFo.GameCore.GameManagers.NetworkManager.Updates.ServerToClient
|
|||
public UpdateTileCreated() { UpdateType = "UpdateTileCreated"; }
|
||||
public Texture2D TextureTile { get; set; }
|
||||
public Vector2 Position { get; set; }
|
||||
public Point Size { get; set; }
|
||||
public Rectangle sourceRectangle { get; set; }
|
||||
public SerializablePoint Size { get; set; }
|
||||
public SerializableRectangle sourceRectangle { get; set; }
|
||||
public string tileSetName { get; set; }
|
||||
}
|
||||
/// <summary>
|
||||
/// При создании тайла TODO move to another file
|
||||
/// </summary>
|
||||
public class UpdateStopObjectCreated : UpdateData
|
||||
{
|
||||
public UpdateStopObjectCreated() { UpdateType = "UpdateStopObjectCreated"; }
|
||||
public Texture2D TextureTile { get; set; }
|
||||
public Vector2 Position { get; set; }
|
||||
public Point Size { get; set; }
|
||||
public Rectangle sourceRectangle { get; set; }
|
||||
public string tileSetName { get; set; }
|
||||
public Rectangle[] collisions { get; set; }
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,15 +24,7 @@ namespace ZoFo.GameCore.GameManagers
|
|||
{
|
||||
//List<string> sounds = AppManager.Instance.Content.Load<List<string>>("sounds/");
|
||||
|
||||
string a = Path.Combine("Content", "sounds");
|
||||
string[] k;
|
||||
if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
|
||||
{
|
||||
k = Directory.GetFiles(Path.Combine("bin", "Debug", "net8.0", "Content", "sounds")).Where(x => x.EndsWith("xnb")).ToArray();
|
||||
}
|
||||
else{
|
||||
k = Directory.GetFiles(Path.Combine(Directory.GetCurrentDirectory(), "Content", "sounds")).Where(x => x.EndsWith("xnb")).ToArray();
|
||||
}
|
||||
string[] k = Directory.GetFiles(Path.Combine(AppContext.BaseDirectory, "Content", "sounds")).Where(x => x.EndsWith("xnb")).ToArray();
|
||||
if (k.Length > 0)
|
||||
{
|
||||
|
||||
|
|
|
@ -14,11 +14,11 @@ namespace ZoFo.GameCore.GameObjects.Entities
|
|||
//public override GraphicsComponent graphicsComponent { get; } = new GraphicsComponent(new List<string> { "тут пишите название анимации" }, "сдублируйте " +
|
||||
|
||||
|
||||
public override GraphicsComponent graphicsComponent { get; } = new AnimatedGraphicsComponent(new List<string> { "player_idle_rotate_weapon" }, "player_idle_rotate_weapon");
|
||||
public override GraphicsComponent graphicsComponent { get; } = new AnimatedGraphicsComponent(new List<string> { "zombie_idle" }, "zombie_idle");
|
||||
|
||||
public EntittyForAnimationTests(Vector2 position) : base(position)
|
||||
{
|
||||
graphicsComponent.ObjectDrawRectangle = new Rectangle(0,0,16*12, 16 * 16);
|
||||
graphicsComponent.ObjectDrawRectangle = new Rectangle(0,0,16*20, 16 * 20);
|
||||
position = new Vector2(10, 10);
|
||||
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@ using System.Collections.Generic;
|
|||
using System.Text;
|
||||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
using ZoFo.GameCore.GameManagers;
|
||||
using ZoFo.GameCore.GameManagers.CollisionManager;
|
||||
|
||||
namespace ZoFo.GameCore.GameObjects.Entities
|
||||
|
@ -36,6 +37,23 @@ namespace ZoFo.GameCore.GameObjects.Entities
|
|||
Update();
|
||||
base.UpdateLogic();
|
||||
}
|
||||
|
||||
public void StartAnimation(string animationId)
|
||||
{
|
||||
(graphicsComponent as Graphics.AnimatedGraphicsComponent).StartAnimation(animationId);
|
||||
AppManager.Instance.server.AddData(new GameManagers.NetworkManager.Updates.ServerToClient.UpdateAnimation()
|
||||
{
|
||||
animationId = animationId,
|
||||
IdEntity = Id
|
||||
});
|
||||
|
||||
}
|
||||
public override void Draw(SpriteBatch spriteBatch)
|
||||
{
|
||||
DrawDebugRectangle(spriteBatch, collisionComponent.stopRectangle.SetOrigin(position), Color.Orange);
|
||||
|
||||
base.Draw(spriteBatch);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -8,6 +8,8 @@ using ZoFo.GameCore.GameManagers.CollisionManager;
|
|||
using ZoFo.GameCore.GameManagers.NetworkManager.Updates.ServerToClient;
|
||||
using ZoFo.GameCore.GameManagers;
|
||||
using ZoFo.GameCore.Graphics;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
using ZoFo.GameCore.GUI;
|
||||
|
||||
namespace ZoFo.GameCore.GameObjects.Entities.Interactables.Collectables
|
||||
{
|
||||
|
@ -18,11 +20,19 @@ namespace ZoFo.GameCore.GameObjects.Entities.Interactables.Collectables
|
|||
{
|
||||
graphicsComponent.ObjectDrawRectangle.Width = 20;
|
||||
graphicsComponent.ObjectDrawRectangle.Height = 20;
|
||||
|
||||
collisionComponent.triggerRectangle = new Rectangle(0, 0, 20, 20);
|
||||
}
|
||||
public override void OnInteraction(object sender, CollisionComponent e)
|
||||
public override void OnInteraction(GameObject sender)
|
||||
{
|
||||
DebugHUD.DebugLog("collected");
|
||||
AppManager.Instance.server.AddData(new UpdateLoot("Ammo"));
|
||||
AppManager.Instance.server.DeleteObject(this);
|
||||
}
|
||||
public override void Draw(SpriteBatch spriteBatch)
|
||||
{
|
||||
DrawDebugRectangle(spriteBatch, collisionComponent.triggerRectangle.SetOrigin(position), Color.Blue);
|
||||
base.Draw(spriteBatch);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,7 +18,7 @@ namespace ZoFo.GameCore.GameObjects.Entities.Interactables.Collectables
|
|||
{
|
||||
|
||||
}
|
||||
public override void OnInteraction(object sender, CollisionComponent e)
|
||||
public override void OnInteraction(GameObject sender)
|
||||
{
|
||||
AppManager.Instance.server.AddData(new UpdateLoot("Antiradine"));
|
||||
AppManager.Instance.server.DeleteObject(this);
|
||||
|
|
|
@ -19,7 +19,7 @@ namespace ZoFo.GameCore.GameObjects.Entities.Interactables.Collectables
|
|||
{
|
||||
|
||||
}
|
||||
public override void OnInteraction(object sender, CollisionComponent e)
|
||||
public override void OnInteraction(GameObject sender)
|
||||
{
|
||||
AppManager.Instance.server.AddData(new UpdateLoot("BottleOfWater"));
|
||||
AppManager.Instance.server.DeleteObject(this);
|
||||
|
|
|
@ -12,7 +12,7 @@ public class Collectable : Interactable
|
|||
{
|
||||
}
|
||||
|
||||
public override void OnInteraction(object sender, CollisionComponent e)
|
||||
public override void OnInteraction(GameObject sender)
|
||||
{
|
||||
//
|
||||
AppManager.Instance.server.AddData(new UpdateLoot());
|
||||
|
|
|
@ -20,7 +20,7 @@ namespace ZoFo.GameCore.GameObjects.Entities.Interactables.Collectables
|
|||
{
|
||||
|
||||
}
|
||||
public override void OnInteraction(object sender, CollisionComponent e)
|
||||
public override void OnInteraction(GameObject sender)
|
||||
{
|
||||
AppManager.Instance.server.AddData(new UpdateLoot("Peeble"));
|
||||
AppManager.Instance.server.DeleteObject(this);
|
||||
|
|
|
@ -18,7 +18,7 @@ namespace ZoFo.GameCore.GameObjects.Entities.Interactables.Collectables
|
|||
public PureBottleOfWater(Vector2 position) : base(position)
|
||||
{
|
||||
}
|
||||
public override void OnInteraction(object sender, CollisionComponent e)
|
||||
public override void OnInteraction(GameObject sender)
|
||||
{
|
||||
AppManager.Instance.server.AddData(new UpdateLoot("PureBottleOfWater"));
|
||||
AppManager.Instance.server.DeleteObject(this);
|
||||
|
|
|
@ -18,7 +18,7 @@ namespace ZoFo.GameCore.GameObjects.Entities.Interactables.Collectables
|
|||
{
|
||||
|
||||
}
|
||||
public override void OnInteraction(object sender, CollisionComponent e)
|
||||
public override void OnInteraction(GameObject sender)
|
||||
{
|
||||
AppManager.Instance.server.AddData(new UpdateLoot("RottenFlesh"));
|
||||
AppManager.Instance.server.DeleteObject(this);
|
||||
|
|
|
@ -18,7 +18,7 @@ namespace ZoFo.GameCore.GameObjects.Entities.Interactables.Collectables
|
|||
public Steel(Vector2 position) : base(position)
|
||||
{
|
||||
}
|
||||
public override void OnInteraction(object sender, CollisionComponent e)
|
||||
public override void OnInteraction(GameObject sender)
|
||||
{
|
||||
AppManager.Instance.server.AddData(new UpdateLoot("Steel"));
|
||||
AppManager.Instance.server.DeleteObject(this);
|
||||
|
|
|
@ -15,7 +15,7 @@ public class Wood : Collectable
|
|||
{
|
||||
|
||||
}
|
||||
public override void OnInteraction(object sender, CollisionComponent e)
|
||||
public override void OnInteraction(GameObject sender)
|
||||
{
|
||||
AppManager.Instance.server.AddData(new UpdateLoot("Wood"));
|
||||
AppManager.Instance.server.DeleteObject(this);
|
||||
|
|
|
@ -16,7 +16,7 @@ public class Door : Interactable
|
|||
//graphicsComponent.OnAnimationEnd += _ => { isOpened = !isOpened; };//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>, <20><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> - SD
|
||||
}
|
||||
|
||||
public override void OnInteraction(object sender, CollisionComponent e)
|
||||
public override void OnInteraction(GameObject sender)
|
||||
{
|
||||
//graphicsComponent.AnimationSelect("DoorInteraction", isOpened);
|
||||
//graphicsComponent.AnimationStep();
|
||||
|
|
|
@ -13,17 +13,19 @@ public class Interactable : Entity
|
|||
|
||||
public Interactable(Vector2 position) : base(position)
|
||||
{
|
||||
collisionComponent.OnTriggerEnter += (sender, e) => ChangeInteraction(sender, e, true);
|
||||
collisionComponent.OnTriggerExit += (sender, e) => ChangeInteraction(sender, e, false);
|
||||
collisionComponent.isTrigger = true;
|
||||
collisionComponent.hasCollision = false;
|
||||
collisionComponent.OnTriggerEnter += (sender) => ChangeInteraction(sender, true);
|
||||
collisionComponent.OnTriggerExit += (sender) => ChangeInteraction(sender, false);
|
||||
collisionComponent.OnTriggerZone += OnInteraction;
|
||||
}
|
||||
|
||||
private void ChangeInteraction(object sender, CollisionComponent e, bool isReady)
|
||||
private void ChangeInteraction(GameObject sender, bool isReady)
|
||||
{
|
||||
AppManager.Instance.server.AddData(new UpdateInteractionReady((sender as Player).Id, isReady));
|
||||
}
|
||||
|
||||
public virtual void OnInteraction(object sender, CollisionComponent e)
|
||||
public virtual void OnInteraction(GameObject sender)
|
||||
{
|
||||
|
||||
}
|
||||
|
|
|
@ -11,12 +11,12 @@ namespace ZoFo.GameCore.GameObjects.Entities.LivingEntities.Enemies
|
|||
{
|
||||
class Zombie : Enemy
|
||||
{
|
||||
public override GraphicsComponent graphicsComponent { get; } = new AnimatedGraphicsComponent("Textures/icons/8");
|
||||
public override GraphicsComponent graphicsComponent { get; } = new AnimatedGraphicsComponent(new List<string> { "zombie_damaged","zombie_walk","zombie_idle","zombie_attack","zombie_death" }, "zombie_walk");
|
||||
public Zombie(Vector2 position) : base(position)
|
||||
{
|
||||
health = 5;
|
||||
speed =2;
|
||||
collisionComponent.stopRectangle = new Rectangle(0, 0, 100, 100);
|
||||
collisionComponent.stopRectangle = new Rectangle(0, 0, 52, 100);
|
||||
graphicsComponent.ObjectDrawRectangle = new Rectangle(0, 0, 100, 100);
|
||||
}
|
||||
|
||||
|
@ -25,13 +25,18 @@ namespace ZoFo.GameCore.GameObjects.Entities.LivingEntities.Enemies
|
|||
Vector2 duration = Vector2.Normalize(
|
||||
AppManager.Instance.server.players[0].position - position
|
||||
);
|
||||
velocity=new Vector2(duration.X * speed, duration.Y*speed);
|
||||
if(position.X>595 && 605>position.X && position.Y>495 && 505>position.Y)
|
||||
velocity+=new Vector2(duration.X * speed, duration.Y*speed);
|
||||
if (Random.Shared.NextDouble() > 0.9)
|
||||
{
|
||||
velocity = Vector2.Zero;
|
||||
|
||||
StartAnimation("zombie_damaged");
|
||||
}
|
||||
//position.X += velocity.X*t;
|
||||
//position.Y += velocity.Y * t;
|
||||
if (Random.Shared.NextDouble() > 0.9)
|
||||
{
|
||||
|
||||
StartAnimation("zombie_idle");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,6 +19,7 @@ public class LivingEntity : Entity
|
|||
public LivingEntity(Vector2 position) : base(position)
|
||||
{
|
||||
inputManager = new InputManager();
|
||||
collisionComponent.hasCollision = true;
|
||||
}
|
||||
|
||||
public override GraphicsComponent graphicsComponent { get; } = null;
|
||||
|
@ -35,6 +36,20 @@ public class LivingEntity : Entity
|
|||
|
||||
}
|
||||
|
||||
public override void UpdateAnimations()
|
||||
{
|
||||
base.UpdateAnimations();
|
||||
}
|
||||
Vector2 prevPosition_forClient;
|
||||
public override void Draw(SpriteBatch spriteBatch)
|
||||
{
|
||||
if ((position - prevPosition_forClient).X< 0)
|
||||
graphicsComponent.Flip = SpriteEffects.FlipHorizontally;
|
||||
else if((position - prevPosition_forClient).X > 0)
|
||||
graphicsComponent.Flip = SpriteEffects.None;
|
||||
base.Draw(spriteBatch);
|
||||
prevPosition_forClient = position;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -18,17 +18,21 @@ public class Player : LivingEntity
|
|||
/// <summary>
|
||||
/// Факт того, что плеер в этом апдейте пытается стрелять
|
||||
/// </summary>
|
||||
public bool IsTryingToShoot { get; set; }
|
||||
//public bool IsTryingToShoot { get; set; }
|
||||
private float speed;
|
||||
private int health;
|
||||
public override GraphicsComponent graphicsComponent { get; } = new AnimatedGraphicsComponent(new List<string> { "player_look_down" }, "player_look_down");
|
||||
private LootData lootData;
|
||||
//public bool isTryingToInteract { get; set; }
|
||||
public Player(Vector2 position) : base(position)
|
||||
{
|
||||
//InputWeaponRotation = new Vector2(0, 0);
|
||||
//InputPlayerRotation = new Vector2(0, 0);
|
||||
graphicsComponent.ObjectDrawRectangle = new Rectangle(0, 0, 100, 100);
|
||||
collisionComponent.stopRectangle = new Rectangle(0, 0, 100, 100);
|
||||
speed = 10;
|
||||
//isTryingToInteract = false;
|
||||
//IsTryingToShoot = false;
|
||||
|
||||
StartAnimation("player_look_down");
|
||||
}
|
||||
|
||||
|
||||
|
@ -37,20 +41,21 @@ public class Player : LivingEntity
|
|||
|
||||
MovementLogic();
|
||||
}
|
||||
float t;
|
||||
public void MovementLogic()
|
||||
{
|
||||
//velocity.X = 3+(float)Math.Sin(t);
|
||||
t++;
|
||||
if (InputPlayerRotation.X > 0.9)
|
||||
{
|
||||
}
|
||||
if (Keyboard.GetState().IsKeyDown(Keys.D)) velocity.X = 5;
|
||||
if (Keyboard.GetState().IsKeyDown(Keys.A)) velocity.X = -5;
|
||||
if (Keyboard.GetState().IsKeyDown(Keys.S)) velocity.Y = 5;
|
||||
if (Keyboard.GetState().IsKeyDown(Keys.W)) velocity.Y = -5;
|
||||
velocity = InputPlayerRotation * speed;
|
||||
}
|
||||
public void HandleNewInput(UpdateInput updateInput)
|
||||
{
|
||||
InputPlayerRotation = updateInput.InputMovementDirection;
|
||||
InputWeaponRotation = updateInput.InputAttackDirection;
|
||||
|
||||
}
|
||||
public void HandleInteract(UpdateInputInteraction updateInputInteraction)
|
||||
{
|
||||
//isTryingToInteract = true;
|
||||
}
|
||||
public void HandleShoot(UpdateInputShoot updateInputShoot)
|
||||
{
|
||||
|
||||
}
|
||||
|
|
|
@ -83,8 +83,6 @@ public abstract class GameObject
|
|||
{
|
||||
graphicsComponent.Draw(graphicsComponent.ObjectDrawRectangle, spriteBatch);
|
||||
//debug
|
||||
DrawDebugRectangle(spriteBatch, graphicsComponent.ObjectDrawRectangle);
|
||||
|
||||
if (AppManager.Instance.InputManager.CollisionsCheat)
|
||||
DrawDebugRectangle(spriteBatch, graphicsComponent.ObjectDrawRectangle);
|
||||
|
||||
|
|
|
@ -125,6 +125,7 @@ namespace ZoFo.GameCore.Graphics
|
|||
|
||||
buildSourceRectangle();
|
||||
SetInterval();
|
||||
|
||||
}
|
||||
|
||||
public void StopAnimation()
|
||||
|
@ -163,6 +164,7 @@ namespace ZoFo.GameCore.Graphics
|
|||
}
|
||||
|
||||
interval--;
|
||||
|
||||
}
|
||||
|
||||
public override void Draw(Rectangle destinationRectangle, SpriteBatch _spriteBatch)
|
||||
|
@ -187,8 +189,9 @@ namespace ZoFo.GameCore.Graphics
|
|||
destinationRectangle.Y -= CameraPosition.Y;
|
||||
|
||||
destinationRectangle = Scaling(destinationRectangle);
|
||||
_spriteBatch.Draw(texture,
|
||||
destinationRectangle, sourceRectangle, Color.White);
|
||||
|
||||
_spriteBatch.Draw(texture, destinationRectangle, sourceRectangle, Color.White, Rotation,
|
||||
Vector2.Zero, Flip, 0);
|
||||
}
|
||||
public override void Draw(Rectangle destinationRectangle, SpriteBatch _spriteBatch, Rectangle sourceRectangle)
|
||||
{
|
||||
|
@ -213,7 +216,8 @@ namespace ZoFo.GameCore.Graphics
|
|||
|
||||
destinationRectangle = Scaling(destinationRectangle);
|
||||
_spriteBatch.Draw(texture,
|
||||
destinationRectangle, sourceRectangle, Color.White);
|
||||
destinationRectangle, sourceRectangle, Color.White, 0,
|
||||
Vector2.Zero, Flip, 0);
|
||||
}
|
||||
private void buildSourceRectangle()
|
||||
{
|
||||
|
|
|
@ -12,7 +12,7 @@ namespace ZoFo.GameCore.Graphics
|
|||
public void LoadAnimations()
|
||||
{
|
||||
Animations = new List<AnimationContainer>();
|
||||
string[] animationFilesNames = Directory.GetFiles("Content/Textures/Animations");
|
||||
string[] animationFilesNames = Directory.GetFiles(Path.Combine(AppContext.BaseDirectory, "Content", "Textures", "Animations"));
|
||||
|
||||
StreamReader reader;
|
||||
foreach (var fileName in animationFilesNames)
|
||||
|
|
|
@ -9,6 +9,9 @@ public abstract class GraphicsComponent
|
|||
public static int scaling = 1;
|
||||
public string mainTextureName;//TODO костыль - пофиксить
|
||||
|
||||
public SpriteEffects Flip = SpriteEffects.None;
|
||||
public float Rotation;
|
||||
|
||||
public abstract void LoadContent();
|
||||
public abstract void Update();
|
||||
public abstract void Draw(Rectangle destinationRectangle, SpriteBatch _spriteBatch);
|
||||
|
|
|
@ -1,16 +0,0 @@
|
|||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
|
||||
namespace ZoFo.GameCore.Graphics;
|
||||
|
||||
public interface IGraphicsComponent
|
||||
{
|
||||
public Rectangle ObjectDrawRectangle { get; set; }
|
||||
public static int scaling = 1;
|
||||
public string mainTextureName { get; set; }//TODO костыль - пофиксить
|
||||
|
||||
public abstract void LoadContent();
|
||||
public abstract void Update();
|
||||
public abstract void Draw(Rectangle destinationRectangle, SpriteBatch _spriteBatch);
|
||||
public abstract void Draw(Rectangle destinationRectangle, SpriteBatch _spriteBatch, Rectangle sourceRectangle);
|
||||
}
|
|
@ -8,7 +8,6 @@ using ZoFo.GameCore.GUI;
|
|||
|
||||
namespace ZoFo.GameCore.Graphics
|
||||
{
|
||||
|
||||
public class StaticGraphicsComponent : GraphicsComponent
|
||||
{
|
||||
private Texture2D texture;
|
||||
|
@ -48,24 +47,28 @@ namespace ZoFo.GameCore.Graphics
|
|||
|
||||
public override void Draw(Rectangle destinationRectangle, SpriteBatch _spriteBatch)
|
||||
{
|
||||
DebugHUD.Instance.Log("draw ");
|
||||
//DebugHUD.Instance.Log("draw ");
|
||||
|
||||
destinationRectangle.X -= CameraPosition.X;
|
||||
destinationRectangle.Y -= CameraPosition.Y;
|
||||
destinationRectangle = Scaling(destinationRectangle);
|
||||
_spriteBatch.Draw(texture, destinationRectangle, Color.White);
|
||||
_spriteBatch.Draw(texture, destinationRectangle, texture.Bounds, Color.White, Rotation,
|
||||
Vector2.Zero, Flip, 0);
|
||||
}
|
||||
|
||||
public override void Draw(Rectangle destinationRectangle, SpriteBatch _spriteBatch, Rectangle sourceRectangle)
|
||||
{
|
||||
DebugHUD.Instance.Log("draw ");
|
||||
//DebugHUD.Instance.Log("draw ");
|
||||
// Uncomment to go brrrr
|
||||
//Rotation = new Random().Next(1, 365);
|
||||
|
||||
destinationRectangle.X -= CameraPosition.X;
|
||||
destinationRectangle.Y -= CameraPosition.Y;
|
||||
|
||||
destinationRectangle = Scaling(destinationRectangle);
|
||||
_spriteBatch.Draw(texture,
|
||||
destinationRectangle, sourceRectangle, Color.White);
|
||||
destinationRectangle, sourceRectangle, Color.White, Rotation,
|
||||
Vector2.Zero, Flip, 0);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -12,6 +12,7 @@ using ZoFo.GameCore.GameManagers.CollisionManager;
|
|||
using ZoFo.GameCore.GameManagers.MapManager;
|
||||
using ZoFo.GameCore.GameManagers.NetworkManager;
|
||||
using ZoFo.GameCore.GameManagers.NetworkManager.Updates;
|
||||
using ZoFo.GameCore.GameManagers.NetworkManager.Updates.ClientToServer;
|
||||
using ZoFo.GameCore.GameManagers.NetworkManager.Updates.ServerToClient;
|
||||
using ZoFo.GameCore.GameObjects;
|
||||
using ZoFo.GameCore.GameObjects.Entities;
|
||||
|
@ -21,6 +22,7 @@ using ZoFo.GameCore.GameObjects.Entities.LivingEntities.Player;
|
|||
using ZoFo.GameCore.GameObjects.MapObjects;
|
||||
using ZoFo.GameCore.GameObjects.MapObjects.StopObjects;
|
||||
using ZoFo.GameCore.Graphics;
|
||||
using ZoFo.GameCore.GameManagers.NetworkManager.SerializableDTO;
|
||||
|
||||
namespace ZoFo.GameCore
|
||||
{
|
||||
|
@ -77,11 +79,17 @@ namespace ZoFo.GameCore
|
|||
break;
|
||||
case "UpdatePlayerParametrs":
|
||||
break;
|
||||
case "UpdatePosition":
|
||||
case "UpdateInput":
|
||||
players[0].HandleNewInput(updateData as UpdateInput);
|
||||
break;
|
||||
case "UpdateTileCreated":
|
||||
break;
|
||||
|
||||
case "UpdateInputInteraction":
|
||||
players[0].HandleInteract(updateData as UpdateInputInteraction);
|
||||
break;
|
||||
case "UpdateInputShoot":
|
||||
players[0].HandleShoot(updateData as UpdateInputShoot);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -130,6 +138,9 @@ namespace ZoFo.GameCore
|
|||
//AppManager.Instance.server.RegisterGameObject(new EntittyForAnimationTests(new Vector2(0, 0)));
|
||||
AppManager.Instance.server.RegisterGameObject(new Player(new Vector2(740, 140)));
|
||||
AppManager.Instance.server.RegisterGameObject(new Zombie(new Vector2(1000, 1000)));
|
||||
AppManager.Instance.server.RegisterGameObject(new Zombie(new Vector2(1300, 1000)));
|
||||
AppManager.Instance.server.RegisterGameObject(new Zombie(new Vector2(1500, 1000)));
|
||||
AppManager.Instance.server.RegisterGameObject(new Zombie(new Vector2(1700, 1000)));
|
||||
AppManager.Instance.server.RegisterGameObject(new Ammo(new Vector2(140, 440)));
|
||||
AppManager.Instance.server.RegisterGameObject(new Ammo(new Vector2(240, 440)));
|
||||
}
|
||||
|
@ -155,7 +166,7 @@ namespace ZoFo.GameCore
|
|||
{
|
||||
go.UpdateLogic();
|
||||
}
|
||||
collisionManager.UpdatePositions();
|
||||
collisionManager.ResolvePhysics();
|
||||
ticks = 0;
|
||||
networkManager.SendData();
|
||||
}
|
||||
|
@ -172,30 +183,13 @@ namespace ZoFo.GameCore
|
|||
{
|
||||
|
||||
gameObjects.Add(gameObject);
|
||||
if (gameObject is StopObject)
|
||||
{
|
||||
AddData(new UpdateStopObjectCreated()
|
||||
{
|
||||
Position = (gameObject as StopObject).position,
|
||||
sourceRectangle = (gameObject as StopObject).sourceRectangle,
|
||||
Size = (gameObject as StopObject).graphicsComponent.ObjectDrawRectangle.Size,
|
||||
collisions = (gameObject as StopObject).collisionComponents.Select(x=>x.stopRectangle).ToArray(),
|
||||
tileSetName = ((gameObject as StopObject).graphicsComponent as StaticGraphicsComponent)._textureName
|
||||
});//TODO
|
||||
foreach (var item in (gameObject as StopObject).collisionComponents)
|
||||
{
|
||||
collisionManager.Register(item);
|
||||
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (gameObject is MapObject)
|
||||
{
|
||||
AddData(new UpdateTileCreated()
|
||||
{
|
||||
Position = (gameObject as MapObject).position,
|
||||
sourceRectangle = (gameObject as MapObject).sourceRectangle,
|
||||
Size = (gameObject as MapObject).graphicsComponent.ObjectDrawRectangle.Size,
|
||||
sourceRectangle = new SerializableRectangle((gameObject as MapObject).sourceRectangle),
|
||||
Size = new SerializablePoint((gameObject as MapObject).graphicsComponent.ObjectDrawRectangle.Size),
|
||||
tileSetName = ((gameObject as MapObject).graphicsComponent as StaticGraphicsComponent)._textureName
|
||||
});//TODO
|
||||
return;
|
||||
|
@ -228,12 +222,18 @@ namespace ZoFo.GameCore
|
|||
/// Удаляет игровой объект
|
||||
/// </summary>
|
||||
/// <param name="gameObject"></param>
|
||||
public void DeleteObject(GameObject gameObject)
|
||||
public void DeleteObject(Entity entity)
|
||||
{
|
||||
gameObjects.Remove(gameObject);
|
||||
if (gameObjects.Contains(entity))
|
||||
gameObjects.Remove(entity);
|
||||
if (entities.Contains(entity))
|
||||
entities.Remove(entity);
|
||||
if (players.Contains(entity))
|
||||
players.Remove(entity as Player);
|
||||
AddData(new UpdateGameObjectDeleted()
|
||||
{ GameObjectType = gameObject.GetType().Name}
|
||||
{ GameObjectType = entity.GetType().Name, IdEntity = entity .Id}
|
||||
);
|
||||
collisionManager.Deregister(entity.collisionComponent);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue