private void GameLogic_Tick(object sender, EventArgs e) { int boatGen = rand.Next(1, 100); int fishGen = rand.Next(1, 200); int powerGen = rand.Next(0, 300); Refresh(); ScoreCounter.Text = "Score: " + score; if (explosion) { explosionTime++; } if (menuScreen) { GameTimer.Enabled = false; } if (powerGen == 22 && powerUp == null) { powerUp = new PowerUp(rand.Next(Height / 2, Height)); Console.WriteLine("Power up dropped"); } if (timeLeft == 0) { Timer.Text = "Time left: 0"; gameOver(); } if (targets.Count > 0) { targets = targets.OrderBy(y => y.getY()).ToList(); } if (targets.Count < 4 && boatGen == 25) { int selector = rand.Next(1, 4); int z = rand.Next(0, 16); if (selector == 1) { targets.Add(new SmallBoat(Height / 3 - z)); } else if (selector == 2) { targets.Add(new MediumBoat(Height / 3 - z)); } else { targets.Add(new LargeBoat(Height / 3 - z)); } } if (fishies.Count < 20 && fishGen == 66) { int y = rand.Next(Height / 3 + 60, Height); fishies.Add(new Fish(y)); Console.WriteLine("Fish added"); } if (explosionTime > 15) { ExplosionGIF.Visible = false; explosion = false; explosionTime = 0; } if (gameRunning) { TargetMovement.Enabled = true; TorpedoMovement.Enabled = true; FishMovement.Enabled = true; GameTimer.Enabled = true; } else { TargetMovement.Enabled = false; TorpedoMovement.Enabled = false; FishMovement.Enabled = false; GameTimer.Enabled = false; } if (powerUp != null) { if (powerUp.getHitbox().IntersectsWith(sub.getHitbox())) { if (maxTorpedos < 4) { maxTorpedos++; powerUp = null; Console.WriteLine("Torpedo count increased"); } } } for (int i = 0; i < targets.Count; i++) { Boats boat = targets.ElementAt(i); Rectangle hitbox = boat.getHitbox(); for (int o = 0; o < torpedos.Count; o++) { Torpedo torp = torpedos.ElementAt(o); Rectangle hit = torp.getHitbox(); if (hitbox.IntersectsWith(hit)) { Console.WriteLine("Kill confirmed!"); torpedos.Remove(torp); if (!explosion) { int h = torp.getY() - 20; int j = torp.getX(); ExplosionGIF.Location = new Point(j, h); ExplosionGIF.Visible = true; explosion = true; explosionSound.Play(); } targets.Remove(boat); score = score + boat.getScore(); } } } if (!menuScreen) { for (int i = 0; i < fishies.Count; i++) { Fish fish = fishies.ElementAt(i); Rectangle hitbox = fish.getHitbox(); if (hitbox.IntersectsWith(sub.getHitbox())) { gameOver(); } } for (int i = 0; i < bombs.Count; i++) { Bomb bomb = bombs.ElementAt(i); Rectangle hitbox = bomb.getHitbox(); if (hitbox.IntersectsWith(sub.getHitbox())) { gameOver(); } } } }