protected override void Initialize() { // TODO: Add your initialization logic here #region List Declarations, and controller State Variables ] currentLocation = boardPos.cover; HatList = new List<HatPosition>(); ArrowList = new List<Arrows>(2); oldKeyState = Keyboard.GetState(); oldKeyState_1 = Keyboard.GetState(); oldDpadState = GamePad.GetState(PlayerIndex.One); #endregion avatarVector = p.PlayerVector; //holds the current location of the avatar. #region Add Score, more object declarations for (double i = 0; i <= pi; i += ((pi) / 500)) { ScoreGraph.Add((float)i); } //creats the graph from 0 to pi. HatPosition h = new HatPosition(hat, 1); //initiates the hatlist class. #endregion // MediaPlayer.IsMuted = true; //can be uncommented to mute the game. base.Initialize(); }
protected override void Update(GameTime gameTime) { if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed) this.Exit(); #region Vibrations vibrationTimer += gameTime.ElapsedGameTime.TotalMilliseconds; if (vibrationTimer > 250) { GamePad.SetVibration(PlayerIndex.One, 0, 0); vibrationTimer = 0; } //stopping the vibration motors if time is greater than .250 secs #endregion #region Controller States KeyboardState currentKeyboard = Keyboard.GetState(); GamePadState currentGamepad = GamePad.GetState(PlayerIndex.One); KeyboardState newKeyState = Keyboard.GetState(); GamePadState newDpadState = GamePad.GetState(PlayerIndex.One); #endregion #region switch (currentLocation) for movement across screens switch (currentLocation) { case boardPos.cover: #region Level Chooser if ((newKeyState.IsKeyDown(Keys.E) && (oldKeyState.IsKeyUp(Keys.E))) || (newDpadState.IsButtonDown(Buttons.X) && (oldDpadState.IsButtonUp(Buttons.X)))) { value = 0; currentLocation = boardPos.gameStyle; MediaPlayer.Play(song6); } if ((newKeyState.IsKeyDown(Keys.M) && (oldKeyState.IsKeyUp(Keys.M))) || (newDpadState.IsButtonDown(Buttons.Y) && (oldDpadState.IsButtonUp(Buttons.Y)))) { value = 1; currentLocation = boardPos.gameStyle; MediaPlayer.Play(song6); } if (currentKeyboard.IsKeyDown(Keys.H) || currentGamepad.IsButtonDown(Buttons.B)) { value = 2; currentLocation = boardPos.gameStyle; MediaPlayer.Play(song6); } //takes in which level the user wants to play in. if (currentKeyboard.IsKeyDown(Keys.T) || currentGamepad.IsButtonDown(Buttons.LeftShoulder)) { currentLocation = boardPos.instructions; MediaPlayer.Play(song7); } //opens up the instructions. rotation = rotationFactor[value]; //sets rotation according to level break; #endregion case boardPos.asteriod: #region Quandrant 1 controls if (avatarVector.X > graphics.PreferredBackBufferWidth - 35) avatarVector.X = graphics.PreferredBackBufferWidth - 35; if (avatarVector.X < 0) { currentLocation = boardPos.planets; MediaPlayer.Play(song2); avatarVector.X = graphics.PreferredBackBufferWidth - 105; } if (avatarVector.Y < 33) avatarVector.Y = 33; if (avatarVector.Y > graphics.PreferredBackBufferHeight) { currentLocation = boardPos.trees; MediaPlayer.Play(song4); avatarVector.Y = 0; } foreach (HatPosition h in HatList) { if (h.HatPositionVector.X > (graphics.PreferredBackBufferWidth - 22)) h.HatVelocity = new Vector2(-h.HatVelocity.X, h.HatVelocity.Y); if (h.HatPositionVector.X < 0) { h.HatPositionVector = new Vector2(graphics.PreferredBackBufferWidth - 22, h.HatPositionVector.Y); h.RandomNumber = 2; } if (h.HatPositionVector.Y < 22) h.HatVelocity = new Vector2(h.HatVelocity.X, -h.HatVelocity.Y); if (h.HatPositionVector.Y > graphics.PreferredBackBufferHeight) { h.HatPositionVector = new Vector2(h.HatPositionVector.X, 0); h.RandomNumber = 4; } } break; #endregion case boardPos.planets: #region Quadrant 2 controls if (avatarVector.X > graphics.PreferredBackBufferWidth - 105) { avatarVector.X = 0; currentLocation = boardPos.asteriod; MediaPlayer.Play(song1); } if (avatarVector.X < 35) { avatarVector.X = 35; } if (avatarVector.Y > graphics.PreferredBackBufferHeight) { avatarVector.Y = 0; currentLocation = boardPos.mountains; MediaPlayer.Play(song3); } if (avatarVector.Y < 33) avatarVector.Y = 33; foreach (HatPosition h in HatList) { if (h.HatPositionVector.X > (graphics.PreferredBackBufferWidth)) { h.HatPositionVector = new Vector2(0, h.HatPositionVector.Y); h.RandomNumber = 1; } if (h.HatPositionVector.X < 22) h.HatVelocity = new Vector2(-h.HatVelocity.X, h.HatVelocity.Y); if (h.HatPositionVector.Y < 22) h.HatVelocity = new Vector2(h.HatVelocity.X, -h.HatVelocity.Y); if (h.HatPositionVector.Y > graphics.PreferredBackBufferHeight - 22) { h.HatPositionVector = new Vector2(h.HatPositionVector.X, 0); h.RandomNumber = 3; } } break; #endregion case boardPos.mountains: #region Quadrant 3 controls if (avatarVector.X < 35) avatarVector.X = 35; if (avatarVector.X > graphics.PreferredBackBufferWidth - 35) { avatarVector.X = graphics.PreferredBackBufferWidth - 33; } if (avatarVector.Y < 0) { avatarVector.Y = graphics.PreferredBackBufferHeight; currentLocation = boardPos.planets; MediaPlayer.Play(song2); } if (avatarVector.Y > graphics.PreferredBackBufferHeight - 33) { avatarVector.Y = graphics.PreferredBackBufferHeight - 33; } foreach (HatPosition h in HatList) { if (h.HatPositionVector.X > (graphics.PreferredBackBufferWidth - 22)) h.HatVelocity = new Vector2(-h.HatVelocity.X, h.HatVelocity.Y); if (h.HatPositionVector.X < 22) h.HatVelocity = new Vector2(-h.HatVelocity.X, h.HatVelocity.Y); if (h.HatPositionVector.Y < 0) { h.HatPositionVector = new Vector2(h.HatPositionVector.X, graphics.PreferredBackBufferHeight - 22); h.RandomNumber = 2; } if (h.HatPositionVector.Y > graphics.PreferredBackBufferHeight - 15) h.HatVelocity = new Vector2(h.HatVelocity.X, -h.HatVelocity.Y); } break; #endregion case boardPos.trees: #region Quadrant 4 controls if (avatarVector.X < 35) { avatarVector.X = 35; } if (avatarVector.X > graphics.PreferredBackBufferWidth - 35) avatarVector.X = graphics.PreferredBackBufferWidth - 35; if (avatarVector.Y > graphics.PreferredBackBufferHeight - 33) avatarVector.Y = graphics.PreferredBackBufferHeight - 33; if (avatarVector.Y < 0) { avatarVector.Y = graphics.PreferredBackBufferHeight; currentLocation = boardPos.asteriod; MediaPlayer.Play(song1); } foreach (HatPosition h in HatList) { if (h.HatPositionVector.X > (graphics.PreferredBackBufferWidth - 22)) h.HatVelocity = new Vector2(-h.HatVelocity.X, h.HatVelocity.Y); if (h.HatPositionVector.X < 22) h.HatVelocity = new Vector2(-h.HatVelocity.X, h.HatVelocity.Y); if (h.HatPositionVector.Y < 0) { h.HatPositionVector = new Vector2(h.HatPositionVector.X, graphics.PreferredBackBufferHeight - 55); h.RandomNumber = 1; } if (h.HatPositionVector.Y > graphics.PreferredBackBufferHeight - 22) h.HatVelocity = new Vector2(h.HatVelocity.X, -h.HatVelocity.Y); } break; #endregion //each of these control the positon of the avatar and hat around the screen, and across the boundaries of each texture. #region checking instructions, choosing gamestyle, and checing highscore case boardPos.instructions: if (currentKeyboard.IsKeyDown(Keys.B) || currentGamepad.IsButtonDown(Buttons.RightShoulder)) { currentLocation = boardPos.cover; MediaPlayer.Play(song0); } //brings back to start menu. break; case boardPos.gameStyle: if ((newKeyState.IsKeyDown(Keys.E) && (oldKeyState.IsKeyUp(Keys.E))) || (newDpadState.IsButtonDown(Buttons.X) && (oldDpadState.IsButtonUp(Buttons.X)))) { currentLocation = boardPos.trees; MediaPlayer.Play(song4); isClassic = false; } //choose endless level. if ((newKeyState.IsKeyDown(Keys.C) && (oldKeyState.IsKeyUp(Keys.C))) || (newDpadState.IsButtonDown(Buttons.Y) && (oldDpadState.IsButtonUp(Buttons.Y)))) { currentLocation = boardPos.trees; MediaPlayer.Play(song4); isClassic = true; } break; //choose classic level. case boardPos.end: if ((newKeyState.IsKeyDown(Keys.B) && (oldKeyState.IsKeyUp(Keys.B))) || (newDpadState.IsButtonDown(Buttons.A) && oldDpadState.IsButtonUp(Buttons.A))) { currentLocation = boardPos.cover; MediaPlayer.Play(song0); } break; //go back to start when at final end page. #endregion } #endregion #region Avatar Movement if (currentKeyboard.IsKeyDown(Keys.Down) || currentGamepad.IsButtonDown(Buttons.DPadDown)) { avatarVector.X -= 15 * ((float)Math.Cos(rotation)); avatarVector.Y -= 10 * ((float)Math.Sin(rotation)); } if (currentKeyboard.IsKeyDown(Keys.Up) || currentGamepad.IsButtonDown(Buttons.DPadUp)) { avatarVector.X += 15 * ((float)Math.Cos(rotation)); avatarVector.Y += 10 * ((float)Math.Sin(rotation)); } if (currentKeyboard.IsKeyDown(Keys.Left) || currentGamepad.ThumbSticks.Right.X < 0) { rotation -= 0.07f; } if (currentKeyboard.IsKeyDown(Keys.Right) || currentGamepad.ThumbSticks.Right.X > 0) { rotation += 0.07f; } #endregion //movement and rotation of avatar. #region assigining quad-number to quadrants' switch (currentLocation) { case boardPos.asteriod: quadNumber = 1; break; case boardPos.planets: quadNumber = 2; break; case boardPos.mountains: quadNumber = 3; break; case boardPos.trees: quadNumber = 4; break; } #endregion //assings a number to currentLocation. #region moving objects foreach (HatPosition h in HatList) { h.move(); } foreach (Arrows a in ArrowList) a.aMove(); #endregion //moves the hats and arrows from their classes. checkCollision(); //call method to check collisions. #region changing Avatar if ((newKeyState.IsKeyDown(Keys.S) && (oldKeyState.IsKeyUp(Keys.S))) || (newDpadState.IsButtonDown(Buttons.RightShoulder) && (oldDpadState.IsButtonUp(Buttons.RightShoulder)))) { if (textureValue >= (SpaceShips.Count() - 1)) textureValue = 0; else textureValue++; } #endregion //change the avatar..on how you wannt it. #region schooting arrows if ((newKeyState.IsKeyDown(Keys.Space) && (oldKeyState.IsKeyUp(Keys.Space))) || newDpadState.IsButtonDown(Buttons.A) && (oldDpadState.IsButtonUp(Buttons.A))) { for (int i = 0; i < arrowCount; i++) ArrowList.Add(new Arrows(avatarVector, rotation)); int count = ScoreGraph.Count; for (int k = count; k > (count - lineRemovalFactor[value]); k--) { if (ScoreGraph.Count != 1) ScoreGraph.RemoveAt(k - 1); } } #endregion //shoot an arrow, lose life. #region hat movement-properties foreach (HatPosition h in HatList) if ((h.RandomNumber == quadNumber) && (Vector2.DistanceSquared(h.HatPositionVector, avatarVector) < 300)) { int count = ScoreGraph.Count; for (int k = count; k > (count - lineRemovalFactor[value]); k--) { if (ScoreGraph.Count != 1) ScoreGraph.RemoveAt(k - 1); } } #endregion //get close to hats, lose life. #region End Screen if ((newKeyState.IsKeyDown(Keys.R) && (oldKeyState.IsKeyUp(Keys.R))) || (newDpadState.IsButtonDown(Buttons.Start) && oldDpadState.IsButtonUp(Buttons.Start)) || (isClassic == true && (ScoreGraph.Count >= 1000))) { if (isClassic == false) { //hs.updateHighScore(1); hs.readHighScore(); hs.updateHighScore(ScoreGraph.Count); } //update highscore if in endless mode. ScoreGraph.Clear(); for (double i = 0; i <= pi; i += ((pi) / 500)) { ScoreGraph.Add((float)i); } HatList.Clear(); for (int i = 0; i < countofHats[value]; i++) { HatList.Add(new HatPosition(hat, i)); } currentLocation = boardPos.end; MediaPlayer.Play(song5); //reinitializes the basic parts of the game. #endregion } oldKeyState = newKeyState; oldDpadState = newDpadState; //reset values of keypad states. base.Update(gameTime); }
public BoardPosition() { currentLocation = boardPos.asteriod; }