Пример #1
0
        public static bool EDetectCollision(Canvas game, Rectangle bullet, gameObject player)
        {
            //BULLET

            double leftB = Convert.ToDouble(bullet.GetValue(Canvas.LeftProperty));
            double topB  = Convert.ToDouble(bullet.GetValue(Canvas.TopProperty));

            Rect bulletPosition = new Rect(leftB, topB, 7, 25);

            //PLAYER
            double leftP = player.getPositionLeft() + 15;
            double topP  = player.getPositionTop();

            Rect playerPosition = new Rect(leftP, topP, 50, 58);


            Rectangle rec1 = new Rectangle();

            rec1.Width  = 50;
            rec1.Height = 58;
            rec1.Stroke = new SolidColorBrush(Colors.Red);
            // rec1.Fill = new SolidColorBrush(Colors.Red);
            Canvas.SetLeft(rec1, leftP);
            Canvas.SetTop(rec1, topP);
            // game.Children.Add(rec1);


            bulletPosition.Intersect(playerPosition);
            if (!(bulletPosition.IsEmpty))
            {
                return(true);
            }

            return(false);
        }
Пример #2
0
 private void gameOStart()
 {
     try
     {
         player = new gameObject(game, "./ship.png", 280, 570, 78, 58);
         bossLabel.Visibility    = Visibility.Hidden;
         scoreMessage.Visibility = Visibility.Hidden;
     }
     catch (Exception)
     {
     }
 }