Esempio n. 1
0
 public void GetExistingEnemyBullet(IObjController enemy)
 {
     for (int i = 0; i < allObjs.Count; i++)
     {
         if (allObjs[i].Type == ObjType.EnemyBullet)
         {
             SetBulletPosition(allObjs[i]);
             break;
         }
     }
     NewEnemyBullet(enemy);
 }
Esempio n. 2
0
 // Remove obj from the interaction area
 public bool ClearFromScreen(IObjController entity)
 {
     if (entity.Type == ObjType.Player || entity.Type == ObjType.PlayerBullet)
     {
         return(entity.Type == ObjType.PlayerBullet ?
                GoToHiddenPos(entity.Image, hiddenPos[0, 0], hiddenPos[0, 1]) :
                GoToHiddenPos(entity.Image, hiddenPos[1, 0], hiddenPos[1, 1]));
     }
     else if (entity.Type == ObjType.Enemy || entity.Type == ObjType.EnemyBullet)
     {
         return(GoToHiddenPos(entity.Image, hiddenPos[1, 0], hiddenPos[1, 1]));
     }
     return(false);
 }
Esempio n. 3
0
 public void NewEnemyBullet(IObjController enemyWhoShot)
 {
     allObjs.Add(new Bullet(15, 1, new Image()
     {
         Height = EnemyBullet.Height,
         Width  = EnemyBullet.Width,
         Source = EnemyBullet.Source,
         HorizontalAlignment = HorizontalAlignment.Left,
         VerticalAlignment   = VerticalAlignment.Top,
         Visibility          = Visibility.Hidden,
         Tag = EnemyBullet.Tag
     }, ObjType.EnemyBullet));
     SetBulletPosition(allObjs.LastOrDefault(), enemyWhoShot);
     currentEnemyBullets++;
 }
Esempio n. 4
0
        // Executes Before all updates
        private void Start()
        {
            score = 0;

            //Test purpose only
            foreach (var img in GameCanvas.Children.OfType <Image>())
            {
                if (img.Tag != null && img.Tag.ToString() == "Enemy")
                {
                    allObjs.Add(new Enemy(3, 3, img, ObjType.Enemy));
                }
            }

            player = new Player(10, 3, PlayerImage, ObjType.Player);
            lbLifePlayer.Content = $"Vidas: {player.Life}";

            allObjs.Add(player);

            //Initializing timers
            elapsedMiliSeconds       = 0;
            timeToShootPlayerBullets = 0;

            //Player Setup
            playerInitialLeftPosition = Canvas.GetLeft(PlayerImage);
            playerInitialTopPosition  = Canvas.GetTop(PlayerImage);
            canMove = true;

            //Enemy Spawner Setup

            //Scene Cleanup
            PlayerBullet.Visibility = Visibility.Hidden;
            //EnemyImage.Visibility = Visibility.Hidden;
            //EnemyBullet.Visibility = Visibility.Hidden;

            //GameCanvas.Children.Remove(EnemyImage);
            //GameCanvas.Children.Remove(EnemyBullet);
            GameCanvas.Children.Remove(PlayerBullet);

            if (!allObjs.Contains(player))
            {
                allObjs.Add(player);
            }
        }
Esempio n. 5
0
        public void SetBulletPosition(IObjController bullet, IObjController whoShot = null)
        {
            if (!GameCanvas.Children.Contains(bullet.Image))
            {
                GameCanvas.Children.Add(bullet.Image);
            }

            bullet.Image.Refresh();
            bullet.Image.Visibility = Visibility.Visible;

            if (bullet.Type == ObjType.PlayerBullet)
            {
                Canvas.SetLeft(bullet.Image, Canvas.GetLeft(PlayerImage) + PlayerImage.ActualWidth);
                Canvas.SetTop(bullet.Image, Canvas.GetTop(PlayerImage) + PlayerImage.ActualHeight - (bullet.Image.ActualHeight * 2));
            }
            else if (bullet.Type == ObjType.EnemyBullet && whoShot != null)
            {
                Canvas.SetLeft(bullet.Image, Canvas.GetLeft(whoShot.Image) + whoShot.Image.ActualWidth);
                Canvas.SetTop(bullet.Image, Canvas.GetTop(whoShot.Image) + whoShot.Image.ActualHeight - (bullet.Image.ActualHeight));
            }
            bullet.Image.Refresh();
            //sfxAudio();
            Audio.InitializeAudios[1].Play();
        }
Esempio n. 6
0
 public void RectUpdate(IObjController obj)
 {
     obj.Rect = new Rect(Canvas.GetLeft(obj.Image), Canvas.GetTop(obj.Image), obj.Image.ActualWidth, obj.Image.ActualHeight);
 }