public void BossActionTimerTimerTick(object sender, EventArgs e) { if (NowInit == 0) { AnimationsRace.AnimationBossInit(this, _mainWindow); } BetterRandom betterRandom = new BetterRandom(); int fire_or_not = betterRandom.Between(1, 2); int move_or_not = betterRandom.Between(1, 3); if (fire_or_not == 1 && !NowFire && NowInit == 2) { if (StopFire) { return; } Sounds.PlaySoundOnce("boss_scream_" + betterRandom.Between(1, 2) + ".wav"); BossFire(); } if (move_or_not == 1 && !NowMove && NowInit == 2) { AnimationsRace.AnimationWalkBossCircle(this, _mainWindow); } else if (move_or_not == 2 && !NowMove && NowInit == 2) { AnimationsRace.AnimationWalkBossRectangle(this, _mainWindow); } }
private async void GameWin() { Sounds.PlaySoundOnce("win_gto.wav"); Sounds.StopBackGround(); Sounds.StopBossBackGround(); BonusGeneratorTimer.Stop(); ObstsGeneratorTimer.Stop(); KeyTrackTimer.Stop(); CollisionTimer.Stop(); stars.StarTimer.Stop(); foreach (Obstacle item in CurrentObsts) { item.ObstacleFiredAnimation(); RemoveElementAfterAnimation(item.ObstToCanvas); } CurrentObsts.Clear(); boss.StopFire = true; boss.CurrentBossAmmos.Clear(); stars.AllStars.Clear(); ship.CurrentAmmos.Clear(); AnimationsRace.AnimationBossNoMore(boss); await Task.Run(() => Thread.Sleep(TimeSpan.FromSeconds(10))); for (int i = MainCanvas.Children.Count - 1; i >= 0; i--) { MainCanvas.Children.Remove(MainCanvas.Children[i]); } ShowWinGifs(); }
public static async void AnimationBossInit(Boss _boss, MainWindow mainWindow) { _boss.NowMove = true; _boss.NowInit = 1; ThicknessAnimation ta_piece = new ThicknessAnimation(); _boss.BossRectangle.Margin = new Thickness(mainWindow.MainCanvas.ActualWidth + 10, 0, 0, 0); ta_piece.From = _boss.BossRectangle.Margin; ta_piece.Duration = TimeSpan.FromSeconds(3); ta_piece.To = new Thickness( _boss.BossRectangle.Margin.Left - _boss.BossRectangle.Width / 2, _boss.BossRectangle.Margin.Top, 0, 0 ); _boss.BossRectangle.BeginAnimation(Rectangle.MarginProperty, ta_piece); await Task.Run(() => System.Threading.Thread.Sleep(3010)); _boss.BossSprite.Visual = (Visual)Application.Current.Resources["boss_regular_angry"]; await Task.Run(() => System.Threading.Thread.Sleep(1000)); _boss.BossSprite.Visual = (Visual)Application.Current.Resources["boss_regular"]; ThicknessAnimation ta_piece1 = new ThicknessAnimation(); ta_piece1.From = _boss.BossRectangle.Margin; ta_piece1.Duration = TimeSpan.FromSeconds(3); ta_piece1.To = new Thickness( _boss.BossRectangle.Margin.Left + _boss.BossRectangle.Width / 2, _boss.BossRectangle.Margin.Top, 0, 0 ); _boss.BossRectangle.BeginAnimation(Rectangle.MarginProperty, ta_piece1); await Task.Run(() => System.Threading.Thread.Sleep(3010)); ThicknessAnimation ta_piece2 = new ThicknessAnimation(); Thickness from_t = new Thickness(mainWindow.MainCanvas.ActualWidth - _boss.BossRectangle.Width - 10, mainWindow.MainCanvas.ActualHeight - 10, 0, 0); ta_piece2.From = from_t; ta_piece2.Duration = TimeSpan.FromSeconds(3); ta_piece2.To = new Thickness( from_t.Left, from_t.Top - _boss.BossRectangle.Height / 2, 0, 0 ); ta_piece2.FillBehavior = FillBehavior.HoldEnd; _boss.BossRectangle.BeginAnimation(Rectangle.MarginProperty, ta_piece2); await Task.Run(() => System.Threading.Thread.Sleep(3010)); _boss.BossSprite.Visual = (Visual)Application.Current.Resources["boss_regular_angry"]; await Task.Run(() => System.Threading.Thread.Sleep(1000)); _boss.BossSprite.Visual = (Visual)Application.Current.Resources["boss_regular"]; ThicknessAnimation ta_piece3 = new ThicknessAnimation(); ta_piece3.From = _boss.BossRectangle.Margin; ta_piece3.Duration = TimeSpan.FromSeconds(3); ta_piece3.To = new Thickness( from_t.Left, from_t.Top + _boss.BossRectangle.Height / 2, 0, 0 ); _boss.BossRectangle.BeginAnimation(Rectangle.MarginProperty, ta_piece3); await Task.Run(() => System.Threading.Thread.Sleep(3010)); ThicknessAnimation ta_piece4 = new ThicknessAnimation(); Thickness from_t4 = new Thickness(mainWindow.MainCanvas.ActualWidth / 2 - _boss.BossRectangle.Width / 2, -_boss.BossRectangle.Height, 0, 0); ta_piece4.From = from_t4; ta_piece4.Duration = TimeSpan.FromSeconds(3); Thickness thickness_to = new Thickness( from_t4.Left, from_t4.Top + _boss.BossRectangle.Height + 20, 0, 0 ); ta_piece4.To = thickness_to; ta_piece4.Completed += (s, _) => AnimationMoveBossCompleted(_boss, null); // ta_piece4.FillBehavior = FillBehavior.HoldEnd; _boss.BossRectangle.BeginAnimation(Rectangle.MarginProperty, ta_piece4); await Task.Run(() => System.Threading.Thread.Sleep(3010)); BetterRandom betterRandom = new BetterRandom(); Sounds.PlaySoundOnce("boss_scream_" + betterRandom.Between(1, 2) + ".wav"); _boss.BossSprite.Visual = (Visual)Application.Current.Resources["boss_mouth_open_angry"]; await Task.Run(() => System.Threading.Thread.Sleep(2000)); _boss.BossSprite.Visual = (Visual)Application.Current.Resources["boss_regular_angry"]; }
private void Window_KeyDown(object sender, KeyEventArgs e) { setarrowarr(e.Key); switch (e.Key) { case Key.Left: { leftpress = true; break; } case Key.Up: { uppress = true; break; } case Key.Right: { rightpress = true; break; } case Key.Down: { downpress = true; break; } case Key.Space: { if (ship.ShipAmmo > 0) { Sounds.PlaySoundOnce("laser_shoot.wav"); } else { Sounds.EmpLaserSoundPlay(); } spacepress = true; break; } case Key.Oem3: { bool has_console = false; foreach (Window item in Application.Current.Windows) { if (item is Console) { has_console = true; item.Close(); break; } } if (!has_console) { Console _console = new Console(); _console.Owner = this; _console.Show(); } break; } case Key.Escape: { Pause(); break; } } }
private void CollisionTimerTimerTick(object sender, EventArgs e) { BetterRandom random_for_some = new BetterRandom(); // check collision obsts and ship for (int i = 0; i < CurrentObsts.Count; i++) { if (ship.ShipHitBox.IntersectsWith(CurrentObsts[i].GetHitBoxObst())) { ser_hurt = true; ship.ShipSprite.Visual = (Visual)Application.Current.Resources["seryoja_hurt"]; ConsoleMethod.WriteToConsole("Obst number " + i + " hitted!", Brushes.White); ship.ShipHp = ship.ShipHp - CurrentObsts[i].ObstDamage <= 0 ? 0 : (int)(ship.ShipHp - CurrentObsts[i].ObstDamage); AnimationsRace.AnimationShipDamage(ship); Sounds.PlaySoundOnce("hurt_" + random_for_some.Between(1, 2) + ".wav"); if (ship.ShipHp == 0) { GameOver(); } } } // check collision bullets and obsts for (int i = ship.CurrentAmmos.Count - 1; i >= 0; i--) { // bullet on obsts for (int j = 0; j < CurrentObsts.Count; j++) { if (CurrentObsts[j].GetHitBoxObst().IntersectsWith( ship.GetHitBoxFire(ship.CurrentAmmos[i])) && !CurrentObsts[j].Hitted) { CurrentObsts[j].Hitted = true; ship.ShipScore += 10; ConsoleMethod.WriteToConsole("Obst number " + j + " fired by bullet number " + i + "!", Brushes.White); CurrentObsts[j].ObstacleFiredAnimation(); RemoveElementAfterAnimation(CurrentObsts[j].ObstToCanvas); CurrentObsts.Remove(CurrentObsts[j]); Sounds.ObstDamageSoundPlay(); } } // bullet on boss if (bossfight) { if (ship.CurrentAmmos.Count == 0) { return; } if (boss.GetBossHitBox().IntersectsWith(ship.GetHitBoxFire(ship.CurrentAmmos[i]))) { if (boss.BossHealthPoint >= 0) { MainCanvas.Children.Remove(ship.CurrentAmmos[i]); boss.BossHealthPoint -= ship.ShipFireDamage; progressBarHealthBoss.Value = boss.BossHealthPoint; ConsoleMethod.WriteToConsole("Boss hitted!", Brushes.GreenYellow); continue; } else { GameWin(); } } } } // collision boss fire with seryoja if (bossfight) { for (int i = 0; i < boss.CurrentBossAmmos.Count; i++) { try { Rect BossFireHitBox = new Rect(); BossFireHitBox.Width = boss.CurrentBossAmmos[i].Width; BossFireHitBox.Height = boss.CurrentBossAmmos[i].Height; BossFireHitBox.X = boss.CurrentBossAmmos[i].Margin.Left; BossFireHitBox.Y = boss.CurrentBossAmmos[i].Margin.Top; if (BossFireHitBox.IntersectsWith(ship.ShipHitBox)) { if (ship.ShipHp > 0) { ship.ShipHp = ship.ShipHp - boss.BossFireDamage <= 0 ? 0 : ship.ShipHp - boss.BossFireDamage; } else { GameOver(); } } } catch { } } } // check collision with bonuses for (int i = 0; i < CurrentBonuses.Count; i++) { if (ship.ShipHitBox.IntersectsWith(CurrentBonuses[i].GetHitBoxObst()) && !CurrentBonuses[i].Hitted) { CurrentBonuses[i].Hitted = true; if (CurrentBonuses[i] is AmmoBonus) { ser_hurt = true; ship.ShipSprite.Visual = (Visual)Application.Current.Resources["seryoja_happy"]; ConsoleMethod.WriteToConsole("Ammo Bonus obtained!", Brushes.White); ship.ShipAmmo += (CurrentBonuses[i] as AmmoBonus).ammo_count; Sounds.PlaySoundOnce("meh_" + random_for_some.Between(1, 2) + ".wav"); } else if (CurrentBonuses[i] is HealthBonus) { ConsoleMethod.WriteToConsole("HP Bonus obtained!", Brushes.White); if (ship.ShipHp < 100) { ser_hurt = true; ship.ShipSprite.Visual = (Visual)Application.Current.Resources["seryoja_happy"]; ship.ShipHp = ship.ShipHp + (CurrentBonuses[i] as HealthBonus).health_count >= 100 ? 100 : ship.ShipHp + (CurrentBonuses[i] as HealthBonus).health_count; Sounds.PlaySoundOnce("meh_" + random_for_some.Between(1, 2) + ".wav"); } else { continue; } } RemoveElementAfterAnimation(CurrentBonuses[i].bonus_rectangle); CurrentBonuses.Remove(CurrentBonuses[i]); } } }