import pygame import random import sys pygame.init() # Initial screen size SCREEN_WIDTH = 500 SCREEN_HEIGHT = 600 FPS = 60 screen = pygame.display.set_mode((SCREEN_WIDTH, SCREEN_HEIGHT), pygame.RESIZABLE) pygame.display.set_caption("Medical Simulator") clock = pygame.time.Clock() # Colors WHITE = (255, 255, 255) LIGHT_BLUE = (200, 240, 255) GREEN = (0, 200, 0) RED = (200, 0, 0) YELLOW = (255, 255, 0) ORANGE = (255, 165, 0) PURPLE = (160, 32, 240) GRAY = (80, 80, 80) BLACK = (0, 0, 0) # Fonts font = pygame.font.SysFont(None, 26) big_font = pygame.font.SysFont(None, 55) # Stretcher STRETCHER_HEIGHT = 20 stretcher_width = 80 stretcher = pygame.Rect(SCREEN_WIDTH//2 - stretcher_width//2, SCREEN_HEIGHT - 50, stretcher_width, STRETCHER_HEIGHT) # Patients PATIENT_SIZE = 40 PATIENT_TYPES = [ {"name": "Fracture", "color": RED, "points": 1}, {"name": "Burn", "color": ORANGE, "points": 2}, {"name": "Allergic", "color": PURPLE, "points": 3} ] # Power-ups POWERUP_TYPES = [ {"name": "SlowMo", "color": YELLOW}, {"name": "BigStretch", "color": GREEN} ] def create_patient(): x = random.randint(100, SCREEN_WIDTH - PATIENT_SIZE) ptype = random.choice(PATIENT_TYPES) return {"rect": pygame.Rect(x, -PATIENT_SIZE, PATIENT_SIZE, PATIENT_SIZE), "type": ptype} def create_powerup(): x = random.randint(100, SCREEN_WIDTH - PATIENT_SIZE) ptype = random.choice(POWERUP_TYPES) return {"rect": pygame.Rect(x, -PATIENT_SIZE, PATIENT_SIZE, PATIENT_SIZE), "type": ptype} patients = [create_patient()] powerups = [] powerup_timer = 0 queue_preview = [random.choice(PATIENT_TYPES) for _ in range(5)] # Game State score = 0 lives = 3 game_over = False slow_motion = 0 big_stretcher = 0 timer_ticks = 0 level = 1 def draw_text(text, font, color, x, y): surface = font.render(text, True, color) screen.blit(surface, (x, y)) def update_level_and_speed(): return 4 + level # Game Loop running = True while running: clock.tick(FPS) screen.fill(LIGHT_BLUE) for event in pygame.event.get(): if event.type == pygame.QUIT: running = False elif event.type == pygame.VIDEORESIZE: SCREEN_WIDTH, SCREEN_HEIGHT = event.w, event.h screen = pygame.display.set_mode((SCREEN_WIDTH, SCREEN_HEIGHT), pygame.RESIZABLE) stretcher.y = SCREEN_HEIGHT - 50 # Timers if not game_over: timer_ticks += 1 seconds = timer_ticks // FPS if seconds % 30 == 0 and seconds != 0: level = 1 + seconds // 30 # Power-up logic if slow_motion > 0: slow_motion -= 1 patient_speed = 2 else: patient_speed = update_level_and_speed() if big_stretcher > 0: big_stretcher -= 1 stretcher.width = 130 else: stretcher.width = 80 # Controls keys = pygame.key.get_pressed() if not game_over: if keys[pygame.K_LEFT] and stretcher.left > 100: stretcher.move_ip(-6, 0) if keys[pygame.K_RIGHT] and stretcher.right < SCREEN_WIDTH: stretcher.move_ip(6, 0) # Power-up spawning powerup_timer += 1 if powerup_timer > 200: if random.random() < 0.3: powerups.append(create_powerup()) powerup_timer = 0 if not game_over: for patient in patients[:]: patient["rect"].move_ip(0, patient_speed) pygame.draw.rect(screen, patient["type"]["color"], patient["rect"]) draw_text(patient["type"]["name"], font, WHITE, patient["rect"].x + 2, patient["rect"].y + 10) if patient["rect"].colliderect(stretcher): score += patient["type"]["points"] patients.remove(patient) new_type = queue_preview.pop(0) queue_preview.append(random.choice(PATIENT_TYPES)) x = random.randint(100, SCREEN_WIDTH - PATIENT_SIZE) patients.append({"rect": pygame.Rect(x, -PATIENT_SIZE, PATIENT_SIZE, PATIENT_SIZE), "type": new_type}) elif patient["rect"].top > SCREEN_HEIGHT: patients.remove(patient) new_type = queue_preview.pop(0) queue_preview.append(random.choice(PATIENT_TYPES)) x = random.randint(100, SCREEN_WIDTH - PATIENT_SIZE) patients.append({"rect": pygame.Rect(x, -PATIENT_SIZE, PATIENT_SIZE, PATIENT_SIZE), "type": new_type}) lives -= 1 if lives <= 0: game_over = True for powerup in powerups[:]: powerup["rect"].move_ip(0, patient_speed) pygame.draw.rect(screen, powerup["type"]["color"], powerup["rect"]) draw_text(powerup["type"]["name"], font, BLACK, powerup["rect"].x + 2, powerup["rect"].y + 10) if powerup["rect"].colliderect(stretcher): if powerup["type"]["name"] == "SlowMo": slow_motion = 300 elif powerup["type"]["name"] == "BigStretch": big_stretcher = 300 powerups.remove(powerup) elif powerup["rect"].top > SCREEN_HEIGHT: powerups.remove(powerup) pygame.draw.rect(screen, GREEN, stretcher) draw_text(f"Score: {score}", font, GRAY, 100, 10) draw_text(f"Lives: {lives}", font, GRAY, 100, 40) draw_text(f"Time: {seconds}s", font, GRAY, 100, 70) draw_text(f"Level: {level}", font, GRAY, 100, 100) # Draw queue pygame.draw.rect(screen, WHITE, (0, 0, 90, SCREEN_HEIGHT)) draw_text("QUEUE", font, BLACK, 10, 10) for i, p in enumerate(queue_preview): y = 50 + i * 60 pygame.draw.rect(screen, p["color"], (20, y, 50, 40)) draw_text(p["name"], font, BLACK, 10, y + 45) else: draw_text("GAME OVER", big_font, RED, SCREEN_WIDTH//2 - 130, SCREEN_HEIGHT//2 - 40) draw_text(f"Score: {score}", font, WHITE, SCREEN_WIDTH//2 - 40, SCREEN_HEIGHT//2 + 10) draw_text("Press R to Restart", font, WHITE, SCREEN_WIDTH//2 - 100, SCREEN_HEIGHT//2 + 50) if keys[pygame.K_r]: # Reset game score = 0 lives = 3 game_over = False patients = [create_patient()] powerups = [] slow_motion = 0 big_stretcher = 0 timer_ticks = 0 level = 1 queue_preview = [random.choice(PATIENT_TYPES) for _ in range(5)] pygame.display.flip() pygame.quit() sys.exit()