Пример #1
0
        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            double width, height;
            width = (double)GraphicsDevice.Viewport.Bounds.Width;
            height = (double)GraphicsDevice.Viewport.Bounds.Height;
            base.Initialize();

            _center.X = width / 2;
            _center.Y = height / 2;

            _lWallRect = new CollidableObjects.Rectangle(0, _center.Y, _horzWallTextures[0].Width / 2, height / 2);

            _rWallRect = new CollidableObjects.Rectangle(width, _center.Y, _horzWallTextures[0].Width / 2, height / 2);

            _tWallRect = new CollidableObjects.Rectangle(_center.X, 0, width / 2, _vertWallTextures[0].Height / 2);

            _bWallRect = new CollidableObjects.Rectangle(_center.X, height, width / 2, _vertWallTextures[0].Height / 2);

            _pad1Rect = new CollidableObjects.Rectangle(60, _center.Y, _paddle1Texture.Width / 2.0, _paddle1Texture.Height / 2.0);

            _pad2Rect = new CollidableObjects.Rectangle(width - 60, _center.Y, _paddle2Texture.Width / 2.0, _paddle2Texture.Height / 2.0);

            _ballCircle = new CollidableObjects.Circle(_center.X, _center.Y, 5.0);

            _leftWall = new ArenaWall(_horzWallTextures, _lWallRect);
            _rightWall = new ArenaWall(_horzWallTextures, _rWallRect);
            _topWall = new ArenaWall(_vertWallTextures, _tWallRect);
            _bottomWall = new ArenaWall(_vertWallTextures, _bWallRect);
            _players = new List<Player>() {new Player(PlayerIndex.One), new Player(PlayerIndex.Two)};
            _paddle1 = new Paddle(_paddle1Texture, _pad1Rect, _players[0]);
            _paddle2 = new Paddle(_paddle2Texture, _pad2Rect, _players[1]);
            _leftWall.Owner = _paddle1.Owner;
            _rightWall.Owner = _paddle2.Owner;
            _topWall.Owner = null;
            _bottomWall.Owner = null;
            _ballVector = new _2D.Vector(50.0, 0);
            _dTime = new TimeSpan(1000000);
            _ball = new Ball(_ballTexture, _center, new _2D.Speed(_ballVector, _dTime));

            /*paddles = new List<Paddle>();
            paddles.Add(_paddle1);
            paddles.Add(_paddle2);*/

            walls = new List<ArenaWall>();
            walls.Add(_leftWall);
            walls.Add(_rightWall);
            walls.Add(_topWall);
            walls.Add(_bottomWall);

            _gameScore = new Score(_font, _players);
            _collidableObjects.Add(_leftWall);
            _collidableObjects.Add(_rightWall);
            _collidableObjects.Add(_topWall);
            _collidableObjects.Add(_bottomWall);
            _collidableObjects.Add(_paddle1);
            _collidableObjects.Add(_paddle2);
            _collidableObjects.Add(_ball);

            _drawObjects.Add(_ball);
            _drawObjects.Add(_paddle1);
            _drawObjects.Add(_paddle2);
            _drawObjects.Add(_leftWall);
            _drawObjects.Add(_rightWall);
            _drawObjects.Add(_topWall);
            _drawObjects.Add(_bottomWall);
            _drawObjects.Add(_gameScore);
            wing_ding_pong.CollisionDetection.RegisterCollisionTrait<wing_ding_pong.CollidableObjects.Circle,
                                                                    wing_ding_pong.CollidableObjects.Rectangle>
                                                                    (new wing_ding_pong.Traits.CircleRecCollisionCheckTraits());
            wing_ding_pong.CollisionDetection.RegisterCollisionTrait<wing_ding_pong.CollidableObjects.Circle,
                                                                    wing_ding_pong.CollidableObjects.Circle>
                                                                    (new wing_ding_pong.Traits.CircleCircleCollisionCheckTraits());
            wing_ding_pong.CollisionDetection.RegisterCollisionTrait<wing_ding_pong.CollidableObjects.Circle,
                                                                    wing_ding_pong.CollidableObjects.Triangle>
                                                                    (new wing_ding_pong.Traits.CircleTriangleCollisionCheckTraits());
            wing_ding_pong.CollisionDetection.RegisterCollisionTrait<wing_ding_pong.CollidableObjects.Rectangle,
                                                                    wing_ding_pong.CollidableObjects.Rectangle>
                                                                    (new wing_ding_pong.Traits.RecRecCollisionCheckTraits());

            _rules.RegisterRule<Ball, ArenaWall>(new Traits.BallArenaWallCollisionRules(_center, _ballVector.Clone(), _ballBounce, _playerScored));
            _rules.RegisterRule<Ball, Paddle>(new Traits.BallPaddleCollisionRules(_ballBounce));
            _rules.RegisterRule<Paddle, ArenaWall>(new Traits.PaddleArenaWallCollisionRules());
            _rules.RegisterRule<Ball, Powerup>(new Traits.BallPowerupCollisionRules());
        }
Пример #2
0
 public ArenaWall(IList<Texture2D> sprites, Rectangle wallObj)
     : base(new List<Tile>() { wallObj })
 {
     _sprites = sprites;
     _wall = (Rectangle)CollidableObjects[0];
 }