コード例 #1
0
ファイル: Ball.cs プロジェクト: Lee-A-N/MyMeadowProjects
        /// <summary>
        /// Initializes a new instance of the Ball class.
        /// </summary>
        /// <param name="asyncGraphics">Graphics object reference</param>
        /// <param name="displayWidth">Width of the display</param>
        /// <param name="displayHeight">Height of the display</param>
        /// <param name="backgroundColor">Background color of the display</param>
        /// <param name="paddle">Reference to the game's paddle object</param>
        /// <param name="soundGenerator">Reference to the game's sound generator object</param>
        /// <param name="minimumY">Minimum y coordinate to use the the ball's enclosing rectangle</param>
        /// <param name="scoreKeeper">Reference to the game's scorekeeper object</param>
        public Ball(
            AsyncGraphics asyncGraphics,
            int displayWidth,
            int displayHeight,
            Color backgroundColor,
            Paddle paddle,
            ISounds soundGenerator,
            int minimumY,
            ScoreKeeper scoreKeeper)
        {
            this.asyncGraphics  = asyncGraphics;
            this.soundGenerator = soundGenerator;

            this.scoreKeeper = scoreKeeper;

            this.backgroundColor = backgroundColor;
            this.paddle          = paddle;

            this.displayWidth = displayWidth;
            this.maxX         = displayWidth - this.width;
            this.maxY         = displayHeight - this.height - Paddle.HEIGHT;
            this.minY         = minimumY;
            this.yPosition    = this.minY + 5;

            this.moveTimer.AutoReset = true;
            this.moveTimer.Elapsed  += this.MoveTimer_Elapsed;
        }
コード例 #2
0
        /// <summary>
        /// Initializes a new instance of the Paddle class
        /// </summary>
        /// <param name="asyncGraphics">Reference to the graphics object</param>
        /// <param name="displayWidth">Width of the display</param>
        /// <param name="displayHeight">Height of the display</param>
        /// <param name="backgroundColor">Background color of the display</param>
        public Paddle(AsyncGraphics asyncGraphics, int displayWidth, int displayHeight, Color backgroundColor)
        {
            this.asyncGraphics = asyncGraphics;

            this.displayWidth    = displayWidth;
            this.backgroundColor = backgroundColor;
            this.y = displayHeight - (Paddle.HEIGHT / 2);
        }
コード例 #3
0
ファイル: Banner.cs プロジェクト: Lee-A-N/MyMeadowProjects
 /// <summary>
 /// Initializes a new instance of the Banner class
 /// </summary>
 /// <param name="displayWidth">Width of the display</param>
 /// <param name="graphics">Graphics object reference</param>
 /// <param name="fontHeight">Height of the text font</param>
 /// <param name="backgroundColor">Background color of the display</param>
 /// <param name="color">Banner color</param>
 /// <param name="top">Top y coordinate for the banner</param>
 public Banner(int displayWidth, AsyncGraphics graphics, int fontHeight, Color backgroundColor, Color color, int top)
 {
     this.width           = displayWidth;
     this.Height          = Banner.HEIGHT;
     this.asyncGraphics   = graphics;
     this.FontHeight      = fontHeight;
     this.backgroundColor = backgroundColor;
     this.color           = color;
     this.top             = top;
 }
コード例 #4
0
        /// <summary>
        /// Initializes a new instance of the MeadowApp class
        /// </summary>
        public MeadowApp()
        {
            MeadowApp.DebugWriteLine("Initializing...");

            this.soundGenerator = new SoundGenerator(
                Device.CreateDigitalInputPort(Device.Pins.D03),
                Device.CreateDigitalInputPort(Device.Pins.D04),
                Device.CreatePwmPort(Device.Pins.D07));

            var config = new SpiClockConfiguration(6000, SpiClockConfiguration.Mode.Mode3);

            this.rotaryPaddle          = new RotaryEncoderWithButton(Device, Device.Pins.D10, Device.Pins.D09, Device.Pins.D08, debounceDuration: 100);
            this.rotaryPaddle.Rotated += this.RotaryPaddle_Rotated;

            this.st7789 = new St7789(
                device: Device,
                spiBus: Device.CreateSpiBus(Device.Pins.SCK, Device.Pins.MOSI, Device.Pins.MISO, config),
                chipSelectPin: Device.Pins.D02,
                dcPin: Device.Pins.D01,
                resetPin: Device.Pins.D00,
                width: 240,
                height: 240);

            this.displayWidth  = Convert.ToInt32(this.st7789.Width);
            this.displayHeight = Convert.ToInt32(this.st7789.Height);

            GraphicsLibrary graphics = new GraphicsLibrary(this.st7789)
            {
                Rotation = GraphicsLibrary.RotationType._270Degrees
            };

            this.asyncGraphics = new AsyncGraphics(graphics);

            this.debounceTimer.AutoReset = false;
            this.debounceTimer.Elapsed  += this.DebounceTimer_Elapsed;

            this.backgroundColor = Color.Blue;

            this.scoreBanner = new Banner(this.displayWidth, this.asyncGraphics, fontHeight: 16, this.backgroundColor, color: Color.Yellow, top: 0)
            {
                Text = Banner.SCORE_TEXT
            };

            this.instructionBanner = new Banner(
                displayWidth: this.displayWidth,
                graphics: this.asyncGraphics,
                fontHeight: 16,
                backgroundColor: this.backgroundColor,
                color: Color.White,
                top: Banner.HEIGHT * 2);
            this.ShowInstructionBanner(Banner.START_TEXT);

            this.paddle = new Paddle(this.asyncGraphics, this.displayWidth, this.displayWidth, this.backgroundColor);

            this.scoreKeeper = new ScoreKeeper();
            this.scoreKeeper.ScoreChanged += this.scoreBanner.OnScoreChanged;

            this.ball = new Ball(
                asyncGraphics: this.asyncGraphics,
                displayWidth: this.displayWidth,
                displayHeight: this.displayHeight,
                backgroundColor: this.backgroundColor,
                paddle: this.paddle,
                soundGenerator: this.soundGenerator,
                minimumY: Banner.HEIGHT + 1,
                scoreKeeper: this.scoreKeeper);

            this.ball.ExplosionOccurred += this.OnExplosionOccurred;

            this.rotaryPaddle.Clicked += this.RotaryPaddle_Clicked;

            this.soundGenerator.PlayConstructionCompleteSound();
        }