Merge branch 'main' of https://github.com/progtime-net/DangerousD
This commit is contained in:
commit
393818d0b8
5 changed files with 44 additions and 24 deletions
|
@ -15,6 +15,7 @@ namespace DangerousD.GameCore
|
|||
protected Vector2 _pos;
|
||||
public Vector2 Pos => _pos;
|
||||
public int id;
|
||||
public bool isChildEntity = false;
|
||||
public bool isIdFromHost = false;
|
||||
public int Width { get; set; }
|
||||
public int Height { get; set; }
|
||||
|
|
|
@ -8,7 +8,7 @@ using System.Linq;
|
|||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using DangerousD.GameCore.Managers;
|
||||
using DangerousD.GameCore.GameObjects;
|
||||
using DangerousD.GameCore.Network;
|
||||
|
||||
namespace DangerousD.GameCore.GameObjects.LivingEntities.Monsters
|
||||
{
|
||||
|
@ -63,6 +63,10 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities.Monsters
|
|||
}
|
||||
|
||||
public override void Attack()
|
||||
{
|
||||
AppManager.Instance.GameManager.GetPlayer1.Death(name);
|
||||
}
|
||||
public void PlayAttackAnimation()
|
||||
{
|
||||
velocity.X = 0;
|
||||
isAttaking = true;
|
||||
|
@ -72,7 +76,6 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities.Monsters
|
|||
{
|
||||
GraphicsComponent.StartAnimation("ZombieRightAttack");
|
||||
}
|
||||
AppManager.Instance.GameManager.players[0].Death(name);
|
||||
}
|
||||
else if (!isGoRight)
|
||||
{
|
||||
|
@ -80,7 +83,6 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities.Monsters
|
|||
{
|
||||
GraphicsComponent.StartAnimation("ZombieLeftAttack");
|
||||
}
|
||||
AppManager.Instance.GameManager.players[0].Death(name);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -121,12 +123,19 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities.Monsters
|
|||
}
|
||||
public override void OnCollision(GameObject gameObject)
|
||||
{
|
||||
if(gameObject is Player)
|
||||
if (gameObject.id == AppManager.Instance.GameManager.GetPlayer1.id && AppManager.Instance.GameManager.GetPlayer1.IsAlive)
|
||||
{
|
||||
if (AppManager.Instance.GameManager.players[0].IsAlive)
|
||||
if (AppManager.Instance.multiPlayerStatus != MultiPlayerStatus.Client)
|
||||
{
|
||||
Attack();
|
||||
|
||||
}
|
||||
}
|
||||
else if (gameObject is Player)
|
||||
{
|
||||
if (AppManager.Instance.multiPlayerStatus == MultiPlayerStatus.Host)
|
||||
{
|
||||
NetworkTask task = new NetworkTask();
|
||||
AppManager.Instance.NetworkTasks.Add(task.KillPlayer(gameObject.id, name));
|
||||
}
|
||||
}
|
||||
base.OnCollision(gameObject);
|
||||
|
|
|
@ -222,7 +222,12 @@ namespace DangerousD.GameCore
|
|||
{
|
||||
switch (networkTask.operation)
|
||||
{
|
||||
case NetworkTaskOperationEnum.TakeDamage:
|
||||
case NetworkTaskOperationEnum.DeleteObject:
|
||||
GameObject gameObject = GameManager.GetAllGameObjects.Find(x => x.id == networkTask.objId);
|
||||
if (gameObject != null)
|
||||
{
|
||||
GameManager.Remove(gameObject);
|
||||
}
|
||||
break;
|
||||
case NetworkTaskOperationEnum.SendSound:
|
||||
SoundManager.StartSound(networkTask.name, networkTask.position, GameManager.GetPlayer1.Pos);
|
||||
|
@ -283,7 +288,13 @@ namespace DangerousD.GameCore
|
|||
remoteConnectedPlayer.id = networkTask.objId;
|
||||
remoteConnectedPlayer.GetGraphicsComponent().parentId = networkTask.objId;
|
||||
break;
|
||||
default:
|
||||
case NetworkTaskOperationEnum.KillPlayer:
|
||||
Player player1 = GameManager.players.Find(x => x.id==networkTask.objId);
|
||||
player1.Death(networkTask.name);
|
||||
NetworkTask task1 = new NetworkTask();
|
||||
NetworkTasks.Add(task1.DeleteObject(player1.id));
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,18 +20,6 @@ namespace DangerousD.GameCore.Network
|
|||
public Type type { get; set; }
|
||||
|
||||
public NetworkTask() { }
|
||||
/// <summary>
|
||||
/// Нанести урон сущности
|
||||
/// </summary>
|
||||
/// <param name="LivingEntityId"></param>
|
||||
/// <param name="Damage"></param>
|
||||
public NetworkTask(int LivingEntityId, int Damage)
|
||||
{
|
||||
operation = NetworkTaskOperationEnum.TakeDamage;
|
||||
objId = LivingEntityId;
|
||||
value = Damage;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Проиграть звук на позиции
|
||||
/// </summary>
|
||||
|
@ -49,14 +37,12 @@ namespace DangerousD.GameCore.Network
|
|||
/// </summary>
|
||||
/// <param name="EntityType"></param>
|
||||
/// <param name="EntityPosition"></param>
|
||||
/// <param name="EntityVelocity"></param>
|
||||
/// <param name="ParentId"></param>
|
||||
public NetworkTask(Type EntityType, Vector2 EntityPosition, Vector2 EntityVelocity, int ParentId)
|
||||
public NetworkTask(Type EntityType, Vector2 EntityPosition, int ParentId)
|
||||
{
|
||||
operation = NetworkTaskOperationEnum.CreateEntity;
|
||||
type = EntityType;
|
||||
position = EntityPosition;
|
||||
velocity = EntityVelocity;
|
||||
objId = ParentId;
|
||||
}
|
||||
|
||||
|
@ -134,5 +120,18 @@ namespace DangerousD.GameCore.Network
|
|||
position = playerPosition;
|
||||
return this;
|
||||
}
|
||||
public NetworkTask DeleteObject(int objectId)
|
||||
{
|
||||
operation = NetworkTaskOperationEnum.DeleteObject;
|
||||
objId = objectId;
|
||||
return this;
|
||||
}
|
||||
public NetworkTask KillPlayer(int playerId, string mosterName)
|
||||
{
|
||||
operation = NetworkTaskOperationEnum.KillPlayer;
|
||||
name = mosterName;
|
||||
objId = playerId;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,6 +9,6 @@ namespace DangerousD.GameCore.Network
|
|||
[Serializable]
|
||||
public enum NetworkTaskOperationEnum
|
||||
{
|
||||
TakeDamage, SendSound, CreateEntity, SendPosition, ChangeState, ConnectToHost, GetClientPlayerId, AddConnectedPlayer
|
||||
DeleteObject, SendSound, CreateEntity, SendPosition, ChangeState, ConnectToHost, GetClientPlayerId, AddConnectedPlayer, KillPlayer
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue