Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Python PyGame Space Invaders basics
- import pygame
- import random
- # Initialize Pygame
- pygame.init()
- # Set up the screen
- screen_width = 800
- screen_height = 600
- screen = pygame.display.set_mode((screen_width, screen_height))
- pygame.display.set_caption("Space Invaders")
- # Set up the game clock
- clock = pygame.time.Clock()
- # Set up the player
- player_image = pygame.image.load("player.png")
- player_width = 64
- player_height = 64
- player_x = (screen_width - player_width) / 2
- player_y = screen_height - player_height - 10
- player_speed = 5
- # Set up the bullets
- bullet_image = pygame.image.load("bullet.png")
- bullet_width = 8
- bullet_height = 16
- bullet_speed = 10
- bullets = []
- # Set up the enemies
- enemy_image = pygame.image.load("enemy.png")
- enemy_width = 64
- enemy_height = 64
- enemy_speed = 2
- enemies = []
- for i in range(6):
- enemy_x = 100 + i * 125
- enemy_y = 50
- enemies.append([enemy_x, enemy_y])
- # Set up the game over text
- game_over_font = pygame.font.SysFont(None, 64)
- # Set up the score
- score = 0
- score_font = pygame.font.SysFont(None, 32)
- # Set up the game loop
- game_running = True
- while game_running:
- # Handle events
- # Full script can be found on my GitHub ;) <----------------> https://github.com/mrlunk/Fun-with-Python/blob/main/Space_Invaders/
- # A python script by: MrLunk
- # https://github.com/mrlunk/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement