public static void Update() { foreach (Asteroid asteroid in _asteroids) { asteroid.Update(); if (_bullet != null && asteroid.Collision(_bullet)) { System.Media.SystemSounds.Beep.Play(); _bullet = null; Score++; int size = rnd.Next(MinAsteroidSize, MaxAsteroidSize); asteroid.Power--; } if (!_ship.Collision(asteroid)) { continue; } _ship?.EnergyChange(1); System.Media.SystemSounds.Asterisk.Play(); if (_ship.Energy <= 0) { _ship?.Die(); } } if (_medicine != null && _ship.Collision(_medicine)) { _ship?.EnergyChange(-1 * MedicinePower); System.Media.SystemSounds.Hand.Play(); _medicine = null; } _medicine?.Update(); _bullet?.Update(); }
/// <summary> /// Метод обновления отрисованных объектов из памяти /// </summary> public static void Update() { _background.Update(); _bullet.Update(); _aids.Update(); if (_ship.Collision(_aids)) { _aids.Play(); _ship.Energy += _aids.Struct; _aids.Init(); } foreach (Star s in _stars) { s.Update(); } foreach (Planets p in _planets) { p.Update(); } foreach (Asteroid a in _asteroids) { a.Update(); if (a.Collision(_bullet)) { a.Play(); a.Init(); _bullet.Init(); } if (a.Collision(_ship)) { a.Play(); a.Init(); _ship.Init(); _ship.Shield -= a.Power; if (_ship.Shield == 0) { _ship.Energy -= a.Power; } else if (_ship.Energy == 0) { _ship.Die(); } } } }
public static void Update() { foreach (var baseObject in _objects) { baseObject.Update(); } _bullet.Update(); foreach (var asteroid in _asteroids) { asteroid.Update(); if (asteroid.Collision(_bullet)) { _bullet.Reborn(); asteroid.Reborn(); System.Media.SystemSounds.Hand.Play(); } } }
/// <summary> /// Обновление объектов /// </summary> public static void Update() { foreach (BaseObject obj in _objs) { obj.Update(); } foreach (var asteroid in _asteroids) { asteroid.Update(); //Сделать так, чтобы при столкновении пули с астероидом они регенерировались в разных концах экрана. if (asteroid.Collision(_bullet)) { System.Media.SystemSounds.Hand.Play(); asteroid.Pos = new Point(rand.Next(0, Width), rand.Next(0, Height)); _bullet.Pos = new Point(0, rand.Next(0, Height)); } } _bullet.Update(); }
public override void Update(GameTime gameTime) { float dt = (float)gameTime.ElapsedGameTime.TotalSeconds; // Update Particles explosionEffect.Update(dt); thrustEffect.Update(dt); // Update the bullets for (int i = 0; i < bullets.Length; i++) { Bullet b = bullets[i]; if (b != null) { b.Update(gameTime); } } if (isActive == false) { // Only allow the explosion particles to update for a short amount of time in the GameOver state if (lives <= 0) { gameOverExplosionTimer -= dt; if (gameOverExplosionTimer < 0f) { return; } } // Trigger an explosion particle effect explosionEffect.Trigger(position); timeTillRespawn -= dt; if (lives > 0 && timeTillRespawn <= 0) { Respawn(); } return; } // Trigger Thrust Particles if (isThrustEnabled) { // Play Sound // thrust_sound.Play(); /* * if (trust_sound_timer < (float)thrust_sound.Duration.TotalSeconds/2) * { * trust_sound_timer = (float)thrust_sound.Duration.TotalSeconds; * * thrust_sound.Play(); * } * trust_sound_timer -= dt; * */ // Update Particles Vector2 p = new Vector2( (float)Math.Sin(rotation), -(float)Math.Cos(rotation) ); thrustEffect.Trigger((position - (p * ship_texture.Height / 2)) - velocity); } // Spawn Protection if (spawnProtectionTime > 0) { spawnProtectionTime -= dt; } // Update the position of the ship position += velocity; // Wrap the screen position = Helper.wrapUniverse(position, ship_texture.Width, ship_texture.Height); base.Update(gameTime); }