예제 #1
0
        public static void Main()
        {
            var oled    = new SSD1306(0x3c, 400, SSD1306.DisplayType.OLED128x64);
            var display = new GraphicsLibrary(oled);

            display.Clear(true);
            display.DrawLine(0, 30, 80, 60, true);
            display.Show();
            Thread.Sleep(1000);

            display.Clear(true);
            display.DrawFilledCircle(63, 31, 20, true);
            display.Show();
            Thread.Sleep(1000);

            display.Clear(true);
            display.DrawRectangle(20, 20, 60, 40);
            display.Show();
            Thread.Sleep(1000);

            display.Clear(true);
            display.DrawFilledRectangle(30, 10, 50, 40);
            display.Show();
            Thread.Sleep(1000);

            display.Clear(true);
            display.CurrentFont = new Font8x8();
            display.DrawText(4, 10, 0, "NETDUINO 3 WiFi");
            display.Show();
            Thread.Sleep(Timeout.Infinite);
        }
예제 #2
0
        void StartGameLoop()
        {
            while (spdt.IsOn)
            {
                graphics.Clear(false);
                graphics.DrawFilledCircle(ballX, ballY, ballRadius);
                graphics.DrawFilledRectangle(playerX, playerY, paddleWidth, paddleHeight);
                graphics.DrawFilledRectangle(cpuX, cpuY, paddleWidth, paddleHeight);

                graphics.DrawText(0, 0, 0, playerScore.ToString());
                graphics.DrawText(120, 0, 0, cpuScore.ToString());

                graphics.Show();

                //move player
                if (buttons[0].State == false)
                {
                    if (playerY > 0)
                    {
                        playerY -= 4;
                    }
                }
                else if (buttons[1].State == false)
                {
                    if (playerY - paddleHeight < 64)
                    {
                        playerY += 4;
                    }
                }

                //move cpu
                if (cpuY < ballY)
                {
                    cpuY++;
                }
                else if (cpuY > ballY)
                {
                    cpuY--;
                }

                ballX += ballXVelocity;
                if (ballY >= playerY &&
                    ballY <= playerY + paddleHeight &&
                    ballX - ballRadius <= playerX)
                {
                    ballXVelocity *= -1;
                    ballX         += ballXVelocity;
                    speaker.PlayTone(300, 25);
                }
                else if (ballX - ballRadius < 0)
                {
                    cpuScore++;
                    ballXVelocity *= -1;
                    ballX         += 64;
                    ballY          = 32;
                    speaker.PlayTone(440, 25);
                    ShowGameOverAnimation();
                }
                else if (ballY >= cpuY &&
                         ballY <= cpuY + paddleHeight &&
                         ballX + ballRadius > cpuX)
                {
                    ballXVelocity *= -1;
                    ballX         += ballXVelocity;
                    speaker.PlayTone(300, 25);
                }
                else if (ballX + ballRadius > 128)
                {
                    playerScore++;
                    ballXVelocity *= -1;
                    ballX          = 64;
                    ballY          = 32;
                    speaker.PlayTone(440, 25);
                    ShowGameOverAnimation();
                }

                ballY += ballYVelocity;
                if (ballY - ballRadius < 0)
                {
                    ballYVelocity *= -1;
                    ballY         += ballYVelocity;
                    speaker.PlayTone(220, 25);
                }
                else if (ballY + ballRadius > 64)
                {
                    ballYVelocity *= -1;
                    ballY         += ballYVelocity;
                    speaker.PlayTone(220, 25);
                }

                Thread.Sleep(25);
            }
        }