private void StoryBoardTimerTimerTick(object sender, EventArgs e) { game_time_sec++; if (game_time_sec >= 60 && !gotospace) { AnimationsRace.AnimationGoToSpace(); AnimationsRace.AnimationRemoveClouds(clouds); if (stars == null) { stars = new Stars(this); } clouds.StarTimer.Stop(); gotospace = true; } if (game_time_sec >= 180 && !bossfight) { bossfight = true; Sounds.StopBackGround(); Sounds.PlayBossBackGround(); boss = new Boss(this); progressBarHealthBoss = new ProgressBar(); progressBarHealthBoss.Minimum = 0; progressBarHealthBoss.Width = MainCanvas.ActualWidth; progressBarHealthBoss.Height = 15; progressBarHealthBoss.Background = Brushes.Black; progressBarHealthBoss.Maximum = boss.BossHealthPoint; progressBarHealthBoss.Value = boss.BossHealthPoint; MainCanvas.Children.Add(progressBarHealthBoss); } }
public void ShipFire() { if (ShipAmmo <= 0) { return; } double coord_y = fire_speed; Rectangle fire = new Rectangle(); fire.Width = 20; fire.Height = 20; VisualBrush vb = new VisualBrush(); vb.Visual = (Visual)Application.Current.Resources["r_fire"]; fire.Fill = vb; fire.OpacityMask = vb; fire.Name = "bullet"; fire.Margin = new Thickness( ShipRectangle.Margin.Left + ShipRectangle.Width / 2, ShipRectangle.Margin.Top + ShipRectangle.Height / 2 - 10, ShipRectangle.Margin.Right, ShipRectangle.Margin.Bottom ); (Application.Current.MainWindow as MainWindow).MainCanvas.Children.Add(fire); AnimationsRace.AnimationBulletfire(fire, shipRectangle, coord_y); CurrentAmmos.Add(fire); ShipAmmo--; }
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 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); }
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); } } }
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 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); }
private void ObstsGeneratorTimerTick(object sender, EventArgs e) { for (int i = 0; i < obst_cout_increasing_for_up_difficulty; i++) { Obstacle obst = new Obstacle(this); CurrentObsts.Add(obst); AnimationsRace.AnimationObstacles(obst); } }
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 DoWork(object sender, System.ComponentModel.DoWorkEventArgs e) //{ // while (pause) // { // Thread.Sleep(1000); // if (_pause.CancellationPending || !pause) // { // e.Cancel = true; // return; // } // Dispatcher.BeginInvoke((Action)(() => { // Thread.Sleep(1000); // })); // } //} private void GameOver() { Sounds.StopBackGround(); Sounds.ShipDestroySoundPlay(); Sounds.StopBossBackGround(); AnimationsRace.AnimationShipGameOver(ship); RemoveElementAfterAnimation(ship.shipRectangle); BonusGeneratorTimer.Stop(); ObstsGeneratorTimer.Stop(); KeyTrackTimer.Stop(); CollisionTimer.Stop(); foreach (Obstacle item in CurrentObsts) { item.ObstacleFiredAnimation(); RemoveElementAfterAnimation(item.ObstToCanvas); } CurrentObsts.Clear(); Sounds.GameOverSoundPlay(); AnimationsRace.AnimationGameOver(); }
private async void Window_Loaded(object sender, RoutedEventArgs e) { ConsoleMethod.WriteToConsole("Game window loaded", Brushes.White); Sounds.PlayBackGround(); clouds = new Clouds(this); //Image image = new Image(); //AnimationBehavior.SetSourceUri(image, new Uri(@"J:\training\WPF\SeryojaTheGame\SeryojaTheGame\Race\bin\Debug\win_gifs\1.gif")); //MainCanvas.Children.Add(image); StarShip starShip_title = new StarShip(null); starShip_title.shipRectangle.Margin = new Thickness(MainCanvas.ActualWidth / 2 - starShip_title.shipRectangle.Width / 2, MainCanvas.ActualHeight - 200, 0, 0); starShip_title.shipRectangle.Name = "ee_tip"; MainCanvas.Children.Add(starShip_title.shipRectangle); while (show_ee_tip) { AnimationsRace.AnimationMainScreen(starShip_title, this); await System.Threading.Tasks.Task.Run(() => System.Threading.Thread.Sleep(23 * 500 + 3000)); } }
public void ObstacleFiredAnimation() { AnimationsRace.AnimationObstFired(this); }
public static void RunConsoleCommand(string command, string param) { switch (command) { case "wingifs": { (Application.Current.MainWindow as MainWindow).ShowWinGifs(); break; } case "sethp": { if ((Application.Current.MainWindow as MainWindow).ship != null) { double hp_count = 0; Double.TryParse(param, out hp_count); (Application.Current.MainWindow as MainWindow).ship.ShipHp = hp_count == 0 ? 100 : hp_count; } else { WriteToConsole("Game ist started!", Brushes.Red); } break; } case "god": { if ((Application.Current.MainWindow as MainWindow).ship != null) { (Application.Current.MainWindow as MainWindow).ship.ShipHp = 9999; } else { WriteToConsole("Game ist started!", Brushes.Red); } break; } case "giveammo": { if ((Application.Current.MainWindow as MainWindow).ship != null) { double ammo_count = 0; Double.TryParse(param, out ammo_count); (Application.Current.MainWindow as MainWindow).ship.ShipAmmo = ammo_count == 0 ? 250 : ammo_count; } else { WriteToConsole("Game ist started!", Brushes.Red); } break; } case "showhitbox": { if ((Application.Current.MainWindow as MainWindow).ship != null) { (Application.Current.MainWindow as MainWindow).ship.ShowHitBoxes = !(Application.Current.MainWindow as MainWindow).ship.ShowHitBoxes ? true : false; } else { WriteToConsole("Game ist started!", Brushes.Red); } break; } case "giveammobonus": { if ((Application.Current.MainWindow as MainWindow).ship != null) { AnimationsRace.AnimationBonus(new AmmoBonus((Application.Current.MainWindow as MainWindow))); } else { WriteToConsole("Game ist started!", Brushes.Red); } break; } case "givehpbonus": { if ((Application.Current.MainWindow as MainWindow).ship != null) { AnimationsRace.AnimationBonus(new HealthBonus((Application.Current.MainWindow as MainWindow))); } else { WriteToConsole("Game ist started!", Brushes.Red); } break; } case "givescore": { if ((Application.Current.MainWindow as MainWindow).ship != null) { int score = 0; Int32.TryParse(param, out score); (Application.Current.MainWindow as MainWindow).ship.ShipScore = score == 0 ? 250 : score; } else { WriteToConsole("Game ist started!", Brushes.Red); } break; } case "gotospace": { if ((Application.Current.MainWindow as MainWindow).ship != null) { AnimationsRace.AnimationGoToSpace(); } else { WriteToConsole("Game ist started!", Brushes.Red); } break; } case "setgametime": { if ((Application.Current.MainWindow as MainWindow).ship != null) { int time = 0; Int32.TryParse(param, out time); if (time != 0) { (Application.Current.MainWindow as MainWindow).game_time_sec = time; } } else { WriteToConsole("Game ist started!", Brushes.Red); } break; } case "setboss": { if ((Application.Current.MainWindow as MainWindow).ship != null) { if ((Application.Current.MainWindow as MainWindow).boss == null) { (Application.Current.MainWindow as MainWindow).boss = new Boss((Application.Current.MainWindow as MainWindow)); } } else { WriteToConsole("Game ist started!", Brushes.Red); } break; } case "bossfire": { if ((Application.Current.MainWindow as MainWindow).ship != null) { if ((Application.Current.MainWindow as MainWindow).boss != null) { (Application.Current.MainWindow as MainWindow).boss.BossFire(); } } else { WriteToConsole("Game ist started!", Brushes.Red); } break; } case "boss_init_a": { if ((Application.Current.MainWindow as MainWindow).ship != null) { if ((Application.Current.MainWindow as MainWindow).boss != null) { AnimationsRace.AnimationBossInit( (Application.Current.MainWindow as MainWindow).boss, (Application.Current.MainWindow as MainWindow) ); } } else { WriteToConsole("Game ist started!", Brushes.Red); } break; } case "boss_walk_a_1": { if ((Application.Current.MainWindow as MainWindow).ship != null) { if ((Application.Current.MainWindow as MainWindow).boss != null) { AnimationsRace.AnimationWalkBossRectangle( (Application.Current.MainWindow as MainWindow).boss, (Application.Current.MainWindow as MainWindow) ); } } else { WriteToConsole("Game ist started!", Brushes.Red); } break; } case "boss_walk_a_2": { if ((Application.Current.MainWindow as MainWindow).ship != null) { if ((Application.Current.MainWindow as MainWindow).boss != null) { AnimationsRace.AnimationWalkBossCircle( (Application.Current.MainWindow as MainWindow).boss, (Application.Current.MainWindow as MainWindow) ); } } else { WriteToConsole("Game ist started!", Brushes.Red); } break; } case "quit": { Application.Current.Shutdown(); 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]); } } }
private void ShowEasterEgg() { AnimationsRace.AnimationEasterEgg(this); }