Created
August 17, 2011 03:30
-
-
Save djanatyn/1150757 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys, pygame | |
pygame.init() | |
clock = pygame.time.Clock() | |
size = width, height = 640, 480 | |
speed = [0,0] | |
black = 0, 0, 0 | |
quitting_time = 0 | |
screen = pygame.display.set_mode(size) | |
ball = pygame.image.load("ball.png") | |
ballrect = ball.get_rect() | |
while not quitting_time: | |
clock.tick(60) | |
speed = [0,0] | |
for event in pygame.event.get(): | |
if event.type == pygame.KEYDOWN: | |
if event.key == pygame.K_LEFT: speed[0] = -10 | |
elif event.key == pygame.K_RIGHT: speed[0] = 10 | |
elif event.key == pygame.K_DOWN: speed[1] = 10 | |
elif event.key == pygame.K_UP: speed[1] = -10 | |
ballrect = ballrect.move(speed) # the important part | |
screen.fill(black) | |
screen.blit(ball, ballrect) | |
pygame.display.flip() | |
pygame.quit() | |
sys.exit(0) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment