파이게임 공이 화면으로 안넘어 가게
실행을 시켜보면 공이 방향키로 움직일수 있는데요...(아직은 미완성)
저 공이 계속 화면으로 넘어가는걸 막을 수 있을까요?
%%code%%
import pygame
pygame.init()
x = 300
y = 400
screen = pygame.display.set_mode((y, x), 0, 32)
pygame.display.set_caption("ball")
WHITE = (255, 255, 255)
ball = pygame.image.load('ball.png')
ballx = 150
bally = 100
ballSize = ball.get_rect().size
ballWidth = ballSize[0]
ballHeight = ballSize[1]
ballXpos = (y / 2) - (ballWidth / 2)
ballYpos = x - ballHeight
done=False
while not done:
for event in pygame.event.get():
if event.type == pygame.QUIT:
done=True
elif event.type == pygame.KEYDOWN:
if event.key == pygame.K_RIGHT:
ballx+=5
elif event.key == pygame.K_LEFT:
ballx-=5
elif event.key == pygame.K_UP:
bally-=5
elif event.key == pygame.K_DOWN:
bally+=5
screen.fill(WHITE)
screen.blit(ball, (ballx, bally))
pygame.display.flip()