protected override void LoadContent() { SpriteBatch = new SpriteBatch(GraphicsDevice); //Create the different managers _chargeBar = new ChargeBar(this, SpriteBatch, Graphics, new Vector2((1900 * Window.ClientBounds.Width) / 1980, (1100 * Window.ClientBounds.Height) / 1080)); _sound = new SoundManager(this); _manager = new GameManager(this); _manager.AddPlayer(new Player(this, "jojo", "ball_red", new Vector3(0, -20, 0))); _manager.LoadGame(1); //Create cameras responsible of following the ball CameraClassic = new Camera(Vector3.Zero, 0, 0, BEPUutilities.Matrix.CreatePerspectiveFieldOfViewRH(MathHelper.PiOver4, Graphics.PreferredBackBufferWidth / (float)Graphics.PreferredBackBufferHeight, .1f, 10000)); Camera = new ChaseCameraControlScheme(_manager.Space.Entities[0], new Vector3(0, 7, 0), false, 50f, CameraClassic, this); //Adding event for sound managing _manager.MainPlayer.Ball.Form.CollisionInformation.Events.ContactCreated += Events_ContactCreated; _manager.MainPlayer.Ball.Form.CollisionInformation.Events.DetectingInitialCollision += Events_DetectingInitialCollision; _manager.MainPlayer.Ball.Form.CollisionInformation.Events.CollisionEnded += Events_CollisionEnded; //Loading font and background for HUD FontSystem fontSystem = FontSystemFactory.Create(GraphicsDevice, 2048, 2048); fontSystem.AddFont(TitleContainer.OpenStream($"{Content.RootDirectory}/font-file.ttf")); _background = Content.Load <Texture2D>("Sprites/background_menu"); //Setup the HUD GuiHelper.Setup(this, fontSystem); _hudFont = Content.Load <SpriteFont>("Hud"); _ui = new IMGUI(); }
/// <summary> /// Constructs the front end and the internal physics representation of the vehicle. /// </summary> /// <param name="position">Position of the tank.</param> /// <param name="owningSpace">Space to add the vehicle to.</param> /// <param name="camera">Camera to attach to the vehicle.</param> /// <param name="game">Running game.</param> /// <param name="drawer">Drawer used to draw the tank.</param> /// <param name="wheelModel">Model to use for the 'wheels' of the tank.</param> /// <param name="wheelTexture">Texture of the wheels on the tank.</param> public TankInput(Vector3 position, Space owningSpace, Camera camera, DemosGame game, ModelDrawer drawer, Model wheelModel, Texture2D wheelTexture) { var bodies = new List<CompoundShapeEntry>() { new CompoundShapeEntry(new BoxShape(4f, 1, 8), new Vector3(0, 0, 0), 500), new CompoundShapeEntry(new BoxShape(3, .7f, 4f), new Vector3(0, .5f + .35f, .5f), 1) }; var body = new CompoundBody(bodies, 501); body.CollisionInformation.LocalPosition = new Vector3(0, .5f, 0); body.Position = (position); //At first, just keep it out of the way. Vehicle = new Vehicle(body); #region RaycastWheelShapes //The wheel model used is not aligned initially with how a wheel would normally look, so rotate them. MaximumDriveForce = 1800; BaseSlidingFriction = 3; Matrix wheelGraphicRotation = Matrix.CreateFromAxisAngle(Vector3.Forward, MathHelper.PiOver2); for (int i = 0; i < 6; i++) { var toAdd = new Wheel( new RaycastWheelShape(.375f, wheelGraphicRotation), new WheelSuspension(2000, 300f, Vector3.Down, 1.3f, new Vector3(-1.9f, 0, -2.9f + i * 1.15f)), new WheelDrivingMotor(10, MaximumDriveForce, MaximumDriveForce), new WheelBrake(7, 7, 1.0f), new WheelSlidingFriction(BaseSlidingFriction, BaseSlidingFriction)); toAdd.DrivingMotor.GripFrictionBlender = FrictionBlender; toAdd.Brake.FrictionBlender = FrictionBlender; toAdd.SlidingFriction.FrictionBlender = FrictionBlender; Vehicle.AddWheel(toAdd); leftTrack.Add(toAdd); } for (int i = 0; i < 6; i++) { var toAdd = new Wheel( new RaycastWheelShape(.375f, wheelGraphicRotation), new WheelSuspension(2000, 300f, Vector3.Down, 1.3f, new Vector3(1.9f, 0, -2.9f + i * 1.15f)), new WheelDrivingMotor(10, 2000, 1000), new WheelBrake(7, 7, 1.0f), new WheelSlidingFriction(BaseSlidingFriction, BaseSlidingFriction)); toAdd.DrivingMotor.GripFrictionBlender = FrictionBlender; toAdd.Brake.FrictionBlender = FrictionBlender; toAdd.SlidingFriction.FrictionBlender = FrictionBlender; Vehicle.AddWheel(toAdd); rightTrack.Add(toAdd); } #endregion foreach (Wheel wheel in Vehicle.Wheels) { //This is a cosmetic setting that makes it looks like the car doesn't have antilock brakes. wheel.Shape.FreezeWheelsWhileBraking = true; //By default, wheels use as many iterations as the space. By lowering it, //performance can be improved at the cost of a little accuracy. wheel.Suspension.SolverSettings.MaximumIterationCount = 1; wheel.Brake.SolverSettings.MaximumIterationCount = 1; wheel.SlidingFriction.SolverSettings.MaximumIterationCount = 1; wheel.DrivingMotor.SolverSettings.MaximumIterationCount = 1; } Space = owningSpace; Space.Add(Vehicle); ModelDrawer = drawer; DisplayModel model; WheelModels = new List<DisplayModel>(); for (int k = 0; k < Vehicle.Wheels.Count; k++) { Vehicle.Wheels[k].Shape.Detector.Tag = "noDisplayObject"; model = new DisplayModel(wheelModel, ModelDrawer); ModelDrawer.Add(model); WheelModels.Add(model); model.Texture = wheelTexture; } CameraControlScheme = new ChaseCameraControlScheme(Vehicle.Body, new Vector3(0, 0.6f, 0), true, 10, camera, game); }
/// <summary> /// Constructs the front end and the internal physics representation of the Vehicle. /// </summary> /// <param name="position">Position of the Vehicle.</param> /// <param name="space">Space to add the Vehicle to.</param> /// <param name="camera">Camera to attach to the Vehicle.</param> /// <param name="game">The running game.</param> /// <param name="drawer">Drawer used to draw the Vehicle.</param> /// <param name="wheelModel">Model of the wheels.</param> /// <param name="wheelTexture">Texture to use for the wheels.</param> public VehicleInput(Vector3 position, Space space, Camera camera, DemosGame game, ModelDrawer drawer, Model wheelModel, Texture2D wheelTexture) { var bodies = new List <CompoundShapeEntry> { new CompoundShapeEntry(new BoxShape((Fix64)2.5m, (Fix64).75m, (Fix64)4.5m), new Vector3(0, 0, 0), 60), new CompoundShapeEntry(new BoxShape((Fix64)2.5m, (Fix64).3m, (Fix64)2f), new Vector3(0, (Fix64).75m / 2 + (Fix64).3m / 2, (Fix64).5m), 1) }; var body = new CompoundBody(bodies, 61); body.CollisionInformation.LocalPosition = new Vector3(0, (Fix64).5m, 0); body.Position = position; //At first, just keep it out of the way. Vehicle = new Vehicle(body); var localWheelRotation = Quaternion.CreateFromAxisAngle(new Vector3(0, 0, 1), MathHelper.PiOver2); //The wheel model used is not aligned initially with how a wheel would normally look, so rotate them. Matrix wheelGraphicRotation = Matrix.CreateFromAxisAngle(Vector3.Forward, MathHelper.PiOver2); Vehicle.AddWheel(new Wheel( new CylinderCastWheelShape((Fix64).375m, (Fix64)0.2m, localWheelRotation, wheelGraphicRotation, false), new WheelSuspension(2000, 100, Vector3.Down, (Fix64)0.325m, new Vector3((Fix64)(-1.1m), (Fix64)(-0.1m), (Fix64)1.8m)), new WheelDrivingMotor((Fix64)2.5m, 30000, 10000), new WheelBrake((Fix64)1.5m, 2, (Fix64).02m), new WheelSlidingFriction(4, 5))); Vehicle.AddWheel(new Wheel( new CylinderCastWheelShape((Fix64).375m, (Fix64)0.2m, localWheelRotation, wheelGraphicRotation, false), new WheelSuspension(2000, 100, Vector3.Down, (Fix64)0.325m, new Vector3((Fix64)(-1.1m), (Fix64)(-0.1m), (Fix64)(-1.8m))), new WheelDrivingMotor((Fix64)2.5m, 30000, 10000), new WheelBrake((Fix64)1.5m, 2, (Fix64).02m), new WheelSlidingFriction(4, 5))); Vehicle.AddWheel(new Wheel( new CylinderCastWheelShape((Fix64).375m, (Fix64)0.2m, localWheelRotation, wheelGraphicRotation, false), new WheelSuspension(2000, 100, Vector3.Down, (Fix64)0.325m, new Vector3((Fix64)1.1m, (Fix64)(-0.1m), (Fix64)1.8m)), new WheelDrivingMotor((Fix64)2.5m, 30000, 10000), new WheelBrake((Fix64)1.5m, 2, (Fix64).02m), new WheelSlidingFriction(4, 5))); Vehicle.AddWheel(new Wheel( new CylinderCastWheelShape((Fix64).375m, (Fix64)0.2m, localWheelRotation, wheelGraphicRotation, false), new WheelSuspension(2000, 100, Vector3.Down, (Fix64)0.325m, new Vector3((Fix64)1.1m, (Fix64)(-0.1m), (Fix64)(-1.8m))), new WheelDrivingMotor((Fix64)2.5m, 30000, 10000), new WheelBrake((Fix64)1.5m, 2, (Fix64).02m), new WheelSlidingFriction(4, 5))); foreach (Wheel wheel in Vehicle.Wheels) { //This is a cosmetic setting that makes it looks like the car doesn't have antilock brakes. wheel.Shape.FreezeWheelsWhileBraking = true; //By default, wheels use as many iterations as the space. By lowering it, //performance can be improved at the cost of a little accuracy. //However, because the suspension and friction are not really rigid, //the lowered accuracy is not so much of a problem. wheel.Suspension.SolverSettings.MaximumIterationCount = 1; wheel.Brake.SolverSettings.MaximumIterationCount = 1; wheel.SlidingFriction.SolverSettings.MaximumIterationCount = 1; wheel.DrivingMotor.SolverSettings.MaximumIterationCount = 1; } Space = space; Space.Add(Vehicle); ModelDrawer = drawer; DisplayModel model; WheelModels = new List <DisplayModel>(); for (int k = 0; k < 4; k++) { Vehicle.Wheels[k].Shape.Detector.Tag = "noDisplayObject"; model = new DisplayModel(wheelModel, ModelDrawer); ModelDrawer.Add(model); WheelModels.Add(model); model.Texture = wheelTexture; } CameraControlScheme = new ChaseCameraControlScheme(Vehicle.Body, new Vector3(0, (Fix64)0.6m, 0), true, 10, camera, game); }
/// <summary> /// Constructs the front end and the internal physics representation of the Vehicle. /// </summary> /// <param name="position">Position of the Vehicle.</param> /// <param name="space">Space to add the Vehicle to.</param> /// <param name="camera">Camera to attach to the Vehicle.</param> /// <param name="game">The running game.</param> /// <param name="drawer">Drawer used to draw the Vehicle.</param> /// <param name="wheelModel">Model of the wheels.</param> /// <param name="wheelTexture">Texture to use for the wheels.</param> public VehicleInput(Vector3 position, Space space, Camera camera, DemosGame game, ModelDrawer drawer, Model wheelModel, Texture2D wheelTexture) { var bodies = new List<CompoundShapeEntry> { new CompoundShapeEntry(new BoxShape(2.5f, .75f, 4.5f), new Vector3(0, 0, 0), 60), new CompoundShapeEntry(new BoxShape(2.5f, .3f, 2f), new Vector3(0, .75f / 2 + .3f / 2, .5f), 1) }; var body = new CompoundBody(bodies, 61); body.CollisionInformation.LocalPosition = new Vector3(0, .5f, 0); body.Position = position; //At first, just keep it out of the way. Vehicle = new Vehicle(body); var localWheelRotation = Quaternion.CreateFromAxisAngle(new Vector3(0, 0, 1), MathHelper.PiOver2); //The wheel model used is not aligned initially with how a wheel would normally look, so rotate them. Matrix wheelGraphicRotation = Matrix.CreateFromAxisAngle(Vector3.Forward, MathHelper.PiOver2); Vehicle.AddWheel(new Wheel( new CylinderCastWheelShape(.375f, 0.2f, localWheelRotation, wheelGraphicRotation, false), new WheelSuspension(2000, 100f, Vector3.Down, 0.325f, new Vector3(-1.1f, -0.1f, 1.8f)), new WheelDrivingMotor(2.5f, 30000, 10000), new WheelBrake(1.5f, 2, .02f), new WheelSlidingFriction(4, 5))); Vehicle.AddWheel(new Wheel( new CylinderCastWheelShape(.375f, 0.2f, localWheelRotation, wheelGraphicRotation, false), new WheelSuspension(2000, 100f, Vector3.Down, 0.325f, new Vector3(-1.1f, -0.1f, -1.8f)), new WheelDrivingMotor(2.5f, 30000, 10000), new WheelBrake(1.5f, 2, .02f), new WheelSlidingFriction(4, 5))); Vehicle.AddWheel(new Wheel( new CylinderCastWheelShape(.375f, 0.2f, localWheelRotation, wheelGraphicRotation, false), new WheelSuspension(2000, 100f, Vector3.Down, 0.325f, new Vector3(1.1f, -0.1f, 1.8f)), new WheelDrivingMotor(2.5f, 30000, 10000), new WheelBrake(1.5f, 2, .02f), new WheelSlidingFriction(4, 5))); Vehicle.AddWheel(new Wheel( new CylinderCastWheelShape(.375f, 0.2f, localWheelRotation, wheelGraphicRotation, false), new WheelSuspension(2000, 100f, Vector3.Down, 0.325f, new Vector3(1.1f, -0.1f, -1.8f)), new WheelDrivingMotor(2.5f, 30000, 10000), new WheelBrake(1.5f, 2, .02f), new WheelSlidingFriction(4, 5))); foreach (Wheel wheel in Vehicle.Wheels) { //This is a cosmetic setting that makes it looks like the car doesn't have antilock brakes. wheel.Shape.FreezeWheelsWhileBraking = true; //By default, wheels use as many iterations as the space. By lowering it, //performance can be improved at the cost of a little accuracy. //However, because the suspension and friction are not really rigid, //the lowered accuracy is not so much of a problem. wheel.Suspension.SolverSettings.MaximumIterationCount = 1; wheel.Brake.SolverSettings.MaximumIterationCount = 1; wheel.SlidingFriction.SolverSettings.MaximumIterationCount = 1; wheel.DrivingMotor.SolverSettings.MaximumIterationCount = 1; } Space = space; Space.Add(Vehicle); ModelDrawer = drawer; DisplayModel model; WheelModels = new List<DisplayModel>(); for (int k = 0; k < 4; k++) { Vehicle.Wheels[k].Shape.Detector.Tag = "noDisplayObject"; model = new DisplayModel(wheelModel, ModelDrawer); ModelDrawer.Add(model); WheelModels.Add(model); model.Texture = wheelTexture; } CameraControlScheme = new ChaseCameraControlScheme(Vehicle.Body, new Vector3(0, 0.6f, 0), true, 10, camera, game); }
/// <summary> /// Constructs the front end and the internal physics representation of the vehicle. /// </summary> /// <param name="position">Position of the tank.</param> /// <param name="owningSpace">Space to add the vehicle to.</param> /// <param name="camera">Camera to attach to the vehicle.</param> /// <param name="game">Running game.</param> /// <param name="drawer">Drawer used to draw the tank.</param> /// <param name="wheelModel">Model to use for the 'wheels' of the tank.</param> /// <param name="wheelTexture">Texture of the wheels on the tank.</param> public TankInput(Vector3 position, Space owningSpace, Camera camera, DemosGame game, ModelDrawer drawer, Model wheelModel, Texture2D wheelTexture) { var bodies = new List <CompoundShapeEntry>() { new CompoundShapeEntry(new BoxShape(4f, 1, 8), new Vector3(0, 0, 0), 500), new CompoundShapeEntry(new BoxShape(3, .7f, 4f), new Vector3(0, .5f + .35f, .5f), 1) }; var body = new CompoundBody(bodies, 501); body.CollisionInformation.LocalPosition = new Vector3(0, .5f, 0); body.Position = (position); //At first, just keep it out of the way. Vehicle = new Vehicle(body); #region RaycastWheelShapes //The wheel model used is not aligned initially with how a wheel would normally look, so rotate them. MaximumDriveForce = 1800; BaseSlidingFriction = 3; Matrix wheelGraphicRotation = Matrix.CreateFromAxisAngle(Vector3.Forward, MathHelper.PiOver2); for (int i = 0; i < 6; i++) { var toAdd = new Wheel( new RaycastWheelShape(.375f, wheelGraphicRotation), new WheelSuspension(2000, 300f, Vector3.Down, 1.3f, new Vector3(-1.9f, 0, -2.9f + i * 1.15f)), new WheelDrivingMotor(10, MaximumDriveForce, MaximumDriveForce), new WheelBrake(7, 7, 1.0f), new WheelSlidingFriction(BaseSlidingFriction, BaseSlidingFriction)); toAdd.DrivingMotor.GripFrictionBlender = FrictionBlender; toAdd.Brake.FrictionBlender = FrictionBlender; toAdd.SlidingFriction.FrictionBlender = FrictionBlender; Vehicle.AddWheel(toAdd); leftTrack.Add(toAdd); } for (int i = 0; i < 6; i++) { var toAdd = new Wheel( new RaycastWheelShape(.375f, wheelGraphicRotation), new WheelSuspension(2000, 300f, Vector3.Down, 1.3f, new Vector3(1.9f, 0, -2.9f + i * 1.15f)), new WheelDrivingMotor(10, 2000, 1000), new WheelBrake(7, 7, 1.0f), new WheelSlidingFriction(BaseSlidingFriction, BaseSlidingFriction)); toAdd.DrivingMotor.GripFrictionBlender = FrictionBlender; toAdd.Brake.FrictionBlender = FrictionBlender; toAdd.SlidingFriction.FrictionBlender = FrictionBlender; Vehicle.AddWheel(toAdd); rightTrack.Add(toAdd); } #endregion foreach (Wheel wheel in Vehicle.Wheels) { //This is a cosmetic setting that makes it looks like the car doesn't have antilock brakes. wheel.Shape.FreezeWheelsWhileBraking = true; //By default, wheels use as many iterations as the space. By lowering it, //performance can be improved at the cost of a little accuracy. wheel.Suspension.SolverSettings.MaximumIterationCount = 1; wheel.Brake.SolverSettings.MaximumIterationCount = 1; wheel.SlidingFriction.SolverSettings.MaximumIterationCount = 1; wheel.DrivingMotor.SolverSettings.MaximumIterationCount = 1; } Space = owningSpace; Space.Add(Vehicle); ModelDrawer = drawer; DisplayModel model; WheelModels = new List <DisplayModel>(); for (int k = 0; k < Vehicle.Wheels.Count; k++) { Vehicle.Wheels[k].Shape.Detector.Tag = "noDisplayObject"; model = new DisplayModel(wheelModel, ModelDrawer); ModelDrawer.Add(model); WheelModels.Add(model); model.Texture = wheelTexture; } CameraControlScheme = new ChaseCameraControlScheme(Vehicle.Body, new Vector3(0, 0.6f, 0), true, 10, camera, game); }