diff --git a/CORTEX_M4F_STM32F407ZG-SK/game/game.c b/CORTEX_M4F_STM32F407ZG-SK/game/game.c index 0f1e136..5fc2fef 100644 --- a/CORTEX_M4F_STM32F407ZG-SK/game/game.c +++ b/CORTEX_M4F_STM32F407ZG-SK/game/game.c @@ -156,6 +156,111 @@ GAME_Update() BallReset(); } + if( ballY <= player1Y + player1H ){ + if( ballX + ballSize >= player1X && ballX <= player1X + player1W ){ + if( ballX - ballSize <= player1Y + player1W/4 ){ + ballVY = 3; + ballVX =-7; + } + else if( ballX >= player1Y + player1W - player1W/4 ){ + ballVY = 3; + ballVX = 7; + } + else if( ballX + ballSize < player1Y + player1W/2 ){ + ballVY = 7; + ballVX =-3; + } + else if( ballX > player1Y + player1W/2 ){ + ballVY = 7; + ballVX = 3; + } + else{ + ballVY = 9; + ballVX = 0; + } + } + else + BallReset(); + } + } + } + else{ //if demoMode == 1 + + //Player1 move + if( ballVY < 0 ){ + if( player1X + player1W/2 < ballX + ballSize/2 ) + player1X += 8; + else + player1X -= 8; + + } + + if( player1X <= 0 ) + player1X = 0; + else if( player1X + player1W >= LCD_PIXEL_WIDTH ) + player1X = LCD_PIXEL_WIDTH - player1W; + + //Player2 move + if( ballVY > 0 ){ + if( player2X + player2W/2 < ballX + ballSize/2 ) + player2X += 8; + else + player2X -= 8; + + } + + if( player2X <= 0 ) + player2X = 0; + else if( player2X + player2W >= LCD_PIXEL_WIDTH ) + player2X = LCD_PIXEL_WIDTH - player2W; + + + //Ball + if( ballIsRun == 1 ){ + + LCD_SetTextColor( LCD_COLOR_BLACK ); + LCD_DrawFullRect( ballX, ballY, ballSize, ballSize ); + + //Touch wall + ballX += ballVX; + if( ballX <= 0 ){ + ballX = 0; + ballVX *= -1; + } + else if( ballX + ballSize >= LCD_PIXEL_WIDTH ){ + ballX = LCD_PIXEL_WIDTH - ballSize; + ballVX *= -1; + } + + //PONG! + ballY += ballVY; + if( ballY + ballSize >= player2Y ){ + if( ballX + ballSize >= player2X && ballX <= player2X + player2W ){ + if( ballX - ballSize <= player2Y + player2W/4 ){ + ballVY =-3; + ballVX =-7; + } + else if( ballX >= player2Y + player2W - player2W/4 ){ + ballVY =-3; + ballVX = 7; + } + else if( ballX + ballSize < player2Y + player2W/2 ){ + ballVY =-7; + ballVX =-3; + } + else if( ballX > player2Y + player2W/2 ){ + ballVY =-7; + ballVX = 3; + } + else{ + ballVY =-9; + ballVX = 0; + } + } + else + BallReset(); + } + if( ballY <= player1Y + player1H ){ if( ballX + ballSize >= player1X && ballX <= player1X + player1W ){ if( ballX - ballSize <= player1Y + player1W/4 ){ @@ -184,8 +289,6 @@ GAME_Update() } } } - else{ //if demoMode == 1 - } } void