Skip to content

Instantly share code, notes, and snippets.

@djanatyn
Created August 17, 2011 03:30
Show Gist options
  • Save djanatyn/1150757 to your computer and use it in GitHub Desktop.
Save djanatyn/1150757 to your computer and use it in GitHub Desktop.
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