Загрузка данных
# rf4_fishing_upgrade.py
import random
import math
import pygame
import pgzrun
from pgzero.builtins import *
WIDTH = 1280
HEIGHT = 720
TITLE = "RF4 Mini Fishing+"
COLORS = {
"water_deep": (20, 80, 150),
"water_light": (50, 130, 200),
"sand": (210, 180, 140),
"danger": (255, 50, 50),
"silver": (192, 192, 192),
"ui": (255,255,255)
}
FISH_DATABASE = {
"Плотва": {"min": 0.1, "max": 1.0, "color": (170,175,180)},
"Карп": {"min": 1.0, "max": 5.0, "color": (190,160,100)},
"Щука": {"min": 1.0, "max": 6.0, "color": (120,140,100)},
}
class Fish:
def __init__(self, x, y, name):
self.name = name
self.data = FISH_DATABASE[name]
self.weight = round(random.uniform(self.data["min"], self.data["max"]), 2)
self.x = x
self.y = y
self.angle = random.uniform(0, math.pi * 2)
self.speed = random.uniform(0.5, 1.2)
self.size = int(self.weight * 8) + 10
self.visible_timer = 0
self.alpha = 0
def update(self):
self.angle += random.uniform(-0.05, 0.05)
self.x += math.cos(self.angle) * self.speed
self.y += math.sin(self.angle) * self.speed
self.x = max(100, min(WIDTH - 100, self.x))
self.y = max(HEIGHT - 400, min(HEIGHT - 100, self.y))
if self.visible_timer <= 0:
if random.random() < 0.012:
self.visible_timer = 120
else:
self.visible_timer -= 1
if self.visible_timer > 0:
self.alpha = min(120, self.alpha + 5)
else:
self.alpha = max(0, self.alpha - 5)
def draw(self):
if self.alpha <= 0:
return
surf = pygame.Surface((self.size*4, self.size*4), pygame.SRCALPHA)
cx, cy = self.size*2, self.size*2
points = []
for i in range(10):
a = self.angle + i * math.pi * 2 / 10
r = self.size
px = cx + math.cos(a) * r
py = cy + math.sin(a) * r * 0.6
points.append((px, py))
color = (*self.data["color"], self.alpha)
pygame.draw.polygon(surf, color, points)
pygame.draw.polygon(surf, (0,0,0,self.alpha), points, 1)
screen.surface.blit(surf, (self.x - cx, self.y - cy))
class Game:
def __init__(self):
self.fishes = []
self.spawn()
self.float_x = WIDTH // 2
self.float_y = HEIGHT - 200
self.cast = False
self.bite = False
self.message = "Кликни мышью или нажми SPACE"
self.cast_cooldown = 0
self.total_weight = 0
self.last_fish = []
def spawn(self):
self.fishes.clear()
for _ in range(10):
name = random.choice(list(FISH_DATABASE.keys()))
self.fishes.append(
Fish(
random.randint(100, WIDTH - 100),
random.randint(HEIGHT - 400, HEIGHT - 100),
name
)
)
def update(self):
if self.cast_cooldown > 0:
self.cast_cooldown -= 1
for f in self.fishes:
f.update()
if self.cast and not self.bite:
for f in self.fishes:
if f.alpha < 20:
continue
dist = math.hypot(f.x - self.float_x, f.y - self.float_y)
if dist < 40:
if random.random() < 0.01:
self.bite = True
self.message = "КЛЁВ! ЖМИ E"
break
def draw(self):
for y in range(HEIGHT):
t = y / HEIGHT
r = int(COLORS["water_deep"][0]*(1-t)+COLORS["water_light"][0]*t)
g = int(COLORS["water_deep"][1]*(1-t)+COLORS["water_light"][1]*t)
b = int(COLORS["water_deep"][2]*(1-t)+COLORS["water_light"][2]*t)
screen.draw.line((0,y),(WIDTH,y),(r,g,b))
screen.draw.filled_rect(Rect(0, HEIGHT-150, WIDTH,150), color=COLORS["sand"])
for f in self.fishes:
f.draw()
if self.cast:
color = COLORS["danger"] if self.bite else COLORS["silver"]
screen.draw.filled_circle((int(self.float_x), int(self.float_y)), 6, color=color)
screen.draw.text(self.message, (20, 20), color="white", fontsize=32)
screen.draw.text(f"Общий улов: {self.total_weight:.2f} кг",
(20, 60), color=COLORS["ui"], fontsize=26)
y = 100
screen.draw.text("Последние 3 рыбы:", (20, y), fontsize=24)
for i, txt in enumerate(self.last_fish):
screen.draw.text(txt, (20, y + 30 + i*25), fontsize=22)
if self.cast_cooldown > 0:
screen.draw.text(f"Ожидание: {self.cast_cooldown//60 + 1}с",
(WIDTH-200, 20), fontsize=24)
def cast_line(self, pos):
if self.cast_cooldown > 0:
self.message = "Подожди..."
return
self.cast = True
self.bite = False
self.float_x, self.float_y = pos
self.message = "Заброс..."
self.cast_cooldown = 360
def try_catch(self):
for f in self.fishes:
if math.hypot(f.x - self.float_x, f.y - self.float_y) < 50:
text = f"{f.name} ({f.weight} кг)"
self.total_weight += f.weight
self.last_fish.insert(0, text)
self.last_fish = self.last_fish[:3]
self.message = f"Поймал: {text}"
self.fishes.remove(f)
self.spawn()
self.cast = False
self.bite = False
return
self.message = "Сорвалась..."
self.cast = False
self.bite = False
def on_key_down(self, key):
if key == keys.SPACE:
self.cast_line((WIDTH//2, HEIGHT-250))
if key == keys.E and self.bite:
self.try_catch()
game = Game()
def update():
game.update()
def draw():
game.draw()
def on_key_down(key):
game.on_key_down(key)
def on_mouse_down(pos, button):
if button == mouse.LEFT:
game.cast_line(pos)
pgzrun.go()