main.py 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. # Simple pygame program
  2. # Import and initialize the pygame library
  3. import pygame
  4. import sys
  5. # Initialize Pygame
  6. pygame.init()
  7. # Set up the drawing window
  8. info = pygame.display.Info()
  9. screen_width = info.current_w
  10. screen_height = info.current_h
  11. GAME_WIDTH=240
  12. GAME_HEIGHT=160
  13. GAME_ASPECT = GAME_WIDTH / GAME_HEIGHT
  14. screen_aspect = screen_width / screen_height
  15. if screen_aspect > GAME_ASPECT:
  16. # Pillarbox (black bars on the sides)
  17. new_width = int(screen_height * GAME_ASPECT)
  18. new_height = screen_height
  19. x_offset = (screen_width - new_width) // 2
  20. y_offset = 0
  21. else:
  22. # Letterbox (black bars on top/bottom)
  23. new_width = screen_width
  24. new_height = int(screen_width / GAME_ASPECT)
  25. x_offset = 0
  26. y_offset = (screen_height - new_height) // 2
  27. screen = pygame.display.set_mode([screen_width, screen_height], pygame.FULLSCREEN)
  28. # Run until the user asks to quit
  29. running = True
  30. while running:
  31. # Did the user click the window close button?
  32. for event in pygame.event.get():
  33. if event.type == pygame.QUIT:
  34. running = False
  35. # Get the state of all keys (whether pressed or not)
  36. keys = pygame.key.get_pressed()
  37. # Handle key states for continuous key checks
  38. if keys[pygame.K_UP]: # Handle UP arrow key
  39. print("Up key pressed")
  40. if keys[pygame.K_DOWN]: # Handle DOWN arrow key
  41. print("Down key pressed")
  42. if keys[pygame.K_LEFT]: # Handle LEFT arrow key
  43. print("Left key pressed")
  44. if keys[pygame.K_RIGHT]: # Handle RIGHT arrow key
  45. print("Right key pressed")
  46. if keys[pygame.K_z]: # Handle 'Z' key
  47. running = False
  48. print("Z key pressed")
  49. if keys[pygame.K_x]: # Handle 'X' key
  50. print("X key pressed")
  51. if keys[pygame.K_c]: # Handle 'C' key
  52. print("C key pressed")
  53. if keys[pygame.K_v]: # Handle 'V' key
  54. print("V key pressed")
  55. if keys[pygame.K_b]: # Handle 'B' key
  56. print("B key pressed")
  57. if keys[pygame.K_n]: # Handle 'N' key
  58. print("N key pressed")
  59. # Fill the background with white
  60. game_surface = pygame.Surface((GAME_WIDTH, GAME_HEIGHT))
  61. game_surface.fill((255, 255, 255))
  62. # Draw a solid blue circle in the center
  63. pygame.draw.circle(game_surface, (0, 0, 255), (120, 80), 35)
  64. scaled_game_surface = pygame.transform.scale(game_surface, (new_width, new_height))
  65. # Blit the scaled game surface to the center with black bars around it
  66. screen.blit(scaled_game_surface, (x_offset, y_offset))
  67. # Flip the display
  68. pygame.display.flip()
  69. # Done! Time to quit.
  70. pygame.quit()