Advertisement
MrLunk

Space Invaders game basics in Python using PyGame module

Feb 22nd, 2023 (edited)
1,203
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.36 KB | None | 0 0
  1. # Python PyGame Space Invaders basics
  2.  
  3. import pygame
  4. import random
  5.  
  6. # Initialize Pygame
  7. pygame.init()
  8.  
  9. # Set up the screen
  10. screen_width = 800
  11. screen_height = 600
  12. screen = pygame.display.set_mode((screen_width, screen_height))
  13. pygame.display.set_caption("Space Invaders")
  14.  
  15. # Set up the game clock
  16. clock = pygame.time.Clock()
  17.  
  18. # Set up the player
  19. player_image = pygame.image.load("player.png")
  20. player_width = 64
  21. player_height = 64
  22. player_x = (screen_width - player_width) / 2
  23. player_y = screen_height - player_height - 10
  24. player_speed = 5
  25.  
  26. # Set up the bullets
  27. bullet_image = pygame.image.load("bullet.png")
  28. bullet_width = 8
  29. bullet_height = 16
  30. bullet_speed = 10
  31. bullets = []
  32.  
  33. # Set up the enemies
  34. enemy_image = pygame.image.load("enemy.png")
  35. enemy_width = 64
  36. enemy_height = 64
  37. enemy_speed = 2
  38. enemies = []
  39. for i in range(6):
  40.     enemy_x = 100 + i * 125
  41.     enemy_y = 50
  42.     enemies.append([enemy_x, enemy_y])
  43.  
  44. # Set up the game over text
  45. game_over_font = pygame.font.SysFont(None, 64)
  46.  
  47. # Set up the score
  48. score = 0
  49. score_font = pygame.font.SysFont(None, 32)
  50.  
  51. # Set up the game loop
  52. game_running = True
  53. while game_running:
  54.  
  55.     # Handle events
  56.  
  57.  
  58. # Full script  can be found on my GitHub ;) <----------------> https://github.com/mrlunk/Fun-with-Python/blob/main/Space_Invaders/
  59.  
  60. # A python script by: MrLunk
  61. # https://github.com/mrlunk/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement