Advertisement
cookertron

Kostik Iln - Input Opens Window

May 18th, 2022
685
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.76 KB | None | 0 0
  1. import sys, time
  2. import pygame
  3. from pygame.locals import *
  4. from pygame import Rect as R
  5. from pygame import Vector2 as V
  6. from random import randint
  7.  
  8. BLACK = (15, 56, 15)
  9. WHITE = (139, 172, 15)
  10.  
  11. pygame.init()
  12. PDR = R(0, 0, 720, 720)
  13. PDS = pygame.display.set_mode(PDR.size) # primary display surface
  14. SDS = PDS.copy() # secondary display surface
  15. FPS = 120
  16.  
  17. window_closed = False
  18.  
  19. ball_pos = V(PDR.center)
  20. ball_dir = V(1, 0).rotate(randint(0, 359))
  21. ball_radius = 50
  22.  
  23. delta = time.perf_counter()
  24.  
  25. exit_demo = False
  26. while not exit_demo:
  27.     now = time.perf_counter()
  28.     interval = (now - delta) * FPS
  29.     delta = now
  30.  
  31.     for e in pygame.event.get():
  32.         if e.type == KEYUP:
  33.             if e.key == K_ESCAPE:
  34.                 exit_demo = True
  35.             if e.key == K_SPACE:
  36.                 if not window_closed:
  37.                     pygame.quit()
  38.                     window_closed = True
  39.     if window_closed:
  40.         text = input(">")
  41.         if text == "open":
  42.             pygame.init()
  43.             PDS = pygame.display.set_mode(PDR.size)
  44.             window_closed = False
  45.              
  46.     SDS.fill(BLACK)
  47.     pygame.draw.circle(SDS, WHITE, ball_pos, ball_radius)
  48.  
  49.     if not window_closed:
  50.         PDS.blit(SDS, (0, 0))
  51.         pygame.display.update()
  52.  
  53.     ball_pos += ball_dir * interval
  54.     if ball_pos.x > PDR.right - ball_radius:
  55.         ball_pos.x = PDR.right - ball_radius
  56.         ball_dir.x = -ball_dir.x
  57.     if ball_pos.x < ball_radius:
  58.         ball_pos.x = ball_radius
  59.         ball_dir.x = -ball_dir.x
  60.     if ball_pos.y > PDR.bottom - ball_radius:
  61.         ball_pos.y = PDR.bottom - ball_radius
  62.         ball_dir.y = -ball_dir.y
  63.     if ball_pos.y < ball_radius:
  64.         ball_pos.y = ball_radius
  65.         ball_dir.y = -ball_dir.y
  66.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement