public void Update(GameTime gameTime) { if (state != AnimationState.Dead) { //Update animationTime animationTime += gameTime.ElapsedGameTime; //Update animation state if (animationTime.TotalMilliseconds >= FRAME_RATE) { state++; if (state == AnimationState.Idle4) { state = AnimationState.Idle0; } animationTime = new TimeSpan(0); } //Check if piece should be moved if (positionCurrent != positionDestination && animationTime.TotalMilliseconds == 0) { positionCurrent = positionDestination; } } else if (state == AnimationState.Dead) { deathParticles.Update(positionCurrent, gameTime); } }
public void Update(GameTime gameTime) { timer += gameTime.ElapsedGameTime; if (placed) { fuseSFX.Play(); toDetonate = true; placed = false; } if (timer.TotalMilliseconds - activated_timer.TotalMilliseconds > fuseSFX.Duration.TotalMilliseconds && toDetonate) { explosionSFX.Play(); active = false; detonated = true; toDetonate = false; detonated_timer = new TimeSpan(0); explosionP = true; } if (timer.TotalMilliseconds - detonated_timer.TotalMilliseconds > explosionSFX.Duration.TotalMilliseconds * 10 && detonated) { detonated = false; } if (explosionP) { explosionParticleSystem.Update(gameTime); } if (timer.TotalMilliseconds - detonated_timer.TotalMilliseconds > explosionSFX.Duration.TotalMilliseconds * 11 && explosionP) { explosionP = false; explosionParticleSystem = newExplosionParticleSystem(game.GraphicsDevice, 5000, explosionParticle); } }
/// <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(); } rainParticle.Update(gameTime); particleSystem.Update(gameTime); finishSystem.Update(gameTime); var keyboardState = Keyboard.GetState(); score = player.score; if (keyboardState.IsKeyDown(Keys.R)) { won = false; lost = false; Initialize(); enemies.RemoveRange(1, enemies.Count - 1); } foreach (Enemy en in enemies) { en.Update(gameTime); } player.Update(gameTime, enemies); 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) { keyboardState = Keyboard.GetState(); if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape)) { Exit(); } ball1.Update(gameTime); ball2.Update(gameTime); player.Update(gameTime); if ((ball1.State == GameState.Game) && (ball2.State == GameState.Game)) { score++; } // TODO: Add your update logic here if (player.Bounds.CollidesWith(ball1.Bounds)) { if (!((ball1.Bounds.Y > player.Bounds.Y + player.Bounds.Height) || (ball1.Bounds.Y + ball1.Bounds.Radius < player.Bounds.Y))) { ball1.Velocity *= 0; ball2.Velocity *= 0; ball1.State = GameState.Over; } else if (!((ball1.Bounds.X > player.Bounds.X + player.Bounds.Width) || (ball1.Bounds.X + ball1.Bounds.Radius < player.Bounds.X))) { ball1.Velocity *= 0; ball2.Velocity *= 0; ball1.State = GameState.Over; } } if (player.Bounds.CollidesWith(ball2.Bounds)) { if (!((ball2.Bounds.Y > player.Bounds.Y + player.Bounds.Height) || (ball2.Bounds.Y + ball2.Bounds.Radius < player.Bounds.Y))) { ball2.Velocity *= 0; ball1.Velocity *= 0; ball2.State = GameState.Over; } else if (!((ball2.Bounds.X > player.Bounds.X + player.Bounds.Width) || (ball2.Bounds.X + ball2.Bounds.Radius < player.Bounds.X))) { ball2.Velocity *= 0; ball1.Velocity *= 0; ball2.State = GameState.Over; } } particleSystem1.Update(gameTime); particleSystem2.Update(gameTime); particleSystem3.Update(gameTime); base.Update(gameTime); }
public void Update(GameTime gameTime) { List <Tuple <ParticleSystem, int> > tuplesToRemove = new List <Tuple <ParticleSystem, int> >(); for (int i = 0; i < limitedParticleSystems.Count; i++) { Tuple <ParticleSystem, int> t = limitedParticleSystems[i]; t.Item1.Update(gameTime); if (t.Item2 == 0) { t.Item1.SpawnPerFrame = 0; if (t.Item1.ActiveParticles > 0) { limitedParticleSystems[i] = new Tuple <ParticleSystem, int>(t.Item1, 0); } else { tuplesToRemove.Add(t); } } else { limitedParticleSystems[i] = new Tuple <ParticleSystem, int>(t.Item1, t.Item2 - 1); } } foreach (Tuple <ParticleSystem, int> t in tuplesToRemove) { limitedParticleSystems.Remove(t); } foreach (ParticleSystem p in particleSystems) { p.Update(gameTime); if (p.ActiveParticles == 0) { particleSystems.Remove(p); } } List <Object> toRemove = new List <Object>(); foreach (Object o in trackingParticleSystems.Keys) { ParticleSystem p = trackingParticleSystems[o]; p.Emitter = o.Collision.Position; p.Update(gameTime); if (p.ActiveParticles == 0) { toRemove.Add(o); } } foreach (Object o in toRemove) { trackingParticleSystems.Remove(o); } }
/// <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) { newKeyboardState = Keyboard.GetState(); if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape)) { Exit(); } if (newKeyboardState.IsKeyDown(Keys.Escape)) { Exit(); } //bullet.Update(gameTime); normalBullet.Update(gameTime); fastBullet.Update(gameTime); bombBullet.Update(gameTime); player.Update(gameTime); //proj.Update(gameTime); if (player.Bounds.CollidesWith(normalBullet.Bounds) || player.Bounds.CollidesWith(fastBullet.Bounds) || player.Bounds.CollidesWith(bombBullet.Bounds)) { color = Color.PaleVioletRed; //bullet.bulletHitFX.Play(); } else { color = Color.Tan; } Lane[] lanes = { lane0, lane1, lane2, lane3, lane4 }; for (int i = 0; i < lanes.Length; i++) { if (player.Bounds.CheckLane(lanes[i].Bounds)) { laneInd = i.ToString(); } } // TODO: Add your update logic here oldKeyboardState = newKeyboardState; //var size = spriteFont.MeasureString("Use Arrow Keys to Navigate"); // TODO: Add your update logic here normalParticle.Update(gameTime); fastParticle.Update(gameTime); bombParticle.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) { smokeParticleSystem.Update(gameTime); coinParticleSystem.Update(gameTime); playerParticleSystem.Update(gameTime); newKS = Keyboard.GetState(); if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape)) { Exit(); } if (Keyboard.GetState().IsKeyDown(Keys.Escape)) { Exit(); } paddle.Update(gameTime); ball.Update(gameTime); if (paddle.bounds.CollidesWith(ball.bounds)) { ball.Velocity *= -1; Console.WriteLine("collided"); Exit(); } if (paddle.bounds.CollidesWith(coin.bounds)) { coinPickupSFX.Play(); Points += 1; Console.WriteLine("+1 point"); double randX = Random.NextDouble(); double randY = Random.NextDouble(); randX = MathHelper.Lerp(0, GraphicsDevice.Viewport.Width, (float)randX); randY = MathHelper.Lerp(0, GraphicsDevice.Viewport.Height, (float)randY); coin.bounds.X = (float)randX; coin.bounds.Y = (float)randY; } oldKS = newKS; base.Update(gameTime); // TODO: Add your update logic here }
/// <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) { newKeyboardState = Keyboard.GetState(); if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape)) { Exit(); } // update player player.Update(gameTime); camera.Follow(player); //update particle system playerParticleSystem.Update(gameTime); rainParticleSystem.Update(gameTime); cometParticleSystem.Update(gameTime); oldKeyboardState = newKeyboardState; base.Update(gameTime); }
/// <summary> /// Update the sprite, moving and animating it /// </summary> /// <param name="gameTime">The GameTime object</param> public void Update(GameTime gameTime) { old_keyboard = keyboard; keyboard = Keyboard.GetState(); float delta = (float)gameTime.ElapsedGameTime.TotalSeconds; // Bomb PowerUp powerUpTimer += gameTime.ElapsedGameTime; if (keyboard.IsKeyDown(Keys.Space) && !old_keyboard.IsKeyDown(Keys.Space) && (int)powerUpTimer.TotalMilliseconds > 10000) { powerUpTimer = new TimeSpan(0); prev_moving_state = moving_state; moving_state = MovingState.Idle; // Place Bomb in front or below character switch (prev_moving_state) { case MovingState.East: bomb.Place(new Vector2(Bounds.X + Bounds.Width / 4, Bounds.Y + Bounds.Height / 2)); break; case MovingState.North: bomb.Place(new Vector2(Bounds.X + Bounds.Width / 4, Bounds.Y + Bounds.Height / 2)); break; case MovingState.West: bomb.Place(new Vector2(Bounds.X + Bounds.Width / 4, Bounds.Y + Bounds.Height / 2)); break; case MovingState.South: bomb.Place(new Vector2(Bounds.X + Bounds.Width / 4, Bounds.Y + Bounds.Height / 2)); break; default: bomb.Place(new Vector2(Bounds.X + Bounds.Width / 4, Bounds.Y + Bounds.Height / 2)); break; } } if (powerUpTimer.TotalMilliseconds > 10000) { powerUpBarSize = 100; } else { powerUpBarSize = (int)(10 * powerUpTimer.TotalSeconds); } bomb.Update(gameTime); // Stamina if (stamina < 0) { drainedStaminaPenalty = true; speedVar = SPEED_PENALTY; staminaDelayTimer = new TimeSpan(0); stamina = 0; speed_state = SpeedState.Penalty; staminaColor = new Color(0, 0, 60); } if ((keyboard.IsKeyDown(Keys.LeftAlt) || keyboard.IsKeyDown(Keys.RightAlt)) && !drainedStaminaPenalty) { speedVar = SPEED_BOOST; stamina -= (float)gameTime.ElapsedGameTime.TotalMilliseconds; speed_state = SpeedState.Boost; } if (!(keyboard.IsKeyDown(Keys.LeftAlt) || keyboard.IsKeyDown(Keys.RightAlt)) && !drainedStaminaPenalty) { speedVar = SPEED_DEFAULT; stamina += (float)gameTime.ElapsedGameTime.TotalMilliseconds * .9f; speed_state = SpeedState.Normal; } if (drainedStaminaPenalty && !(staminaDelayTimer.TotalMilliseconds < staminaDelay)) { stamina += (float)gameTime.ElapsedGameTime.TotalMilliseconds * .4f; } if (stamina >= MAX_STAMINA) { drainedStaminaPenalty = false; stamina = MAX_STAMINA; } staminaDelayTimer += gameTime.ElapsedGameTime; if (stamina == MAX_STAMINA) { staminaBarSize = 100; } else { staminaBarSize = (int)(100 * (stamina / MAX_STAMINA)); } // Dirt Particles dirtTimer += gameTime.ElapsedGameTime; var dirtRefresh = 500; dirtOrigin = new Vector2(Bounds.X + Bounds.Width / 4, Bounds.Y + Bounds.Height - 10); if (speed_state != SpeedState.Boost && dirtTimer.TotalMilliseconds > dirtRefresh) { dirtParticleSystem = newDirtParticleSystem(game.GraphicsDevice, 1, dirtParticle, Vector2.Zero); } // Update the player state based on input if (keyboard.IsKeyDown(Keys.Up)) { prev_moving_state = moving_state; moving_state = MovingState.North; curPosition.Y -= delta * PLAYER_SPEED * speedVar; if (speed_state == SpeedState.Boost && dirtTimer.TotalMilliseconds > dirtRefresh) { dirtParticleSystem = newDirtParticleSystem(game.GraphicsDevice, 50, dirtParticle, new Vector2(0, -1)); } } else if (keyboard.IsKeyDown(Keys.Left)) { prev_moving_state = moving_state; moving_state = MovingState.West; curPosition.X -= delta * PLAYER_SPEED * speedVar; if (speed_state == SpeedState.Boost && dirtTimer.TotalMilliseconds > dirtRefresh) { dirtParticleSystem = newDirtParticleSystem(game.GraphicsDevice, 50, dirtParticle, new Vector2(-1, 0)); } } else if (keyboard.IsKeyDown(Keys.Right)) { prev_moving_state = moving_state; moving_state = MovingState.East; curPosition.X += delta * PLAYER_SPEED * speedVar; if (speed_state == SpeedState.Boost && dirtTimer.TotalMilliseconds > dirtRefresh) { dirtParticleSystem = newDirtParticleSystem(game.GraphicsDevice, 50, dirtParticle, new Vector2(1, 0)); } } else if (keyboard.IsKeyDown(Keys.Down)) { prev_moving_state = moving_state; moving_state = MovingState.South; curPosition.Y += delta * PLAYER_SPEED * speedVar; if (speed_state == SpeedState.Boost && dirtTimer.TotalMilliseconds > dirtRefresh) { dirtParticleSystem = newDirtParticleSystem(game.GraphicsDevice, 50, dirtParticle, new Vector2(0, 1)); } } else { moving_state = MovingState.Idle; } dirtParticleSystem.Update(gameTime); if (curPosition.X < 0) { curPosition.X = 0; } // Update the player animation timer when the player is moving if (moving_state != MovingState.Idle) { timer += gameTime.ElapsedGameTime; } // Determine the frame should increase. Using a while // loop will accomodate the possiblity the animation should // advance more than one frame. while (timer.TotalMilliseconds > ANIMATION_FRAME_RATE) { // increase by one frame frame++; // reduce the timer by one frame duration timer -= new TimeSpan(0, 0, 0, 0, ANIMATION_FRAME_RATE); } // Keep the frame within Bounds (there are four frames) frame %= 4; Bounds.X = curPosition.X; Bounds.Y = curPosition.Y; }
/// <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) { player.Update(gameTime); if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape)) { Exit(); } youWin.Update(gameTime); rain.Update(gameTime); youDie.Update(gameTime); bubbles.Update(gameTime); if (player.Bounds.Y < graphics.PreferredBackBufferHeight - 130) { deadFlag = false; } // TODO: Add your update logic here for (int i = 0; i < 4; i++) { if (player.Bounds.CollidesWith(levelOne[i].Bounds)) { splat.Play(); player.Reset(); deadFlag = true; deathCount++; } else if (player.Bounds.CollidesWith(levelTwo[i].Bounds)) { splat.Play(); player.Reset(); deadFlag = true; deathCount++; } else if (player.Bounds.CollidesWith(levelThree[i].Bounds)) { splat.Play(); player.Reset(); deadFlag = true; deathCount++; } else if (player.Bounds.CollidesWith(levelFour[i].Bounds)) { splat.Play(); player.Reset(); deadFlag = true; deathCount++; } else if (player.Bounds.CollidesWith(levelFive[i].Bounds)) { splat.Play(); player.Reset(); deadFlag = true; deathCount++; } //Update cars levelFive[i].Update(gameTime, 3); levelFour[i].Update(gameTime, 3); levelThree[i].Update(gameTime, 3); levelTwo[i].Update(gameTime, 2); levelOne[i].Update(gameTime, 1); } if (player.Bounds.Y < 96) { finishFlag = true; } else { finishFlag = false; } 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(); } updateable = new List <iUpdateable>(); if (viewState == ViewState.IDLE) { oldkeyboardState = keyboardState; keyboardState = Keyboard.GetState(); if (keyboardState.IsKeyDown(Keys.P) && !oldkeyboardState.IsKeyDown(Keys.P)) { NextLevel(); } if (keyboardState.IsKeyDown(Keys.Q) && !oldkeyboardState.IsKeyDown(Keys.Q)) { PreviousLevel(); } if (keyboardState.IsKeyDown(Keys.E) && !oldkeyboardState.IsKeyDown(Keys.E)) { player.curPosition = current_maze.endingPosition; } if (keyboardState.IsKeyDown(Keys.S) && !oldkeyboardState.IsKeyDown(Keys.S)) { player.curPosition = current_maze.startingPosition; } if (keyboardState.IsKeyDown(Keys.B) && !oldkeyboardState.IsKeyDown(Keys.B)) { if (current_level == 1) { player.curPosition = new Vector2(551, 451); } if (current_level == 2) { player.curPosition = new Vector2(951, 401); } } if (!win && !game_over) { if (player.Bounds.X > graphics.GraphicsDevice.Viewport.Width) { NextLevel(); return; } current_maze = levels[current_level]; // TODO: Add your update logic here updateable.Add(player); foreach (Spike spike in current_maze.spikes) { updateable.Add(spike); } foreach (Cell cell in current_maze.cells) { updateable.Add(cell); } foreach (iUpdateable obj in updateable) { obj.Update(gameTime); } foreach (Cell cell in current_maze.getNearCells(player)) { foreach (iCollidable collidable in cell.collidables) { if (collidable is Wall wall) { if (player.Bounds.CollidesWith(wall.Bounds) && !wall.destroyed) { float delta; switch (player.moving_state) { case MovingState.East: delta = (player.Bounds.X + player.Bounds.Width) - wall.Bounds.X; player.curPosition.X = wall.Bounds.X - player.Bounds.Width - delta; break; case MovingState.North: delta = (wall.Bounds.Y + wall.Bounds.Height) - player.Bounds.Y; player.curPosition.Y = wall.Bounds.Y + wall.Bounds.Height + delta; break; case MovingState.West: delta = (wall.Bounds.X + wall.Bounds.Width) - player.Bounds.X; player.curPosition.X = wall.Bounds.X + wall.Bounds.Width + delta + 1; break; case MovingState.South: delta = (player.Bounds.Y + player.Bounds.Height) - wall.Bounds.Y; player.curPosition.Y = wall.Bounds.Y - player.Bounds.Height - delta; break; } } if (player.bomb.Explosion.CollidesWith(wall.Bounds) && player.bomb.detonated && !wall.destroyed) { if (wall.isBombable) { // Wall crumble apart particle system implemented here wallParticleSystem = newWallParticleSystem(graphics.GraphicsDevice, 100, particle, wall.Position()); wall.Bounds.X = -50; wall.Bounds.Y = -50; score += 5000; } } } if (collidable is Spike spike) { if (player.Bounds.CollidesWith(spike.Bounds) && spike.on) { player.ouchSFX.Play(1, 0, 0); GameOverDeath(); } if (player.bomb.Explosion.CollidesWith(spike.Bounds) && player.bomb.detonated && spike.on) { spike.destroyed = true; score += 2000; } } if (collidable is Exit exit) { if (player.Bounds.CollidesWith(exit.Bounds)) { NextLevelExit(); // Change to Transition Slide return; } } } } foreach (Cell cell in current_maze.getNearCells(player.bomb)) { foreach (iCollidable collidable in cell.collidables) { Wall wall = collidable as Wall; Spike spike = collidable as Spike; if (wall != null) { if (player.bomb.Explosion.CollidesWith(wall.Bounds) && player.bomb.detonated && !wall.destroyed) { if (wall.isBombable) { // Wall crumble apart particle system implemented here wallParticleSystem = newWallParticleSystem(graphics.GraphicsDevice, 100, particle, wall.Position()); wall.Bounds.X = -50; wall.Bounds.Y = -50; score += 5000; } } } if (spike != null) { if (player.bomb.Explosion.CollidesWith(spike.Bounds) && player.bomb.detonated && spike.on) { spike.destroyed = true; score += 2000; } } } } if (player.Bounds.CollidesWith(player.bomb.Explosion) && player.bomb.detonated) { player.ouchBombSFX.Play(1, 0, 0); GameOverDeath(); } score--; } wallTimer += gameTime.ElapsedGameTime; if (wallTimer.TotalMilliseconds > wallTimeLimit) { wallParticleSystem = newWallParticleSystem(graphics.GraphicsDevice, 1, particle, Vector2.Zero); } wallParticleSystem.Update(gameTime); } else if (viewState == ViewState.TRANSITION_RIGHT) { } 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) { newKeyboardState = Keyboard.GetState(); if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape)) { Exit(); } // TODO: Add your update logic here player.Update(gameTime); // Enemy spawning logic if (enemySpawnCounter <= 0) { EnemyBasic enemy = new EnemyBasic(this); enemy.LoadContent(Content); enemyBasics.Add(enemy); enemySpawnX = enemy.Bounds.X + (enemy.Bounds.Width / 2); enemySpawnCounter = enemySpawnDelay; if (enemySpawnDelay >= 1) { enemySpawnDelay -= 5; } } else if (enemySpawnCounter > 0) { enemySpawnCounter--; } for (int i = 0; i < enemyBasics.Count; i++) { enemyBasics[i].Update(gameTime); if (enemyBasics[i].Bounds.Y > graphics.PreferredBackBufferHeight) { enemyBasics.RemoveAt(i); } } // Check bullet/enemy and player/enemy collisions for (int i = 0; i < enemyBasics.Count; i++) { if (CollidesWith(enemyBasics[i].Bounds, player.Bounds)) { if (!Gameover) { sfx[1].Play(); } Gameover = true; } for (int j = 0; j < player.bulletLefts.Count; j++) { if (CollidesWith(enemyBasics[i].Bounds, player.bulletLefts[j].Bounds)) { enemyBasics[i].Health--; player.bulletLefts.RemoveAt(j); } } for (int k = 0; k < player.bulletRights.Count; k++) { if (CollidesWith(enemyBasics[i].Bounds, player.bulletRights[k].Bounds)) { enemyBasics[i].Health--; player.bulletRights.RemoveAt(k); } } if (enemyBasics[i].Health <= 0) { SoundEffect.MasterVolume = 0.5f; sfx[2].Play(); SoundEffect.MasterVolume = 0.1f; explosions.Add(new Explosion(this, animations, enemyBasics[i].Bounds.X, enemyBasics[i].Bounds.Y)); score++; enemyBasics.RemoveAt(i); } } // Explosion timers for (int i = 0; i < explosions.Count; i++) { explosions[i].timer--; if (explosions[i].timer <= 0) { explosions.RemoveAt(i); } } particleSystem.Update(gameTime); particleSystemEnemy.Update(gameTime); oldKeyboardState = newKeyboardState; base.Update(gameTime); }
public void Update(GameTime gameTime) { if (!game.Gameover) { /*------------------------- * Player ship movement * -------------------------*/ var keyboardState = Keyboard.GetState(); if (keyboardState.IsKeyDown(Keys.Left)) { Bounds.X -= (float)gameTime.ElapsedGameTime.TotalMilliseconds - 5; } if (keyboardState.IsKeyDown(Keys.Right)) { Bounds.X += (float)gameTime.ElapsedGameTime.TotalMilliseconds - 5; } /*------------------------- * Player ship main firing * -------------------------*/ if (keyboardState.IsKeyDown(Keys.Z) && bulletDelayCounter == 0) { BulletLeft bulletl = new BulletLeft(game, textureBullet, this); BulletRight bulletr = new BulletRight(game, textureBullet, this); bulletLefts.Add(bulletl); bulletRights.Add(bulletr); bulletDelayCounter = bulletDelay; sfx[0].Play(); particleSystem.boolSpawn = true; } else if (bulletDelayCounter > 0) { // Ensures shots aren't produced every frame while key is held. bulletDelayCounter--; } /*------------------------- * Keep ship on screen * -------------------------*/ if (Bounds.X < 0) { Bounds.X = 0; } if (Bounds.X > game.GraphicsDevice.Viewport.Width - Bounds.Width) { Bounds.X = game.GraphicsDevice.Viewport.Width - Bounds.Width; } /*------------------------- * Update bullets, removing them if necessary * -------------------------*/ for (int i = 0; i < bulletLefts.Count; i++) { bulletLefts[i].Update(gameTime); if (bulletLefts[i].Bounds.Y <= -87) { bulletLefts.RemoveAt(i); } } for (int i = 0; i < bulletRights.Count; i++) { bulletRights[i].Update(gameTime); if (bulletRights[i].Bounds.Y <= -87) { bulletRights.RemoveAt(i); } } } particleSystem.Update(gameTime); particleSystem.boolSpawn = false; }
/// <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) { rainParticle.Update(gameTime); fireParticle.Update(gameTime); collisionParticle.Update(gameTime); //var keyboard = Keyboard.GetState(); if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape)) { Exit(); } if (!win) { time = gameTime.TotalGameTime.TotalSeconds; time = Math.Truncate(time * 1000) / 1000; } // TODO: Add your update logic here //map.Update(gameTime, player); var keyboard = Keyboard.GetState(); for (int i = 0; i < 15; i++) { for (int j = 0; j < 25; j++) { if (map.walls[i, j] != null) { //Tile tempwall = map.walls[i, j]; map.walls[i, j].Update(gameTime); if (map.walls[i, j].Bounds.Intersects(player.bounds)) { if (player.moving) { collisionParticle.SpawnPerFrame = 10; collisionParticle.SpawnParticle = (ref Particle particle) => { MouseState mouse = Mouse.GetState(); particle.Position = new Vector2(player.bounds.X + 8, player.bounds.Y + 8); if (player.direction == 0) { particle.Velocity = new Vector2( MathHelper.Lerp(0, 100, (float)random.NextDouble()), // X between -50 and 50 MathHelper.Lerp(100, -100, (float)random.NextDouble()) // Y between 0 and 100 ); } else if (player.direction == 1) { particle.Velocity = new Vector2( MathHelper.Lerp(-100, 100, (float)random.NextDouble()), // X between -50 and 50 MathHelper.Lerp(0, 100, (float)random.NextDouble()) // Y between 0 and 100 ); } else if (player.direction == 2) { particle.Velocity = new Vector2( MathHelper.Lerp(0, -100, (float)random.NextDouble()), // X between -50 and 50 MathHelper.Lerp(100, -100, (float)random.NextDouble()) // Y between 0 and 100 ); } else if (player.direction == 3) { particle.Velocity = new Vector2( MathHelper.Lerp(-100, 100, (float)random.NextDouble()), // X between -50 and 50 MathHelper.Lerp(0, -100, (float)random.NextDouble()) // Y between 0 and 100 ); } particle.Acceleration = 0.1f * new Vector2(0, (float)-random.NextDouble()); particle.Color = Color.Gold; particle.Scale = 1f; particle.Life = 0.3f; }; } else { collisionParticle.SpawnParticle = (ref Particle particle) => { MouseState mouse = Mouse.GetState(); particle.Position = new Vector2(-10, -10); particle.Velocity = new Vector2( MathHelper.Lerp(0, 100, (float)random.NextDouble()), // X between -50 and 50 MathHelper.Lerp(100, -100, (float)random.NextDouble()) // Y between 0 and 100 ); particle.Acceleration = 0.1f * new Vector2(0, (float)-random.NextDouble()); particle.Color = Color.Gold; particle.Scale = 1f; particle.Life = 0.3f; }; collisionParticle.SpawnPerFrame = 0; } if (map.walls[i, j].Type.Equals("wall")) { player.moving = false; if (player.direction == 0) { player.bounds.X += 1; } else if (player.direction == 1) { player.bounds.Y += 1; } else if (player.direction == 2) { player.bounds.X -= 1; } else if (player.direction == 3) { player.bounds.Y -= 1; } } else if (map.walls[i, j].Type.Equals("goal")) { win = true; } else if (map.walls[i, j].Type.Equals("FirePowerup")) { player.speed = 10; fireParticle.SpawnParticle = (ref Particle particle) => { MouseState mouse = Mouse.GetState(); particle.Position = new Vector2(player.bounds.X + 8, player.bounds.Y + 8); particle.Velocity = new Vector2( MathHelper.Lerp(-5, 5, (float)random.NextDouble()), // X between -50 and 50 MathHelper.Lerp(0, -100, (float)random.NextDouble()) // Y between 0 and 100 ); particle.Acceleration = 0.1f * new Vector2(0, (float)-random.NextDouble()); particle.Color = Color.Red; particle.Scale = 1f; particle.Life = 0.3f; }; map.walls[i, j] = null; } /*if (keyboard.IsKeyDown(Keys.Up)) * { * player.up = false; * //player.bounds.Y += 1; * } * //else { player.up = true; } * if (keyboard.IsKeyDown(Keys.Down)) * { * player.down = false; * //player.bounds.Y -= 1; * } * //else { player.down = true; } * if (keyboard.IsKeyDown(Keys.Left)) * { * player.left = false; * //player.bounds.X += 1; * } * //else { player.left = true; } * if (keyboard.IsKeyDown(Keys.Right)) * { * player.right = false; * //player.bounds.X -= 1; * } * //else { player.right = true; }*/ } /*else * { * player.up = true; * player.down = true; * player.left = true; * player.right = true; * player.color = Color.Yellow; * }*/ } } } player.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) { keyboardState = Keyboard.GetState(); if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape)) { Exit(); } if (keyboardState.IsKeyDown(Keys.Escape)) { Exit(); } if (keyboardState.IsKeyDown(Keys.Tab)) { this.Reset(); } // TODO: Add your update logic here particleSystem.Update(gameTime); sparkleSystem.Update(gameTime); fireSystem.Update(gameTime); player.Update(gameTime); cake.Update(gameTime); cookie.Update(gameTime); donut.Update(gameTime); carrot.Update(gameTime); broccoli.Update(gameTime); if (player.collidesWithCake(cake)) { cake.eating.Play(); score += cake.pointVal; cake.Bounds.Y = 0; cake.Bounds.X = RandomizeItem(); } if (player.collidesWithCookie(cookie)) { cookie.eating.Play(); score += cookie.pointVal; cookie.Bounds.Y = 0; cookie.Bounds.X = RandomizeItem(); } if (player.collidesWithCarrot(carrot)) { carrot.cough.Play(); score += carrot.pointVal; carrot.Bounds.Y = 0; carrot.Bounds.X = RandomizeItem(); } if (player.collidesWithBroccoli(broccoli)) { broccoli.cough.Play(); score += broccoli.pointVal; broccoli.Bounds.Y = 0; broccoli.Bounds.X = RandomizeItem(); } if (player.collidesWithDonut(donut)) { donut.eating.Play(); score += donut.pointVal; donut.Bounds.Y = 0; donut.Bounds.X = RandomizeItem(); } if (PlayerCollidesWithButton()) { buttonRect.Y += 20; score += 10; } var blockQuery = world.QueryRange(player.position.X, player.position.X + player.FRAME_WIDTH); player.CheckForBlockCollision(blockQuery); base.Update(gameTime); }
public void Update(GameTime gameTime) { particleSystem.Update(gameTime); }
public void Update(GameTime gameTime) { particleSystem.Update(gameTime); aliveTime += gameTime.ElapsedGameTime.TotalMilliseconds; }