Untitled
unknown
plain_text
7 months ago
1.6 kB
3
Indexable
Never
import pygame import random # Initialize Pygame pygame.init() # Screen dimensions WIDTH, HEIGHT = 800, 600 CELL_SIZE = 10 # Colors WHITE = (255, 255, 255) BLACK = (0, 0, 0) FIRE_COLORS = [(255, 0, 0), (255, 69, 0), (255, 165, 0), (255, 215, 0)] # Initialize the screen screen = pygame.display.set_mode((WIDTH, HEIGHT)) pygame.display.set_caption("Fire Game") # Function to initialize the grid def initialize_grid(): grid = [[0 for _ in range(WIDTH // CELL_SIZE)] for _ in range(HEIGHT // CELL_SIZE)] for i in range(len(grid[0])): grid[0][i] = random.choice([0, 1]) return grid # Function to update the grid def update_grid(grid): for y in range(1, len(grid)): for x in range(len(grid[0])): if y < len(grid) - 1: grid[y][x] = grid[y - 1][x] or grid[y - 1][max(x - 1, 0)] or grid[y - 1][min(x + 1, len(grid[0]) - 1)] return grid # Function to draw the grid def draw_grid(grid): for y in range(len(grid)): for x in range(len(grid[0])): if grid[y][x] == 1: color = random.choice(FIRE_COLORS) pygame.draw.rect(screen, color, (x * CELL_SIZE, y * CELL_SIZE, CELL_SIZE, CELL_SIZE)) # Main function def main(): grid = initialize_grid() running = True while running: screen.fill(BLACK) for event in pygame.event.get(): if event.type == pygame.QUIT: running = False grid = update_grid(grid) draw_grid(grid) pygame.display.update() pygame.time.delay(100) pygame.quit() if __name__ == "__main__": main()
Leave a Comment