Beispiel #1
0
 public GameField(int x, int y, int width, int height)
 {
     fieldRect = new Rectangle(x, y, width, height);
     balls = new List<Ball>();
     player = new Player(new Vector2(width/2, height - Player.PlayerHeight/2), PlayerSpeed, ShootSpeed);
     lasers = new List<Laser>();
 }
Beispiel #2
0
        public bool CheckForPlayerHit(Ball ball, Player player)
        {
            double playerTop = height - player.Height + 1;
            if (ball.Center.Y + ball.Radius >= playerTop)
            {
                double leftMost = player.PosX - player.SpriteWidth / 2;
                double rightMost = player.PosX + player.SpriteWidth / 2;

                if (ball.Center.X >= leftMost && ball.Center.X <= rightMost) return true;

                if (ball.Center.Y < playerTop)
                {
                    double distance = 0;
                    if (ball.Center.X < leftMost) distance = Math.Sqrt(Math.Pow(ball.Center.X - leftMost, 2) + Math.Pow(ball.Center.Y - playerTop, 2));
                    else distance = Math.Sqrt(Math.Pow(ball.Center.X - rightMost, 2) + Math.Pow(ball.Center.Y - playerTop, 2));

                    if (distance <= ball.Radius) return true;

                    else return false;
                }
                else
                {
                    if (ball.Center.X < leftMost) return ball.Center.X + ball.Radius >= leftMost;
                    else return ball.Center.X - ball.Radius <= rightMost;
                }
            }
            else return false;
        }
        private void GameWin_Loaded(object sender, RoutedEventArgs e)
        {
            int width = (int)MainGrid.ActualWidth;
            int height = (int)MainGrid.ActualHeight;

            Player player = new Player(width / 2 - 16, 0, width);

            List<Ball> startBalls = new List<Ball>();

            startBalls.Add(new Ball(50, new Point(width / 2, height / 3), new Point(1, -0.65), Colors.Aqua, 3));

            GameEngine = new Game(MainGrid, player, startBalls);

            GameLoop();
        }
Beispiel #4
0
        public Game(Grid mainGrid, Player player, List<Ball> balls)
        {
            this.width = mainGrid.ActualWidth;
            this.height = mainGrid.ActualHeight;

            this.mainGrid = mainGrid;

            this.player = player;
            this.mainGrid.Children.Add(player);

            this.balls = new List<Ball>();
            foreach (Ball ball in balls)
            {
                this.balls.Add(ball);
                this.mainGrid.Children.Add(ball);
            }

            canShoot = true;
        }