import pygame
import random
# Initialize pygame
pygame.init()
# Setup screen and clock
screen = pygame.display.set_mode((1500, 1500))
clock = pygame.time.Clock()
# File paths for images
address = "safsa/"
background_img = pygame.image.load(address + "sd.jpg")
troll_img = pygame.image.load(address + "TROLL.png")
new_image = pygame.transform.scale(background_img, (1500, 1500))
# Player setup
player_pos = pygame.Vector2(screen.get_width() / 2, screen.get_height() / 2)
player_radius = 40
# Troll class to handle each troll's behavior
class Troll:
def init(self):
self.pos = pygame.Vector2(random.randint(0, screen.get_width()), random.randint(0, screen.get_height()))
self.size = 100 # Scale the troll image
self.image = pygame.transform.scale(troll_img, (self.size, self.size))
self.is_alive = True
def respawn(self):
self.pos = pygame.Vector2(random.randint(0, screen.get_width()), random.randint(0, screen.get_height()))
self.is_alive = True
def draw(self):
if self.is_alive:
screen.blit(self.image, (self.pos.x, self.pos.y))
# Initialize 10 trolls
trolls = [Troll() for _ in range(10)]
# Game loop
running = True
dt = 0
while running:
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
# Get user input
keys = pygame.key.get_pressed()
if keys[pygame.K_w]:
player_pos.y -= 300 * dt
if keys[pygame.K_s]:
player_pos.y += 300 * dt
if keys[pygame.K_a]:
player_pos.x -= 300 * dt
if keys[pygame.K_d]:
player_pos.x += 300 * dt
# Fill the screen with background image
screen.blit(new_image, (0, 0))
# Draw player (red circle)
pygame.draw.circle(screen, "red", player_pos, player_radius)
# Check for collisions between player and trolls
for troll in trolls:
if troll.is_alive:
# Calculate distance between player and troll
distance = player_pos.distance_to(troll.pos)
if distance < player_radius + troll.size / 2:
# Player collided with troll, "kill" the troll
troll.is_alive = False
# Respawn the troll after a short delay (this is instant in this example)
troll.respawn()
# Draw the troll
troll.draw()
# Update the screen
pygame.display.flip()
# Limit FPS and calculate delta time (dt)
dt = clock.tick(12431255220) / 1000
# Quit pygame
pygame.quit()




