public override void Update(GameTime gameTime, Rectangle clientBounds) { position.X = Mouse.GetState().X - 20; position.Y = Mouse.GetState().Y - 20; currentFrame.X = CollisionRect.Contains(new Point((int)position.X, (int)position.Y)) ? 1 : 0; base.Update(gameTime, clientBounds); }
public override void Update(GameTime gameTime, Rectangle clientBounds) { #region Нанесение урона //позиция центра башни Vector2 centerPos = new Vector2(position.X + podiumFrameSize.X / 2, position.Y + podiumFrameSize.Y / 2); //общее количество миллисекунд с начала суток _timeSinceLastFrame += 16; #region Если цель не захвачена if (currentTarget == null) { for (int i = 0; i < SpriteManager.zombieList.Count; i++) { var distance = Vector2.Distance(centerPos, new Vector2(SpriteManager.zombieList[i].CollisionRect.Center.X, SpriteManager.zombieList[i].CollisionRect.Center.Y)); if (distance < Range && SpriteManager.zombieList[i].Health >= 0) { currentTarget = SpriteManager.zombieList[i]; break; } } } #endregion #region Если цель захвачена if (currentTarget != null) { var direction = (new Vector2(currentTarget.CollisionRect.Center.X, currentTarget.CollisionRect.Center.Y) - centerPos); angle = (float)Math.Atan2(direction.Y, direction.X) + MathHelper.Pi; float distance = Vector2.Distance(centerPos, new Vector2(currentTarget.CollisionRect.Center.X, currentTarget.CollisionRect.Center.Y)); if (distance < Range && _timeSinceLastFrame >= TowerSpeed && currentTarget.Health >= 0) { _timeSinceLastFrame = 0; if (currentTarget.Health >= 0) { if (_fireCounter == 0) { showFire = true; } currentTarget.Health -= Damage; #region Splash if (SplashDamage != 0) { for (int i = 0; i < SpriteManager.zombieList.Count; i++) { var distanceBetweenZombies = Vector2.Distance( new Vector2(currentTarget.CollisionRect.Center.X, currentTarget.CollisionRect.Center.Y), new Vector2(SpriteManager.zombieList[i].CollisionRect.Center.X, SpriteManager.zombieList[i].CollisionRect.Center.Y)); if (distanceBetweenZombies < SplashRange) { if (currentTarget == SpriteManager.zombieList[i]) { continue; } SpriteManager.zombieList[i].Health -= SplashDamage; } } } #endregion } else { currentTarget = null; } } else { currentTarget = null; } } #endregion #endregion #region Огонь if (showFire) { if (_fireCounter == 5) { showFire = false; _fireCounter = 0; } else { _fireCounter++; } } #endregion #region Табличка характеристик башни mouseState = Mouse.GetState(); mousePos = new Point(mouseState.X, mouseState.Y); if (CollisionRect.Contains(mousePos) && !onMouse) { showTowerTable = true; } else { showTowerTable = false; } #endregion base.Update(gameTime, clientBounds); }