void loadBug(List <int> bugInt, List <Point> bugPoint, List <String> bugPath, Player player) { BitmapImage[] beeImages = { UtilityMethods.LoadImage("pics/bee0.png"), UtilityMethods.LoadImage("pics/bee1.png") }; BitmapImage[] bugImages = { UtilityMethods.LoadImage("pics/redBug0.png"), UtilityMethods.LoadImage("pics/redBug1.png") }; int spaceX = 0; Image[] beesPic = new Image[bugPath.Count]; for (int i = 0; i < bugInt.Count; i++) { if (bugInt[i] == 2) { if (bugPath[i].Contains("bee0.png")) { bees = new Bug[beesPic.Length]; beesPic[i] = new Image(); beesPic[i].Source = UtilityMethods.LoadImageFullPath(bugPath[i]); beesPic[i].Width = 34; beesPic[i].Height = 26; canvas.Children.Add(beesPic[i]); Canvas.SetLeft(beesPic[i], bugPoint[i].X + spaceX); Canvas.SetTop(beesPic[i], bugPoint[i].Y); spaceX += 60; Point beePos = new Point(); beePos.X = bugPoint[i].X; beePos.Y = bugPoint[i].Y; Animation beeAnimation = new Animation(beesPic[i], beeImages, true); Bug bee = new Bug(beePos, beesPic[i], canvas, beeAnimation); bees[i] = bee; enemies.Add(bees[i]); bees[i].setTarget(player); bees[i].Fly(200); } else { Image[] bugsPic = new Image[beesPic.Length]; redbugs = new Bug[bugsPic.Length]; spaceX = 0; bugsPic[i] = new Image(); bugsPic[i].Width = 34; bugsPic[i].Height = 26; canvas.Children.Add(bugsPic[i]); Canvas.SetLeft(bugsPic[i], bugPoint[i].X + spaceX); Canvas.SetTop(bugsPic[i], bugPoint[i].Y); spaceX += 60; Point bugPos = new Point(); bugPos.X = bugPoint[i].X; bugPos.Y = bugPoint[i].Y; Animation bugAnimation = new Animation(bugsPic[i], bugImages, true); Bug bug = new Bug(bugPos, bugsPic[i], canvas, bugAnimation); redbugs[i] = bug; enemies.Add(redbugs[i]); redbugs[i].setTarget(player); redbugs[i].Fly(200); } } } }
/// <summary> /// The Play Method creates and displays all enemies and the player on /// the Canvas (screen). /// </summary> public async void Play() { Player.ColdDown = 0; if (this.round == 1) { DisplayLevel(); await Task.Delay(2000); this.canvas.Children.Remove(lv2Pic); } else { this.shipsNum = new List <int>() { 0, 1, 2, 3, 4, 5, 6, 7 }; this.commandersNum = new List <int>() { 0, 1, 2, 3 }; this.ufosNum = new List <int>() { 0, 1, 2, 3, 4 }; this.exists1 = false; this.exists2 = false; this.exists3 = false; this.spaceX = 0; await Task.Delay(1500); } lv2Pic = new Image(); lv2Pic.Height = 40; lv2Pic.Width = 100; this.canvas.Children.Add(lv2Pic); lv2Pic.Source = UtilityMethods.LoadImage("pics/level2.png"); //bee creation BitmapImage[] beeImages = { UtilityMethods.LoadImage("pics/bee0.png"), UtilityMethods.LoadImage("pics/bee1.png") }; Image[] beesPic = new Image[8]; //int spaceX = 0; bool isDive = false; Bug[] bees = new Bug[beesPic.Length]; for (int i = 0; i < beesPic.Length; i++) { beesPic[i] = new Image(); beesPic[i].Width = 34; beesPic[i].Height = 26; canvas.Children.Add(beesPic[i]); Canvas.SetLeft(beesPic[i], 181 + spaceX); Canvas.SetTop(beesPic[i], 185); spaceX += 60; Point beePos = new Point(); beePos.X = Canvas.GetLeft(beesPic[i]); beePos.Y = Canvas.GetTop(beesPic[i]); Animation beeAnimation = new Animation(beesPic[i], beeImages, true); Bug bee = new Bug(beePos, beesPic[i], canvas, beeAnimation); bees[i] = bee; enemies.Add(bees[i]); bees[i].setTarget(player); bees[i].setDive(isDive); if (isDive) { isDive = false; } else { isDive = true; } bees[i].setDiveFrequency(8); bees[i].Fly(180); } //--------------------------------------------------------------------------- //redbugs creation BitmapImage[] bugImages = { UtilityMethods.LoadImage("pics/redBug0.png"), UtilityMethods.LoadImage("pics/redBug1.png") }; Image[] bugsPic = new Image[9]; Bug[] redbugs = new Bug[bugsPic.Length]; spaceX = 0; isDive = false; for (int i = 0; i < bugsPic.Length; i++) { bugsPic[i] = new Image(); bugsPic[i].Width = 34; bugsPic[i].Height = 26; canvas.Children.Add(bugsPic[i]); Canvas.SetLeft(bugsPic[i], 154 + spaceX); Canvas.SetTop(bugsPic[i], 145); spaceX += 60; Point bugPos = new Point(); bugPos.X = Canvas.GetLeft(bugsPic[i]); bugPos.Y = Canvas.GetTop(bugsPic[i]); Animation bugAnimation = new Animation(bugsPic[i], bugImages, true); Bug bug = new Bug(bugPos, bugsPic[i], canvas, bugAnimation); redbugs[i] = bug; enemies.Add(redbugs[i]); redbugs[i].setTarget(player); redbugs[i].setDive(isDive); if (isDive) { isDive = false; } else { isDive = true; } redbugs[i].setDiveFrequency(8); redbugs[i].setMoveCounter(2); redbugs[i].Fly(180); } //--------------------------------------------------------------------------- //ships creation Image[] shipsPic = new Image[8]; ships = new SpaceShip[shipsPic.Length]; isDive = false; spaceX = 0; for (int i = 0; i < ships.Length; i++) { shipsPic[i] = new Image(); shipsPic[i].Source = UtilityMethods.LoadImage("pics/spaceShip.png"); shipsPic[i].Width = 34; shipsPic[i].Height = 26; canvas.Children.Add(shipsPic[i]); Canvas.SetLeft(shipsPic[i], 181 + spaceX); Canvas.SetTop(shipsPic[i], 105); spaceX += 60; Point shipPos = new Point(); shipPos.X = Canvas.GetLeft(shipsPic[i]); shipPos.Y = Canvas.GetTop(shipsPic[i]); SpaceShip ship = new SpaceShip(shipPos, shipsPic[i], canvas); ships[i] = ship; enemies.Add(ships[i]); ships[i].setTarget(player); ships[i].setDive(isDive); if (isDive) { isDive = false; } else { isDive = true; } ships[i].setDiveFrequency(8); ships[i].Fly(180); // ships[i].Shoot(200); } //--------------------------------------------------------------------------- //UFO creation Image[] ufoPics = new Image[5]; this.ufos = new SpaceShip[ufoPics.Length]; spaceX = 0; for (int i = 0; i < ufoPics.Length; i++) { ufoPics[i] = new Image(); ufoPics[i].Source = UtilityMethods.LoadImage("pics/UFO.png"); ufoPics[i].Width = 34; ufoPics[i].Height = 26; canvas.Children.Add(ufoPics[i]); Canvas.SetLeft(ufoPics[i], 200 + spaceX); Canvas.SetTop(ufoPics[i], 65); spaceX += 60; Point ufoPos = new Point(); ufoPos.X = Canvas.GetLeft(ufoPics[i]); ufoPos.Y = Canvas.GetTop(ufoPics[i]); SpaceShip ufo = new SpaceShip(ufoPos, ufoPics[i], canvas); ufos[i] = ufo; enemies.Add(ufos[i]); ufos[i].setTarget(player); ufos[i].setMoveCounter(2); ufos[i].Fly(180); // ships[i].Shoot(200); } //--------------------------------------------------------------------------- //commanders creation BitmapImage[] commanderImages = { UtilityMethods.LoadImage("pics/commander.png"), UtilityMethods.LoadImage("pics/commander2.png") }; Image[] commanderPic = new Image[4]; commanders = new Commander[commanderPic.Length]; spaceX = 0; for (int i = 0; i < commanderPic.Length; i++) { commanderPic[i] = new Image(); //commanderPic[i].Source = UtilityMethods.LoadImage("pics/spaceShip.png"); commanderPic[i].Width = 34; commanderPic[i].Height = 26; canvas.Children.Add(commanderPic[i]); Canvas.SetLeft(commanderPic[i], 260 + spaceX); Canvas.SetTop(commanderPic[i], 30); spaceX += 90; Point commanderPos = new Point(); commanderPos.X = Canvas.GetLeft(commanderPic[i]); commanderPos.Y = Canvas.GetTop(commanderPic[i]); Animation commanderAnimation = new Animation(commanderPic[i], commanderImages, true); Commander commander = new Commander(commanderPos, commanderPic[i], canvas, commanderAnimation); commanders[i] = commander; enemies.Add(commanders[i]); commanders[i].setTarget(player); commanders[i].Fly(180); } player.SetEnemyTarget(enemies); StartGame(); }
/// <summary> /// The Play Method creates and displays all enemies and the player on /// the Canvas (screen). /// </summary> public async void Play() { Player.ColdDown = 0; DisplayLevel(); await Task.Delay(2000); this.canvas.Children.Remove(lv1Pic); lv1Pic = new Image(); lv1Pic.Height = 40; lv1Pic.Width = 100; this.canvas.Children.Add(lv1Pic); lv1Pic.Source = UtilityMethods.LoadImage("pics/level1.png"); //bee creation BitmapImage[] beeImages = { UtilityMethods.LoadImage("pics/bee0.png"), UtilityMethods.LoadImage("pics/bee1.png") }; Image[] beesPic = new Image[8]; //int spaceX = 0; bool isDive = false; Bug[] bees = new Bug[beesPic.Length]; for (int i = 0; i < beesPic.Length; i++) { beesPic[i] = new Image(); beesPic[i].Width = 34; beesPic[i].Height = 26; canvas.Children.Add(beesPic[i]); Canvas.SetLeft(beesPic[i], 181 + spaceX); Canvas.SetTop(beesPic[i], 185); spaceX += 60; Point beePos = new Point(); beePos.X = Canvas.GetLeft(beesPic[i]); beePos.Y = Canvas.GetTop(beesPic[i]); Animation beeAnimation = new Animation(beesPic[i], beeImages, true); Bug bee = new Bug(beePos, beesPic[i], canvas, beeAnimation); bees[i] = bee; enemies.Add(bees[i]); bees[i].setTarget(player); bees[i].setDive(isDive); if (isDive) { isDive = false; } else { isDive = true; } bees[i].Fly(300); } //--------------------------------------------------------------------------- //red bugs creation BitmapImage[] bugImages = { UtilityMethods.LoadImage("pics/redBug0.png"), UtilityMethods.LoadImage("pics/redBug1.png") }; Image[] bugsPic = new Image[9]; isDive = false; Bug[] redbugs = new Bug[bugsPic.Length]; spaceX = 0; for (int i = 0; i < bugsPic.Length; i++) { bugsPic[i] = new Image(); bugsPic[i].Width = 34; bugsPic[i].Height = 26; canvas.Children.Add(bugsPic[i]); Canvas.SetLeft(bugsPic[i], 154 + spaceX); Canvas.SetTop(bugsPic[i], 145); spaceX += 60; Point bugPos = new Point(); bugPos.X = Canvas.GetLeft(bugsPic[i]); bugPos.Y = Canvas.GetTop(bugsPic[i]); Animation bugAnimation = new Animation(bugsPic[i], bugImages, true); Bug bug = new Bug(bugPos, bugsPic[i], canvas, bugAnimation); redbugs[i] = bug; enemies.Add(redbugs[i]); redbugs[i].setTarget(player); redbugs[i].setDive(isDive); if (isDive) { isDive = false; } else { isDive = true; } redbugs[i].Fly(300); } //--------------------------------------------------------------------------- //spaceships creation Image[] shipsPic = new Image[8]; ships = new SpaceShip[shipsPic.Length]; spaceX = 0; for (int i = 0; i < ships.Length; i++) { shipsPic[i] = new Image(); shipsPic[i].Source = UtilityMethods.LoadImage("pics/spaceShip.png"); shipsPic[i].Width = 34; shipsPic[i].Height = 26; canvas.Children.Add(shipsPic[i]); Canvas.SetLeft(shipsPic[i], 181 + spaceX); Canvas.SetTop(shipsPic[i], 105); spaceX += 60; Point shipPos = new Point(); shipPos.X = Canvas.GetLeft(shipsPic[i]); shipPos.Y = Canvas.GetTop(shipsPic[i]); SpaceShip ship = new SpaceShip(shipPos, shipsPic[i], canvas); ships[i] = ship; enemies.Add(ships[i]); ships[i].setTarget(player); ships[i].Fly(300); } //---------------------------------------------------------------------------- //commanders creation BitmapImage[] commanderImages = { UtilityMethods.LoadImage("pics/commander.png"), UtilityMethods.LoadImage("pics/commander2.png") }; Image[] commanderPic = new Image[4]; commanders = new Commander[commanderPic.Length]; spaceX = 0; for (int i = 0; i < commanderPic.Length; i++) { commanderPic[i] = new Image(); commanderPic[i].Width = 34; commanderPic[i].Height = 26; canvas.Children.Add(commanderPic[i]); Canvas.SetLeft(commanderPic[i], 260 + spaceX); Canvas.SetTop(commanderPic[i], 65); spaceX += 90; Point commanderPos = new Point(); commanderPos.X = Canvas.GetLeft(commanderPic[i]); commanderPos.Y = Canvas.GetTop(commanderPic[i]); Animation commanderAnimation = new Animation(commanderPic[i], commanderImages, true); Commander commander = new Commander(commanderPos, commanderPic[i], canvas, commanderAnimation); commanders[i] = commander; enemies.Add(commanders[i]); commanders[i].setTarget(player); commanders[i].Fly(300); } player.SetEnemyTarget(enemies); StartGame(); }