コード例 #1
0
        private void CollisionsWithBalls(ref List <Ball> balls)
        {
            Rect collisionArea = GetCollisionArea();

            foreach (Ball ball in balls)
            {
                Rect ballArea = new Rect(ball.Margin.Left, ball.Margin.Top, ball.Width, ball.Height);
                if (collisionArea.IntersectsWith(ballArea))
                {
                    double ballRelativeMiddleX = ballArea.Left + (ballArea.Width / 2.0) - collisionArea.Left;
                    double platformMiddleX     = collisionArea.Width / 2.0;

                    double percent = Convert.ToDouble((ballRelativeMiddleX - platformMiddleX)) / (collisionArea.Width / 2.0);
                    if (percent > 0.8)
                    {
                        percent = 0.8;
                    }
                    else if (percent < -0.8)
                    {
                        percent = -0.8;
                    }

                    ball.Angle = ((3.0 / 2.0) * Math.PI) + percent * 0.5 * Math.PI;
                    ball.SetPosition(ball.Margin.Left, _platformMiddle.Margin.Top - ball.Height);

                    if (!ball.IsGlued())
                    {
                        GameControl.PlaySound(GameControl.Sound.BouncingBall);
                    }
                }
            }
        }
コード例 #2
0
        //ACTIONS PERFORMED ON GAME ELEMENTS
        private void BallsActions()
        {
            List <Ball> destroyedBalls = new List <Ball>();

            foreach (Ball ball in balls)
            {
                ball.Move();

                foreach (Rect wall in walls)
                {
                    if (ball.HasCollisionWith(wall))
                    {
                        ball.Bounce(wall);
                        GameControl.PlaySound(GameControl.Sound.BouncingBall);
                    }
                }

                if (ball.IsDestroyed())
                {
                    destroyedBalls.Add(ball);
                }
            }
            foreach (Ball ball in destroyedBalls)
            {
                balls.Remove(ball);
            }
        }
コード例 #3
0
        private void SaveScore(int score)
        {
            if (scoreboard.IsAScoreBeaten(score))
            {
                GameControl.PlaySound(GameControl.Sound.Record);

                Point         wtbPosition = new Point(Left + Width / 2.0, Top + Height / 2.0);
                WindowTextBox wtb         = new WindowTextBox("Enter your name", "score: " + score + "!", wtbPosition);
                string        name        = wtb.TextBox.Text;

                ScoreboardItem item = new ScoreboardItem(name, score);
                scoreboard.AddItem(item);
                SaveScoreboard();
            }
        }
コード例 #4
0
ファイル: Brick.cs プロジェクト: Wojdak-Gliszczynski/Arkanoid
        public void Collisions(Grid grid, List <Ball> balls, List <Brick> bricks, List <Brick> destroyedBricks)
        {
            Rect collisionsArea = new Rect(Margin.Left, Margin.Top, Width, Height);

            foreach (Ball ball in balls)
            {
                Rect ballArea = new Rect(ball.Margin.Left, ball.Margin.Top, ball.Width, ball.Height);
                if (collisionsArea.IntersectsWith(ballArea))
                {
                    double ballAngle = ball.Angle;
                    ball.Bounce(collisionsArea);

                    switch (_typeID)
                    {
                    case BrickType.Normal:
                        GameControl.AddPoints(25);
                        GameControl.PlaySound(GameControl.Sound.BreakBrick);
                        destroyedBricks.Add(this);
                        return;

                    case BrickType.Reinforced:
                        GameControl.AddPoints(10);
                        GameControl.PlaySound(GameControl.Sound.BreakReinforcement);
                        _typeID = BrickType.Normal;
                        Source  = new BitmapImage(GetPath(_typeID, _colorID));
                        break;

                    case BrickType.Indestructible:
                        GameControl.PlaySound(GameControl.Sound.BouncingBall);
                        break;

                    case BrickType.Ball:
                        GameControl.AddPoints(15);
                        GameControl.PlaySound(GameControl.Sound.ExtraBall);
                        destroyedBricks.Add(this);
                        balls.Add(new Ball(grid, ball.Speed, ballAngle, Margin.Left + Width / 2 - 8, Margin.Top + Height / 2 - 8));
                        return;

                    case BrickType.TNT:
                        GameControl.AddPoints(5);
                        GameControl.PlaySound(GameControl.Sound.Explosion);
                        destroyedBricks.Add(this);
                        Explosion explosion = new Explosion(grid, balls, bricks, this, destroyedBricks);
                        return;
                    }
                }
            }
        }
コード例 #5
0
        public void UseBonus(ref Grid grid, ref Platform platform, ref List <Ball> balls)
        {
            if (_id == BonusName.Random)
            {
                _id = (BonusName)_rand.Next(1, _maxBonusID + 1);
            }

            switch (_id)
            {
            case BonusName.DoubleBall:
                GameControl.PlaySound(GameControl.Sound.ExtraBall);
                int ballsCount = balls.Count;
                for (int i = 0; i < ballsCount; i++)
                {
                    balls.Add(new Ball(balls[i]));
                }
                break;

            case BonusName.BallSizeUp:
                foreach (Ball ball in balls)
                {
                    ball.SizeUp();
                }
                break;

            case BonusName.BallSizeDown:
                foreach (Ball ball in balls)
                {
                    ball.SizeDown();
                }
                break;

            case BonusName.BallSpeedDown:
                foreach (Ball ball in balls)
                {
                    ball.Speed--;
                }
                break;

            case BonusName.BallSpeedUp:
                foreach (Ball ball in balls)
                {
                    ball.Speed++;
                }
                break;

            case BonusName.PlatformSizeUp:
                platform.SizeUp();
                break;

            case BonusName.PlatformSizeDown:
                platform.SizeDown();
                break;

            case BonusName.PlatformSpeedUp:
                platform.Speed++;
                break;

            case BonusName.PlatformSpeedDown:
                platform.Speed--;
                break;

            case BonusName.ExtraLife:
                GameControl.AddLife();
                break;

            case BonusName.ExtraPoints:
                GameControl.AddPoints(1000);
                GameControl.PlaySound(GameControl.Sound.ExtraPoints);
                break;

            case BonusName.Skull:
                foreach (Ball ball in balls)
                {
                    grid.Children.Remove(ball);
                }
                balls.Clear();
                break;
            }

            grid.Children.Remove(this);
        }