diff --git a/VSCode/Pong/src/main.cpp b/VSCode/Pong/src/main.cpp index 1e91909..f6ac0c0 100755 --- a/VSCode/Pong/src/main.cpp +++ b/VSCode/Pong/src/main.cpp @@ -27,7 +27,7 @@ #define GAME_DELAY 40 // in ms #define BALL_DELAY_MAX 200 // in ms #define BALL_DELAY_MIN 50 // in ms -#define BALL_DELAY_STEP 5 // in ms +#define BALL_DELAY_STEP 10 // in ms #define PLAYER_AMOUNT 2 #define PLAYER_1 0 @@ -40,9 +40,12 @@ #define PADDLE_MOVE_DOWN 2 #define LED_TYPE_OFF 1 -#define LED_TYPE_PADDLE 2 -#define LED_TYPE_BALL 3 -#define LED_TYPE_BALL_RED 4 +#define LED_TYPE_PADDLE_BLUE 2 +#define LED_TYPE_PADDLE_RED 3 +#define LED_TYPE_BALL 4 +#define LED_TYPE_BALL_YELLOW 5 +#define LED_TYPE_POINTS_BLUE 6 +#define LED_TYPE_POINTS_RED 7 #define TONE_PLAYER 1 #define TONE_WALL 2 @@ -61,6 +64,9 @@ struct Coords { byte y; }; +byte pointsPlayerRed =0; +byte pointsPlayerBlue =0; + Adafruit_WS2801 pixels = Adafruit_WS2801((uint16_t)10 ,(uint16_t)20, dataPin, clockPin ); bool buttonPressed = false; byte gameState; @@ -138,6 +144,7 @@ void loop() switch(gameState) { case GAME_STATE_INIT: + initGame(); break; case GAME_STATE_RUNNING: @@ -154,13 +161,36 @@ void loop() void initGame() { + resetLEDs(); lastButtonClick = millis(); - ball.y = 1; - ball.x = (X_MAX/2) - (PADDLE_WIDTH/2) + 1; - ballMovement[0] = -1; - ballMovement[1] = 1; + ball.y = random(7,13); + ball.x = random(3,6); + switch(random(3)) + { + case 0: + + ballMovement[0] = -1; + ballMovement[1] = 1; + break; + + case 1: + + ballMovement[0] = 1; + ballMovement[1] = -1; + break; + + case 2: + ballMovement[0] = -1; + ballMovement[1] = -1; + break; + + case 3: + ballMovement[0] = 1; + ballMovement[1] = 1; + break; + } ballDelay = BALL_DELAY_MAX; for(byte i=0; i