public void AddEnemy() { if (CharPool.Count == 0) { gameLevel.levelUp(); TheForm.TimerCreateLetter.Interval = gameLevel.ENEMY_APPEAR; TheForm.TimerMoveEnemies.Interval = gameLevel.ENEMY_SPEED; generatePool(); } int i = random.Next(0, CharPool.Count); Char selected = CharPool[i]; CharPool.RemoveAt(i); Enemy enemy = new Enemy(TheForm, findValidSpawn(), selected); Enemies.Add(enemy); TheForm.GetControls().Add(enemy); }
private void DrawStrike(Enemy res) { Canon cannon = CannonToShot(res); Graphics graphics = TheForm.CreateGraphics(); Point[] points = { new Point(cannon.Left + cannon.Width/2 - 8, cannon.Top), new Point(cannon.Left + cannon.Width/2 + 8, cannon.Top), new Point(res.Left + res.Width / 2 + 5, res.Top + res.Height / 2), new Point(res.Left + res.Width / 2 - 5, res.Top + res.Height / 2)}; PathGradientBrush brush = new PathGradientBrush(points); brush.CenterPoint = new Point(cannon.Left + cannon.Width / 2, cannon.Top); brush.CenterColor = Color.DarkBlue; brush.SurroundColors = new[] { Color.White, Color.Violet}; FillMode fillMode = FillMode.Winding; graphics.FillPolygon(brush, points, fillMode); TimerStrike.Start(); }
private Canon ClosestCannon(Enemy enemy) { int min = int.MaxValue; Canon minCannon = null; foreach (Canon cannon in Cannons) { if (Math.Abs(cannon.Left - enemy.Left) < min) { min = Math.Abs(cannon.Left - enemy.Left); minCannon = cannon; } } return minCannon; }
private bool CanonIsHit(Enemy enemy) { if (Cannons.Count > 0) return enemy.Top + enemy.Height >= Cannons[0].Top; else return false; }
private Canon CannonToShot(Enemy enemy) { if (enemy.Left <= TheForm.Width / 3) return Cannons[random.Next(Cannons.Count == 1 ? 0 : 1, Cannons.Count)]; else if (enemy.Left > 2 / 3 * TheForm.Width) return Cannons[random.Next(0, Cannons.Count - 1)]; else return Cannons[random.Next(0, Cannons.Count)]; }
/// <summary> /// Checks if the spawn position does not overlap with the other letter /// </summary> /// <param name="left">Left coordinate for the test enemy</param> /// <param name="enemy">Position of the already spawned enemy</param> /// <returns>True if invalid position, false otherwise</returns> private static bool checkInvalidSpawn(int left, Enemy enemy) { return ((left >= enemy.Left) && (left <= (enemy.Left + enemy.Width)) || (left <= enemy.Left) && (left >= (enemy.Left - enemy.Width))) && (enemy.Top <= ( enemy.Height + 56)); }