public void update(float angle, GameTime gametime) { if (!inAir && isOnTarget) { archerytarget.update(); this.Position.Y = archerytarget.getPosition().Y + changeY; } if (inAir) { if (docked & !beenshot) { rotation = angle; Position.Y = 768 - 45 + (float)Math.Sin(angle) * 18; Position.X = 20 + (float)Math.Cos(angle) * 16; } else if (!docked && !beenshot) { elapsed += (float)gametime.ElapsedGameTime.TotalSeconds; if (stopxveloc) { Velocity.X = 0; Velocity.Y = 10f; } else if (!isOnTarget) { Velocity.X = initVeloc.X; Velocity.Y = (float)(initVeloc.Y + (9.8 * 2) * elapsed); } Position.X += Velocity.X; Position.Y += Velocity.Y; rotation = (float)Math.Atan(Velocity.Y / Velocity.X); Collidable.Rotation = this.rotation; Collidable.Position = this.Position; if (Position.Y > SCREEN_HEIGHT - texture.Height * 3) { Position.Y = SCREEN_HEIGHT - texture.Height * 3.5f; docked = true; beenshot = true; inAir = false; } } } //ifinAir } // update
} // LoadContent protected override void Update(GameTime gameTime) { keyboardstate = Keyboard.GetState(); mousestate = Mouse.GetState(); // Allows the game to exit if (keyboardstate.IsKeyDown(Keys.Escape)) { this.Exit(); } if (keyboardstate.IsKeyDown(Keys.F5) && lastkeystate.IsKeyUp(Keys.F5)) { graphics.ToggleFullScreen(); graphics.ApplyChanges(); } if (!mainThemePlaying && !nyancat.IsMoving()) { mainTheme = soundbank.GetCue("mainTheme"); mainTheme.Play(); mainThemePlaying = true; } if (nyancat.IsMoving()) { mainTheme.Stop(AudioStopOptions.AsAuthored); mainThemePlaying = false; } switch (gameState) { case GameState.Menu: menu.MoveOfforOnScreen(true); bow.update(gameTime, Content); HandleCollisions(); nyancat.update(gameTime, soundbank); break; case GameState.Target: archeryTarget.update(); menu.MoveOfforOnScreen(false); bow.update(gameTime, Content); HandleCollisions(); nyancat.update(gameTime, soundbank); break; case GameState.Bear: menu.MoveOfforOnScreen(false); bearMode.update(gameTime, Content); bow.update(gameTime, Content); HandleCollisions(); nyancat.update(gameTime, soundbank); break; case GameState.GameOver: if (firstGameOverpass) { if (LoginForm.IsNewHighScore(username, bearMode.bearsKilled)) { LoginForm.UpdateHighScore(username, bearMode.bearsKilled); isHighScore = true; } firstGameOverpass = false; } if ((mousestate.LeftButton == ButtonState.Pressed) && (mousestate.X < 100 && mousestate.Y < 10)) { firstGameOverpass = true; isHighScore = false; bearMode.reset(); gameState = GameState.Menu; bow.resetArrows(Content); } break; case GameState.Login: loginForm.Update(gameTime.ElapsedGameTime.Ticks); LoggedIn = loginForm.Is_Logged_In(); if (loginForm.IsDone()) { LoggedIn = loginForm.Is_Logged_In(); if (LoggedIn) { username = loginForm.GetUsername(); } gameState = GameState.Menu; loginForm = new LoginForm(Content); } break; } lastkeystate = keyboardstate; base.Update(gameTime); } // Update