public void TestResetWhileUnpaused() { GameClock gc = new GameClock(); gc.Start(); GameTime gt = new GameTime(new TimeSpan(100), new TimeSpan(100)); gc.Update(gt); Assert.AreEqual(new TimeSpan(100), gc.ElapsedTime); gc.Reset(); Assert.AreEqual(new TimeSpan(), gc.ElapsedTime); gc.Update(gt); Assert.AreEqual(new TimeSpan(100), gc.ElapsedTime); }
/// <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) { // For Mobile devices, this logic will close the Game when the Back button is pressed if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape)) { #if !__IOS__ Exit(); #endif } CurrentTime.Update(gameTime); //restart the bounby numbers if (Keyboard.GetState().IsKeyDown(Keys.Space)) { bounce.Start(start, end); } if (Keyboard.GetState().IsKeyDown(Keys.A)) { num.Add(100); } else if (Keyboard.GetState().IsKeyDown(Keys.Z)) { num.Add(-100); } // TODO: Add your update logic here base.Update(gameTime); }
public override float Write(string text, Vector2 position, Justify justification, float scale, Color color, SpriteBatch spriteBatch, GameClock time) { if (string.IsNullOrEmpty(text)) { return(position.X); } //First draw the shadow Font.Write(text, position, justification, ShadowSize * scale, ShadowColor, spriteBatch, time); _timer.Update(time); var currentTime = _timer.CurrentTime; //Pulsate the size of the text var pulsate = PulsateSize * (float)(Math.Sin(currentTime - (Math.PI * 0.5)) + 1.0f); pulsate *= 0.15f; //make it waaay smaller pulsate += 1; //bump it up so it starts at 1 //adjust the y position so it pulsates straight out var textSize = Font.MeasureString(text.ToString()); var adjust = ((textSize * scale * pulsate) - (textSize * scale)) / 2f; if (StraightPulsate) { switch (justification) { case Justify.Left: { position.X -= adjust.X; } break; case Justify.Right: { position.X += adjust.X; } break; } ; } position.Y -= adjust.Y; //Draw the menu item, with the pulsing return(Font.Write(text, position, justification, scale * pulsate, color, spriteBatch, time)); }
/// <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) { // Allows the game to exit if ((GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed) || Keyboard.GetState().IsKeyDown(Keys.Escape)) { #if !__IOS__ this.Exit(); #endif } //update the timer _clock.Update(gameTime); //update the input _inputState.Update(); _inputWrapper.Update(_inputState, false); //check veritcal movement if (_inputWrapper.Controller.CheckKeystrokeHeld(EKeystroke.Up)) { _circle1.Translate(0.0f, -circleMovementSpeed * _clock.TimeDelta); } else if (_inputWrapper.Controller.CheckKeystrokeHeld(EKeystroke.Down)) { _circle1.Translate(0.0f, circleMovementSpeed * _clock.TimeDelta); } //check horizontal movement if (_inputWrapper.Controller.CheckKeystrokeHeld(EKeystroke.Forward)) { _circle1.Translate(circleMovementSpeed * _clock.TimeDelta, 0.0f); } else if (_inputWrapper.Controller.CheckKeystrokeHeld(EKeystroke.Back)) { _circle1.Translate(-circleMovementSpeed * _clock.TimeDelta, 0.0f); } //add camera shake when the two circles crash into each other if (CollisionCheck.CircleCircleCollision(_circle1, _circle2)) { if (!_colliding) { _camera.AddCameraShake(0.25f); } _colliding = true; } else { _colliding = false; } //update the camera _camera.Update(_clock); base.Update(gameTime); }
/// <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) { if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape)) { //Exit(); } _time.Update(gameTime); base.Update(gameTime); }
/// <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) { // Allows the game to exit if ((GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed) || Keyboard.GetState().IsKeyDown(Keys.Escape)) { #if !__IOS__ this.Exit(); #endif } //update the timer _clock.Update(gameTime); //update the input _inputState.Update(); _inputWrapper.Update(_inputState, false); //move the circle float movespeed = 1600.0f; //check veritcal movement if (_inputWrapper.Controller.CheckKeystrokeHeld(EKeystroke.Up)) { _circle1.Translate(0.0f, -movespeed * _clock.TimeDelta); } else if (_inputWrapper.Controller.CheckKeystrokeHeld(EKeystroke.Down)) { _circle1.Translate(0.0f, movespeed * _clock.TimeDelta); } //check horizontal movement if (_inputWrapper.Controller.CheckKeystrokeHeld(EKeystroke.Forward)) { _circle1.Translate(movespeed * _clock.TimeDelta, 0.0f); } else if (_inputWrapper.Controller.CheckKeystrokeHeld(EKeystroke.Back)) { _circle1.Translate(-movespeed * _clock.TimeDelta, 0.0f); } //add camera shake? if (_inputWrapper.Controller.CheckKeystroke(EKeystroke.A)) { _camera.AddCameraShake(0.5f); } //update the camera _camera.Update(_clock); base.Update(gameTime); }
public void TestUpdate() { GameClock gc = new GameClock(); Assert.AreEqual(new TimeSpan(0), gc.ElapsedTime); //test Update GameTime gt = new GameTime(new TimeSpan(100), new TimeSpan(100)); //test Update gc.Start(); gc.Update(gt); Assert.AreEqual(new TimeSpan(100), gc.ElapsedTime); }
/// <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) { // Allows the game to exit if ((GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed) || Keyboard.GetState().IsKeyDown(Keys.Escape)) { #if !__IOS__ this.Exit(); #endif } // TODO: Add your update logic here base.Update(gameTime); _clock.Update(gameTime); }
/// <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) { // For Mobile devices, this logic will close the Game when the Back button is pressed if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape)) { #if !__IOS__ Exit(); #endif } CurrentTime.Update(gameTime); var curKeyboard = Keyboard.GetState(); if (CheckKey(curKeyboard, Keys.A)) { ++number; } else if (CheckKey(curKeyboard, Keys.Z)) { --number; } else if (CheckKey(curKeyboard, Keys.S)) { number += 100; } else if (CheckKey(curKeyboard, Keys.X)) { number -= -100; } else if (CheckKey(curKeyboard, Keys.D)) { number += 1000; } else if (CheckKey(curKeyboard, Keys.C)) { number -= -1000; } prevKeyboard = curKeyboard; foreach (var num in buddies) { num.Number = number; } // TODO: Add your update logic here base.Update(gameTime); }
/// <summary> /// Reference page contains links to related conceptual articles. /// </summary> /// <param name="gameTime">Time passed since the last call to Update.</param> protected override void Update(GameTime gameTime) { base.Update(gameTime); if (exitStatus) { this.Exit(); } GameClock.Update(); ForceSignIn(); gameSaver.Update(); audio.Update(gameTime); controller.Update(); screens.Update(); background.Update(); }
public override float Write(string text, Vector2 position, Justify justification, float scale, Color color, SpriteBatch spriteBatch, GameClock time) { _timer.Update(time); if (string.IsNullOrEmpty(text)) { return(position.X); } float currentTime = _timer.CurrentTime; // When the menu selection changes, entries gradually fade between // their selected and deselected appearance, rather than instantly // popping to the new state. double fadeSpeed = currentTime * 4.0f; if (Selected) { SelectionFade = (float)Math.Min(SelectionFade + fadeSpeed, 1); } else { SelectionFade = (float)Math.Max(SelectionFade - fadeSpeed, 0); } //Pulsate the size of the text var pulsate = PulsateSize * (float)(Math.Sin(currentTime)); var pulseScale = 1 + pulsate * 0.15f * SelectionFade; //adjust the y position so it pulsates straight out var adjust = ((Font.MeasureString(text) * scale * pulseScale) - (Font.MeasureString(text) * scale)) / 2.0f; position.X -= adjust.X; WriteShadow(text, position, justification, scale, spriteBatch, time); //Draw the menu item, with the pulsing return(Font.Write(text, position, justification, scale, color, spriteBatch, time)); }
/// <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) { #if !__IOS__ // Allows the game to exit if ((GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed) || Keyboard.GetState().IsKeyDown(Keys.Escape)) { this.Exit(); } #endif //update the timer _clock.Update(gameTime); //update the input _inputState.Update(); _inputWrapper.Update(_inputState, false); _Grid.Update(_inputWrapper); base.Update(gameTime); }
protected override void Update(GameTime gameTime) { if (Keyboard.GetState().IsKeyDown(Keys.Escape)) { #if !__IOS__ this.Exit(); #endif } //update the timer _clock.Update(gameTime); //update the input _inputState.Update(); _inputWrapper.Update(_inputState, false); //check input to increment/decrement the current bullet pattern if (_inputWrapper.Controller.CheckKeystroke(EKeystroke.LShoulder)) { //decrement the pattern if (0 >= _CurrentPattern) { //if it is at the beginning, move to the end _CurrentPattern = _myPatterns.Count - 1; } else { _CurrentPattern--; } AddBullet(); } else if (_inputWrapper.Controller.CheckKeystroke(EKeystroke.RShoulder)) { //increment the pattern if ((_myPatterns.Count - 1) <= _CurrentPattern) { //if it is at the beginning, move to the end _CurrentPattern = 0; } else { _CurrentPattern++; } AddBullet(); } //reset the bullet pattern if (_inputWrapper.Controller.CheckKeystroke(EKeystroke.A)) { AddBullet(); } //increase/decrease the rank if (_inputWrapper.Controller.CheckKeystroke(EKeystroke.LShoulder)) { if (_Rank > 0.0f) { _Rank -= 0.1f; } if (_Rank < 0.0f) { _Rank = 0.0f; } } else if (_inputWrapper.Controller.CheckKeystroke(EKeystroke.RShoulder)) { if (_Rank < 1.0f) { _Rank += 0.1f; } if (_Rank > 1.0f) { _Rank = 1.0f; } } //if y is held down, do some slowdown if (_inputWrapper.Controller.CheckKeystroke(EKeystroke.Y)) { _moverManager.TimeSpeed = 0.5f; } else { _moverManager.TimeSpeed = 1.0f; } //if b is held down, make it bigger if (_inputWrapper.Controller.CheckKeystroke(EKeystroke.LTrigger)) { _moverManager.Scale -= 0.1f; } else if (_inputWrapper.Controller.CheckKeystroke(EKeystroke.RTrigger)) { _moverManager.Scale += 0.1f; } _moverManager.Update(); myship.Update(); base.Update(gameTime); }
public static void Update(GameTime gameTime) { UpdateGameSpeed(gameTime); Clock.Update(gameTime); }