コード例 #1
0
        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            // TODO: Add your initialization logic here
            world = new WorldGraphics();

            model = new GraphicsModel();
            int diameter = 64;
            int radius = diameter/2;
            int spriteID = 201;
            int id = 0;
            int space = 3;
            for (int y = 0; y < 3; y++)
            {
                for (int x = 0; x < 3; x++)
                {
                    model.Update(new GraphicsObject(id, (diameter*(x+1))+space*x, (diameter*(y+1))+space*y, radius, 0, spriteID, id));
                    id++;
                }
            }

            world.SetGraphicsModel(model);

            base.Initialize();
        }
コード例 #2
0
 ///<summary>Sets the GraphicsModel that this class will reference and use
 /// to render the game world.</summary>
 /// <param name="model">The GraphicsModel object that this class will use</param>
 public void SetGraphicsModel(GraphicsModel model)
 {
     this.model = model;
 }
コード例 #3
0
        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// </summary>
        protected override void Initialize()
        {
            // TODO: Add some name detection from forms.
            strName = "nicktest";
            world = new WorldGraphics();
            model = new GraphicsModel();
            world.SetGraphicsModel(model);

            //Setup ships for players 1 & 2 (offscreen to start)
            //GraphicsObject(int id, float x, float y, float radius, float angle, int spriteID, int colorID)
            GraphicsObject ship1 = new GraphicsObject(1, 0, 0, 16, 0, 1, 5);
            model.Update(ship1);
            shipList.Add(ship1);
            GraphicsObject ship2 = new GraphicsObject(2, -16, -16, 16, 0, 1, 7);
            model.Update(ship2);
            shipList.Add(ship2);

            //Setup planet
            GraphicsObject planet = new GraphicsObject(3, 400, 300, 32, 0, 201, 0);
            model.Update(planet);
            planetList.Add(planet);

            //******** Networking Stuff *************
            //Using UDP sockets
            clientSocket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
            IPHostEntry ipHostInfo = Dns.Resolve(Dns.GetHostName());
            IPAddress ipAddress = ipHostInfo.AddressList[0];
            Console.WriteLine(ipAddress);

            //Server is listening on port 1000
            IPEndPoint ipEndPoint = new IPEndPoint(ipAddress, 11000);
            epServer = (EndPoint)ipEndPoint;

            //Get message ready
            Data msgToSend = new Data();
            msgToSend.cmdCommand = Command.Login;
            msgToSend.strMessage = null;
            msgToSend.strName = strName;
            byte[] byteData = msgToSend.ToByte();

            //Login to the server
            clientSocket.BeginSendTo(byteData, 0, byteData.Length, SocketFlags.None, epServer, new AsyncCallback(OnSend), null);
            byteData = new byte[1024];
            //Start listening to the data asynchronously
            clientSocket.BeginReceiveFrom(byteData, 0, byteData.Length, SocketFlags.None, ref epServer, new AsyncCallback(OnReceive), null);
            //******** End Networking Stuff *************
            base.Initialize();
        }