public void ExecuteCommand(float deltaTime) { if (playerCommands.Count > 0) { PlayerCommandObject command = playerCommands.Dequeue(); ApplyPlayerCommand(command, deltaTime); } }
private void ApplyPlayerCommand(PlayerCommandObject command, float deltaTime) { if (command.Command.HasFlag(PlayerCommand.UP)) { Transform.p.Y -= Constants.PLAYER_SPEED * Constants.DELTA_TIME; IsCollidingWithWall = Room.IsCollisionWithMap(this); if (IsCollidingWithWall) { Transform.p.Y += Constants.PLAYER_SPEED * Constants.DELTA_TIME; } } else if (command.Command.HasFlag(PlayerCommand.Down)) { Transform.p.Y += Constants.PLAYER_SPEED * Constants.DELTA_TIME; IsCollidingWithWall = Room.IsCollisionWithMap(this); if (IsCollidingWithWall) { Transform.p.Y -= Constants.PLAYER_SPEED * Constants.DELTA_TIME; } } if (command.Command.HasFlag(PlayerCommand.Left)) { Transform.p.X += Constants.PLAYER_SPEED * Constants.DELTA_TIME; IsCollidingWithWall = Room.IsCollisionWithMap(this); if (IsCollidingWithWall) { Transform.p.X -= Constants.PLAYER_SPEED * Constants.DELTA_TIME; } } else if (command.Command.HasFlag(PlayerCommand.Right)) { Transform.p.X -= Constants.PLAYER_SPEED * Constants.DELTA_TIME; IsCollidingWithWall = Room.IsCollisionWithMap(this); if (IsCollidingWithWall) { Transform.p.X += Constants.PLAYER_SPEED * Constants.DELTA_TIME; } } if (command.Command.HasFlag(PlayerCommand.Rotate)) { //Transform.r = command.Rotation; //angle = command.Rotation; } if (command.Command.HasFlag(PlayerCommand.Shoot)) { //var bullet = game.GetAvaliableBullet(); //// todo: make Gun offset constant (offset moved inside init) //bullet.Init(Peer.ID, Transform.p.X + 0.0f, Transform.p.Y, angle); } playerStateCache = PlayerStateOperation.GetOperation(command.seqNo, Peer.Id, (int)(base.Transform.p.X * 1000), (int)(base.Transform.p.Y * 1000), (int)(command.Rotation * 1000), (int)(Hp * 1000), command.Command.HasFlag(PlayerCommand.Shoot)); SendToAll((Operation)playerStateCache); // logger.Information($"pId {Peer.ID} Proximity: {ProximityList.Count} - cmd {command.Command} - Pos {Transform.p} - Rot {angle} - seqNo {command.seqNo}"); }
public void AddPlayerCommand(PlayerCommandObject command) { playerCommands.Enqueue(command); }