コード例 #1
0
ファイル: GameEngine.cs プロジェクト: StephGarland/Pong
        /// <summary>
        /// Initialises Game Engine with given dimensions of game-world
        /// </summary>
        /// <param name="clientSize">dimensions of game-world</param>
        public GameEngine(Size clientSize)
        {
            this.clientSize = clientSize;
            ballStartPosition = new Point(clientSize.Width / 2, clientSize.Height / 2);
            ball = new Ball(BALL_SIZE, Color.Orange, clientSize, ballStartPosition);

            Size paddleSize = new Size(PADDLE_WIDTH, PADDLE_HEIGHT);

            Point paddlePosition = new Point(PADDLE_X, PADDLE_Y);
            leftPaddle = new Paddle(paddleSize, paddlePosition, Color.Red, clientSize, "femaleGrunt.wav");

            paddlePosition = new Point((clientSize.Width - PADDLE_WIDTH) - PADDLE_X, PADDLE_Y);
            rightPaddle = new Paddle(paddleSize, paddlePosition, Color.Red, clientSize, "maleGrunt.wav");

            topCentre = new Point((clientSize.Width / 2), 0);
            bottomCentre = new Point((clientSize.Width / 2), clientSize.Height);
            dashedLinePen = new Pen(Color.White, PENWIDTH);
            dashedLinePen.DashStyle = DashStyle.Dash;

            winConditions = false;

            int x = Convert.ToInt32((clientSize.Width * POSITION_1ST_QUARTER) - FONT_SIZE);
            Point position = new Point(x, (clientSize.Height / POSITION_Y_DIVISOR));
            scoreLeft = new Score(position);

            x = Convert.ToInt32((clientSize.Width * POSITION_3RD_QUARTER) - FONT_SIZE);
            position = new Point (x, (clientSize.Height / POSITION_Y_DIVISOR));
            scoreRight = new Score(position);
        }
コード例 #2
0
 public BallOutMananger(Ball ball, int worldWidth, SoundEffect soundEffect, Score score)
 {
     this.score = score;
     this.ball = ball;
     this.worldWidth = worldWidth;
     this.soundEffect = soundEffect;
 }
コード例 #3
0
ファイル: Game1.cs プロジェクト: rubik951/Pong
        protected override void LoadContent()
        {
            spriteBatch = new SpriteBatch(GraphicsDevice);

            var gameBoundaries = new Rectangle(0, 0, Window.ClientBounds.Width, Window.ClientBounds.Height);
            var paddleTexture = Content.Load<Texture2D>("Paddle");

            playerPaddle = new Paddle(paddleTexture, Vector2.Zero, gameBoundaries, PlayerTypes.Human);
            computerPaddle = new Paddle(paddleTexture, new Vector2(gameBoundaries.Width - paddleTexture.Width, 0), gameBoundaries, PlayerTypes.Computer);
            ball = new Ball(Content.Load<Texture2D>("Ball"), Vector2.Zero, gameBoundaries);
            ball.AttachTo(playerPaddle);

            score = new Score(Content.Load<SpriteFont>("GameFont"), gameBoundaries);

            gameObjects = new GameObjects { PlayerPaddle = playerPaddle, ComputerPaddle = computerPaddle, Ball = ball, Score=score };
        }
コード例 #4
0
ファイル: Game1.cs プロジェクト: Brown-James/PongGame
        /// <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);

            // create ball and paddle objects
            pongBall = new Ball(Content, new Vector2(WINDOW_WIDTH / 2, WINDOW_HEIGHT / 2), 10);
            pongBall.GiveRandomVelocity();

            leftPaddle = new Paddle(Content, 100, 20, "left", GraphicsDevice);
            rightPaddle = new Paddle(Content, 100, 20, "right", GraphicsDevice);

            // load audio components
            audioEngine = new AudioEngine(@"Content/Pong.xgs");
            waveBank = new WaveBank(audioEngine, @"Content/Wave Bank.xwb");
            soundBank = new SoundBank(audioEngine, @"Content/Sound Bank.xsb");

            // set the board rectangle to the size of the window, load the board texture
            boardRectangle = new Rectangle(0, 0, WINDOW_WIDTH, WINDOW_HEIGHT);
            boardTexture = Content.Load<Texture2D>("board");

            playerOneScore = new Score(Content, new Vector2(WINDOW_WIDTH / 4, 25), 39, 75);
            playerTwoScore = new Score (Content, new Vector2 ((3 * (WINDOW_WIDTH / 4)), 25), 39, 75);
        }
コード例 #5
0
ファイル: Game1.cs プロジェクト: hirako2000/MonoPingPong
        /// <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);

            Content.RootDirectory = "Content";
            var barTexture = Content.Load<Texture2D>("PongBar");
            var ballTexture = Content.Load<Texture2D>("PongBall");

            var ballOutSound = Content.Load<SoundEffect>("ballOutSound");
            var ballCollideWithBarSound = Content.Load<SoundEffect>("ballBarCollision");
            var ballCollideWithEdgeSound = Content.Load<SoundEffect>("ballEdgeCollision");

            var music = Content.Load<SoundEffect>("music");
            SoundEffectInstance soundEffectInstance = music.CreateInstance();
            soundEffectInstance.IsLooped = true;
            soundEffectInstance.Play();

            var font = Content.Load<SpriteFont>("Score");

            playerBar = new Bar(barTexture, BarToEdgePadding, Height, ballCollideWithBarSound);
            cpuBar = new Bar(barTexture, Width - BarToEdgePadding, Height, ballCollideWithBarSound);

            var ball = new Ball(ballTexture, Width / 2, Width, Height, ballCollideWithEdgeSound);

            score = new Score(font);
            ballOutManager = new BallOutMananger(ball, Width, ballOutSound, score);

            cpuController = new CpuController(cpuBar, ball, Height);
        }