English
Language : 

LCD-14048 Datasheet, PDF (17/33 Pages) SparkFun Electronics – TeensyView Hookup Guide
while ((ball_X ­ ball_rad > 1) &&
(ball_X + ball_rad < oled.getLCDWidth() ­ 2))
{
// Increment ball's position
ball_X += ballVelocityX;
ball_Y += ballVelocityY;
// Check if the ball is colliding with the left paddle
if (ball_X ­ ball_rad < paddle0_X + paddleW)
{
// Check if ball is within paddle's height
if ((ball_Y > paddle0_Y) && (ball_Y < paddle0_Y + paddle
H))
{
ball_X++; // Move ball over one to the right
ballVelocityX = ­ballVelocityX; // Change velocity
}
}
// Check if the ball hit the right paddle
if (ball_X + ball_rad > paddle1_X)
{
// Check if ball is within paddle's height
if ((ball_Y > paddle1_Y) && (ball_Y < paddle1_Y + paddle
H))
{
ball_X­­; // Move ball over one to the left
ballVelocityX = ­ballVelocityX; // change velocity
}
}
// Check if the ball hit the top or bottom
if ((ball_Y <= ball_rad) || (ball_Y >= (oled.getLCDHeight
() ­ ball_rad ­ 1)))
{
// Change up/down velocity direction
ballVelocityY = ­ballVelocityY;
}
// Move the paddles up and down
paddle0_Y += paddle0Velocity;
paddle1_Y += paddle1Velocity;
// Change paddle 0's direction if it hit top/bottom
if ((paddle0_Y <= 1) || (paddle0_Y > oled.getLCDHeight()
­ 2 ­ paddleH))
{
paddle0Velocity = ­paddle0Velocity;
}
// Change paddle 1's direction if it hit top/bottom
if ((paddle1_Y <= 1) || (paddle1_Y > oled.getLCDHeight()
­ 2 ­ paddleH))
{
paddle1Velocity = ­paddle1Velocity;
}
// Draw the Pong Field
oled.clear(PAGE); // Clear the page
// Draw an outline of the screen:
oled.rect(0, 0, oled.getLCDWidth() ­ 1, oled.getLCDHeight
());
// Draw the center line
oled.rectFill(oled.getLCDWidth() / 2 ­ 1, 0, 2, oled.getLC
DHeight());
// Draw the Paddles:
oled.rectFill(paddle0_X, paddle0_Y, paddleW, paddleH);
oled.rectFill(paddle1_X, paddle1_Y, paddleW, paddleH);
// Draw the ball:
oled.circle(ball_X, ball_Y, ball_rad);
// Actually draw everything on the screen:
Page 17 of 33