Esempio n. 1
0
        public static void Start(float w, float h, int max)
        {
            width  = w;
            height = h;

            World = new World(new Vector2(0, 0));

            maxShips = max;
            ships    = new List <Ship>();

            SpawnQueue = new ShipQueue(32);

            CreateBounds(width, height);

            var asteroidCount = (width * height) / 50;

            for (var i = 0; i < (int)asteroidCount; i++)
            {
                var position = FindOpenSpace(new Vector2(2, 2));
                if (!position.HasValue)
                {
                    throw new Exception("oh my god too many asteroids");
                }

                var asteroid = CreateAsteroid();
                asteroid.Position = position.Value;
                asteroid.Rotation = (float)(Random.NextDouble() * (Math.PI * 2));
            }

            Server.Connected += session =>
            {
                var scene = new Scene();
                scene.Width  = width * Constants.PixelsPerMeter;
                scene.Height = height * Constants.PixelsPerMeter;

                foreach (var body in World.BodyList)
                {
                    var data = (RadarData)body.UserData;

                    if (data.UserData == null)
                    {
                        continue;
                    }

                    var netObj = (NetObject)data.UserData;
                    if (netObj.IsStatic)
                    {
                        scene.Items.Add(netObj);
                    }
                }

                Server.Send(scene, session, NetDeliveryMethod.ReliableUnordered);
            };
        }
Esempio n. 2
0
        public static void Start(float w, float h, int max)
        {
            width = w;
            height = h;

            World = new World(new Vector2(0, 0));

            maxShips = max;
            ships = new List<Ship>();

            SpawnQueue = new ShipQueue(32);

            CreateBounds(width, height);

            var asteroidCount = (width * height) / 50;
            for (var i = 0; i < (int)asteroidCount; i++)
            {
                var position = FindOpenSpace(new Vector2(2, 2));
                if (!position.HasValue)
                    throw new Exception("oh my god too many asteroids");

                var asteroid = CreateAsteroid();
                asteroid.Position = position.Value;
                asteroid.Rotation = (float)(Random.NextDouble() * (Math.PI * 2));
            }

            Server.Connected += session =>
            {
                var scene = new Scene();
                scene.Width = width * Constants.PixelsPerMeter;
                scene.Height = height * Constants.PixelsPerMeter;

                foreach (var body in World.BodyList)
                {
                    var data = (RadarData)body.UserData;

                    if (data.UserData == null)
                        continue;

                    var netObj = (NetObject)data.UserData;
                    if (netObj.IsStatic)
                        scene.Items.Add(netObj);
                }

                Server.Send(scene, session, NetDeliveryMethod.ReliableUnordered);
            };
        }