/// <summary> /// sendLife method handles the provision of an extra life for the player. /// An image of a spaceship will appear and the method will make it move down /// in order for the player to have the choice to take it by checking any /// collision /// </summary> /// <param name="sender">object that raised the event</param> /// <param name="e">the sendLife event that was raised</param> private void sendLife(object sender, EventArgs e) { double posLifeY = Canvas.GetTop(this.life); double posLifeX = Canvas.GetLeft(this.life); double posPlayerX = Canvas.GetLeft(player.GetImage()); double posPlayerY = Canvas.GetTop(player.GetImage()); Rect rectLife = new Rect(posLifeX, posLifeY, this.life.Width - 5, this.life.Height - 5); Rect rectPlayer = new Rect(posPlayerX, posPlayerY, this.life.Width - 5, this.life.Height - 5); if (posLifeY <= 530) { Canvas.SetTop(this.life, posLifeY += 8); this.life.Source = UtilityMethods.LoadImage("pics/galaga_ship.png"); //check if the player touched the extra life image if (rectPlayer.IntersectsWith(rectLife)) { this.lifeTimer.Stop(); if (player.getCoins() >= 200 && player.GetLives() < 2) { player.addLife(); } canvas.Children.Remove(this.life); } } else { canvas.Children.Remove(this.life); } }
/// <summary> /// The addLife method adds life to player and sets the image on the screen. /// </summary> public void addLife() { if (this.lives == 2) { this.newLife = new Image(); this.shipLives.Insert(0, newLife); newLife.Width = 34; newLife.Height = 26; canvas.Children.Add(newLife); double posX = Canvas.GetLeft(shipLives[1]); Canvas.SetLeft(newLife, posX - 30); Canvas.SetTop(newLife, 585); newLife.Source = UtilityMethods.LoadImage("pics/galaga_ship.png"); } else { this.newLife = new Image(); this.shipLives.Insert(0, newLife); newLife.Width = 34; newLife.Height = 26; canvas.Children.Add(newLife); double posX = Canvas.GetLeft(shipLives[shipLives.Count - 1]); Canvas.SetLeft(newLife, posX - 30); Canvas.SetTop(newLife, 585); newLife.Source = UtilityMethods.LoadImage("pics/galaga_ship.png"); } this.lives++; this.points = this.points - 2000; updatePoints(); }
/// <summary> /// The displayBoss method creates the final Boss enemy and /// defines all its movements and shooting patherns. /// </summary> private void displayBoss() { Point bossPos = new Point(); bossPos.X = 300; bossPos.Y = 100; Animation bossAnimation; Image bossPic = new Image(); bossPic.Height = 120; bossPic.Width = 140; bossPic.Source = UtilityMethods.LoadImage("pics/boss/boss.png"); canvas.Children.Add(bossPic); Canvas.SetLeft(bossPic, 200); BitmapImage[] bossImages = { UtilityMethods.LoadImage("pics/boss/boss1.png"), UtilityMethods.LoadImage("pics/boss/boss2.png"),UtilityMethods.LoadImage("pics/boss/boss3.png"), }; bossAnimation = new Animation(bossPic, bossImages, true); this.boss = new Boss(bossPos, bossPic, canvas, bossAnimation); Animation.Initiate(bossAnimation, 500); enemies.Add(boss); boss.setTarget(player); this.boss.Fly(200); this.boss.Shoot(2); }
/// <summary> /// The Live method is called if the Boss is hitted but the /// counter is less than 33.It randomly moves the Boss on the screen /// giving an impression that the Boss is disapearing and reapearing /// in another location. /// </summary> public void live() { Animation bossAnimation; if (hitCounter < 34) { Random randX = new Random(); this.point.X = randX.Next(500); Random randY = new Random(); this.point.Y = randY.Next(300); this.image = new Image(); this.image.Height = 120; this.image.Width = 140; this.canvas.Children.Add(this.image); Canvas.SetTop(this.image, this.point.Y); Canvas.SetLeft(this.image, this.point.X); // this.setPointX(this.point.X); //this.setPointnY(this.point.Y); this.image.Source = UtilityMethods.LoadImage(SwitchImage()[0]); BitmapImage[] bossImages = { UtilityMethods.LoadImage(SwitchImage()[0]), UtilityMethods.LoadImage(SwitchImage()[1]),UtilityMethods.LoadImage(SwitchImage()[2]), }; bossAnimation = new Animation(image, bossImages, true); Animation.Initiate(bossAnimation, 200); } }
/// <summary> /// The Mainwindow Constructor will invoke the InitializeComponent method /// and load the Main window of the Game. /// </summary> public MainWindow() { this.Closed += MainWindow_Closed; this.Closing += MainWindow_Closing; InitializeComponent(); BitmapImage[] newGameSources = { UtilityMethods.LoadImage("pics/newGame_white.png") , UtilityMethods.LoadImage("pics/newGame_lightBlue.png") }; Animation newGameAnimation = new Animation(newGamePic, newGameSources, true); Animation.Initiate(newGameAnimation, 100); BitmapImage[] titleSources = { UtilityMethods.LoadImage("pics/GameTitle_Blue.png") , UtilityMethods.LoadImage("pics/GameTitle_lightBlue.png") }; Animation titleAnimation = new Animation(titlePic, titleSources, true); Animation.Initiate(titleAnimation, 150); BitmapImage[] loadGameSoures = { UtilityMethods.LoadImage("pics/loadGame_blue.png") , UtilityMethods.LoadImage("pics/loadGame_white.png") }; Animation loadGameAnim = new Animation(loadGamePic, loadGameSoures, true); Animation.Initiate(loadGameAnim, 150); }
/// <summary> /// The ShootRightSide method takes as input a string path for /// the bullet image and initiates the timer for the timerShootRightSide /// timer which calls the ShootRightSide event handler method /// </summary> /// <param name="path"></param> public void ShootRightSide(String path) { this.image.Source = UtilityMethods.LoadImage(path); timerShootRightSide = new DispatcherTimer(DispatcherPriority.Normal); timerShootRightSide.Interval = TimeSpan.FromMilliseconds(1); timerShootRightSide.Start(); timerShootRightSide.Tick += new EventHandler(ShootRightSide); }
/// <summary> /// The changeImage method changes the image of the commander once /// it is shot once as an indication to the user and initiates a new animation /// for that new image. /// </summary> public void changeImage() { this.animation.Stop(); BitmapImage[] commanderImages = { UtilityMethods.LoadImage("pics/commanderGreen0.png"), UtilityMethods.LoadImage("pics/commanderGreen1.png") }; this.animation = new Animation(this.image, commanderImages, true); Animation.Initiate(animation, 500); }
public LoadLevels(List <int> shipInt, List <Point> shipPoint, List <String> shipPath, List <int> commanderInt, List <Point> commanderPoint, List <String> commanderPath, List <int> bugInt, List <Point> bugPoint, List <String> bugPath, Canvas canvas, Window window, List <double> minXShip, List <double> maxXShip, List <double> minXCom, List <double> maxXCom, List <double> minXBug, List <double> maxXBug, int coins, int lives, int level) { this.canvas = canvas; this.lives = lives; this.coins = coins; this.level = level; this.window = window; Image playerPic = new Image(); playerPic.Source = UtilityMethods.LoadImage("pics/galaga_ship.png"); playerPic.Width = 42; playerPic.Height = 46; canvas.Children.Add(playerPic); Canvas.SetLeft(playerPic, 405); Canvas.SetTop(playerPic, 500); Point playerPoint = new Point(27, 490); player = new Player(playerPoint, playerPic, canvas, 15, lives, coins); staticPlayer = player; player.setCurrentLevel(level); player.setCoins(coins); player.setLives(lives); staticPlayer.setCurrentLevel(level); staticPlayer.setCoins(coins); staticPlayer.setLives(lives); if (level < 4) { this.commanderPic = new Image[commanderPath.Count]; loadCommanders(commanderInt, commanderPoint, commanderPath, minXCom, maxXCom, player); loadShip(shipInt, shipPoint, shipPath, maxXShip, minXShip, player); loadBug(bugInt, bugPoint, bugPath, maxXBug, minXBug, player); player.SetEnemyTarget(enemies); newPlayer = new Player(player); StartGame(); } else { Level4 lv4 = new Level4(window, canvas, player); lv4.Play(); } }
/// <summary> /// The DisplayLevel method displays an image on the canvas indicating the Level of the game. /// </summary> void DisplayLevel() { lv2Pic = new Image(); lv2Pic.Height = 50; lv2Pic.Width = 140; this.canvas.Children.Add(lv2Pic); Canvas.SetTop(lv2Pic, 200); Canvas.SetLeft(lv2Pic, 350); lv2Pic.Source = UtilityMethods.LoadImage("pics/level2.png"); }
/// <summary> /// The overriden Die method initiates the animation of the explosion of /// the bug once shot already. The method also increases /// the points of the player if the bug is eliminated and stops the /// timer for moving and shooting of the bug. /// </summary> public override void Die() { this.target.addCoins(100); BitmapImage[] explosions = { UtilityMethods.LoadImage("pics/explosions/enemiesExp0.png"), UtilityMethods.LoadImage("pics/explosions/enemiesExp1.png"), UtilityMethods.LoadImage("pics/explosions/enemiesExp2.png"), UtilityMethods.LoadImage("pics/explosions/enemiesExp3.png") }; this.stopMove(); this.animation = new Animation(this.image, explosions, false, canvas); Animation.Initiate(this.animation, 40); }
public GameWindow(Boolean load) { this.Closed += GameWindow_Closed; this.Closing += GameWindow_Closing; InitializeComponent(); this.loaded = load; backgroundImage.Width = 860; backgroundImage.Height = 650; mediaElement.Source = new Uri("audio/main2.wav", UriKind.Relative); mediaElement.BeginInit(); mediaElement.Position = TimeSpan.FromSeconds(1); //mediaElement.Stop(); mediaElement.Volume = 0.07; //mediaElement.MediaOpened += new RoutedEventHandler(Element_MediaOpened); mediaElement.Play(); mediaElement.MediaEnded += new RoutedEventHandler(Element_MediaEnded); //mediaElement.Play(); // if (loaded == true) { lv1 = new Level1(this, canvas, player, true); } else { Image playerPic = new Image(); playerPic.Source = UtilityMethods.LoadImage("pics/galaga_ship.png"); ImageBehavior.SetAnimatedSource(playerPic, playerPic.Source); playerPic.Width = 42; playerPic.Height = 46; canvas.Children.Add(playerPic); Canvas.SetLeft(playerPic, 405); Canvas.SetTop(playerPic, 500); Point playerPoint = new Point(27, 490); player = new Player(playerPoint, playerPic, canvas, 15); lv1 = new Level1(this, canvas, player); lv1.Play(); } // Level4 lv4 = new Level4(this, canvas, player); //lv4.Play(); KeyDown += new KeyEventHandler(MyGrid_KeyDown); DecrementColdDown(); }
/// <summary> /// The setDisplayLives displays the number of lives on the screen in form of the player image. /// </summary> public void setDisplayLives(int lives) { // this.shipLives = new List<Image>(3); int spaceX = 0; for (int i = 0; i < lives; i++) { shipLives.Add(new Image()); shipLives[i].Width = 34; shipLives[i].Height = 26; this.canvas.Children.Add(shipLives[i]); Canvas.SetLeft(shipLives[i], 745 + spaceX); Canvas.SetTop(shipLives[i], 585); spaceX += 30; shipLives[i].Source = UtilityMethods.LoadImage("pics/galaga_ship.png"); } }
/// <summary> /// The overriden Die method initiates the animation of the explosion of /// the SpaceShip enemy once shot already. The method also increases /// the points of the player if the spaceShip is eliminated and stops the /// timer for moving and shooting. /// </summary> public override void Die() { this.dead = true; this.target.addCoins(200); //this.isShot = true; BitmapImage[] explosions = { UtilityMethods.LoadImage("pics/explosions/enemiesExp0.png"), UtilityMethods.LoadImage("pics/explosions/enemiesExp1.png"), UtilityMethods.LoadImage("pics/explosions/enemiesExp2.png"), UtilityMethods.LoadImage("pics/explosions/enemiesExp3.png") }; this.stopMove(); this.StopShoot(); Animation explode = new Animation(this.image, explosions, false, canvas); Animation.Initiate(explode, 40); }
void GameOver() { if (loaded) { if (LoadLevels.getStaticPlayer().GetLives() == 0) { Image gameOverPic = new Image(); gameOverPic.Height = 200; gameOverPic.Width = 250; this.canvas.Children.Add(gameOverPic); Canvas.SetTop(gameOverPic, 200); Canvas.SetLeft(gameOverPic, 300); gameOverPic.Source = UtilityMethods.LoadImage("pics/gameOver.png"); mediaElement.Stop(); mediaElement.Source = null; LoadLevels.getStaticPlayer().shootSoundEffect.StopSound(); LoadLevels.getStaticPlayer().shootSoundEffect.Dispose(); sound.playSoundLooping(); sound.Dispose(); BackToMainWindow(); } } else { if (player.GetLives() == 0) { Image gameOverPic = new Image(); gameOverPic.Height = 200; gameOverPic.Width = 250; this.canvas.Children.Add(gameOverPic); Canvas.SetTop(gameOverPic, 200); Canvas.SetLeft(gameOverPic, 300); gameOverPic.Source = UtilityMethods.LoadImage("pics/gameOver.png"); mediaElement.Stop(); mediaElement.Source = null; player.shootSoundEffect.StopSound(); player.shootSoundEffect.Dispose(); sound.playSoundLooping(); sound.Dispose(); BackToMainWindow(); } } }
/// <summary> /// The overriden Die method initiates the animation of the explosion of /// the Player once shot already. The method also stops the explosion /// sound effect and dispose its resources invoking the Dispose method /// from the GameSound Class. /// </summary> public override void Die() { decrementLives(); BitmapImage[] explosions = { UtilityMethods.LoadImage("pics/explosions/explosion0.png"), UtilityMethods.LoadImage("pics/explosions/explosion1.png"), UtilityMethods.LoadImage("pics/explosions/explosion2.png"), UtilityMethods.LoadImage("pics/explosions/explosion3.png") }; Animation animation = new Animation(this.image, explosions, false, canvas); Animation.Initiate(animation, 100); explosionSoundEffect.playSound(); explosionSoundEffect.Dispose(); live(); }
/// <summary> /// The overriden Die method initiates the animation of the explosion of /// the Boss once the Boss is hit 33 times. If the commander is eliminated it stops the /// timer for moving and shooting of the Boss and the game finishes. /// </summary> public override void Die() { hitCounter++; BitmapImage[] explosions = { UtilityMethods.LoadImage("pics/bossExplosions/explosion1.png"), UtilityMethods.LoadImage("pics/bossExplosions/explosion2.png"), UtilityMethods.LoadImage("pics/bossExplosions/explosion3.png"), UtilityMethods.LoadImage("pics/bossExplosions/explosion4.png"), UtilityMethods.LoadImage("pics/bossExplosions/explosion5.png"), UtilityMethods.LoadImage("pics/bossExplosions/explosion6.png"), UtilityMethods.LoadImage("pics/bossExplosions/explosion7.png"), UtilityMethods.LoadImage("pics/bossExplosions/explosion8.png"), UtilityMethods.LoadImage("pics/bossExplosions/explosion9.png") }; if (hitCounter == 33) { this.stopMove(); this.animation = new Animation(this.image, explosions, false, canvas); Animation.Initiate(this.animation, 40); //this.canvas.Children.Remove(lv4Pic); sound.playSound(); Image missionAccomplished = new Image(); missionAccomplished.Height = 300; missionAccomplished.Width = 500; this.canvas.Children.Add(missionAccomplished); Canvas.SetTop(missionAccomplished, 150); Canvas.SetLeft(missionAccomplished, 170); BitmapImage[] missionAccomplishedSources = { UtilityMethods.LoadImage("pics/missAccomplised_blue.png") , UtilityMethods.LoadImage("pics/missAccomplised_white.png") }; Animation missionAccomplishedAnim = new Animation(missionAccomplished, missionAccomplishedSources, true); Animation.Initiate(missionAccomplishedAnim, 100); } else { canvas.Children.Remove(this.image); live(); } }
public LoadLevel1(List <int> shipInt, List <Point> shipPoint, List <String> shipPath, List <int> commanderInt, List <Point> commanderPoint, List <String> commanderPath, List <int> bugInt, List <Point> bugPoint, List <String> bugPath, Canvas canvas, Window window, int currentLevel) { this.canvas = canvas; this.window = window; this.commanderPic = new Image[commanderPath.Count]; this.currentLevel = currentLevel; Image playerPic = new Image(); playerPic.Source = UtilityMethods.LoadImage("pics/galaga_ship.png"); playerPic.Width = 42; playerPic.Height = 46; canvas.Children.Add(playerPic); Canvas.SetLeft(playerPic, 405); Canvas.SetTop(playerPic, 500); Point playerPoint = new Point(27, 490); player = new Player(playerPoint, playerPic, canvas, 15); if (currentLevel == 1) { loadCommanders(commanderInt, commanderPoint, commanderPath, player); loadShip(shipInt, shipPoint, shipPath, player); loadBug(bugInt, bugPoint, bugPath, player); staticPlayer = player; player.setCurrentLevel(currentLevel); staticPlayer.setCurrentLevel(currentLevel); } player.SetEnemyTarget(enemies); newPlayer = new Player(player); StartGame(); }
/// <summary> /// The ShootUp method handler handles the shoot up sequence of /// a bullet and it is called by the ShootUp method /// </summary> /// <param name="sender">Object raising the event</param> /// <param name="e">The ShootUp event </param> void ShootUp(Object sender, EventArgs e) { //move bullet up until it reaches to the top if (this.point.Y >= 0) { this.point.Y -= 3; this.image.Source = UtilityMethods.LoadImage("pics/bullet.png"); Canvas.SetTop(this.image, this.point.Y); //check for player collision if (enemies != null) { for (int i = 0; i < enemies.Count; i++) { OnCollision(enemies[i]); } } } else //stop bullet movement and remove it if it reaches the top { StopShootUp(); //stop bullet up this.Die(); } }
/// <summary> /// The live method creates a new instance image of the player if the lives still greater than 0. /// If the lives is not greater than 0 the explosion of the soundeffect stops and it is Disposed. /// </summary> public async void live() { if (lives > 0) { coldDown = 0; this.image = new Image(); this.image.Height = 46; this.image.Width = 42; this.canvas.Children.Add(this.image); Canvas.SetTop(this.image, 500); Canvas.SetLeft(this.image, 405); this.SetPointX(27); this.SetPointY(490); await Task.Delay(1500); this.image.Source = UtilityMethods.LoadImage("pics/galaga_ship.png"); } else { explosionSoundEffect.StopSound(); explosionSoundEffect.Dispose(); } }
/// <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(); }
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); } } } }
void loadShip(List <int> shipInt, List <Point> shipPoint, List <String> shipPath, Player player) { Image[] shipsPic = new Image[shipPath.Count]; int spaceX = 0; for (int i = 0; i < shipInt.Count; i++) { if (shipInt[i] == 0) { if (shipPath[i].Contains("spaceShip.png")) { 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], shipPoint[i].X + spaceX); Canvas.SetTop(shipsPic[i], shipPoint[i].Y); spaceX += 60; Point shipPos = new Point(); shipPos.X = shipPoint[i].X; shipPos.Y = shipPoint[i].Y; SpaceShip ship = new SpaceShip(shipPos, shipsPic[i], canvas); ships.Add(ship); enemies.Add(ships[i]); ships[i].setTarget(player); ships[i].Fly(200); // ships[i].Shoot(200); arr1.Add(i); } else if (shipPath[i].Contains("UFO.png")) { Image[] ufoPics = new Image[shipInt.Count]; spaceX = 0; ufoPics[i] = new Image(); ufoPics[i].Source = UtilityMethods.LoadImageFullPath(shipPath[i]); ufoPics[i].Width = 34; ufoPics[i].Height = 26; canvas.Children.Add(ufoPics[i]); Canvas.SetLeft(ufoPics[i], shipPoint[i].X + spaceX); Canvas.SetTop(ufoPics[i], shipPoint[i].Y); spaceX += 60; Point ufoPos = new Point(); ufoPos.X = shipPoint[i].X; ufoPos.Y = shipPoint[i].Y; SpaceShip ufo = new SpaceShip(ufoPos, ufoPics[i], canvas); ufos.Add(ufo); } } } for (int i = 0; i < ufos.Count; i++) { enemies.Add(ufos[i]); ufos[i].setTarget(player); ufos[i].setMoveCounter(2); ufos[i].Fly(180); // ships[i].Shoot(200); } }
/// <summary> /// SetImageSource method sets the source of the image of /// the game elements /// </summary> /// <param name="path">string value for the path of the image</param> public void SetImageSource(string path) { this.image.Source = UtilityMethods.LoadImage(path); }
/// <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(); }