import pygame import random import sys # Khởi tạo Pygame pygame.init() # Cài đặt màn hình WIDTH, HEIGHT = 800, 600 screen = pygame.display.set_mode((WIDTH, HEIGHT)) pygame.display.set_caption("Câu Cá Vạn Cân - Python Edition") clock = pygame.time. import pygame import random import sys # Khởi tạo Pygame pygame.init() # Cài đặt màn hình WIDTH, HEIGHT = 800, 600 screen = pygame.display.set_mode((WIDTH, HEIGHT)) pygame.display.set_caption("Câu Cá Vạn Cân - Pro Edition") clock = pygame.time.Clock() # Phông chữ font = pygame.font.SysFont("Arial", 32, bold=True) small_font = pygame.font.SysFont("Arial", 22) # Màu sắc BLUE = (30, 144, 255) DEEP_BLUE = (0, 0, 139) SKY = (135, 206, 235) BROWN = (101, 67, 33) WHITE = (255, 255, 255) GOLD = (255, 215, 0) RED = (220, 20, 60) # Danh sách cá (Tên, Cân nặng, Giá trị, Màu sắc, Độ khó) FISH_DATA = [ ("Cá Rô", 5, 10, (144, 238, 144), 1), ("Cá Trê", 20, 50, (75, 75, 75), 3), ("Cá Chép", 100, 250, (255, 165, 0), 7), ("Cá Ngừ", 500, 1500, (70, 130, 180), 15), ("Quái Vật Biển", 10000, 50000, (148, 0, 211), 40) ] class Fish: def __init__(self): data = random.choice(FISH_DATA) self.name, self.weight, self.value, self.color, self.difficulty = data self.x = random.randint(300, WIDTH - 50) self.y = random.randint(350, HEIGHT - 50) self.speed = random.uniform(1, 3) def draw(self, surface): # Vẽ thân cá pygame.draw.ellipse(surface, self.color, (self.x, self.y, 50, 30)) # Đuôi pygame.draw.polygon(surface, self.color, [(self.x, self.y+15), (self.x-15, self.y), (self.x-15, self.y+30)]) # Mắt pygame.draw.circle(surface, WHITE, (self.x + 35, self.y + 10), 4) class Game: def __init__(self): self.money = 0 self.rod_level = 1 self.pull_power = 10 self.line_max = 350 self.is_casting = False self.line_len = 0 self.hook_y = 300 self.fish_on_hook = None self.progress = 0 # 0 to 100 self.bubbles = [[random.randint(0, WIDTH), random.randint(300, HEIGHT)] for _ in range(20)] def draw_env(self): screen.fill(SKY) # Trời pygame.draw.rect(screen, BLUE, (0, 300, WIDTH, 300)) # Nước # Hiệu ứng bong bóng for b in self.bubbles: b[1] -= 0.5 if b[1] < 300: b[1] = HEIGHT pygame.draw.circle(screen, (255, 255, 255, 100), (int(b[0]), int(b[1])), 3, 1) # Cầu cảng / Thuyền pygame.draw.rect(screen, BROWN, (0, 260, 200, 40)) # HUD money_txt = font.render(f"Tiền: ${self.money}", True, WHITE) level_txt = small_font.render(f"Cần Câu Lv.{self.rod_level} (Space: Câu/Kéo | U: Nâng cấp $500)", True, WHITE) screen.blit(money_txt, (20, 20)) screen.blit(level_txt, (20, 60)) def run(self): while True: self.draw_env() rod_tip = (180, 270) for event in pygame.event.get(): if event.type == pygame.QUIT: pygame.quit() sys.exit() if event.type == pygame.KEYDOWN: if event.key == pygame.K_SPACE: if not self.is_casting and not self.fish_on_hook: self.is_casting = True elif self.fish_on_hook: self.progress += self.pull_power if event.key == pygame.K_u: # Nâng cấp if self.money >= 500: self.money -= 500 self.rod_level += 1 self.pull_power += 3 self.line_max += 20 # Logic dây câu if self.is_casting: self.line_len += 4 if self.line_len > self.line_max: self.line_len = self.line_max # Ngẫu nhiên cá cắn if random.random() < 0.02: self.fish_on_hook = Fish() self.is_casting = False self.progress = 30 # Vẽ dây câu curr_hook_y = 270 + self.line_len pygame.draw.line(screen, WHITE, rod_tip, (rod_tip[0], curr_hook_y), 2) pygame.draw.circle(screen, RED, (rod_tip[0], curr_hook_y), 5) # Mini-game kéo cá if self.fish_on_hook: self.fish_on_hook.x, self.fish_on_hook.y = rod_tip[0] - 25, curr_hook_y - 15 self.fish_on_hook.draw(screen) # Cá vùng vẫy (độ khó) self.progress -= (self.fish_on_hook.difficulty * 0.5) # Thanh tiến trình bar_rect = (WIDTH//2 - 100, 100, 200, 20) pygame.draw.rect(screen, WHITE, bar_rect, 2) fill_w = max(0, min(200, (self.progress / 100) * 200)) pygame.draw.rect(screen, GOLD, (bar_rect[0], bar_rect[1], fill_w, 20)) info = small_font.render(f"Đang kéo: {self.fish_on_hook.name} ({self.fish_on_hook.weight}kg)", True, WHITE) screen.blit(info, (WIDTH//2 - 100, 70)) if self.progress >= 100: # Thắng self.money += self.fish_on_hook.value self.fish_on_hook = None self.line_len = 0 elif self.progress <= 0: # Thua self.fish_on_hook = None self.line_len = 0 pygame.display.flip() clock.tick(60) if __name__ == "__main__": Game().run()