public Vector3 CheckCollisionNormal(ScreenModel CheckArg) { Vector3 Test = Vector3.Zero; if (CheckArg.CollisionType == ObjectTypes.Box) if (this.CollisionType == ObjectTypes.Box) Test = this.CheckBBArray(CheckArg.MovingBoxes, CheckArg.Velocity); return (Test); }
public void ApplyBounce(ScreenModel CheckArg) { //stores the velocity Vector3 StoreVelocity = this.Velocity; //Moves the object backwards this.MoveModelBox(this.Velocity * -1); /*this will figure out which axises the object has to change direction in*/ //checks the X-axis this.MoveModelBox(new Vector3(Velocity.X, 0, 0)); bool intersected = (CheckArg == null) ? false : CheckCollision(CheckArg); if (intersected) { this.MoveModelBox(new Vector3(Velocity.X * -1, 0, 0)); Velocity.X *= -1; } //checks the Y-axis this.MoveModelBox(new Vector3(0, Velocity.Y, 0)); intersected = (CheckArg == null) ? ((Position.Y - ((this.CollisionType == ObjectTypes.Sphere) ? this.GetBoundingSpheres().Radius : DataValues.VectorDistance(this.GetBoundingBoxes().Max - this.Position)) <= 0) ? true : false) : CheckCollision(CheckArg); if (intersected) { this.MoveModelBox(new Vector3(0, Velocity.Y * -1, 0)); Velocity.Y *= -1; FallCntr = 1; } //checks the Z-axis this.MoveModelBox(new Vector3(0, 0, Velocity.Z)); intersected = (CheckArg == null) ? false : CheckCollision(CheckArg); if (intersected) { this.MoveModelBox(new Vector3(0, 0, Velocity.Z * -1)); Velocity.Z *= -1; } //will apply friction only to axises that changed direction if (Velocity.X == StoreVelocity.X * -1) this.Velocity.X *= this.Bounce; if (Velocity.Y == StoreVelocity.Y * -1) this.Velocity.Y *= this.Bounce; if (Velocity.Z == StoreVelocity.Z * -1) this.Velocity.Z *= this.Bounce; //will stop objects if they are moving too slowly if (Math.Abs(this.Velocity.X) < .0001f) this.Velocity.X = 0; if (Math.Abs(this.Velocity.Z) < .0001f) this.Velocity.Z = 0; //if (this.FallCntr < 5) //this.Velocity.Y = 0; }
//uses a series of checks to determine the best method to call for checking collisions, based on the collision type selected public bool CheckCollision(ScreenModel CheckArg) { bool Test = false; if (CheckArg.CollisionType == ObjectTypes.Box) { if (this.CollisionType == ObjectTypes.Box) { Test = this.CheckBBArray(CheckArg.MovingBoxes); } if (this.CollisionType == ObjectTypes.Sphere) { Test = this.CheckBoundingSpheres(CheckArg.MovingBoxes); } } else if (CheckArg.CollisionType == ObjectTypes.Sphere) { if (this.CollisionType == ObjectTypes.Box) { Test = this.CheckBBArray(CheckArg.GetBoundingSpheres()); } if (this.CollisionType == ObjectTypes.Sphere) { Test = this.CheckBoundingSpheres(CheckArg.GetBoundingSpheres()); } } return (Test); }
//method that provides logic in picking up/dropping of an object, called in main program public void DeterminePickUp() { //uses a local variable so that this.HoldingObject is not changing unless someone presses F ScreenModel ThisModel=null; //one cannot hold multiple/different objects if (!HoldingObjectTrue) { ThisModel = ObjectIsInfront(); } else if (DataValues.IsPressed(Keys.F)) { DropObject(); return; } if (ThisModel != null) { //as this method will also return objects that are not pickup-able (like special "Action" objects) this check is needed if ((ThisModel.PickUpable == true)||(IsForgeModeRunning)) { if (((!GamePad.GetState(PlayerIndexValue).IsConnected) && (((DataValues.IsPressed(Keys.F)) && (!LastState.IsKeyDown(Keys.F)))) || ((GamePad.GetState(PlayerIndexValue).IsConnected) && (((GamePad.GetState(PlayerIndexValue).IsButtonDown(Buttons.X)) && (!GamePadLastState.IsButtonDown(Buttons.X))))))) { this.HoldingObject = ThisModel; //1st hit, pick it up if (!HoldingObjectTrue) { PickUpObject(); } //2nd hit, drop the object else { DropObject(); } } } } }
public static void UpdateActions(ScreenModel ThisModel) { if (ThisModel.GetType() == typeof(Wall)) ((Wall)ThisModel).UpdateActionString(); if (ThisModel.GetType() == typeof(Door)) ((Door)ThisModel).UpdateActionString(); if (ThisModel.GetType() == typeof(Light)) ((Light)ThisModel).UpdateActionString(); }
//---------------------------------------protype copy public bool CheckEitherSurroundings(ScreenModel CheckArg, ScreenModel PCheckArg) { //loop that checks the list for chrashing collisions for (int cntr = 0; cntr < NearObjects.Count; cntr++) { //Check this logic out...try using the series of bounding boxes if ((NearObjects[cntr].CheckCollision(CheckArg)) && (NearObjects[cntr] != CheckArg) && (NearObjects[cntr] != PCheckArg)) { //allows us to move moving objects CheckMovingOjects(NearObjects[cntr]); return (false); } } return (true); }
//-----------------------------------end prototype //awesomeness; if an object is moveable and is moving and pushes the person with force, then move the person! //*****TO BE CALLED WHEN A COLLISION HIT HAS BEEN CONFIRMED******** public void CheckMovingOjects(ScreenModel CheckArg) { if ((CheckArg.Moveable)&&(CheckArg.Velocity!=Vector3.Zero)) { //moves camera and entities with it PersonalShield.Center = Position + CheckArg.Velocity; CameraPosition += CheckArg.Velocity; Position = CameraPosition + DataValues.CameraModelOffSet; //moves the object based on any forced applied by the user, running in the opposite direction //for (int counter = 0; counter < DataValues.MovePrecision; counter++) CheckArg.MoveModelBox(this.Velocity); } //move objects that can be moved when I apply force to them if ((CheckArg.Moveable) && (CheckArg.Velocity == Vector3.Zero)) { //for (int counter = 0; counter < DataValues.MovePrecision; counter++) CheckArg.MoveModelBox(this.Velocity); CheckEitherSurroundings(CheckArg, PCheckArg); PCheckArg = CheckArg; } }
/* //overloads the compare to method public int CompareTo(object Object) { //if these are the same object (same memory reference) then return 0 if (Object == this) { return (0); } //if not, return -1 as I don't care if it's located or not return (-1); }*/ //to generically find a door public static bool FindTypeOfDoor(ScreenModel Test) { if (Test.GetType() == typeof(Door)) { return (true); } else { return (false); } }
public static Vector3 FindCenterRoom(ScreenModel screenModel) { //throw new NotImplementedException(); if (screenModel != null) return (screenModel.Position); else return (Vector3.Zero); }
//-------------------------------------------------------------------------------------------------------------- //method that checks if the object is visibly in front of the user private bool ObjectIsInfront(ScreenModel ToTestPickUp) { //use reticule /* if (Math.Abs(ToTestPickUp.Position.X) >= Math.Abs(this.Position.X)) { if (Math.Abs(ToTestPickUp.Position.Y) >= Math.Abs(this.Position.Y)) { if (Math.Abs(ToTestPickUp.Position.Z) >= Math.Abs(this.Position.Z)) { return (true); } } }*/ return (true); }
//method that provides logic in picking up/dropping of an object private void DeterminePickUp(ScreenModel ToTestPickUp) { //Console.WriteLine("Key Hit: "+GameRef.MyScreen.KeyHasBeenPressed(Keys.E)); //first tests if the object can be picked up and if the object is infront of the user if ((ToTestPickUp.PickUpable)&&(ObjectIsInfront(ToTestPickUp))) { //for picking up/putting down objects || //for picking up/putting down objects, with the E button /* (((!GamePad.GetState(PlayerIndexValue).IsConnected) && (GameRef.MyScreen.KeyHasBeenPressed(Keys.E))) ||((GamePad.GetState(PlayerIndexValue).IsConnected) && (GameRef.MyScreen.ButtonHasBeenPressed(Buttons.X)))) */ if ((!GamePad.GetState(PlayerIndexValue).IsConnected) && (Mouse.GetState().LeftButton==ButtonState.Pressed)) //||((GamePad.GetState(PlayerIndexValue).IsConnected) && (GamePad.GetState(PlayerIndexValue).Triggers.Right==)) { Console.WriteLine("Getting Past IF"); //1st hit, pick it up if (!HoldingObjectTrue) { //changes the sign of the bool HoldingObjectTrue = true; //object is now held under a new name this.HoldingObject = ToTestPickUp; //the object's position is infront of you by a set distance infront of you HoldingObject.Position = this.Position + HoldingObjectOffSet; //MOVE BOUNDING BOX WITH OBJECT!!!!!!!!!!!!!!!!!!!!!!!!!!!!! } //2nd hit, drop the object else { HoldingObjectTrue = false; } } } }
//awesomeness; if an object is moveable and is moving and pushes the person with force, then move the person! //*****TO BE CALLED WHEN A COLLISION HIT HAS BEEN CONFIRMED******** private void CheckMovingOjects(ScreenModel CheckArg) { if ((CheckArg.Moveable)&&(CheckArg.Velocity!=Vector3.Zero)) { //moves camera and entities with it PersonalShield.Center = Position + CheckArg.Velocity; CameraPosition += CheckArg.Velocity; Position = CameraPosition + CameraModelOffSet; //moves the object based on any forced applied by the user, running in the opposite direction CheckArg.MoveModelBox(this.Velocity); //updating the drawing is not actually needed, as it is handled by the game's drawing code //CheckArg.Update(); } //move objects that can be moved when I apply force to them if ((CheckArg.Moveable) && (CheckArg.Velocity == Vector3.Zero)) { CheckArg.MoveModelBox(this.Velocity); //CheckArg.Update(); } }