import pygame import sys import time import random pygame.init() WIDTH, HEIGHT = 800, 600 screen = pygame.display.set_mode((WIDTH, HEIGHT)) pygame.display.set_caption("Farming Simulator Expanded") clock = pygame.time.Clock() font = pygame.font.SysFont("arial", 24) # Sound pygame.mixer.music.load('background_music.mp3') # Add your own music file here pygame.mixer.music.play(-1) plant_sound = pygame.mixer.Sound('plant.wav') # Add your own sounds harvest_sound = pygame.mixer.Sound('harvest.wav') # Colors WHITE, GREEN, DARK_GREEN, BROWN, BLACK = (255,255,255), (50,200,50), (0,150,0), (139,69,19), (0,0,0) SEASON_COLORS = {"Spring": (180, 255, 180), "Summer": (255, 255, 180), "Autumn": (255, 200, 150), "Winter": (200, 230, 255)} # Player player = pygame.Rect(100, 100, 40, 40) player_speed = 5 # Grid TILE_SIZE = 40 fields = [] planted = {} # Seasons seasons = ["Spring", "Summer", "Autumn", "Winter"] season_index = 0 season_start_time = time.time() # Inventory and shop inventory = {"Carrot": 3, "Corn": 2, "Pumpkin": 1} money = 0 shop_open = False selected_crop = "Carrot" # Crop Data crops = { "Carrot": {"time": 5, "value": 10, "color": (255,165,0), "price": 5}, "Corn": {"time": 8, "value": 20, "color": (255,255,0), "price": 8}, "Pumpkin": {"time": 12, "value": 35, "color": (255,140,0), "price": 12}, } def draw_grid(): for x in range(0, WIDTH, TILE_SIZE): for y in range(0, HEIGHT, TILE_SIZE): rect = pygame.Rect(x, y, TILE_SIZE, TILE_SIZE) pygame.draw.rect(screen, BROWN, rect, 1) fields.append(rect) def draw_crops(): now = time.time() for pos, data in planted.items(): x, y = pos crop = data["type"] age = now - data["planted"] grow_time = crops[crop]["time"] color = crops[crop]["color"] if age >= grow_time: pygame.draw.rect(screen, DARK_GREEN, pygame.Rect(x, y, TILE_SIZE, TILE_SIZE)) else: pygame.draw.rect(screen, color, pygame.Rect(x, y, TILE_SIZE, TILE_SIZE)) def draw_player(): pygame.draw.rect(screen, BLACK, player) def draw_ui(): text = font.render(f"Money: ${money}", True, BLACK) screen.blit(text, (10, 10)) inv_text = font.render(f"Inventory: {inventory}", True, BLACK) screen.blit(inv_text, (10, 40)) crop_text = font.render(f"Selected: {selected_crop}", True, BLACK) screen.blit(crop_text, (10, 70)) season_text = font.render(f"Season: {seasons[season_index]}", True, BLACK) screen.blit(season_text, (10, 100)) def draw_shop(): pygame.draw.rect(screen, (220, 220, 220), (200, 150, 400, 300)) shop_text = font.render("SHOP - Press number to buy seeds", True, BLACK) screen.blit(shop_text, (220, 160)) for i, (name, data) in enumerate(crops.items()): item_text = font.render(f"{i+1}. {name} - ${data['price']} each", True, BLACK) screen.blit(item_text, (220, 200 + i * 40)) def get_tile_under_player(): for field in fields: if player.colliderect(field): return field return None def update_season(): global season_index, season_start_time if time.time() - season_start_time > 60: season_index = (season_index + 1) % len(seasons) season_start_time = time.time() def adjust_crop_growth_time(crop): base = crops[crop]["time"] current_season = seasons[season_index] if current_season == "Spring": return base * 0.9 if current_season == "Summer": return base if current_season == "Autumn": return base * 1.1 if current_season == "Winter": return base * 1.3 return base # Game loop running = True while running: screen.fill(SEASON_COLORS[seasons[season_index]]) fields = [] draw_grid() draw_crops() draw_player() draw_ui() update_season() if shop_open: draw_shop() for event in pygame.event.get(): if event.type == pygame.QUIT: running = False if event.type == pygame.KEYDOWN: if event.key == pygame.K_s: shop_open = not shop_open elif event.key == pygame.K_1: if shop_open: if money >= crops["Carrot"]["price"]: inventory["Carrot"] += 1 money -= crops["Carrot"]["price"] else: selected_crop = "Carrot" elif event.key == pygame.K_2: if shop_open: if money >= crops["Corn"]["price"]: inventory["Corn"] += 1 money -= crops["Corn"]["price"] else: selected_crop = "Corn" elif event.key == pygame.K_3: if shop_open: if money >= crops["Pumpkin"]["price"]: inventory["Pumpkin"] += 1 money -= crops["Pumpkin"]["price"] else: selected_crop = "Pumpkin" # Controls keys = pygame.key.get_pressed() if keys[pygame.K_LEFT]: player.x -= player_speed if keys[pygame.K_RIGHT]: player.x += player_speed if keys[pygame.K_UP]: player.y -= player_speed if keys[pygame.K_DOWN]: player.y += player_speed tile = get_tile_under_player() # Plant if keys[pygame.K_SPACE] and tile: pos = (tile.x, tile.y) if pos not in planted and inventory[selected_crop] > 0: planted[pos] = {"type": selected_crop, "planted": time.time()} inventory[selected_crop] -= 1 plant_sound.play() # Harvest if keys[pygame.K_RETURN] and tile: pos = (tile.x, tile.y) if pos in planted: crop = planted[pos]["type"] age = time.time() - planted[pos]["planted"] grow_time = adjust_crop_growth_time(crop) if age >= grow_time: money += crops[crop]["value"] harvest_sound.play() del planted[pos] pygame.display.flip() clock.tick(60) pygame.quit() sys.exit()