|
| 1 | +import pygame |
| 2 | + |
| 3 | +BLACK = (0, 0, 0) |
| 4 | + |
| 5 | +def draw_lighting(screen, player, walls, enemies, items, light_positions): |
| 6 | + dark_surface = pygame.Surface(screen.get_size()).convert_alpha() |
| 7 | + dark_surface.fill((0, 0, 0, 220)) # Slightly less dark for ambiance |
| 8 | + |
| 9 | + for pos_x, pos_y, radius in light_positions: |
| 10 | + light_surface = pygame.Surface((radius * 2, radius * 2)).convert_alpha() |
| 11 | + light_surface.fill((0, 0, 0, 0)) |
| 12 | + pygame.draw.circle(light_surface, (255, 255, 0, 100), (radius, radius), radius) # Yellow tint |
| 13 | + for r in range(radius, 0, -5): |
| 14 | + alpha = int(255 * (1 - r / radius)) |
| 15 | + pygame.draw.circle(light_surface, (255, 255, 255, alpha), (radius, radius), r) |
| 16 | + |
| 17 | + light_pos = (pos_x - radius, pos_y - radius) |
| 18 | + dark_surface.blit(light_surface, light_pos, special_flags=pygame.BLEND_RGBA_SUB) |
| 19 | + |
| 20 | + temp_surface = pygame.Surface(screen.get_size()) |
| 21 | + temp_surface.fill(BLACK) |
| 22 | + walls.draw(temp_surface) |
| 23 | + enemies.draw(temp_surface) |
| 24 | + items.draw(temp_surface) |
| 25 | + temp_surface.blit(player.image, player.rect) |
| 26 | + temp_surface.blit(dark_surface, (0, 0)) |
| 27 | + screen.blit(temp_surface, (0, 0)) |
0 commit comments