Initialize the const Screen Width and Height, BallRadius, Pad Width and Height
function - change the ball direction, velocity("direction")
{
if "direction" == right: // when going right
ball_velocity_vector[0] = - ball_velocity_vector[0] // change the direction
ball_velocity_vector[0] += 1 // increase the velocity
if ball_velocity_vector[1] >= 0: // when touching the screen - y direction
ball_velocity_vector[1] += 0.3 // also, increase the velocity
else if ball_velocity_vector[1] < 0
ball_velocity_vector[1] -= 0.3
else if ... right...
}
function - make a new game
{
pad_velocity = 0 // reset the pad velocity and position
pad_position = [coord_x, coord_y]
if player1 win:
score1 += 1
else if player2 win:
score2 += 1}
}
//Loop, printing the pad and ball position through the screen
Loop body
{
pad1_position += pad1_velocity
pad2_position += pad2_velocity
//when the ball touch the pad, collision
if ball_position[x] touch the screen line
if ball_position[y] touch the height of pad
call the change the ball function("direction")
if ball_position is beyond the screen
initialize the ball_position
randomly generate the new ball_velocity
call the function of making a new game
}
댓글 없음:
댓글 쓰기