Ejemplo n.º 1
0
        //static int counter = 0;
        /// <summary>
        /// Empties current update queue and processes it. Resets timeout counter for players that sent an update.
        /// </summary>
        /// <param name="dt">Delta time in seconds</param>
        void ProcessClientUpdates(double dt)
        {
            foreach (var u in clientsManager.PollClientUpdates())
            {
                if (u.DT < 0.0f)                //Means that the client quit
                {
                    var cmd = new Shared.PlayerDisconnectedCmd(u.PlayerID);
                    sCmdsToBroadcast.Add(cmd);
                    eCmdsToExecute.Add(cmd.Translate());
                }
                else if (engine.World.players.TryGetValue(u.PlayerID, out Player player))
                {
                    //Tick down the cooldown
                    if (player.CurrFireCooldown > 0.0)
                    {
                        player.CurrFireCooldown -= u.DT;
                    }
                    eCmdsToExecute.Add(u.GenPlayerMovement());
                    eCmdsToExecute.Add(u.GenTowerCmd());

                    if (u.LeftMouse && player.CurrFireCooldown <= 0.0)
                    {
                        //Reset the cooldown
                        player.CurrFireCooldown += Player.fireCooldown;
                        //Shift to have zero angle=(1,0) dir
                        var shootingAngle = player.TowerAngle - MathHelper.PiOver2;
                        var dir           = new Vector2((float)Math.Cos(shootingAngle), (float)Math.Sin(shootingAngle));
                        var cmd           = new Shared.PlayerFireCmd(u.PlayerID, dir, player.Position.Xy);
                        sCmdsToBroadcast.Add(cmd);
                        eCmdsToExecute.Add(cmd.Translate());
                    }
                }
            }
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Tick connected players, enqueues ServerCmds,EngineCmds representing timed-out players.
 /// </summary>
 void TickClients()
 {
     foreach (var timedOutID in clientsManager.TickClients(ticksToTimeout))
     {
         var sCmd = new Shared.PlayerDisconnectedCmd(timedOutID);
         sCmdsToBroadcast.Add(sCmd);
         eCmdsToExecute.Add(sCmd.Translate());
     }
 }