Beispiel #1
0
        public PlayerPhysicsCharacter(Entity owner, World world, Vector2 position, float width, float height, float density, OnCollision onCollision, OnSeparation onSeparation)
            : base(owner, world, position, width, height, density, onCollision, onSeparation)
        {
            // Load resources
            ConfigFile configFile = PhysicsSystem.GetPhysicsConfigFile();

            runSpeed              = configFile.SettingGroups[physicsSettings].Settings["runSpeed"].GetValueAsFloat();
            runAirControlSpeed    = configFile.SettingGroups[physicsSettings].Settings["airControlSpeed"].GetValueAsFloat();
            jumpImpulse           = configFile.SettingGroups[physicsSettings].Settings["jumpImpulse"].GetValueAsFloat();
            wallJumpImpulse       = configFile.SettingGroups[physicsSettings].Settings["wallJumpImpulse"].GetValueAsFloat();
            airControlAbility     = configFile.SettingGroups[physicsSettings].Settings["airControlAbility"].GetValueAsFloat();
            terminalVelocity      = configFile.SettingGroups[physicsSettings].Settings["terminalVelocity"].GetValueAsFloat();
            slideTerminalVelocity = configFile.SettingGroups[physicsSettings].Settings["slideTerminalVelocity"].GetValueAsFloat();
            dashMultiplier        = configFile.SettingGroups[physicsSettings].Settings["dashMultiplier"].GetValueAsFloat();

            wallSlideEnabled       = false;
            onGroundTimer          = new Timer();
            onLeftWallTimer        = new Timer();
            onRightWallTimer       = new Timer();
            enableOnGroundDelay    = true;
            enableOnLeftWallDelay  = true;
            enableOnRightWallDelay = true;

            moveSpeed       = runSpeed;
            airControlSpeed = runAirControlSpeed;
        }
Beispiel #2
0
        public Game1()
        {
            ConfigFile configFile = new ConfigFile(gameSettingsIni);

            // engine settings
            gameSpeed = configFile.SettingGroups[engineSettings].Settings["gameSpeed"].GetValueAsFloat();
            defaultResolutionHeight = configFile.SettingGroups[engineSettings].Settings["defaultResolutionHeight"].GetValueAsInt();
            enableDebugging         = configFile.SettingGroups[engineSettings].Settings["enableDebugging"].GetValueAsBool();
            this.ShowDebugView      = false;

            // video settings
            graphics = new GraphicsDeviceManager(this);
            graphics.IsFullScreen = configFile.SettingGroups[videoSettings].Settings["Fullscreen"].GetValueAsBool();
            if (graphics.IsFullScreen)
            {
                graphics.PreferredBackBufferWidth  = configFile.SettingGroups[videoSettings].Settings["Width"].GetValueAsInt();
                graphics.PreferredBackBufferHeight = configFile.SettingGroups[videoSettings].Settings["Height"].GetValueAsInt();
            }
            else
            {
                // default resolution and windowed resolution
                graphics.PreferredBackBufferWidth  = 1280;
                graphics.PreferredBackBufferHeight = 720;
            }
            SetVsync(configFile.SettingGroups[videoSettings].Settings["Vsync"].GetValueAsBool());
            graphics.ApplyChanges();

            if (enableDebugging)
            {
                Components.Add(new DebugComponent(this, Content, graphics));
            }

            Content.RootDirectory = "Content";
            physicsSystem         = new PhysicsSystem();
            ConvertUnits.SetDisplayUnitToSimUnitRatio(64f);

            // players get updated twice as much as all other entities
            playersFixedTimeStep = new FixedTimeStepSystem(fixedTimestep, maxSteps, new SingleStep(PlayersSingleStep), new PostStepping(PlayersPostStepping));
            fixedTimeStep        = new FixedTimeStepSystem(fixedTimestep * 2f, maxSteps, new SingleStep(SingleStep), new PostStepping(PostStepping));

            // general settings
            GameVariables.NumPlayers = configFile.SettingGroups[generalSettings].Settings["NumPlayers"].GetValueAsInt();
            GameVariables.Difficulty = configFile.SettingGroups[generalSettings].Settings["Difficulty"].GetValueAsInt();
            GameVariables.Pvp        = configFile.SettingGroups[generalSettings].Settings["Pvp"].GetValueAsBool();
        }
Beispiel #3
0
        public Game1()
        {
            ConfigFile configFile = new ConfigFile(gameSettingsIni);

            // engine settings
            gameSpeed = configFile.SettingGroups[engineSettings].Settings["gameSpeed"].GetValueAsFloat();
            defaultResolutionHeight = configFile.SettingGroups[engineSettings].Settings["defaultResolutionHeight"].GetValueAsInt();
            enableDebugging = configFile.SettingGroups[engineSettings].Settings["enableDebugging"].GetValueAsBool();
            this.ShowDebugView = false;

            // video settings
            graphics = new GraphicsDeviceManager(this);
            graphics.IsFullScreen = configFile.SettingGroups[videoSettings].Settings["Fullscreen"].GetValueAsBool();
            if (graphics.IsFullScreen)
            {
                graphics.PreferredBackBufferWidth = configFile.SettingGroups[videoSettings].Settings["Width"].GetValueAsInt();
                graphics.PreferredBackBufferHeight = configFile.SettingGroups[videoSettings].Settings["Height"].GetValueAsInt();
            }
            else
            {
                // default resolution and windowed resolution
                graphics.PreferredBackBufferWidth = 1280;
                graphics.PreferredBackBufferHeight = 720;
            }
            SetVsync(configFile.SettingGroups[videoSettings].Settings["Vsync"].GetValueAsBool());
            graphics.ApplyChanges();

            if (enableDebugging)
            {
                Components.Add(new DebugComponent(this, Content, graphics));
            }

            Content.RootDirectory = "Content";
            physicsSystem = new PhysicsSystem();
            ConvertUnits.SetDisplayUnitToSimUnitRatio(64f);

            // players get updated twice as much as all other entities
            playersFixedTimeStep = new FixedTimeStepSystem(fixedTimestep, maxSteps, new SingleStep(PlayersSingleStep), new PostStepping(PlayersPostStepping));
            fixedTimeStep = new FixedTimeStepSystem(fixedTimestep * 2f, maxSteps, new SingleStep(SingleStep), new PostStepping(PostStepping));

            // general settings
            GameVariables.NumPlayers = configFile.SettingGroups[generalSettings].Settings["NumPlayers"].GetValueAsInt();
            GameVariables.Difficulty = configFile.SettingGroups[generalSettings].Settings["Difficulty"].GetValueAsInt();
            GameVariables.Pvp = configFile.SettingGroups[generalSettings].Settings["Pvp"].GetValueAsBool();
        }
Beispiel #4
0
        protected override void SetUpPhysics(Entity owner, World world, Vector2 position, float width, float height, float density)
        {
            // Load resources
            ConfigFile configFile = PhysicsSystem.GetPhysicsConfigFile();

            brakeSpeed              = configFile.SettingGroups[physicsSettings].Settings["brakeSpeed"].GetValueAsFloat();
            defaultBodyFriction     = configFile.SettingGroups[physicsSettings].Settings["defaultBodyFriction"].GetValueAsFloat();
            defaultBodyRestitution  = configFile.SettingGroups[physicsSettings].Settings["defaultBodyRestitution"].GetValueAsFloat();
            defaultWheelFriction    = configFile.SettingGroups[physicsSettings].Settings["defaultWheelFriction"].GetValueAsFloat();
            defaultWheelRestitution = configFile.SettingGroups[physicsSettings].Settings["defaultWheelRestitution"].GetValueAsFloat();

            //Create a fixture with a body almost the size of the entire object
            //but with the bottom part cut off.
            float upperBodyHeight = height - (width / 2);

            body          = BodyFactory.CreateRectangle(world, (float)ConvertUnits.ToSimUnits(width), (float)ConvertUnits.ToSimUnits(upperBodyHeight), density / 2);
            body.BodyType = BodyType.Dynamic;

            // tested a rounded rectangle.. didn't work so well. Should I revisit? ***
            //body = BodyFactory.CreateRoundedRectangle(world, ConvertUnits.ToSimUnits(width), ConvertUnits.ToSimUnits(upperBodyHeight), ConvertUnits.ToSimUnits(0.5f), ConvertUnits.ToSimUnits(0.5f), 2, density / 2, ConvertUnits.ToSimUnits(position));
            //body.BodyType = BodyType.Dynamic;

            // player needs low restitution so he won't bounce on the ground
            // and low friction to avoid the "edge catching" problem
            body.Restitution = defaultBodyRestitution;
            body.Friction    = defaultBodyFriction;
            fixture          = body.FixtureList[0];

            //also shift it up a tiny bit to keep the new object's center correct
            body.Position = ConvertUnits.ToSimUnits(position - (Vector2.UnitY * (width / 4)));
            centerOffset  = position.Y - (float)ConvertUnits.ToDisplayUnits(body.Position.Y); //remember the offset from the center for drawing

            //Now let's make sure our upperbody is always facing up.
            fixedAngleJoint = JointFactory.CreateFixedAngleJoint(world, body);

            // Create our bottom part of the player which interacts with the terrain
            wheelBody = BodyFactory.CreateCircle(world, (float)ConvertUnits.ToSimUnits(width / 2), density / 2);

            //And position its center at the bottom of the upper body
            wheelBody.Position    = body.Position + ConvertUnits.ToSimUnits(Vector2.UnitY * (upperBodyHeight / 2));
            wheelBody.BodyType    = BodyType.Dynamic;
            wheelBody.Restitution = defaultWheelRestitution;
            //Set the friction higher for fast stopping/starting
            //or set it lower to make the character slip.
            wheelBody.Friction = defaultWheelFriction;

            //These two bodies together are width wide and height high :)
            //So lets connect them together
            motor = JointFactory.CreateRevoluteJoint(world, body, wheelBody, Vector2.Zero);
            motor.MotorEnabled   = true;
            motor.MaxMotorTorque = defaultMaxMotorTorque;
            motor.MotorSpeed     = 0;

            //Make sure the two fixtures don't collide with each other
            wheelBody.IgnoreCollisionWith(body);
            body.IgnoreCollisionWith(wheelBody);

            // make sure the bodies point to the owners
            wheelBody.UserData = owner;
            body.UserData      = owner;

            // so that we don't slip off the edge
            brakeJoint = JointFactory.CreateFixedAngleJoint(world, wheelBody);

            // Set contact handlers
            body.OnCollision       += new OnCollisionEventHandler(onCollisionWithBody);
            body.OnSeparation      += new OnSeparationEventHandler(onSeparationWithBody);
            wheelBody.OnCollision  += new OnCollisionEventHandler(onCollisionWithBottom);
            wheelBody.OnSeparation += new OnSeparationEventHandler(onSeparationWithBottom);
        }