Skip to content

Commit

Permalink
Add demo mode
Browse files Browse the repository at this point in the history
  • Loading branch information
TheKK committed Apr 13, 2014
1 parent 6950db0 commit 4f66ddd
Showing 1 changed file with 105 additions and 2 deletions.
107 changes: 105 additions & 2 deletions CORTEX_M4F_STM32F407ZG-SK/game/game.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 ){
Expand Down Expand Up @@ -184,8 +289,6 @@ GAME_Update()
}
}
}
else{ //if demoMode == 1
}
}

void
Expand Down

0 comments on commit 4f66ddd

Please sign in to comment.