Spaces:
Sleeping
Sleeping
Create Game
Browse files
Game
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import pygame
|
| 2 |
+
import random
|
| 3 |
+
|
| 4 |
+
# Initialize Pygame
|
| 5 |
+
pygame.init()
|
| 6 |
+
|
| 7 |
+
# Screen dimensions
|
| 8 |
+
WIDTH, HEIGHT = 800, 600
|
| 9 |
+
screen = pygame.display.set_mode((WIDTH, HEIGHT))
|
| 10 |
+
pygame.display.set_caption("Extreme Alien FPS Shooter")
|
| 11 |
+
|
| 12 |
+
# Colors
|
| 13 |
+
WHITE = (255, 255, 255)
|
| 14 |
+
BLACK = (0, 0, 0)
|
| 15 |
+
GREEN = (0, 255, 0)
|
| 16 |
+
RED = (255, 0, 0)
|
| 17 |
+
|
| 18 |
+
# Player settings
|
| 19 |
+
player_pos = [WIDTH // 2, HEIGHT - 50]
|
| 20 |
+
player_size = 50
|
| 21 |
+
player_speed = 10
|
| 22 |
+
|
| 23 |
+
# Alien settings
|
| 24 |
+
alien_size = 50
|
| 25 |
+
alien_speed = 5
|
| 26 |
+
aliens = [[random.randint(0, WIDTH - alien_size), 0]]
|
| 27 |
+
|
| 28 |
+
# Bullet settings
|
| 29 |
+
bullet_size = 5
|
| 30 |
+
bullets = []
|
| 31 |
+
bullet_speed = 15
|
| 32 |
+
|
| 33 |
+
# Game loop
|
| 34 |
+
clock = pygame.time.Clock()
|
| 35 |
+
running = True
|
| 36 |
+
while running:
|
| 37 |
+
for event in pygame.event.get():
|
| 38 |
+
if event.type == pygame.QUIT:
|
| 39 |
+
running = False
|
| 40 |
+
|
| 41 |
+
keys = pygame.key.get_pressed()
|
| 42 |
+
if keys[pygame.K_LEFT] and player_pos[0] > 0:
|
| 43 |
+
player_pos[0] -= player_speed
|
| 44 |
+
if keys[pygame.K_RIGHT] and player_pos[0] < WIDTH - player_size:
|
| 45 |
+
player_pos[0] += player_speed
|
| 46 |
+
if keys[pygame.K_SPACE]:
|
| 47 |
+
bullets.append([player_pos[0] + player_size // 2, player_pos[1]])
|
| 48 |
+
|
| 49 |
+
# Move aliens
|
| 50 |
+
for alien in aliens:
|
| 51 |
+
alien[1] += alien_speed
|
| 52 |
+
if alien[1] > HEIGHT:
|
| 53 |
+
aliens.remove(alien)
|
| 54 |
+
aliens.append([random.randint(0, WIDTH - alien_size), 0])
|
| 55 |
+
|
| 56 |
+
# Move bullets
|
| 57 |
+
for bullet in bullets:
|
| 58 |
+
bullet[1] -= bullet_speed
|
| 59 |
+
if bullet[1] < 0:
|
| 60 |
+
bullets.remove(bullet)
|
| 61 |
+
|
| 62 |
+
# Check for collisions
|
| 63 |
+
for alien in aliens:
|
| 64 |
+
for bullet in bullets:
|
| 65 |
+
if (alien[0] < bullet[0] < alien[0] + alien_size) and (alien[1] < bullet[1] < alien[1] + alien_size):
|
| 66 |
+
bullets.remove(bullet)
|
| 67 |
+
aliens.remove(alien)
|
| 68 |
+
aliens.append([random.randint(0, WIDTH - alien_size), 0])
|
| 69 |
+
|
| 70 |
+
# Drawing
|
| 71 |
+
screen.fill(BLACK)
|
| 72 |
+
pygame.draw.rect(screen, GREEN, (player_pos[0], player_pos[1], player_size, player_size))
|
| 73 |
+
for alien in aliens:
|
| 74 |
+
pygame.draw.rect(screen, RED, (alien[0], alien[1], alien_size, alien_size))
|
| 75 |
+
for bullet in bullets:
|
| 76 |
+
pygame.draw.rect(screen, WHITE, (bullet[0], bullet[1], bullet_size, bullet_size))
|
| 77 |
+
|
| 78 |
+
pygame.display.flip()
|
| 79 |
+
clock.tick(30)
|
| 80 |
+
|
| 81 |
+
pygame.quit()
|