NetworkAnimationSupport(ChangeState)
This commit is contained in:
parent
5f032d527b
commit
bed41c5bf0
5 changed files with 65 additions and 25 deletions
|
@ -30,6 +30,7 @@ namespace DangerousD.GameCore
|
||||||
|
|
||||||
LoadContent();
|
LoadContent();
|
||||||
AppManager.Instance.GameManager.Register(this);
|
AppManager.Instance.GameManager.Register(this);
|
||||||
|
GraphicsComponent.parentId = id;
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual void OnCollision(GameObject gameObject)
|
public virtual void OnCollision(GameObject gameObject)
|
||||||
|
@ -62,5 +63,9 @@ namespace DangerousD.GameCore
|
||||||
//wdaspriteBatch.Draw(debugTexture,new Rectangle(Rectangle.X-GraphicsComponent.CameraPosition.X,Rectangle.Y-GraphicsComponent.CameraPosition.Y,Rectangle.Width,Rectangle.Height), Color.White);
|
//wdaspriteBatch.Draw(debugTexture,new Rectangle(Rectangle.X-GraphicsComponent.CameraPosition.X,Rectangle.Y-GraphicsComponent.CameraPosition.Y,Rectangle.Width,Rectangle.Height), Color.White);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
public GraphicsComponent GetGraphicsComponent()
|
||||||
|
{
|
||||||
|
return this.GraphicsComponent;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -32,6 +32,8 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities
|
||||||
private int bullets;
|
private int bullets;
|
||||||
public bool FallingThroughPlatform = false;
|
public bool FallingThroughPlatform = false;
|
||||||
public bool isUping = false;
|
public bool isUping = false;
|
||||||
|
public bool isNetworkPlayer;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -40,6 +42,7 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities
|
||||||
public Player(Vector2 position, bool isNetworkPlayer = false) : base(position)
|
public Player(Vector2 position, bool isNetworkPlayer = false) : base(position)
|
||||||
|
|
||||||
{
|
{
|
||||||
|
this.isNetworkPlayer = isNetworkPlayer;
|
||||||
Width = 16;
|
Width = 16;
|
||||||
Height = 32;
|
Height = 32;
|
||||||
|
|
||||||
|
@ -48,24 +51,24 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities
|
||||||
AppManager.Instance.InputManager.ShootEvent += Shoot;
|
AppManager.Instance.InputManager.ShootEvent += Shoot;
|
||||||
AppManager.Instance.InputManager.MovEventJump += Jump;
|
AppManager.Instance.InputManager.MovEventJump += Jump;
|
||||||
AppManager.Instance.InputManager.MovEventDown += MoveDown;
|
AppManager.Instance.InputManager.MovEventDown += MoveDown;
|
||||||
|
velocity = new Vector2(0, 0);
|
||||||
|
rightBorder = (int)position.X + 100;
|
||||||
|
leftBorder = (int)position.X - 100;
|
||||||
|
bullets = 5;
|
||||||
|
|
||||||
|
this.GraphicsComponent.actionOfAnimationEnd += (a) =>
|
||||||
|
{
|
||||||
|
if (a == "playerShootLeft" || a == "playerShootRight")
|
||||||
|
{
|
||||||
|
isShooting = false;
|
||||||
|
}
|
||||||
|
if (a == "playerReload")
|
||||||
|
{
|
||||||
|
bullets++;
|
||||||
|
}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
velocity = new Vector2(0, 0);
|
|
||||||
rightBorder = (int)position.X + 100;
|
|
||||||
leftBorder = (int)position.X - 100;
|
|
||||||
bullets = 5;
|
|
||||||
|
|
||||||
this.GraphicsComponent.actionOfAnimationEnd += (a) =>
|
|
||||||
{
|
|
||||||
if (a == "playerShootLeft" || a == "playerShootRight")
|
|
||||||
{
|
|
||||||
isShooting = false;
|
|
||||||
}
|
|
||||||
if (a == "playerReload")
|
|
||||||
{
|
|
||||||
bullets++;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool IsAlive { get { return isAlive; } }
|
public bool IsAlive { get { return isAlive; } }
|
||||||
|
@ -251,6 +254,5 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities
|
||||||
isOnGround = false;
|
isOnGround = false;
|
||||||
AppManager.Instance.DebugHUD.Log("FallingThroughPlatform");
|
AppManager.Instance.DebugHUD.Log("FallingThroughPlatform");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
using DangerousD.GameCore.Managers;
|
using DangerousD.GameCore.Managers;
|
||||||
|
using DangerousD.GameCore.Network;
|
||||||
using Microsoft.Xna.Framework;
|
using Microsoft.Xna.Framework;
|
||||||
using Microsoft.Xna.Framework.Content;
|
using Microsoft.Xna.Framework.Content;
|
||||||
using Microsoft.Xna.Framework.Graphics;
|
using Microsoft.Xna.Framework.Graphics;
|
||||||
|
@ -18,6 +19,7 @@ namespace DangerousD.GameCore.Graphics
|
||||||
private List<string> texturesNames;
|
private List<string> texturesNames;
|
||||||
private AnimationContainer currentAnimation;
|
private AnimationContainer currentAnimation;
|
||||||
static private int scaling = 4;
|
static private int scaling = 4;
|
||||||
|
public int parentId;
|
||||||
public AnimationContainer CurrentAnimation
|
public AnimationContainer CurrentAnimation
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
|
@ -105,6 +107,14 @@ namespace DangerousD.GameCore.Graphics
|
||||||
|
|
||||||
public void StartAnimation(string startedanimationId)
|
public void StartAnimation(string startedanimationId)
|
||||||
{
|
{
|
||||||
|
if (startedanimationId == "playerShootRight" && parentId == 17)
|
||||||
|
{
|
||||||
|
string a = "2";
|
||||||
|
}
|
||||||
|
if (AppManager.Instance.multiPlayerStatus != MultiPlayerStatus.SinglePlayer && startedanimationId != GetCurrentAnimation)
|
||||||
|
{
|
||||||
|
AppManager.Instance.NetworkTasks.Add(new NetworkTask(parentId, startedanimationId, Vector2.Zero));
|
||||||
|
}
|
||||||
currentFrame = 0;
|
currentFrame = 0;
|
||||||
currentAnimation = animations.Find(x => x.Id == startedanimationId);
|
currentAnimation = animations.Find(x => x.Id == startedanimationId);
|
||||||
|
|
||||||
|
|
|
@ -111,9 +111,8 @@ namespace DangerousD.GameCore
|
||||||
{
|
{
|
||||||
if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
|
if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
|
||||||
Exit();
|
Exit();
|
||||||
|
|
||||||
if (GameManager.GetPlayer1 != null)
|
if (GameManager.GetPlayer1 != null)
|
||||||
DebugHUD.Set("Objid: ", GameManager.GetPlayer1.id.ToString());
|
DebugHUD.Set("id: ", GameManager.GetPlayer1.id.ToString());
|
||||||
InputManager.Update();
|
InputManager.Update();
|
||||||
SoundManager.Update();
|
SoundManager.Update();
|
||||||
|
|
||||||
|
@ -229,10 +228,11 @@ namespace DangerousD.GameCore
|
||||||
case NetworkTaskOperationEnum.CreateEntity:
|
case NetworkTaskOperationEnum.CreateEntity:
|
||||||
break;
|
break;
|
||||||
case NetworkTaskOperationEnum.SendPosition:
|
case NetworkTaskOperationEnum.SendPosition:
|
||||||
if (networkTask.objId != GameManager.GetPlayer1.id)
|
if (networkTask.objId != GameManager.GetPlayer1.id )
|
||||||
{
|
{
|
||||||
LivingEntity entity = GameManager.livingEntities.Find(x => x.id == networkTask.objId);
|
LivingEntity entity = GameManager.livingEntities.Find(x => x.id == networkTask.objId);
|
||||||
entity.SetPosition(networkTask.position);
|
if (entity != null)
|
||||||
|
entity.SetPosition(networkTask.position);
|
||||||
if (multiPlayerStatus == MultiPlayerStatus.Host)
|
if (multiPlayerStatus == MultiPlayerStatus.Host)
|
||||||
{
|
{
|
||||||
NetworkTasks.Add(networkTask);
|
NetworkTasks.Add(networkTask);
|
||||||
|
@ -240,6 +240,20 @@ namespace DangerousD.GameCore
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case NetworkTaskOperationEnum.ChangeState:
|
case NetworkTaskOperationEnum.ChangeState:
|
||||||
|
if (networkTask.objId != GameManager.GetPlayer1.id)
|
||||||
|
{
|
||||||
|
List<GraphicsComponent> gcs = new List<GraphicsComponent>();
|
||||||
|
foreach (var player in GameManager.players)
|
||||||
|
{
|
||||||
|
gcs.Add(player.GetGraphicsComponent());
|
||||||
|
}
|
||||||
|
LivingEntity entity = GameManager.livingEntities.Find(x => x.id == networkTask.objId);
|
||||||
|
if (entity != null)
|
||||||
|
{
|
||||||
|
GraphicsComponent gc = entity.GetGraphicsComponent();
|
||||||
|
gc.StartAnimation(networkTask.name);
|
||||||
|
}
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case NetworkTaskOperationEnum.ConnectToHost:
|
case NetworkTaskOperationEnum.ConnectToHost:
|
||||||
Player connectedPlayer = new Player(Vector2.Zero, true);
|
Player connectedPlayer = new Player(Vector2.Zero, true);
|
||||||
|
@ -257,13 +271,15 @@ namespace DangerousD.GameCore
|
||||||
if (!GameManager.GetPlayer1.isIdFromHost)
|
if (!GameManager.GetPlayer1.isIdFromHost)
|
||||||
{
|
{
|
||||||
GameManager.GetPlayer1.id = networkTask.objId;
|
GameManager.GetPlayer1.id = networkTask.objId;
|
||||||
|
GraphicsComponent gcsd = GameManager.GetPlayer1.GetGraphicsComponent();
|
||||||
|
gcsd.parentId = networkTask.objId;
|
||||||
GameManager.GetPlayer1.isIdFromHost = true;
|
GameManager.GetPlayer1.isIdFromHost = true;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case NetworkTaskOperationEnum.AddConnectedPlayer:
|
case NetworkTaskOperationEnum.AddConnectedPlayer:
|
||||||
Player remoteConnectedPlayer = new Player(networkTask.position, true);
|
Player remoteConnectedPlayer = new Player(networkTask.position, true);
|
||||||
remoteConnectedPlayer.id = networkTask.objId;
|
remoteConnectedPlayer.id = networkTask.objId;
|
||||||
|
remoteConnectedPlayer.GetGraphicsComponent().parentId = networkTask.objId;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -150,14 +150,21 @@ namespace DangerousD.GameCore
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
||||||
|
|
||||||
{
|
{
|
||||||
for (int i = 0; i < livingEntitiesWithoutPlayers.Count; i++)
|
for (int i = 0; i < livingEntitiesWithoutPlayers.Count; i++)
|
||||||
{
|
{
|
||||||
livingEntitiesWithoutPlayers[i].PlayAnimation();
|
livingEntitiesWithoutPlayers[i].PlayAnimation();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
foreach (Player player in players)
|
||||||
|
{
|
||||||
|
if (player.id != GetPlayer1.id)
|
||||||
|
{
|
||||||
|
player.PlayAnimation();
|
||||||
|
}
|
||||||
|
}
|
||||||
GetPlayer1.Update(gameTime);
|
GetPlayer1.Update(gameTime);
|
||||||
|
|
||||||
foreach (var item in otherObjects)
|
foreach (var item in otherObjects)
|
||||||
item.Update(gameTime);
|
item.Update(gameTime);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue