Added clouds.

This commit is contained in:
justin committed 2025-07-14 11:01:34 -07:00
1 parent 5f1727e857
commit de1166b4bb
1 file changed
+48 -1
+48 -1
View File
@@ -1,6 +1,7 @@
import pygame import pygame
import random import random
import sys import sys
import math
pygame.init() pygame.init()
pygame.mixer.init() pygame.mixer.init()
@@ -20,6 +21,7 @@ clock = pygame.time.Clock()
CAT_SIZE = [160, 160] CAT_SIZE = [160, 160]
SUSHI_SIZE = (50, 50) SUSHI_SIZE = (50, 50)
CLOUD_SIZE = (200, 120)
cat_left_base = pygame.image.load("tuna-left.png").convert_alpha() cat_left_base = pygame.image.load("tuna-left.png").convert_alpha()
cat_right_base = pygame.image.load("tuna-right.png").convert_alpha() cat_right_base = pygame.image.load("tuna-right.png").convert_alpha()
@@ -36,6 +38,9 @@ for i in [1, 2, 4, 5]:
wasabi_img = pygame.image.load("sushi3.png").convert_alpha() wasabi_img = pygame.image.load("sushi3.png").convert_alpha()
wasabi_img = pygame.transform.smoothscale(wasabi_img, SUSHI_SIZE) wasabi_img = pygame.transform.smoothscale(wasabi_img, SUSHI_SIZE)
cloud_base = pygame.image.load("cloud.png").convert_alpha()
cloud_img = pygame.transform.smoothscale(cloud_base, CLOUD_SIZE)
chomp_sound = pygame.mixer.Sound("audio_chomp.mp3") chomp_sound = pygame.mixer.Sound("audio_chomp.mp3")
meow_sound = pygame.mixer.Sound("audio_meow.mp3") meow_sound = pygame.mixer.Sound("audio_meow.mp3")
@@ -62,6 +67,11 @@ sushi_fall_speed = 5
sushi_interval = 125 sushi_interval = 125
objects = [] objects = []
clouds = []
cloud_spawn_interval = 4000
last_cloud_spawn = 0
cloud_speed_multiplier = 1.0
start_time = pygame.time.get_ticks() start_time = pygame.time.get_ticks()
speed_increase_time = start_time speed_increase_time = start_time
@@ -89,7 +99,7 @@ def draw_centered_multiline_text(lines, color=(255,255,255), line_spacing=10):
y += surf.get_height() + line_spacing y += surf.get_height() + line_spacing
def reset_game(): def reset_game():
global score, objects, game_over, cat_rect, cat_img, cat_facing, game_over_time, paused, pause_by_controller, start_time, speed_increase_time, sushi_fall_speed, CAT_SIZE, cat_left, cat_right global score, objects, game_over, cat_rect, cat_img, cat_facing, game_over_time, paused, pause_by_controller, start_time, speed_increase_time, sushi_fall_speed, CAT_SIZE, cat_left, cat_right, clouds, last_cloud_spawn, cloud_speed_multiplier
score = 0 score = 0
objects = [] objects = []
game_over = False game_over = False
@@ -105,6 +115,9 @@ def reset_game():
cat_rect.centerx = WIDTH // 2 cat_rect.centerx = WIDTH // 2
cat_rect.bottom = HEIGHT cat_rect.bottom = HEIGHT
sushi_fall_speed = 5 sushi_fall_speed = 5
clouds.clear()
last_cloud_spawn = pygame.time.get_ticks() - cloud_spawn_interval
cloud_speed_multiplier = 1.0
start_time = pygame.time.get_ticks() start_time = pygame.time.get_ticks()
speed_increase_time = start_time speed_increase_time = start_time
@@ -115,6 +128,19 @@ def spawn_sushi():
rect = img.get_rect(midtop=(x, -40)) rect = img.get_rect(midtop=(x, -40))
objects.append({'img': img, 'rect': rect, 'wasabi': is_wasabi}) objects.append({'img': img, 'rect': rect, 'wasabi': is_wasabi})
def spawn_cloud():
y = 50
direction = random.choice(["left_to_right", "right_to_left"])
if direction == "left_to_right":
x = -CLOUD_SIZE[0]
speed = 1.5
else:
x = WIDTH + CLOUD_SIZE[0]
speed = -1.5
rect = cloud_img.get_rect(topleft=(x, y))
phase = random.uniform(0, 2 * math.pi)
clouds.append({'rect': rect, 'speed': speed, 'base_y': y, 'phase': phase})
reset_game() reset_game()
last_spawn = pygame.time.get_ticks() last_spawn = pygame.time.get_ticks()
@@ -174,8 +200,26 @@ while True:
if now - speed_increase_time > 30000: if now - speed_increase_time > 30000:
sushi_fall_speed += 1 sushi_fall_speed += 1
cloud_speed_multiplier += 0.1
speed_increase_time = now speed_increase_time = now
if now - last_cloud_spawn > cloud_spawn_interval:
spawn_cloud()
last_cloud_spawn = now
for cloud in clouds[:]:
cloud['rect'].x += cloud['speed'] * cloud_speed_multiplier
time_seconds = pygame.time.get_ticks() / 1000
amplitude = 10
frequency = 1
vertical_offset = amplitude * math.sin(2 * math.pi * frequency * time_seconds + cloud['phase'])
cloud['rect'].y = cloud['base_y'] + vertical_offset
if cloud['speed'] > 0 and cloud['rect'].left > WIDTH:
clouds.remove(cloud)
elif cloud['speed'] < 0 and cloud['rect'].right < 0:
clouds.remove(cloud)
if not game_over: if not game_over:
if keys[pygame.K_a]: if keys[pygame.K_a]:
move = -cat_speed move = -cat_speed
@@ -233,6 +277,9 @@ while True:
pygame.quit() pygame.quit()
sys.exit() sys.exit()
for cloud in clouds:
screen.blit(cloud_img, cloud['rect'])
screen.blit(cat_img, cat_rect) screen.blit(cat_img, cat_rect)
for obj in objects: for obj in objects: