Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import pygame_sdl2
- pygame_sdl2.import_as_pygame()
- import pygame
- import sys
- # define some colors
- BLACK = (0, 0, 0)
- WHITE = (255, 255, 255)
- # set up pygame
- pygame.init()
- DS = pygame.display.set_mode((640, 480))
- CLOCK = pygame.time.Clock()
- # frame per second
- FPS = 120
- # you can't set the width and height of the pygame window, it's
- # fullscreen by default so you need to get the dimensions
- W = DS.get_width()
- H = DS.get_height()
- HW, HH = int(W / 2), int(H / 2)
- x = 0
- dx = 4 # change this value to make the ball go faster or slower
- while True:
- e = pygame.event.get()
- pygame.draw.circle(DS, WHITE, (x, HH), 30)
- x += dx
- if x > W or x < 0:
- dx = -dx
- x += dx
- pygame.display.update()
- DS.fill(BLACK)
- CLOCK.tick(FPS)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement