public Stars(MainWindow mainWindow) { _mainWindow = mainWindow; RandGenerator = new BetterRandom(); AllStars = new List <Ellipse>(); StarTimer = new DispatcherTimer(); StarTimer.Interval = TimeSpan.FromMilliseconds(500); StarTimer.Tick += StarTimerTick; StarTimer.Start(); int starscount = RandGenerator.Between(50, 100); for (int i = 0; i < starscount; i++) { Ellipse ell = new Ellipse(); ell.Fill = Brushes.White; ell.Name = "star_ellipse"; ell.Width = 2; ell.Height = 2; ell.Margin = new Thickness( RandGenerator.Between(0, (int)_mainWindow.MainCanvas.ActualWidth), RandGenerator.Between(0, (int)_mainWindow.MainCanvas.ActualHeight), ell.Margin.Top, ell.Margin.Bottom ); AllStars.Add(ell); _mainWindow.MainCanvas.Children.Add(ell); } }
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 void BonusGeneratorTimerTick(object sender, EventArgs e) { // up difficulty if (ship.ShipScore > prev_ship_score + 500 && obst_cout_increasing_for_up_difficulty < 15) { prev_ship_score = ship.ShipScore; obst_cout_increasing_for_up_difficulty += 2; ConsoleMethod.WriteToConsole("Difficulty up! Now " + obst_cout_increasing_for_up_difficulty, Brushes.Green); } ship.ShipScore += 1; if (RandForSomethings.Between(0, 5) == 1) { if (RandForSomethings.Between(0, 1) == 0) { AmmoBonus bonus = new AmmoBonus(this); CurrentBonuses.Add(bonus); AnimationsRace.AnimationBonus(bonus); } else { HealthBonus bonus = new HealthBonus(this); CurrentBonuses.Add(bonus); AnimationsRace.AnimationBonus(bonus); } } }
public Obstacle(MainWindow mainWindow) { _mainWindow = mainWindow; RandForObst = new BetterRandom(); ObstToCanvas = new Rectangle(); VisualBrush vb_for_background = new VisualBrush(); vb_for_background.Stretch = Stretch.Fill; int image_num = RandForObst.Between(1, 4); vb_for_background.Visual = (Visual)Application.Current.Resources["bact_" + image_num]; ObstToCanvas.Fill = vb_for_background; ObstToCanvas.Width = RandForObst.Between(30, 60); ObstToCanvas.Name = "obst"; ObstToCanvas.Height = RandForObst.Between(30, 60); VisualBrush vb = new VisualBrush(); vb.Visual = (Visual)Application.Current.Resources["bact_" + image_num]; ObstToCanvas.OpacityMask = vb; ObstToCanvas.Margin = new Thickness( RandForObst.Between(0, (int)(_mainWindow.MainCanvas.ActualWidth - ObstToCanvas.Width)), RandForObst.Between(-(int)_mainWindow.MainCanvas.ActualHeight, -50), 0, 0); _mainWindow.MainCanvas.Children.Add(ObstToCanvas); }
public static void AnimationObstFired(Obstacle obst) { BetterRandom RandForAnimaObst = new BetterRandom(); //List<Rectangle> ObstPieces = new List<Rectangle>(); int count_of_pieces = RandForAnimaObst.Between(3, 5); for (int i = 0; i < count_of_pieces; i++) { // piece init Rectangle piece = new Rectangle(); VisualBrush vb_for_background = new VisualBrush(); vb_for_background.Stretch = Stretch.Fill; int image_num = RandForAnimaObst.Between(1, 4); vb_for_background.Visual = (Visual)Application.Current.Resources["bact_" + image_num]; piece.Fill = vb_for_background; piece.Width = RandForAnimaObst.Between((int)(obst.ObstToCanvas.Width * 0.3), (int)(obst.ObstToCanvas.Width * 0.4)); piece.Name = "piece"; piece.Height = RandForAnimaObst.Between((int)(obst.ObstToCanvas.Height * 0.3), (int)(obst.ObstToCanvas.Height * 0.4)); VisualBrush vb = new VisualBrush(); vb.Visual = (Visual)Application.Current.Resources["bact_" + image_num]; piece.OpacityMask = vb; piece.Margin = new Thickness( obst.ObstToCanvas.Margin.Left + obst.ObstToCanvas.Width / 2, obst.ObstToCanvas.Margin.Top + obst.ObstToCanvas.Height / 2, 0, 0 ); //ObstPieces.Add(piece); (Application.Current.MainWindow as MainWindow).MainCanvas.Children.Add(piece); // piece animation DoubleAnimation da_piece = new DoubleAnimation(); da_piece.From = 1; da_piece.To = 0; da_piece.Duration = TimeSpan.FromSeconds(RandForAnimaObst.Between(2, 4)); da_piece.FillBehavior = FillBehavior.HoldEnd; da_piece.Completed += (s, _) => AnimationObstFiredCompleted(piece); ThicknessAnimation ta_piece = new ThicknessAnimation(); ta_piece.From = piece.Margin; ta_piece.Duration = TimeSpan.FromSeconds(RandForAnimaObst.Between(2, 4)); double coord_x = Math.Cos(Math.PI / 180 * (RandForAnimaObst.Between((360 / count_of_pieces) * i, (360 / count_of_pieces) * (i + 1)) + 90)); double coord_y = Math.Cos(Math.PI / 180 * (RandForAnimaObst.Between((360 / count_of_pieces) * i, (360 / count_of_pieces) * (i + 1)))); ta_piece.To = new Thickness( piece.Margin.Left - (coord_x * RandForAnimaObst.Between(50, 100)), piece.Margin.Top - (coord_y * RandForAnimaObst.Between(50, 100)), 0, 0 ); piece.BeginAnimation(Rectangle.OpacityProperty, da_piece); piece.BeginAnimation(Rectangle.MarginProperty, ta_piece); } }
public void BossFire() { BetterRandom betterRandom = new BetterRandom(); int count_of_ammos = betterRandom.Between(100, 150); this.BossSprite.Visual = (Visual)Application.Current.Resources["boss_mouth_open_angry"]; AnimationsRace.AnimationBossFire(this, _mainWindow, count_of_ammos); }
public HealthBonus(MainWindow mainWindow) { _mainWindow = mainWindow; RandForBonus = new BetterRandom(); bonus_rectangle = new Rectangle(); bonus_rectangle.Width = healthbonus_side; bonus_rectangle.Height = healthbonus_side; VisualBrush vb_for_background = new VisualBrush(); vb_for_background.Stretch = Stretch.Fill; vb_for_background.Visual = (Visual)Application.Current.Resources["HpBonus"]; bonus_rectangle.Fill = vb_for_background; bonus_rectangle.Margin = new Thickness( RandForBonus.Between(0, (int)(_mainWindow.MainCanvas.ActualWidth - bonus_rectangle.Width)), RandForBonus.Between(-(int)_mainWindow.MainCanvas.ActualHeight, -50), 0, 0); _mainWindow.MainCanvas.Children.Add(bonus_rectangle); }
private void StarTimerTick(object sender, EventArgs e) { int starscount = RandGenerator.Between(25, 25); for (int i = 0; i < starscount; i++) { Ellipse ell = new Ellipse(); ell.Fill = Brushes.White; ell.Width = 2; ell.Height = 2; ell.Margin = new Thickness( RandGenerator.Between(0, (int)_mainWindow.MainCanvas.ActualWidth), RandGenerator.Between(-(int)_mainWindow.MainCanvas.ActualHeight / 2, 0), ell.Margin.Top, ell.Margin.Bottom ); AllStars.Add(ell); _mainWindow.MainCanvas.Children.Add(ell); } AnimationsRace.AnimationStars(AllStars); }
private void StarTimerTick(object sender, EventArgs e) { StarTimer.Interval = TimeSpan.FromSeconds(25); int starscount = RandGenerator.Between(2, 3); for (int i = 0; i < starscount; i++) { Rectangle ell = new Rectangle(); VisualBrush vb = new VisualBrush(); vb.Opacity = RandGenerator.Between(10, 40); vb.Visual = (Visual)Application.Current.Resources["cloud_" + Convert.ToString(RandGenerator.Between(1, 3))]; ell.Fill = vb; ell.OpacityMask = vb; ell.Name = "star_ellipse"; ell.Width = RandGenerator.Between(100, 200); ell.Height = RandGenerator.Between(40, 60); ell.Margin = new Thickness( RandGenerator.Between((int)ell.Width, (int)(_mainWindow.MainCanvas.ActualWidth - ell.Width)), RandGenerator.Between(-(int)_mainWindow.MainCanvas.ActualHeight / 2, 0), ell.Margin.Top, ell.Margin.Bottom ); AllStars.Add(ell); _mainWindow.MainCanvas.Children.Add(ell); } AnimationsRace.AnimationClouds(AllStars); }
public static void AnimationBonus(Bonus bonus) { ThicknessAnimation ta_bonus = new ThicknessAnimation(); ta_bonus.From = bonus.bonus_rectangle.Margin; ta_bonus.To = new Thickness(bonus.bonus_rectangle.Margin.Left, bonus.bonus_rectangle.Margin.Top + Math.Abs(bonus.bonus_rectangle.Margin.Top) + Application.Current.MainWindow.ActualHeight + bonus.bonus_rectangle.Width , bonus.bonus_rectangle.Margin.Right, bonus.bonus_rectangle.Margin.Bottom); ta_bonus.FillBehavior = FillBehavior.HoldEnd; ta_bonus.Completed += (s, _) => AnimationBonusCompleted(bonus.bonus_rectangle); BetterRandom rand = new BetterRandom(); ta_bonus.Duration = TimeSpan.FromSeconds(rand.Between(5, 7)); bonus.bonus_rectangle.BeginAnimation(Ellipse.MarginProperty, ta_bonus); }
public static void AnimationObstacles(Obstacle obst) { ThicknessAnimation ta_obst = new ThicknessAnimation(); ta_obst.From = obst.ObstToCanvas.Margin; ta_obst.To = new Thickness(obst.ObstToCanvas.Margin.Left, obst.ObstToCanvas.Margin.Top + Math.Abs(obst.ObstToCanvas.Margin.Top) + Application.Current.MainWindow.ActualHeight + obst.ObstToCanvas.Width , obst.ObstToCanvas.Margin.Right, obst.ObstToCanvas.Margin.Bottom); ta_obst.FillBehavior = FillBehavior.HoldEnd; ta_obst.Completed += (s, _) => AnimationObstaclesCompleted(obst); BetterRandom rand = new BetterRandom(); ta_obst.Duration = TimeSpan.FromSeconds(rand.Between(5, 7)); obst.ObstToCanvas.BeginAnimation(Ellipse.MarginProperty, ta_obst); }
public static void AnimationShipDamage(StarShip ship) { BetterRandom RandForAnimaObst = new BetterRandom(); //List<Rectangle> ObstPieces = new List<Rectangle>(); int count_of_pieces = RandForAnimaObst.Between(1, 2); for (int i = 0; i < count_of_pieces; i++) { // piece init Ellipse piece = new Ellipse(); piece.Fill = RandForAnimaObst.Between(1, 2) == 1 ? Brushes.Red : Brushes.Yellow; piece.Width = ship.shipRectangle.Width * 0.05; piece.Name = i == count_of_pieces - 1 ? "last_damage" : "damage"; piece.Height = ship.shipRectangle.Height * 0.04; piece.Margin = new Thickness( ship.shipRectangle.Margin.Left + ship.shipRectangle.Width / 2, ship.shipRectangle.Margin.Top + ship.shipRectangle.Height / 2, 0, 0 ); //ObstPieces.Add(piece); (Application.Current.MainWindow as MainWindow).MainCanvas.Children.Add(piece); // piece animation DoubleAnimation da_piece = new DoubleAnimation(); da_piece.From = 1; da_piece.To = 0; da_piece.Duration = TimeSpan.FromSeconds(RandForAnimaObst.Between(2, 4)); da_piece.FillBehavior = FillBehavior.HoldEnd; da_piece.Completed += (s, _) => AnimationShipDamageCompleted(piece); ThicknessAnimation ta_piece = new ThicknessAnimation(); ta_piece.From = piece.Margin; ta_piece.Duration = TimeSpan.FromSeconds(RandForAnimaObst.Between(2, 4)); double coord_x = Math.Cos(Math.PI / 180 * (RandForAnimaObst.Between((360 / count_of_pieces) * i, (360 / count_of_pieces) * (i + 1)) + 90)); double coord_y = Math.Cos(Math.PI / 180 * (RandForAnimaObst.Between((360 / count_of_pieces) * i, (360 / count_of_pieces) * (i + 1)))); ta_piece.To = new Thickness( piece.Margin.Left - (coord_x * RandForAnimaObst.Between(50, 100)), piece.Margin.Top - (coord_y * RandForAnimaObst.Between(50, 100)), 0, 0 ); piece.BeginAnimation(Rectangle.OpacityProperty, da_piece); piece.BeginAnimation(Rectangle.MarginProperty, ta_piece); } }
public static void AnimationClouds(List <Rectangle> stars) { BetterRandom rand = new BetterRandom(); for (int i = 0; i < stars.Count; i++) { ThicknessAnimation ta_stars = new ThicknessAnimation(); ta_stars.From = stars[i].Margin; double stars_to = stars[i].Margin.Top < 0 ? stars[i].Margin.Top * 2 + Application.Current.MainWindow.ActualHeight + stars[i].Width : Application.Current.MainWindow.ActualHeight - stars[i].Margin.Top + stars[i].Width; ta_stars.To = new Thickness(stars[i].Margin.Left, stars[i].Margin.Top + stars_to, stars[i].Margin.Right, stars[i].Margin.Bottom); ta_stars.FillBehavior = FillBehavior.HoldEnd; ta_stars.Duration = TimeSpan.FromSeconds(rand.Between(20, 30)); Rectangle curr_ell = stars[i]; ta_stars.Completed += (s, _) => AnimationCloudCompleted(curr_ell); stars[i].BeginAnimation(Ellipse.MarginProperty, ta_stars); } }
public static void AnimationEasterEgg(MainWindow mainWindow) { BetterRandom betterRandom = new BetterRandom(); DoubleAnimation da_piece = new DoubleAnimation(); da_piece.From = 1; da_piece.To = 0; da_piece.Duration = TimeSpan.FromSeconds(1); da_piece.FillBehavior = FillBehavior.HoldEnd; Image image = new Image(); image.Source = (BitmapImage)Application.Current.Resources["ee_" + betterRandom.Between(1, 5)]; image.Height = mainWindow.MainCanvas.ActualHeight; double coef = (image.Source as BitmapImage).Height / image.Height; image.Margin = new Thickness(mainWindow.MainCanvas.ActualWidth / 2 - ((image.Source as BitmapImage).Width / coef) / 2, 0, 0, 0); mainWindow.MainCanvas.Children.Add(image); da_piece.Completed += (s, _) => AnimationEasterEggCompleted(image); image.BeginAnimation(Rectangle.OpacityProperty, da_piece); }
public async void SetWinImages() { if (game_win) { return; } game_win = true; DateTime d11 = DateTime.Now; if (gifs_for_win == null) { image_gifs_for_win = new List <Image>(); //for (int i = 0; i < 10; i++) //{ // image_gifs_for_win.Add(new Image()); //} gifs_for_win = new List <string>(); BitmapImage_gifs_for_win = new List <BitmapImage>(); if (Directory.Exists(AppDomain.CurrentDomain.BaseDirectory + "win_gifs")) { string[] hats_files = Directory.GetFiles(AppDomain.CurrentDomain.BaseDirectory + "win_gifs/", "*.gif", SearchOption.TopDirectoryOnly); for (int i = 0; i < hats_files.Length; i++) { gifs_for_win.Add(System.IO.Path.GetFullPath(hats_files[i])); image_gifs_for_win.Add(new Image()); BitmapImage bitmapImage = new BitmapImage(); bitmapImage.BeginInit(); bitmapImage.UriSource = new Uri(hats_files[i]); bitmapImage.EndInit(); BitmapImage_gifs_for_win.Add(bitmapImage); } } } BetterRandom betterRandom = new BetterRandom(); BitmapImage_gifs_for_win = Shuffle <BitmapImage>(BitmapImage_gifs_for_win); //gifs_for_win = Shuffle(gifs_for_win); for (int i = 0; i < image_gifs_for_win.Count; i++) { image_gifs_for_win[i].Width = betterRandom.Between(100, 200); MainCanvas.Children.Add(image_gifs_for_win[i]); //double coef = widths_gifs_for_win[i] / image_gifs_for_win[i].Width; //image_gifs_for_win[i].Height = heights_gifs_for_win[i] / coef; image_gifs_for_win[i].Margin = new Thickness(betterRandom.Between(50, (int)MainCanvas.ActualWidth - (int)image_gifs_for_win[i].Width), betterRandom.Between(10, (int)MainCanvas.ActualHeight - 10), 0, 0); ImageBehavior.SetAnimatedSource(image_gifs_for_win[i], BitmapImage_gifs_for_win[i]); //AnimationBehavior.SetSourceUri(image_gifs_for_win[i], new Uri(gifs_for_win[i])); //await Task.Run(() => Thread.Sleep(100)); } }
public static async void AnimationBossNoMore(Boss _boss) { BetterRandom betterRandom = new BetterRandom(); for (int i = 0; i < 20; i++) { ThicknessAnimation ta_piece = new ThicknessAnimation(); ta_piece.From = _boss.BossRectangle.Margin; ta_piece.Duration = TimeSpan.FromMilliseconds(100); int x_margin = betterRandom.Between(-1, 1); int y_margin = betterRandom.Between(-1, 1); ta_piece.To = new Thickness( _boss.BossRectangle.Margin.Left + x_margin * 10, _boss.BossRectangle.Margin.Top + y_margin * 10, 0, 0 ); _boss.BossRectangle.BeginAnimation(Rectangle.MarginProperty, ta_piece); await System.Threading.Tasks.Task.Run(() => System.Threading.Thread.Sleep(110)); } for (int i = (Application.Current.MainWindow as MainWindow).MainCanvas.Children.Count - 1; i >= 0; i--) { if ((Application.Current.MainWindow as MainWindow).MainCanvas.Children[i] is Rectangle && ((Application.Current.MainWindow as MainWindow).MainCanvas.Children[i] as Rectangle).Name == "Boss") { (Application.Current.MainWindow as MainWindow).MainCanvas.Children.Remove((Application.Current.MainWindow as MainWindow).MainCanvas.Children[i]); break; } } BetterRandom RandForAnimaObst = new BetterRandom(); int count_of_pieces = RandForAnimaObst.Between(5, 5); int count_of_repeat = RandForAnimaObst.Between(3, 3); for (int j = 0; j < count_of_repeat; j++) { for (int i = 0; i < count_of_pieces; i++) { // piece init Ellipse piece = new Ellipse(); piece.Fill = RandForAnimaObst.Between(1, 2) == 1 ? Brushes.Red : Brushes.Yellow; piece.Width = RandForAnimaObst.Between((int)(_boss.bossRectangle.Width * 0.1), (int)(_boss.bossRectangle.Width * 0.4)); piece.Name = "gameover"; piece.Height = RandForAnimaObst.Between((int)(_boss.bossRectangle.Height * 0.1), (int)(_boss.bossRectangle.Height * 0.4)); piece.Margin = new Thickness( _boss.bossRectangle.Margin.Left + _boss.bossRectangle.Width / 2, _boss.bossRectangle.Margin.Top + _boss.bossRectangle.Height / 2, 0, 0 ); (Application.Current.MainWindow as MainWindow).MainCanvas.Children.Add(piece); // piece animation DoubleAnimation da_piece = new DoubleAnimation(); da_piece.From = 1; da_piece.To = 0; da_piece.Duration = TimeSpan.FromSeconds(RandForAnimaObst.Between(2, 2)); da_piece.FillBehavior = FillBehavior.HoldEnd; if (i == count_of_pieces - 1) { piece.Name = "win_a"; } da_piece.Completed += (s, _) => AnimationShipDamageCompleted(piece); ThicknessAnimation ta_piece = new ThicknessAnimation(); ta_piece.From = piece.Margin; ta_piece.Duration = TimeSpan.FromSeconds(RandForAnimaObst.Between(2, 2)); double coord_x = Math.Cos(Math.PI / 180 * (RandForAnimaObst.Between((360 / count_of_pieces) * i, (360 / count_of_pieces) * (i + 1)) + 90)); double coord_y = Math.Cos(Math.PI / 180 * (RandForAnimaObst.Between((360 / count_of_pieces) * i, (360 / count_of_pieces) * (i + 1)))); ta_piece.To = new Thickness( piece.Margin.Left - (coord_x * RandForAnimaObst.Between(50, 100)), piece.Margin.Top - (coord_y * RandForAnimaObst.Between(50, 100)), 0, 0 ); piece.BeginAnimation(Rectangle.OpacityProperty, da_piece); piece.BeginAnimation(Rectangle.MarginProperty, ta_piece); } } }
public static async void AnimationBossFire(Boss _boss, MainWindow mainWindow, int count_of_ammos) { _boss.NowFire = true; BetterRandom betterRandom = new BetterRandom(); int attack_type = betterRandom.Between(1, 2); if (_boss.StopFire) { return; } //int attack_type = 2; if (attack_type == 1) { for (int i = 0; i < count_of_ammos; i++) { if (_boss == null) { return; } Ellipse fire = new Ellipse(); fire.Width = _boss.size_of_ammo; fire.Height = _boss.size_of_ammo; fire.Fill = Brushes.Red; fire.Name = "boss_fire"; _boss.CurrentBossAmmos.Add(fire); fire.Margin = new Thickness(_boss.BossRectangle.Margin.Left + _boss.BossRectangle.Width / 2 - 10, _boss.BossRectangle.Margin.Top + _boss.BossRectangle.Height * 0.7, 0, 0); mainWindow.MainCanvas.Children.Add(fire); ThicknessAnimation ta_piece = new ThicknessAnimation(); ta_piece.From = fire.Margin; ta_piece.Duration = TimeSpan.FromSeconds(2); ta_piece.To = new Thickness( fire.Margin.Left, mainWindow.ActualHeight + fire.Height, 0, 0 ); if (i == count_of_ammos - 1) { try { fire.Name = "finish"; (Application.Current.MainWindow as MainWindow).boss.BossSprite.Visual = (Visual)Application.Current.Resources["boss_regular_angry"]; } catch { } } Ellipse ell = fire; ta_piece.Completed += (s, _) => AnimationFireBossCompleted(ell); fire.BeginAnimation(Rectangle.MarginProperty, ta_piece); await Task.Run(() => System.Threading.Thread.Sleep(80)); } } else if (attack_type == 2) { double to_left = 0; int plusOrMinus = 0; double to_top = (Application.Current.MainWindow as MainWindow).ActualHeight; for (int i = 0; i < count_of_ammos; i++) { if (_boss == null) { return; } Ellipse fire = new Ellipse(); fire.Width = _boss.size_of_ammo; fire.Height = _boss.size_of_ammo; fire.Fill = Brushes.Red; _boss.CurrentBossAmmos.Add(fire); fire.Margin = new Thickness(_boss.BossRectangle.Margin.Left + _boss.BossRectangle.Width / 2 - 10, _boss.BossRectangle.Margin.Top + _boss.BossRectangle.Height * 0.7, 0, 0); mainWindow.MainCanvas.Children.Add(fire); ThicknessAnimation ta_piece = new ThicknessAnimation(); ta_piece.From = fire.Margin; ta_piece.Duration = TimeSpan.FromSeconds(2); ta_piece.To = new Thickness( to_left, to_top + fire.Height, 0, 0 ); if (i == count_of_ammos - 1) { try { fire.Name = "finish"; (Application.Current.MainWindow as MainWindow).boss.BossSprite.Visual = (Visual)Application.Current.Resources["boss_regular_angry"]; } catch { } } Ellipse ell = fire; ta_piece.Completed += (s, _) => AnimationFireBossCompleted(ell); fire.BeginAnimation(Rectangle.MarginProperty, ta_piece); await Task.Run(() => System.Threading.Thread.Sleep(70)); if (plusOrMinus == 0) { if (to_left >= (Application.Current.MainWindow as MainWindow).ActualWidth) { plusOrMinus = 2; } to_left += 20; } else { if (to_left <= 0) { plusOrMinus = 0; } to_left -= 20; } } } }
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"]; }
public static async void AnimationWalkBossCircle(Boss _boss, MainWindow mainWindow) { _boss.NowMove = true; BetterRandom betterRandom = new BetterRandom(); int repeat_times = 1; int speed_time = betterRandom.Between(2, 4); ThicknessAnimation ta_piece = new ThicknessAnimation(); ta_piece.From = _boss.BossRectangle.Margin; ta_piece.Duration = TimeSpan.FromSeconds(1); ta_piece.FillBehavior = FillBehavior.HoldEnd; Thickness thickness_to = new Thickness( 20, mainWindow.MainCanvas.ActualHeight / 2 - _boss.BossRectangle.Height / 2, 0, 0 ); ta_piece.To = thickness_to; _boss.BossRectangle.BeginAnimation(Rectangle.MarginProperty, ta_piece); await Task.Run(() => System.Threading.Thread.Sleep(1010)); for (int i = 0; i < repeat_times; i++) { ThicknessAnimation from_left_to_right = new ThicknessAnimation(); from_left_to_right.From = _boss.BossRectangle.Margin; from_left_to_right.Duration = TimeSpan.FromSeconds(2); from_left_to_right.FillBehavior = FillBehavior.HoldEnd; from_left_to_right.To = new Thickness(mainWindow.MainCanvas.ActualWidth / 2 - _boss.BossRectangle.Width / 2 - 20, 20 , 0, 0); _boss.BossRectangle.BeginAnimation(Rectangle.MarginProperty, from_left_to_right); await Task.Run(() => System.Threading.Thread.Sleep(2010)); ThicknessAnimation from_up_to_down = new ThicknessAnimation(); from_up_to_down.From = _boss.BossRectangle.Margin; from_up_to_down.Duration = TimeSpan.FromSeconds(1); from_up_to_down.FillBehavior = FillBehavior.HoldEnd; from_up_to_down.To = new Thickness(mainWindow.MainCanvas.ActualWidth - _boss.BossRectangle.Width - 20, mainWindow.MainCanvas.ActualHeight / 2 - _boss.BossRectangle.Height / 2 , 0, 0); _boss.BossRectangle.BeginAnimation(Rectangle.MarginProperty, from_up_to_down); await Task.Run(() => System.Threading.Thread.Sleep(1010)); ThicknessAnimation from_right_to_left = new ThicknessAnimation(); from_right_to_left.From = _boss.BossRectangle.Margin; from_right_to_left.Duration = TimeSpan.FromSeconds(2); from_right_to_left.FillBehavior = FillBehavior.HoldEnd; from_right_to_left.To = new Thickness(mainWindow.MainCanvas.ActualWidth / 2 - _boss.BossRectangle.Width / 2, mainWindow.MainCanvas.ActualHeight / 2 , 0, 0); _boss.BossRectangle.BeginAnimation(Rectangle.MarginProperty, from_right_to_left); await Task.Run(() => System.Threading.Thread.Sleep(2010)); ThicknessAnimation from_down_to_up = new ThicknessAnimation(); from_down_to_up.From = _boss.BossRectangle.Margin; from_down_to_up.Duration = TimeSpan.FromSeconds(1); from_down_to_up.FillBehavior = FillBehavior.HoldEnd; from_down_to_up.To = new Thickness(_boss.BossRectangle.Margin.Left, 20 , 0, 0); from_down_to_up.Completed += (s, _) => AnimationMoveBossCompleted(_boss, null); _boss.BossRectangle.BeginAnimation(Rectangle.MarginProperty, from_down_to_up); } }
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]); } } }