Ejemplo n.º 1
0
        private void ProcesskCollisition()
        {
            Wall[] walls = new Wall[] { northWall, southWall};
            for (int i = 0; i < walls.Length; i++)
            {
                BoundingBox box = walls[i].Bounding;
                BoundingSphere sphere = ball.Bounding;
                if (box.Intersects(sphere) &&
                    Vector2.Dot(ball.Vector, walls[i].Direction) < 0) {

                    Vector2 reflectVector = Vector2.Reflect(ball.Vector, walls[i].Direction);
                    reflectVector.X += ((float)random.NextDouble() - 0.5f) * 2.0f * reflectRandom;
                    reflectVector.Y += ((float)random.NextDouble() - 0.5f) * 2.0f * reflectRandom;
                    ball.Vector = reflectVector;
                    ball.Speed += reflectAccele;
                }
            }

            // �p�h���̏Փ˔���
            for (int i = 0; i < paddles.Length; i++)
            {
                BoundingBox box = paddles[i].Bounding;
                BoundingSphere sphere = ball.Bounding;
                if (box.Intersects(sphere) &&
                    Vector2.Dot(ball.Vector, paddles[i].Direction) < 0) {

                    Vector2 reflectVector = Vector2.Reflect(ball.Vector, paddles[i].Direction);
                    reflectVector.X += ((float)random.NextDouble() - 0.5f) * 2.0f * reflectRandom;
                    reflectVector.Y += ((float)random.NextDouble() - 0.5f) * 2.0f * reflectRandom;
                    ball.Vector = reflectVector;
                    ball.Speed += reflectAccele;
                }
            }

            if (ball.Speed > ballLimitSpeed) ball.Speed = ballLimitSpeed;
        }
Ejemplo n.º 2
0
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);

            // TODO: use this.Content to load your game content here
            font = Content.Load<SpriteFont>("DefaultFont");
            image = Content.Load<Texture2D>("niconicochan");

            titleImage = Content.Load<Texture2D>("title");
            winImage = Content.Load<Texture2D>("win");
            enterImage = Content.Load<Texture2D>("enter");

            for (int i = 0; i < numberImages.Length; i++)
            {
                numberImages[i] = Content.Load<Texture2D>("number" + i);
            }

            ball = new Ball(Content.Load<Texture2D>("ball"));
            ball.Reset(new Vector2(320, 240), new Vector2(-1, -1), ballStartSpeed);

            Texture2D wallImage = Content.Load<Texture2D>("wall");
            northWall = new Wall(wallImage, new Vector2(0, 1), new Vector2(screenWidth / 2, 10));
            southWall = new Wall(wallImage, new Vector2(0, -1), new Vector2(screenWidth / 2, 470.0f));

            centerline = Content.Load<Texture2D>("centerline");

            Texture2D paddleImage = Content.Load<Texture2D>("paddle");

            paddles[0] = new KeyboardPaddle(paddleImage, new Vector2(1,0), new Vector2(10.0f, 240.0f));

            CpuPaddle cpuPaddle = new CpuPaddle(paddleImage, new Vector2(-1, 0), new Vector2(630.0f, 240.0f));
            cpuPaddle.Ball = ball;
            paddles[1] = cpuPaddle;

            gameState = GameState.Title;
        }