import pygame
import sys
pygame.init()
WIDTH, HEIGHT = 800, 600
screen = pygame.display.set_mode((WIDTH, HEIGHT))
pygame.display.set_caption("Mini Brawl")
WHITE = (255, 255, 255)
BLUE = (50, 100, 255)
RED = (255, 50, 50)
player = pygame.Rect(100, 100, 40, 40)
bullets = []
clock = pygame.time.Clock()
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
sys.exit()
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_SPACE:
bullets.append(pygame.Rect(player.centerx, player.centery, 10, 5))
keys = pygame.key.get_pressed()
if keys[pygame.K_w]:
player.y -= 5
if keys[pygame.K_s]:
player.y += 5
if keys[pygame.K_a]:
player.x -= 5
if keys[pygame.K_d]:
player.x += 5
for bullet in bullets:
bullet.x += 10
bullets = [b for b in bullets if b.x < WIDTH]
screen.fill(WHITE)
pygame.draw.rect(screen, BLUE, player)
for bullet in bullets:
pygame.draw.rect(screen, RED, bullet)
pygame.display.flip()
clock.tick(60)
import pygame
import sys
pygame.init()
WIDTH, HEIGHT = 800, 600
screen = pygame.display.set_mode((WIDTH, HEIGHT))
pygame.display.set_caption("Mini Brawl")
WHITE = (255, 255, 255)
BLUE = (50, 100, 255)
RED = (255, 50, 50)
player = pygame.Rect(100, 100, 40, 40)
bullets = []
clock = pygame.time.Clock()
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
sys.exit()