override public void Initialize() { content = ScreenManager.getManager(); device = ScreenManager.getDevice(); XboxcurrentState = GamePad.GetState(PlayerIndex.One); XboxoldState = GamePad.GetState(PlayerIndex.One); currentState = Keyboard.GetState(); oldState = Keyboard.GetState(); Sound.playSoundOnce("Sound\\victory", content); GamePlayScreen.getScores(level, out numberOfEntries, out names, out scores, out datesInMillis); int[] oldScores = new int[scores.Length]; Array.Copy(scores, oldScores, scores.Length); Array.Sort <int, string>(scores, names, null); scores = oldScores; Array.Sort <int, long>(scores, datesInMillis, null); Array.Reverse(scores); Array.Reverse(names); Array.Reverse(datesInMillis); Console.WriteLine("NOW=" + Ticks); for (int i = 0; i < numberOfEntries; i++) { if (Math.Abs(datesInMillis[i] - Ticks) < 1000) { yourScore = i; Console.WriteLine(names[i] + " | " + scores[i] + " | " + datesInMillis[i] + "*"); } else { Console.WriteLine(names[i] + " | " + scores[i] + " | " + datesInMillis[i]); } } }
private void getHeightAndNormal(Vector3 Position, out float height, out Vector3 normal) { if (main.heightMap.IsOnHeightmap(Position)) { main.heightMap.GetHeightAndNormal(Position, out height, out normal); } else { height = 0; normal = new Vector3(0, 1, 0); Sound.playSoundOnce("Sound\\pop", main.Content); position = new Vector3(main.random.Next(-2500, 3000), 0, main.random.Next(-2500, 3000)); } }
public void jump() { if (!canJump || jumpDelayTimer.IsRunning) { return; } Vector3 jumpVector = Vector3.UnitY / 2; jumpVector += normalToGround; Console.WriteLine("Jump: X(" + jumpVector.X.ToString("000.000") + ") Y(" + jumpVector.Y.ToString("000.000") + ") Z(" + jumpVector.Z.ToString("000.000") + ")"); jumpVector.Normalize(); velocity += jumpVector * 600; Sound.playSoundOnce(properties.JumpSound, main.Content); }
public void dash() { if (!canDash || dashDelayTimer.IsRunning) { return; } dashDelayTimer.Start(); canDash = false; acceleration.Y = 0; velocity.Y = 0; float heightDifference = MathHelper.Clamp(position.Y - Math.Max(heightOfGround, -1000f), 50f, 400f); velocity += Direction * properties.DashSpeed * heightDifference / 200f; Console.WriteLine("Dash: " + properties.DashSpeed * heightDifference / 200f); Sound.playSoundOnce("Sound\\dash", main.Content); }
override public void Update(GameTime time) { if (goUp) { MenuScale[Selected] += .01f; } else { MenuScale[Selected] -= .01f; } if (MenuScale[Selected] > 1.4 || MenuScale[Selected] < 1) { goUp = !goUp; } oldState = currentState; XboxoldState = XboxcurrentState; XboxcurrentState = GamePad.GetState(PlayerIndex.One); currentState = Keyboard.GetState(); if ((currentState.IsKeyDown(Keys.Up) && !oldState.IsKeyDown(Keys.Up)) || (XboxcurrentState.DPad.Up == ButtonState.Pressed && XboxoldState.DPad.Up != ButtonState.Pressed)) { Sound.playSoundOnce("Sound\\tap", content); MenuScale[Selected] = 1; Selected--; if (Selected < 0) { Selected = 2; } MenuScale[Selected] = 1; goUp = true; } if ((currentState.IsKeyDown(Keys.Down) && !oldState.IsKeyDown(Keys.Down)) || (XboxcurrentState.DPad.Down == ButtonState.Pressed && XboxoldState.DPad.Down != ButtonState.Pressed)) { Sound.playSoundOnce("Sound\\tap", content); MenuScale[Selected] = 1; Selected++; if (Selected > 5) { Selected = 0; } MenuScale[Selected] = 1; goUp = true; } if ((currentState.IsKeyDown(Keys.Enter) && !oldState.IsKeyDown(Keys.Enter)) || (XboxcurrentState.IsButtonDown(Buttons.A) && !XboxoldState.IsButtonDown(Buttons.A))) { //Enter was pressed on a menu Item. if (Selected == 0) { Entrance newGame = new Entrance(); newGame.Level = 1; ScreenManager.AddScreen(newGame); } else if (Selected == 1) { Entrance newGame = new Entrance(); newGame.Level = 2; ScreenManager.AddScreen(newGame); } else if (Selected == 2) { Entrance newGame = new Entrance(); newGame.Level = 3; ScreenManager.AddScreen(newGame); } else if (Selected == 3) { Entrance newGame = new Entrance(); newGame.Level = 4; ScreenManager.AddScreen(newGame); } else if (Selected == 4) { Entrance newGame = new Entrance(); newGame.Level = 5; ScreenManager.AddScreen(newGame); } else if (Selected == 5) { ScreenManager.RemoveAll(); ScreenManager.AddScreen(new MainMenu()); } } }
/// <summary> /// Allows the game to run logic such as updating the world, /// checking for collisions, gathering input, and playing audio. /// </summary> /// <param name="gameTime">Provides a snapshot of timing values.</param> override public void Update(GameTime gameTime) { timeInMillis += gameTime.ElapsedGameTime.Milliseconds; LevelTime -= gameTime.ElapsedGameTime.Milliseconds; if (LevelTime < 0 || ball.position.Y <= pitHeight) { Sound.pauseSound("Sound\\" + this.level, content); GameOver startOver = new GameOver(); startOver.Level = this.level; startOver.Name = this.name; ScreenManager.AddScreen(startOver); } lastKeyboardState = currentKeyboardState; lastGamePadState = currentGamePadState; lastMousState = currentMouseState; currentKeyboardState = Keyboard.GetState(); currentGamePadState = GamePad.GetState(PlayerIndex.One); currentMouseState = Mouse.GetState(); Int32 middleX = device.Viewport.Bounds.Width / 2; Int32 middleY = device.Viewport.Bounds.Height / 2;; #if XBOX // Exit when the Escape key or Back button is pressed if (currentGamePadState.Buttons.Back == ButtonState.Pressed) { ScreenManager.RemoveScreen(this); } if (!ball.onGround && currentGamePadState.IsButtonDown(Buttons.B) && !lastGamePadState.IsButtonDown(Buttons.B)) { ball.dash(); } else if (currentGamePadState.IsButtonDown(Buttons.A) && !lastGamePadState.IsButtonDown(Buttons.A)) { if (ball.onGround && !ball.jumpDelayTimer.IsRunning) { //ball.dashDelayTimer.Start(); ball.jump(); } } if (currentGamePadState.DPad.Down == ButtonState.Pressed) { Vector3 offset = camera.DesiredPositionOffset; offset.Y = MathHelper.Clamp(offset.Y += 2, 20, 150); if (Math.Abs(offset.Y - camera.DesiredPositionOffset.Y) > 0.0001) { Sound.playSoundOnce("Sound\\rotateCam", content); } camera.DesiredPositionOffset = offset; } else if (currentGamePadState.DPad.Up == ButtonState.Pressed) { Vector3 offset = camera.DesiredPositionOffset; offset.Y = MathHelper.Clamp(offset.Y -= 2, 20, 150); if (Math.Abs(offset.Y - camera.DesiredPositionOffset.Y) > 0.0001) { Sound.playSoundOnce("Sound\\rotateCam", content); } camera.DesiredPositionOffset = offset; } if (currentGamePadState.IsButtonDown(Buttons.LeftShoulder) && !lastGamePadState.IsButtonDown(Buttons.LeftShoulder)) { if (currentBallProperties.Equals(beachBallProperties)) { currentBallProperties = airBallProperties; } else if (currentBallProperties.Equals(airBallProperties)) { currentBallProperties = metalBallProperties; } else if (currentBallProperties.Equals(metalBallProperties)) { currentBallProperties = beachBallProperties; } Sound.playSoundOnce(currentBallProperties.ChangeToSound, content); } else if (currentGamePadState.IsButtonDown(Buttons.RightShoulder) && !lastGamePadState.IsButtonDown(Buttons.RightShoulder)) { if (currentBallProperties.Equals(beachBallProperties)) { currentBallProperties = metalBallProperties; } else if (currentBallProperties.Equals(metalBallProperties)) { currentBallProperties = airBallProperties; } else if (currentBallProperties.Equals(airBallProperties)) { currentBallProperties = beachBallProperties; } Sound.playSoundOnce(currentBallProperties.ChangeToSound, content); } else if (currentGamePadState.IsButtonDown(Buttons.Back) && !lastGamePadState.IsButtonDown(Buttons.Back)) { Sound.pauseSound(background, content); ScreenManager.AddScreen(new MainMenu()); } if (currentGamePadState.IsButtonDown(Buttons.RightStick) && !lastGamePadState.IsButtonDown(Buttons.RightStick)) { ball.Reset(); camera.Reset(); } #endif #if WINDOWS // Exit when the Escape key or Back button is pressed if (currentKeyboardState.IsKeyDown(Keys.Escape) || currentGamePadState.Buttons.Back == ButtonState.Pressed) { ScreenManager.RemoveScreen(this); } if (!ball.onGround && !lastKeyboardState.IsKeyDown(Keys.Space) && currentKeyboardState.IsKeyDown(Keys.Space)) { ball.dash(); } else if (currentKeyboardState.IsKeyDown(Keys.Space)) { if (ball.onGround && !ball.jumpDelayTimer.IsRunning) { //ball.dashDelayTimer.Start(); ball.jump(); } } if (currentKeyboardState.IsKeyDown(Keys.I) || (currentMouseState.RightButton == ButtonState.Pressed) && (currentMouseState.Y > middleY)) { Vector3 offset = camera.DesiredPositionOffset; offset.Y = MathHelper.Clamp(offset.Y += 2, 20, 150); if (Math.Abs(offset.Y - camera.DesiredPositionOffset.Y) > 0.0001) { Sound.playSoundOnce("Sound\\rotateCam", content, 0.5f); } camera.DesiredPositionOffset = offset; } else if (currentKeyboardState.IsKeyDown(Keys.K) || (currentMouseState.RightButton == ButtonState.Pressed) && (currentMouseState.Y <= middleY)) { Vector3 offset = camera.DesiredPositionOffset; offset.Y = MathHelper.Clamp(offset.Y -= 2, 20, 150); if (Math.Abs(offset.Y - camera.DesiredPositionOffset.Y) > 0.0001) { Sound.playSoundOnce("Sound\\rotateCam", content, 0.5f); } camera.DesiredPositionOffset = offset; } if (currentKeyboardState.IsKeyDown(Keys.Q) && !lastKeyboardState.IsKeyDown(Keys.Q)) { if (currentBallProperties.Equals(beachBallProperties)) { currentBallProperties = airBallProperties; } else if (currentBallProperties.Equals(airBallProperties)) { currentBallProperties = metalBallProperties; } else if (currentBallProperties.Equals(metalBallProperties)) { currentBallProperties = beachBallProperties; } Sound.playSoundOnce(currentBallProperties.ChangeToSound, content); } else if (currentKeyboardState.IsKeyDown(Keys.E) && !lastKeyboardState.IsKeyDown(Keys.E)) { if (currentBallProperties.Equals(beachBallProperties)) { currentBallProperties = metalBallProperties; } else if (currentBallProperties.Equals(metalBallProperties)) { currentBallProperties = airBallProperties; } else if (currentBallProperties.Equals(airBallProperties)) { currentBallProperties = beachBallProperties; } Sound.playSoundOnce(currentBallProperties.ChangeToSound, content); } else if (currentKeyboardState.IsKeyDown(Keys.M)) { Sound.pauseSound(background, content); ScreenManager.AddScreen(new MainMenu()); } if (currentKeyboardState.IsKeyDown(Keys.Z)) { System.Diagnostics.Debug.WriteLine(ball.position); } bool touchTopLeft = currentMouseState.LeftButton == ButtonState.Pressed && lastMousState.LeftButton != ButtonState.Pressed && currentMouseState.X < device.Viewport.Width / 10 && currentMouseState.Y < device.Viewport.Height / 10; if (currentKeyboardState.IsKeyDown(Keys.R) || currentGamePadState.Buttons.RightStick == ButtonState.Pressed) { ball.Reset(); camera.Reset(); } #endif ArrowRotation = RotateToFace(ball.position, ExitPosition, Vector3.Up); ExitRotation = RotateToFace(ExitPosition, ball.position, Vector3.Up); if (ExitBox.Contains(ball.position) == ContainmentType.Contains || currentKeyboardState.IsKeyDown(Keys.P)) { long nowTicks = DateTime.Now.Ticks; #if WINDOWS sendScore(name, level, (int)(LevelTime), nowTicks); #endif VictoryScreen victoryScreen = new VictoryScreen(); victoryScreen.Level = this.level; victoryScreen.Name = this.name; victoryScreen.Ticks = nowTicks; ScreenManager.AddScreen(victoryScreen); } //Test stuff if (heightMap.IsOnHeightmap(ball.position)) { heightMap.GetHeightAndNormal(ball.position, out h, out norm); norm.Normalize(); h = Vector3.Dot(new Vector3(0, 1, 0), norm); a = Math.Acos(h); //a = getSignedAngle(new Vector3(0, 1, 0), norm); b = Math.Atan2(norm.Y, norm.X); } for (int x = 0; x < coinList.Count; x++) { coinList[x].Update(gameTime); if (coinList[x].detectIntersection(ball.position)) { LevelTime += 5000f; Sound.playSoundOnce("Sound\\ding", content); coinList.RemoveAt(x); } } for (int x = 0; x < teleporterList.Count; x++) { teleporterList[x].Update(gameTime); if (teleporterList[x].detectIntersection(ball.position)) { Sound.playSoundOnce("Sound\\pop", content); ball.position = new Vector3(RandomNumber(-2500, 3000), 0, RandomNumber(-2500, 3000)); } } ball.properties = currentBallProperties; ball.Update(gameTime); camera.ChasePosition = ball.position; camera.ChaseDirection = ball.Direction; camera.Up = ball.Up; camera.Reset(); particleEngine.EmitterLocation = new Vector2(Mouse.GetState().X, Mouse.GetState().Y); particleEngine.Update(); base.Update(gameTime); }
override public void Update(GameTime time) { if (goUp) { MenuScale[Selected] += .005f; } else { MenuScale[Selected] -= .005f; } if (MenuScale[Selected] > 0.6 || MenuScale[Selected] < 0.5) { goUp = !goUp; } oldState = currentState; XboxoldState = XboxcurrentState; XboxcurrentState = GamePad.GetState(PlayerIndex.One); currentState = Keyboard.GetState(); if ((currentState.IsKeyDown(Keys.Up) && !oldState.IsKeyDown(Keys.Up)) || (XboxcurrentState.DPad.Up == ButtonState.Pressed && XboxoldState.DPad.Up != ButtonState.Pressed)) { Sound.playSoundOnce("Sound\\tap", content); MenuScale[Selected] = 0.5f; Selected--; if (Selected < 0) { Selected = 2; } MenuScale[Selected] = 0.5f; goUp = true; } if ((currentState.IsKeyDown(Keys.Down) && !oldState.IsKeyDown(Keys.Down)) || (XboxcurrentState.DPad.Down == ButtonState.Pressed && XboxoldState.DPad.Down != ButtonState.Pressed)) { Sound.playSoundOnce("Sound\\tap", content); MenuScale[Selected] = 0.5f; Selected++; if (Selected > 2) { Selected = 0; } MenuScale[Selected] = 0.5f; goUp = true; } if ((currentState.IsKeyDown(Keys.Enter) && !oldState.IsKeyDown(Keys.Enter)) || (XboxcurrentState.IsButtonDown(Buttons.A) && !XboxoldState.IsButtonDown(Buttons.A))) { //Enter was pressed on a menu Item. if (Selected == 0) { ScreenManager.RemoveAll(); GamePlayScreen level = new GamePlayScreen(); level.Level = this.level; level.Terrain = "Models\\" + this.level; level.TerrainTexture = "Textures\\" + this.level; level.Background = "Sound\\" + this.level; level.Name = this.name; ScreenManager.AddScreen(level); } else if (Selected == 1) { ScreenManager.RemoveAll(); GamePlayScreen level = new GamePlayScreen(); this.level++; if (this.level >= 5) { this.level = 0; } level.Level = this.level; level.Terrain = "Models\\" + this.level; level.TerrainTexture = "Textures\\" + this.level; level.Background = "Sound\\" + this.level; level.Name = this.name; ScreenManager.AddScreen(level); } else if (Selected == 2) { ScreenManager.RemoveAll(); ScreenManager.AddScreen(new MainMenu()); } } }
/// <summary> /// Allows the game to run logic such as updating the world, /// checking for collisions, gathering input, and playing audio. /// </summary> /// <param name="gameTime">Provides a snapshot of timing values.</param> protected override void Update(GameTime gameTime) { timeInMillis += gameTime.ElapsedGameTime.Milliseconds; lastKeyboardState = currentKeyboardState; lastGamePadState = currentGamePadState; lastMousState = currentMouseState; currentKeyboardState = Keyboard.GetState(); currentGamePadState = GamePad.GetState(PlayerIndex.One); currentMouseState = Mouse.GetState(); // Exit when the Escape key or Back button is pressed if (currentKeyboardState.IsKeyDown(Keys.Escape) || currentGamePadState.Buttons.Back == ButtonState.Pressed) { Exit(); } if (currentKeyboardState.IsKeyDown(Keys.Space)) { if (ball.onGround && !ball.jumpDelayTimer.IsRunning) { ball.ApplyForce(new Vector3(0, 300, 0)); Sound.playSoundOnce("Sound\\jump", Content); } } if (currentKeyboardState.IsKeyDown(Keys.I)) { Vector3 offset = camera.DesiredPositionOffset; offset.Y = MathHelper.Clamp(offset.Y += 2, 20, 150); camera.DesiredPositionOffset = offset; Sound.playSoundOnce("Sound\\rotateCam", Content); } else if (currentKeyboardState.IsKeyDown(Keys.K)) { Vector3 offset = camera.DesiredPositionOffset; offset.Y = MathHelper.Clamp(offset.Y -= 2, 20, 150); camera.DesiredPositionOffset = offset; Sound.playSoundOnce("Sound\\rotateCam", Content); } if (currentKeyboardState.IsKeyDown(Keys.Q) && !lastKeyboardState.IsKeyDown(Keys.Q)) { if (ballTexture.Equals(ballTextureBeach)) { ballTexture = ballTextureMetal; } else if (ballTexture.Equals(ballTextureMetal)) { ballTexture = ballTextureBeach; } Sound.playSoundOnce("Sound\\changeBall", Content); } else if (currentKeyboardState.IsKeyDown(Keys.E) && !lastKeyboardState.IsKeyDown(Keys.E)) { if (ballTexture.Equals(ballTextureBeach)) { ballTexture = ballTextureMetal; } else if (ballTexture.Equals(ballTextureMetal)) { ballTexture = ballTextureBeach; } Sound.playSoundOnce("Sound\\changeBall", Content); } if (currentKeyboardState.IsKeyDown(Keys.N)) { Sound.pauseSound("Sound\\background", Content); Sound.playSoundLoop("Sound\\background2", Content); } if (currentKeyboardState.IsKeyDown(Keys.M)) { Sound.pauseSound("Sound\\background2", Content); Sound.playSoundLoop("Sound\\background", Content); } bool touchTopLeft = currentMouseState.LeftButton == ButtonState.Pressed && lastMousState.LeftButton != ButtonState.Pressed && currentMouseState.X < GraphicsDevice.Viewport.Width / 10 && currentMouseState.Y < GraphicsDevice.Viewport.Height / 10; if (currentKeyboardState.IsKeyDown(Keys.R) || currentGamePadState.Buttons.RightStick == ButtonState.Pressed) { ball.Reset(); camera.Reset(); } //if (currentKeyboardState.IsKeyDown(Keys.Z)) //{ // IPEndPoint ip = new IPEndPoint(IPAddress.Parse("128.143.69.241"), 9050); // Socket server = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); // try // { // server.Connect(ip); // } // catch (SocketException e) // { // Console.WriteLine("Unable to connect to server."); // return; // } // server.Send(Encoding.ASCII.GetBytes("HIGHSCORE-INSERT-1-5000")); // byte[] data = new byte[1024]; // int receivedDataLength = server.Receive(data); // string stringData = Encoding.ASCII.GetString(data, 0, receivedDataLength); // Console.WriteLine("DATA FROM SERVER: " + stringData); //} ball.Update(gameTime); camera.ChasePosition = ball.Position; camera.ChaseDirection = ball.Direction; camera.Up = ball.Up; camera.Reset(); base.Update(gameTime); }