Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import time
- import pygame
- from pygame.locals import *
- from pygame import Rect as R
- from pygame import Vector2 as V
- from random import randint
- BLACK = (15, 56, 15)
- WHITE = (139, 172, 15)
- pygame.init()
- PDR = R(0, 0, 320, 240)
- PDS = pygame.display.set_mode(PDR.size)#, FULLSCREEN | SCALED) # primary display surface
- SDS = PDS.copy() # secondary display surface
- FPS = 120
- window_closed = False
- ball_pos = V(PDR.center)
- ball_dir = V(1, 0).rotate(randint(0, 359))
- ball_radius = 10
- delta = time.perf_counter()
- exit_demo = False
- while not exit_demo:
- now = time.perf_counter()
- interval = (now - delta) * FPS
- delta = now
- if not window_closed:
- for e in pygame.event.get():
- if e.type == KEYUP:
- if e.key == K_ESCAPE:
- exit_demo = True
- if e.key == K_SPACE:
- pygame.quit()
- window_closed = True
- SDS.fill(BLACK)
- pygame.draw.circle(SDS, WHITE, ball_pos, ball_radius)
- if not window_closed:
- PDS.blit(SDS, (0, 0))
- pygame.display.update()
- ball_pos += ball_dir * interval
- if ball_pos.x > PDR.right - ball_radius:
- ball_pos.x = PDR.right - ball_radius
- ball_dir.x = -ball_dir.x
- if ball_pos.x < ball_radius:
- ball_pos.x = ball_radius
- ball_dir.x = -ball_dir.x
- if ball_pos.y > PDR.bottom - ball_radius:
- ball_pos.y = PDR.bottom - ball_radius
- ball_dir.y = -ball_dir.y
- if ball_pos.y < ball_radius:
- ball_pos.y = ball_radius
- ball_dir.y = -ball_dir.y
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement