Example #1
0
        public  Shape this[BipedFixtureIndex index]
        {
            get
            {
                switch (index)
                {
                case BipedFixtureIndex.LCalf:
                    return(_shapes[(int)BipedFixtureIndex.RCalf]);

                case BipedFixtureIndex.LFoot:
                    return(_shapes[(int)BipedFixtureIndex.RFoot]);

                case BipedFixtureIndex.LForearm:
                    return(_shapes[(int)BipedFixtureIndex.RForearm]);

                case BipedFixtureIndex.LHand:
                    return(_shapes[(int)BipedFixtureIndex.RHand]);

                case BipedFixtureIndex.LThigh:
                    return(_shapes[(int)BipedFixtureIndex.RThigh]);

                case BipedFixtureIndex.LUpperArm:
                    return(_shapes[(int)BipedFixtureIndex.RUpperArm]);
                }
                return(_shapes[(int)index]);
            }
        }
Example #2
0
 public Shape this[BipedFixtureIndex index]
 {
     get
     {
         switch (index)
         {
         case BipedFixtureIndex.LCalf:
             return _shapes[(int)BipedFixtureIndex.RCalf];
         case BipedFixtureIndex.LFoot:
             return _shapes[(int)BipedFixtureIndex.RFoot];
         case BipedFixtureIndex.LForearm:
             return _shapes[(int)BipedFixtureIndex.RForearm];
         case BipedFixtureIndex.LHand:
             return _shapes[(int)BipedFixtureIndex.RHand];
         case BipedFixtureIndex.LThigh:
             return _shapes[(int)BipedFixtureIndex.RThigh];
         case BipedFixtureIndex.LUpperArm:
             return _shapes[(int)BipedFixtureIndex.RUpperArm];
         }
         return _shapes[(int)index];
     }
 }
Example #3
0
 public BipedBodyDescriptor(BipedFixtureIndex index, Biped biped)
 {
     FixtureIndex = index;
     Biped        = biped;
 }
Example #4
0
 public BipedBodyDescriptor(BipedFixtureIndex index, Biped biped)
 {
     FixtureIndex = index;
     Biped = biped;
 }
Example #5
0
        void Simulate()
        {
            if (networkOptions.Hosting)
            {
                // Prepare for simulation. Typically we use a time step of 1/60 of a
                // second (60Hz) and 10 iterations. This provides a high quality simulation
                // in most game scenarios.
                float timeStep = 1.0f / settingsHz;

                const int MoveSpeed = 450 * 9;

                BipedFixtureIndex[] fixturesToMove;
                float speedMultiplier = 1;

                if (server.Clients.Count != 0)
                {
                    for (int i = 0; i < 2; ++i)
                    {
                        if (server.Clients.Count == i)
                            break;

                        if ((server.Clients[i].Keys & GameKeys.Legs) != 0)
                        {
                            fixturesToMove = new BipedFixtureIndex[] { BipedFixtureIndex.LFoot, BipedFixtureIndex.RFoot };
                            speedMultiplier = 0.25f;
                        }
                        else if ((server.Clients[i].Keys & GameKeys.Hands) != 0)
                        {
                            fixturesToMove = new BipedFixtureIndex[] { BipedFixtureIndex.LHand, BipedFixtureIndex.RHand };
                            speedMultiplier = 0.25f;
                        }
                        else
                            fixturesToMove = new BipedFixtureIndex[] { BipedFixtureIndex.Chest };

                        if ((server.Clients[i].Keys & GameKeys.Up) != 0)
                        {
                            foreach (var x in fixturesToMove)
                                players[i].Biped.Bodies[(int)x].ApplyForce(new Vector2(0, MoveSpeed * speedMultiplier), players[i].Biped.Bodies[(int)x].WorldCenter);
                        }
                        if ((server.Clients[i].Keys & GameKeys.Down) != 0)
                        {
                            foreach (var x in fixturesToMove)
                                players[i].Biped.Bodies[(int)x].ApplyForce(new Vector2(0, (-MoveSpeed / 2) * speedMultiplier), players[i].Biped.Bodies[(int)x].WorldCenter);
                        }
                        if ((server.Clients[i].Keys & GameKeys.Left) != 0)
                        {
                            foreach (var x in fixturesToMove)
                                players[i].Biped.Bodies[(int)x].ApplyForce(new Vector2((-MoveSpeed / 2) * speedMultiplier, 0), players[i].Biped.Bodies[(int)x].WorldCenter);
                        }
                        if ((server.Clients[i].Keys & GameKeys.Right) != 0)
                        {
                            foreach (var x in fixturesToMove)
                                players[i].Biped.Bodies[(int)x].ApplyForce(new Vector2((MoveSpeed / 2) * speedMultiplier, 0), players[i].Biped.Bodies[(int)x].WorldCenter);
                        }

                        players[i].StickingHands = (server.Clients[i].Keys & GameKeys.StickHands) != 0;
                        players[i].StickingLegs = (server.Clients[i].Keys & GameKeys.StickLegs) != 0;

                        if ((server.Clients[i].Keys & GameKeys.StiffToggle) != 0)
                        {
                            players[i].Biped.StickBody();
                            server.Clients[i].Keys &= ~GameKeys.StiffToggle;
                        }
                    }
                }

                // This is our little game loop.
                // Instruct the world to perform a single step of simulation.
                // It is generally best to keep the time step and iterations fixed.
                world.Step(timeStep);

                for (int z = 0; z < 2; ++z)
                for (int i = 0; i < players[z].WeldDefs.Length; ++i)
                {
                    if (players[z].Welds[i] != null && players[z].WeldDefs[i])
                    {
                        world.AddJoint(players[z].Welds[i]);
                        players[z].WeldDefs[i] = false;
                    }

                    if (i < 2 && !players[z].StickingLegs ||
                    i >= 2 && !players[z].StickingHands)
                    {
                        if (players[z].Welds[i] != null)
                        {
                            world.RemoveJoint(players[z].Welds[i]);
                            players[z].Welds[i] = null;
                        }
                    }
                }

                server.Stream.Write((byte)Networking.EClientDataPacketType.FramePacket);
                server.Stream.Write(server.Frame);
                for (int i = 0; i < (int)BipedFixtureIndex.Max; ++i)
                {
                    server.Stream.Write(players[0].Biped.Bodies[(int)i].Position.X);
                    server.Stream.Write(players[0].Biped.Bodies[(int)i].Position.Y);
                    server.Stream.Write(players[0].Biped.Bodies[(int)i].Rotation);

                    server.Stream.Write(players[1].Biped.Bodies[(int)i].Position.X);
                    server.Stream.Write(players[1].Biped.Bodies[(int)i].Position.Y);
                    server.Stream.Write(players[1].Biped.Bodies[(int)i].Rotation);
                }
            }
            else
            {
                if (_oldGameKeys != _gameKeys)
                {
                    client.Udp.Stream.Write((byte)Networking.EServerDataPacketType.ClientCmd);
                    client.Udp.Stream.Write((int)_gameKeys);

                    _oldGameKeys = _gameKeys;
                }

                if ((_gameKeys & GameKeys.StiffToggle) != 0)
                {
                    _gameKeys &= ~GameKeys.StiffToggle;
                    _oldGameKeys &= ~GameKeys.StiffToggle;
                }
            }

            if (networkOptions.Hosting)
            {
                server.Check();

                server.Frame++;
            }
            else
            {
                client.Check();

                client.Frame++;
            }
        }
Example #6
0
        void Simulate()
        {
            if (networkOptions.Hosting)
            {
                // Prepare for simulation. Typically we use a time step of 1/60 of a
                // second (60Hz) and 10 iterations. This provides a high quality simulation
                // in most game scenarios.
                float timeStep = 1.0f / settingsHz;

                const int MoveSpeed = 450 * 9;

                BipedFixtureIndex[] fixturesToMove;
                float speedMultiplier = 1;

                if (server.Clients.Count != 0)
                {
                    for (int i = 0; i < 2; ++i)
                    {
                        if (server.Clients.Count == i)
                        {
                            break;
                        }

                        if ((server.Clients[i].Keys & GameKeys.Legs) != 0)
                        {
                            fixturesToMove  = new BipedFixtureIndex[] { BipedFixtureIndex.LFoot, BipedFixtureIndex.RFoot };
                            speedMultiplier = 0.25f;
                        }
                        else if ((server.Clients[i].Keys & GameKeys.Hands) != 0)
                        {
                            fixturesToMove  = new BipedFixtureIndex[] { BipedFixtureIndex.LHand, BipedFixtureIndex.RHand };
                            speedMultiplier = 0.25f;
                        }
                        else
                        {
                            fixturesToMove = new BipedFixtureIndex[] { BipedFixtureIndex.Chest }
                        };

                        if ((server.Clients[i].Keys & GameKeys.Up) != 0)
                        {
                            foreach (var x in fixturesToMove)
                            {
                                players[i].Biped.Bodies[(int)x].ApplyForce(new Vector2(0, MoveSpeed * speedMultiplier), players[i].Biped.Bodies[(int)x].WorldCenter);
                            }
                        }
                        if ((server.Clients[i].Keys & GameKeys.Down) != 0)
                        {
                            foreach (var x in fixturesToMove)
                            {
                                players[i].Biped.Bodies[(int)x].ApplyForce(new Vector2(0, (-MoveSpeed / 2) * speedMultiplier), players[i].Biped.Bodies[(int)x].WorldCenter);
                            }
                        }
                        if ((server.Clients[i].Keys & GameKeys.Left) != 0)
                        {
                            foreach (var x in fixturesToMove)
                            {
                                players[i].Biped.Bodies[(int)x].ApplyForce(new Vector2((-MoveSpeed / 2) * speedMultiplier, 0), players[i].Biped.Bodies[(int)x].WorldCenter);
                            }
                        }
                        if ((server.Clients[i].Keys & GameKeys.Right) != 0)
                        {
                            foreach (var x in fixturesToMove)
                            {
                                players[i].Biped.Bodies[(int)x].ApplyForce(new Vector2((MoveSpeed / 2) * speedMultiplier, 0), players[i].Biped.Bodies[(int)x].WorldCenter);
                            }
                        }

                        players[i].StickingHands = (server.Clients[i].Keys & GameKeys.StickHands) != 0;
                        players[i].StickingLegs  = (server.Clients[i].Keys & GameKeys.StickLegs) != 0;

                        if ((server.Clients[i].Keys & GameKeys.StiffToggle) != 0)
                        {
                            players[i].Biped.StickBody();
                            server.Clients[i].Keys &= ~GameKeys.StiffToggle;
                        }
                    }
                }

                // This is our little game loop.
                // Instruct the world to perform a single step of simulation.
                // It is generally best to keep the time step and iterations fixed.
                world.Step(timeStep);

                for (int z = 0; z < 2; ++z)
                {
                    for (int i = 0; i < players[z].WeldDefs.Length; ++i)
                    {
                        if (players[z].Welds[i] != null && players[z].WeldDefs[i])
                        {
                            world.AddJoint(players[z].Welds[i]);
                            players[z].WeldDefs[i] = false;
                        }

                        if (i < 2 && !players[z].StickingLegs ||
                            i >= 2 && !players[z].StickingHands)
                        {
                            if (players[z].Welds[i] != null)
                            {
                                world.RemoveJoint(players[z].Welds[i]);
                                players[z].Welds[i] = null;
                            }
                        }
                    }
                }

                server.Stream.Write((byte)Networking.EClientDataPacketType.FramePacket);
                server.Stream.Write(server.Frame);
                for (int i = 0; i < (int)BipedFixtureIndex.Max; ++i)
                {
                    server.Stream.Write(players[0].Biped.Bodies[(int)i].Position.X);
                    server.Stream.Write(players[0].Biped.Bodies[(int)i].Position.Y);
                    server.Stream.Write(players[0].Biped.Bodies[(int)i].Rotation);

                    server.Stream.Write(players[1].Biped.Bodies[(int)i].Position.X);
                    server.Stream.Write(players[1].Biped.Bodies[(int)i].Position.Y);
                    server.Stream.Write(players[1].Biped.Bodies[(int)i].Rotation);
                }
            }
            else
            {
                if (_oldGameKeys != _gameKeys)
                {
                    client.Udp.Stream.Write((byte)Networking.EServerDataPacketType.ClientCmd);
                    client.Udp.Stream.Write((int)_gameKeys);

                    _oldGameKeys = _gameKeys;
                }

                if ((_gameKeys & GameKeys.StiffToggle) != 0)
                {
                    _gameKeys    &= ~GameKeys.StiffToggle;
                    _oldGameKeys &= ~GameKeys.StiffToggle;
                }
            }

            if (networkOptions.Hosting)
            {
                server.Check();

                server.Frame++;
            }
            else
            {
                client.Check();

                client.Frame++;
            }
        }

        void OnGLResize()
        {
            InitOpenGL(pictureBox1.Size, _currentZoom, PointF.Empty);
        }