/// <summary> /// Actualiza la posición de las colecciones de proyectiles /// </summary> /// <param name="gameTime">Valor de tiempo actual</param> public void UpdateProjectiles(GameTime gameTime) { lock (l) { for (int i = Projectiles.Count - 1; i >= 0; i--) { Projectiles[i].Update(gameTime); if (!GameMain.ScreenRect.Contains(Projectiles[i].Location.ToPoint())) { Projectiles.Remove(Projectiles[i]); Player.ProjectilesAvailable++; } } for (int i = EnemyProjectiles.Count - 1; i >= 0; i--) { EnemyProjectiles[i].Update(gameTime); if (!GameMain.ScreenRect.Contains(EnemyProjectiles[i].Location.ToPoint())) { Projectiles.Remove(EnemyProjectiles[i]); } } } }
public void DestroyProjectile(Projectile projectile) { if (projectile == null) { return; } Projectiles.Remove(projectile); OnChange(); }
public void AddProjectile(ISimulatedEntity entity) { Projectiles.Add(entity); solver.AddEntity(entity); entity.Destroyed += () => { Projectiles.Remove(entity); solver.RemoveEntity(entity); }; }
/// <summary> /// Called by projectiles when they land / hit, this is where we apply damage/slows etc. /// </summary> public void ApplyEffects(IAttackableUnit u, IProjectile p = null) { if (SpellData.HaveHitEffect && !string.IsNullOrEmpty(SpellData.HitEffectName)) { ApiFunctionManager.AddParticleTarget(Owner, SpellData.HitEffectName, u); } _spellGameScript.ApplyEffects(Owner, u, this, p); if (p.IsToRemove()) { Projectiles.Remove(p.NetId); } }
/// <summary> /// Updates the projectiles. /// </summary> /// <param name="gameTime">The GameTime.</param> private void UpdateProjectiles(GameTime gameTime) { for (int i = 0; i < Projectiles.Count; i++) { Projectile t = Projectiles[i]; if (t.Position.X > 801) { Projectiles.Remove(t); i++; } else { t.Update(gameTime); } } }
public void Update(GameTime gameTime, float screenWidth, float screenHeight, float topBoundary) { Velocity += shipSpeed * Input.GetMovementDirection(); base.Update(gameTime, screenWidth, screenHeight); Position = Vector2.Clamp(Position, new Vector2(0, (GameRoot.ScreenSize.Y / 2 + Size.Y / 2)), new Vector2(GameRoot.ScreenSize.X, (GameRoot.ScreenSize.Y - Size.Y / 2))); _direction = Velocity.X < 0 ? ShipDirection.Left : Velocity.X > 0 ? ShipDirection.Right : ShipDirection.Middle; if (explosionTime == 0) { CreateProjectiles(gameTime); MakeExhaustFire(gameTime); } for (int i = Projectiles.Count - 1; i >= 0; i--) { if (Projectiles[i].Position.Y <= 0) { Projectiles.Remove(Projectiles[i]); //_projectiles[i].Active = false; } else { Projectiles[i].Update(gameTime, screenWidth, screenHeight); } } if (explosionTime > 0 && (gameTime.TotalGameTime.TotalSeconds - explosionTime) > 2) { explosionTime = 0; Position.X = screenWidth / 2; Position.Y = screenHeight; blinkTime = gameTime.TotalGameTime.TotalSeconds; } if (blinkTime > 0 && (gameTime.TotalGameTime.TotalSeconds - blinkTime) > 5) { blinkTime = 0; blinking = false; } Velocity = Vector2.Zero; }
private void DoWithProjectiles() { //полёт снарядов foreach (var p in Projectiles) { p.Run(); } foreach (var p in PackmanProjectiles) { p.Run(); } //столкновение снаряда с границей foreach (var t in Projectiles) { switch (t._direction) { case Direction.Left: if (t.X + 10 < 0) { Projectiles.Remove(t); } break; case Direction.Right: if (t.X + 20 > _fieldWidth) { Projectiles.Remove(t); } break; case Direction.Up: if (t.Y + 10 < 0) { Projectiles.Remove(t); } break; case Direction.Down: if (t.Y + 20 > _fieldHeight) { Projectiles.Remove(t); } break; } break; } foreach (var t in PackmanProjectiles) { switch (t._direction) { case Direction.Left: if (t.X + 10 < 0) { PackmanProjectiles.Remove(t); } break; case Direction.Right: if (t.X + 20 > _fieldWidth) { PackmanProjectiles.Remove(t); } break; case Direction.Up: if (t.Y + 10 < 0) { PackmanProjectiles.Remove(t); } break; case Direction.Down: if (t.Y + 20 > _fieldHeight) { PackmanProjectiles.Remove(t); } break; } break; } //столкновение снаряда со стеной foreach (var a in Walls) { for (int i = 0; i < Projectiles.Count; i++) { if (AllCollision.BoxCollides(Projectiles[i].X + 10, Projectiles[i].Y + 10, 10, 10, a.XLeft, a.YUp, a.XRight - a.XLeft, a.YDown - a.YUp)) { Projectiles.Remove(Projectiles[i]); } } } foreach (var a in Walls) { for (int i = 0; i < PackmanProjectiles.Count; i++) { if (AllCollision.BoxCollides(PackmanProjectiles[i].X + 10, PackmanProjectiles[i].Y + 10, 10, 10, a.XLeft, a.YUp, a.XRight - a.XLeft, a.YDown - a.YUp)) { PackmanProjectiles.Remove(PackmanProjectiles[i]); } } } }
/// <summary> /// Removes a specified projectile from the list of projectiles /// </summary> /// <param name="ID"> ID of the specified projectile to be removed </param> public void ProjectileRemove(int ID) { Projectiles.Remove(ID); }
/// <summary> /// Updates the collisions. /// </summary> /// <param name="gameTime">The GameTime.</param> private void UpdateCollisions(GameTime gameTime) { var deadEnemies = new List <Enemy>(); for (int i = 0; i < Enemies.Count; i++) { Enemy enemy = Enemies[i]; if (enemy.IntersectsWith(Player)) { Player.Damage(Enemy.AttackDamage); Enemies.Remove(enemy); i++; if (Player.Health <= 0) { GameOver = true; } //create explosion #if AUDIO_ENABLED #endif CreateExplosion(new Vector2(enemy.Position.X - 40, enemy.Position.Y - 33)); } else { for (int x = 0; x < Projectiles.Count; x++) { Projectile projectile = Projectiles[x]; if (projectile.IntersectsWith(enemy)) { enemy.Damage(Projectile.AttackDamage); //remove the projectile on hit. Projectiles.Remove(projectile); x++; if (enemy.Health <= 0) { //remove the enemy if health is 0 or lower. Enemies.Remove(enemy); i++; var score = (int)(enemy.Velocity * 1000); CreateScoreIndicator(enemy.Position, score, Color.White); Score += score; //notify achievement AchievementManager.Get <EnemyDestroyedAchievement>().Add(1); AchievementManager.Get <ScoreAchievement>().Add(Score); //create explosion #if AUDIO_ENABLED new Task(() => { _explosion.Play(); }).Start(); #endif CreateExplosion(new Vector2(enemy.Position.X - 20, enemy.Position.Y - 30)); } } } } //check collision between enemies. for (int x = 0; x < Enemies.Count - 1; x++) { if (enemy != Enemies[x]) { if (enemy.IntersectsWith(Enemies[x])) { enemy.Damage(Enemy.AttackDamage); Enemies[x].Damage(Enemy.AttackDamage); #if AUDIO_ENABLED new Task(() => { _explosion.Play(); }).Start(); #endif deadEnemies.Add(enemy); CreateExplosion(new Vector2(enemy.Position.X - 20, enemy.Position.Y - 30)); deadEnemies.Add(Enemies[x]); CreateExplosion(new Vector2(Enemies[x].Position.X - 20, Enemies[x].Position.Y - 30)); } } } } foreach (Enemy enemy in deadEnemies) { Enemies.Remove(enemy); } }
internal void RemoveProjectile(Projectile projectile) { Projectiles.Remove(projectile); DrawNodeUsers.Remove(projectile); RemoveChild(projectile); }