Exemple #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);
        }
Exemple #2
0
        public void OnKeyDownHandler(object sender, KeyEventArgs e)
        {
            if (!(player.getPositionLeft() == 560 || player.getPositionLeft() == 0))
            {
                if (pauser == false)
                {
                    switch (e.Key) //check if outside of screen ----> size of canvas -> 559 Ship set to 280
                    {
                    case Key.Left:
                        player.moveLeft(10);
                        break;

                    case Key.Right:
                        player.moveRight(10);
                        break;
                    }
                }
            }
            else
            if (player.getPositionLeft() == 560)
            {
                if (e.Key == Key.Left)
                {
                    player.moveLeft(10);
                }
            }
            else if (player.getPositionLeft() == 0)
            {
                if (e.Key == Key.Right)
                {
                    player.moveRight(10);
                }
            }
            //Shooting projectiles
            if (e.Key == Key.Space && projInPlay == 0 && pauser == false)
            {
                projectile.Stroke = new SolidColorBrush(Colors.Red);
                projectile.Fill   = new SolidColorBrush(Colors.Red);
                projectile.Width  = 10;
                projectile.Height = 30;
                Canvas.SetLeft(projectile, (player.getPositionLeft() + 34));
                Canvas.SetTop(projectile, 570);
                game.Children.Add(projectile);
                projInPlay = 1;
            }
            if (e.Key == Key.R)
            {
                System.Diagnostics.Process.Start(Application.ResourceAssembly.Location);
                Application.Current.Shutdown();
                timerCalled = true;
            }
            if (e.Key == Key.P)
            {
                if (pauser == false)
                {
                    enemyTimer1.Stop();
                    shootTimer.Stop();
                    EshootTimer.Stop();
                    bossTimer1.Stop();
                    messageTimer.Stop();
                    enemylvl2.Stop();
                    pauser = true;
                }
                else if (pauser)
                {
                    enemyTimer1.Start();
                    shootTimer.Start();
                    EshootTimer.Start();
                    bossTimer1.Start();
                    messageTimer.Start();
                    enemylvl2.Start();
                    pauser = false;
                }
            }
            if (e.Key == Key.S)
            {
                save();
            }

            if (e.Key == Key.L)
            {
                load();
            }
        }