public Game1() { graphics = new GraphicsDeviceManager(this); Content.RootDirectory = "Content"; //Turn on and off rendering bounding boxes m_PhysicsDebug = false; m_debugMode = false; //Starting amount of money m_Money = 5; //The amount of prizes won m_prizesObtained = 0; //Current state of the UFO m_ufoState = e_UFOStates.e_freeRoam; //Checker to make sure only 1 coin/money is inserted at a time. m_coinInsertedOnceChecker = true; //Initalize lists m_GameObjects = new List<GameObject>(); m_prizesList = new List<Prize>(); //Turn on and off sounds m_playSounds = true; }
//Collision function for the UFO public bool UFOCollisionDetection(CollisionSkin owner, CollisionSkin collidee) { //If the UFO collides with the bottom of the box if (collidee.Equals(m_UFOCatcherBox.m_skin) && m_ufoState == e_UFOStates.e_grabbing) { m_ufoState = e_UFOStates.e_moveBackUp; return true; } //If the UFO collides with a prize foreach( Prize ob in m_prizesList) { if( collidee.Equals(ob.m_skin)) { //Move the ufo back and m_ufoState = e_UFOStates.e_moveBackUp; ob.m_UFOBody = m_UFO.m_body; ob.moveToTarget = true; return true; } } // all other collisions will be handled by physicengine return true; }
public void UFOLogic() { KeyboardState keyboardState = Keyboard.GetState(); GamePadState gamePadState = GamePad.GetState(PlayerIndex.One); //Grabbing dropping states for logic if (m_ufoState == e_UFOStates.e_freeRoam) { //If there is atleast 1 coin inserted allow the player to move the UFO if (m_coinsInserted > 0) { if (keyboardState.IsKeyDown(Keys.Left) || gamePadState.DPad.Left == ButtonState.Pressed) { m_UFOController.force0 = new Vector3(-GameVariables.ufoMoveSpeed, 0, 0); } else if (keyboardState.IsKeyDown(Keys.Right) || gamePadState.DPad.Right == ButtonState.Pressed) { m_UFOController.force0 = new Vector3(GameVariables.ufoMoveSpeed, 0, 0); } else if (keyboardState.IsKeyDown(Keys.Up) || gamePadState.DPad.Up == ButtonState.Pressed) { m_UFOController.force0 = new Vector3(0, 0, -GameVariables.ufoMoveSpeed); } else if (keyboardState.IsKeyDown(Keys.Down) || gamePadState.DPad.Down == ButtonState.Pressed) { m_UFOController.force0 = new Vector3(0, 0, GameVariables.ufoMoveSpeed); } //Set the UFO to grab if (keyboardState.IsKeyDown(Keys.Space) || gamePadState.Buttons.A == ButtonState.Pressed) { //Clear forces and set all forces to 0 so the UFO doesn't move based on previous moving forces. m_UFO.m_body.ClearForces(); m_UFO.m_body.Velocity = new Vector3(0, 0, 0); m_UFOController.force0 = Vector3.Zero; //Remove a try/coin m_coinsInserted--; //Play grabbing Sound effect if (m_playSounds) m_UFObeamingSE.Play(); //Change state to grabbing m_ufoState = e_UFOStates.e_grabbing; } } } else if (m_ufoState == e_UFOStates.e_grabbing) { m_mainCamera = m_FirstPersonCamera; //Move UFO down m_UFOController.force0 = new Vector3(0, -GameVariables.grabSpeed, 0); } else if (m_ufoState == e_UFOStates.e_moveBackUp) { //If the body of the UFO is not at/around the original position if (m_UFO.m_body.Position.Y < m_UFO.m_GOPos.Y) { //Move it back up m_UFOController.force0 = new Vector3(0, GameVariables.grabSpeed, 0); } //If it has else if (m_UFO.m_body.Position.Y >= m_UFO.m_GOPos.Y) { //Clear all forces again so it doesn't move higher m_UFO.m_body.ClearForces(); m_UFO.m_body.Velocity = new Vector3(0, 0, 0); m_UFOController.force0 = Vector3.Zero; //Change state to move across m_ufoState = e_UFOStates.e_moveBackAcross; } } else if (m_ufoState == e_UFOStates.e_moveBackAcross) { //Seek to the original position with slowing down algorithm based on the steering paper Vector3 targetOffset = m_UFO.m_GOPos - m_UFO.m_body.Position; float distance = targetOffset.Length(); float rampedSpeed = GameVariables.ufoMoveSpeed * (distance/50); float clippedSpeed = MathHelper.Min(rampedSpeed, GameVariables.ufoMoveSpeed); Vector3 desiredVelocity = (clippedSpeed/distance) * targetOffset; Vector3 steering = desiredVelocity - m_UFO.m_body.Velocity; m_UFOController.force0 = steering; //If the UFO is within the distance from the starting point if (distance <= 0.5f) { //Clear forces m_UFO.m_body.ClearForces(); m_UFO.m_body.Velocity = new Vector3(0, 0, 0); m_UFOController.force0 = Vector3.Zero; //Change state to drop the prizes m_ufoState = e_UFOStates.e_drop; } } else if (m_ufoState == e_UFOStates.e_drop) { //Drop all prizes. The ones grabbed will fall while the ones not grabbed will stay still foreach (Prize ob in m_prizesList) { ob.Drop(); } m_mainCamera = m_ThirdPersonCamera; //Allow the player to move again m_ufoState = e_UFOStates.e_freeRoam; } }
public bool PrizeCollisionDetection(CollisionSkin owner, CollisionSkin collidee) { //If the UFO collides with the bottom of the box if (collidee.Equals(m_UFO.m_skin) && m_ufoState == e_UFOStates.e_grabbing) { m_ufoState = e_UFOStates.e_moveBackUp; return true; } // here is handled what happens if your Object collides with another special Object (= OtherObject) foreach (Prize ob in m_prizesList) { if (collidee.Equals(ob.m_skin)) { ob.m_body = null; ob.m_skin = null; m_GameObjects.Remove(ob); m_prizesList.Remove(ob); Components.Remove(ob); m_prizesObtained++; return true; } } // all other collisions will be handled by physicengine return true; }