示例#1
0
        public void Init()
        {
            _host = new TestGame(1);
            //_host.Game.OrderHandler = new ServerOrderHandler(_host.Game, 4888);

            _client    = new Game();
            _netClient = new Networking.NetworkClient("localhost", 4888, new GameVM());//ugly, refactor so GameVM isn't required and or network isnt needed to be created here?
            //_client.OrderHandler = new ClientOrderHandler(_client, _netClient);
        }
示例#2
0
文件: Form2.cs 项目: RubisetCie/box2c
        private void Form2_Load(object sender, EventArgs e)
        {
            using (NetworkDialog dialog = new NetworkDialog())
            {
                dialog.ShowDialog();

                if (!dialog.checkBox1.Checked && (string.IsNullOrEmpty(dialog.textBox2.Text) ||
                    string.IsNullOrEmpty(dialog.textBox1.Text)))
                {
                    Close();
                    return;
                }

                networkOptions.Name = dialog.textBox1.Text;
                networkOptions.IP = dialog.textBox2.Text;
                networkOptions.Hosting = dialog.checkBox1.Checked;
            }

            if (networkOptions.Hosting)
                server = new Networking.NetworkServer();
            else
                client = new Networking.NetworkClient(System.Net.IPAddress.Parse(networkOptions.IP), networkOptions.Name);

            renderWindow = new SFML.Graphics.RenderWindow(pictureBox1.Handle, new ContextSettings(32, 0, 12));
            renderWindow.Resized += new EventHandler<SizeEventArgs>(render_Resized);
            //renderWindow.MouseButtonPressed += new EventHandler<MouseButtonEventArgs>(renderWindow_MouseButtonPressed);
            //renderWindow.MouseButtonReleased += new EventHandler<MouseButtonEventArgs>(renderWindow_MouseButtonReleased);
            //renderWindow.MouseMoved += new EventHandler<MouseMoveEventArgs>(renderWindow_MouseMoved);
            renderWindow.KeyPressed += new EventHandler<SFML.Window.KeyEventArgs>(renderWindow_KeyPressed);
            renderWindow.KeyReleased += new EventHandler<SFML.Window.KeyEventArgs>(renderWindow_KeyReleased);
            renderWindow.Show(true);

            InitOpenGL(pictureBox1.Size, _currentZoom, PointF.Empty);
            Tao.FreeGlut.Glut.glutInit();

            Il.ilInit();
            Ilut.ilutInit();

            _debugDraw = new GDIDebugThing();

            if (networkOptions.Hosting)
            {
                // Define the gravity vector.
                Vector2 gravity = new Vector2(0.0f, -17.0f);

                // Construct a world object, which will hold and simulate the rigid bodies.
                FarseerPhysics.Settings.UseFPECollisionCategories = true;
                FarseerPhysics.Settings.PositionIterations = 8;
                FarseerPhysics.Settings.VelocityIterations = 16;

                world = new World(gravity);
                world.ContactManager.BeginContact += BeginContact;

                {
                    float bottom = (float)(86);
                    float left = (float)(86);

                    FixtureFactory.CreateEdge(world, new Vector2(-left, -bottom), new Vector2(left, -bottom)).Body.UserData = new GroundBodyDescriptor();
                    FixtureFactory.CreateEdge(world, new Vector2(-left, bottom), new Vector2(-left, -bottom)).Body.UserData = new GroundBodyDescriptor();
                    FixtureFactory.CreateEdge(world, new Vector2(left, bottom), new Vector2(left, -bottom)).Body.UserData = new GroundBodyDescriptor();
                    FixtureFactory.CreateEdge(world, new Vector2(left, bottom), new Vector2(-left, bottom)).Body.UserData = new GroundBodyDescriptor();
                }

                players[0] = new Player(world, new Vector2(-24, 0), 9, 9);
                players[1] = new Player(world, new Vector2(24, 0), -9, 9);
            }

            simulationThread = new System.Threading.Thread(SimulationLoop);
            simulationThread.Start();
        }
示例#3
0
        private void Form2_Load(object sender, EventArgs e)
        {
            using (NetworkDialog dialog = new NetworkDialog())
            {
                dialog.ShowDialog();

                if (!dialog.checkBox1.Checked && (string.IsNullOrEmpty(dialog.textBox2.Text) ||
                                                  string.IsNullOrEmpty(dialog.textBox1.Text)))
                {
                    Close();
                    return;
                }

                networkOptions.Name    = dialog.textBox1.Text;
                networkOptions.IP      = dialog.textBox2.Text;
                networkOptions.Hosting = dialog.checkBox1.Checked;
            }

            if (networkOptions.Hosting)
            {
                server = new Networking.NetworkServer();
            }
            else
            {
                client = new Networking.NetworkClient(System.Net.IPAddress.Parse(networkOptions.IP), networkOptions.Name);
            }

            renderWindow          = new SFML.Graphics.RenderWindow(pictureBox1.Handle, new ContextSettings(32, 0, 12));
            renderWindow.Resized += new EventHandler <SizeEventArgs>(render_Resized);
            //renderWindow.MouseButtonPressed += new EventHandler<MouseButtonEventArgs>(renderWindow_MouseButtonPressed);
            //renderWindow.MouseButtonReleased += new EventHandler<MouseButtonEventArgs>(renderWindow_MouseButtonReleased);
            //renderWindow.MouseMoved += new EventHandler<MouseMoveEventArgs>(renderWindow_MouseMoved);
            renderWindow.KeyPressed  += new EventHandler <SFML.Window.KeyEventArgs>(renderWindow_KeyPressed);
            renderWindow.KeyReleased += new EventHandler <SFML.Window.KeyEventArgs>(renderWindow_KeyReleased);
            renderWindow.Show(true);

            InitOpenGL(pictureBox1.Size, _currentZoom, PointF.Empty);
            Tao.FreeGlut.Glut.glutInit();

            Il.ilInit();
            Ilut.ilutInit();

            _debugDraw = new GDIDebugThing();

            if (networkOptions.Hosting)
            {
                // Define the gravity vector.
                Vector2 gravity = new Vector2(0.0f, -17.0f);

                // Construct a world object, which will hold and simulate the rigid bodies.
                FarseerPhysics.Settings.UseFPECollisionCategories = true;
                FarseerPhysics.Settings.PositionIterations        = 8;
                FarseerPhysics.Settings.VelocityIterations        = 16;

                world = new World(gravity);
                world.ContactManager.BeginContact += BeginContact;

                {
                    float bottom = (float)(86);
                    float left   = (float)(86);

                    FixtureFactory.CreateEdge(world, new Vector2(-left, -bottom), new Vector2(left, -bottom)).Body.UserData = new GroundBodyDescriptor();
                    FixtureFactory.CreateEdge(world, new Vector2(-left, bottom), new Vector2(-left, -bottom)).Body.UserData = new GroundBodyDescriptor();
                    FixtureFactory.CreateEdge(world, new Vector2(left, bottom), new Vector2(left, -bottom)).Body.UserData   = new GroundBodyDescriptor();
                    FixtureFactory.CreateEdge(world, new Vector2(left, bottom), new Vector2(-left, bottom)).Body.UserData   = new GroundBodyDescriptor();
                }

                players[0] = new Player(world, new Vector2(-24, 0), 9, 9);
                players[1] = new Player(world, new Vector2(24, 0), -9, 9);
            }

            simulationThread = new System.Threading.Thread(SimulationLoop);
            simulationThread.Start();
        }