Example #1
0
        private void Update()
        {
            double time = DateTime.UtcNow.TimeOfDay.TotalSeconds;

            byte[] bytes;
            if (time - lastIterationTime >= iterationTime)
            {
                gameTime++;
                float deltaTime = (float)(time - lastIterationTime);
                lastIterationTime = time;
                for (int i = 0; i < players.Count; i++)
                {
                    if (players[i].Initialized && !CheckPlayerConnection(players[i]))
                    {
                        structConverter.ConvertStructToBytes(new DestroyShipActionData()
                        {
                            id = players[i].Id
                        }, DataType.DestroyShipAction, out bytes);
                        players.RemoveAt(i);
                        i--;
                        foreach (Player player in players)
                        {
                            player.SendTcpData(bytes);
                        }
                    }
                }
                ShipStateData[] shipsStateData = new ShipStateData[players.Count];
                projectilesController.Update(deltaTime);
                physicsController.CheckCollisions();

                for (int i = 0; i < players.Count; i++)
                {
                    shipsStateData[i] = players[i].GetShipStateData(time - 0.2d);
                    if (shipsStateData[i].shipData.health <= 0f)
                    {
                        DestroyShipActionData destroyShipActionData = new DestroyShipActionData()
                        {
                            id = shipsStateData[i].shipId
                        };
                        structConverter.ConvertStructToBytes(destroyShipActionData, DataType.DestroyShipAction, out bytes);
                        foreach (Player player in players)
                        {
                            player.SendTcpData(bytes);
                        }
                        players[i].CreateShip();
                        structConverter.ConvertStructToBytes(players[i].GetCreateShipActionData(), DataType.CreateShipAction, out bytes);
                        foreach (Player player in players)
                        {
                            player.SendTcpData(bytes);
                        }
                    }
                }
                structConverter.ConvertStructsToBytes(shipsStateData, DataType.ShipState, out bytes);
                foreach (Player player in players)
                {
                    udp.SendTo(bytes, player.PlayerEndPoint);
                }
            }
        }
Example #2
0
        public void Update(float deltaTime)
        {
            GUIController.Update(deltaTime);

            particleSystem.Update(deltaTime);

            camera.Update(deltaTime);

            foreach (IController controller in controllers)
            {
                controller.Update(deltaTime);
            }

            physicsController.CheckCollisions();
            netController.Update();
        }