Update game2
parent
e4044183b5
commit
2b09f7d005
76
game2
76
game2
|
@ -27,24 +27,21 @@ PURPLE = (128, 0, 128)
|
||||||
GREEN = (0, 255, 0)
|
GREEN = (0, 255, 0)
|
||||||
|
|
||||||
# Load additional sound files
|
# Load additional sound files
|
||||||
if os.path.exists("wearethechampions.mp3"):
|
sound_files = {
|
||||||
win_sound = pygame.mixer.Sound("wearethechampions.mp3")
|
"wearethechampions.mp3": "win_sound",
|
||||||
if os.path.exists("waltzn2.mp3"):
|
"waltzn2.mp3": "bg_music",
|
||||||
bg_music = pygame.mixer.Sound("waltzn2.mp3")
|
"dishesfall.mp3": "fall_sound",
|
||||||
if os.path.exists("dishesfall.mp3"):
|
"boing.wav": "boing_sound",
|
||||||
fall_sound = pygame.mixer.Sound("dishesfall.mp3")
|
"glassbreaking.mp3": "block_sound",
|
||||||
if os.path.exists("boing.wav"):
|
"lookatthisdude.mp3": "death_sound",
|
||||||
boing_sound = pygame.mixer.Sound("boing.wav")
|
"chew.wav": "chew_sound",
|
||||||
if os.path.exists("glassbreaking.mp3"):
|
"meow.mp3": "meow_sound",
|
||||||
block_sound = pygame.mixer.Sound("glassbreaking.mp3")
|
"rimshot.mp3": "rimshot_sound"
|
||||||
if os.path.exists("lookatthisdude.mp3"):
|
}
|
||||||
death_sound = pygame.mixer.Sound("lookatthisdude.mp3")
|
|
||||||
if os.path.exists("chew.wav"):
|
for file, name in sound_files.items():
|
||||||
chew_sound = pygame.mixer.Sound("chew.wav")
|
if os.path.exists(file):
|
||||||
if os.path.exists("meow.mp3"):
|
globals()[name] = pygame.mixer.Sound(file)
|
||||||
meow_sound = pygame.mixer.Sound("meow.mp3")
|
|
||||||
if os.path.exists("rimshot.mp3"):
|
|
||||||
rimshot_sound = pygame.mixer.Sound("rimshot.mp3")
|
|
||||||
|
|
||||||
# Create the game window
|
# Create the game window
|
||||||
screen = pygame.display.set_mode((WIDTH, HEIGHT))
|
screen = pygame.display.set_mode((WIDTH, HEIGHT))
|
||||||
|
@ -67,21 +64,19 @@ trollface_original_image = pygame.image.load("trollface.png").convert_alpha()
|
||||||
trollface_image = pygame.transform.scale(trollface_original_image, (TROLLFACE_WIDTH, TROLLFACE_HEIGHT))
|
trollface_image = pygame.transform.scale(trollface_original_image, (TROLLFACE_WIDTH, TROLLFACE_HEIGHT))
|
||||||
|
|
||||||
# Load character images
|
# Load character images
|
||||||
purple_cat_original_image = pygame.image.load("cat.png").convert_alpha()
|
characters = {
|
||||||
orange_cat_original_image = pygame.image.load("orangecat.jpg").convert_alpha()
|
"Purple Cat": pygame.image.load("cat.png").convert_alpha(),
|
||||||
cool_tomato_original_image = pygame.image.load("tomato.png").convert_alpha()
|
"Orange Cat": pygame.image.load("orangecat.jpg").convert_alpha(),
|
||||||
confused_lemon_original_image = pygame.image.load("lemon.jpg").convert_alpha()
|
"Cool Tomato": pygame.image.load("tomato.png").convert_alpha(),
|
||||||
|
"Confused Lemon": pygame.image.load("lemon.jpg").convert_alpha()
|
||||||
|
}
|
||||||
|
|
||||||
# Constants for character selection
|
# Constants for character selection
|
||||||
CHARACTER_WIDTH, CHARACTER_HEIGHT = 100, 100
|
CHARACTER_WIDTH, CHARACTER_HEIGHT = 100, 100
|
||||||
CHARACTER_SPACING = 50
|
CHARACTER_SPACING = 50
|
||||||
CHARACTER_Y = HEIGHT // 2 - CHARACTER_HEIGHT // 2
|
CHARACTER_Y = HEIGHT // 2 - CHARACTER_HEIGHT // 2
|
||||||
CHARACTER_OPTIONS = [
|
CHARACTER_OPTIONS = [{"name": name, "image": pygame.transform.scale(image, (CHARACTER_WIDTH, CHARACTER_HEIGHT))}
|
||||||
{"name": "Purple Cat", "image": pygame.transform.scale(purple_cat_original_image, (CHARACTER_WIDTH, CHARACTER_HEIGHT))},
|
for name, image in characters.items()]
|
||||||
{"name": "Orange Cat", "image": pygame.transform.scale(orange_cat_original_image, (CHARACTER_WIDTH, CHARACTER_HEIGHT))},
|
|
||||||
{"name": "Cool Tomato", "image": pygame.transform.scale(cool_tomato_original_image, (CHARACTER_WIDTH, CHARACTER_HEIGHT))},
|
|
||||||
{"name": "Confused Lemon", "image": pygame.transform.scale(confused_lemon_original_image, (CHARACTER_WIDTH, CHARACTER_HEIGHT))}
|
|
||||||
]
|
|
||||||
SELECT_CHAR_FONT = pygame.font.Font(None, 36)
|
SELECT_CHAR_FONT = pygame.font.Font(None, 36)
|
||||||
SELECT_CHAR_TEXT = SELECT_CHAR_FONT.render("Select your character:", True, WHITE)
|
SELECT_CHAR_TEXT = SELECT_CHAR_FONT.render("Select your character:", True, WHITE)
|
||||||
SELECT_CHAR_TEXT_POS = SELECT_CHAR_TEXT.get_rect(center=(WIDTH // 2, HEIGHT // 4))
|
SELECT_CHAR_TEXT_POS = SELECT_CHAR_TEXT.get_rect(center=(WIDTH // 2, HEIGHT // 4))
|
||||||
|
@ -190,6 +185,21 @@ def draw_heart(surface, color, pos):
|
||||||
(pos[0] + 20, pos[1] + 5), (pos[0] + 25, pos[1] + 10), (pos[0] + 15, pos[1] + 25),
|
(pos[0] + 20, pos[1] + 5), (pos[0] + 25, pos[1] + 10), (pos[0] + 15, pos[1] + 25),
|
||||||
(pos[0], pos[1] + 10)])
|
(pos[0], pos[1] + 10)])
|
||||||
|
|
||||||
|
class FallingObject:
|
||||||
|
def __init__(self, image, width, height, speed):
|
||||||
|
self.image = image
|
||||||
|
self.width = width
|
||||||
|
self.height = height
|
||||||
|
self.x = random.randint(0, WIDTH - self.width)
|
||||||
|
self.y = 0 - self.height
|
||||||
|
self.speed = speed
|
||||||
|
|
||||||
|
def update(self):
|
||||||
|
self.y += self.speed # Adjust the falling speed as needed
|
||||||
|
|
||||||
|
def draw(self, surface):
|
||||||
|
surface.blit(self.image, (self.x, self.y))
|
||||||
|
|
||||||
# Main game loop
|
# Main game loop
|
||||||
while not game_over:
|
while not game_over:
|
||||||
for event in pygame.event.get():
|
for event in pygame.event.get():
|
||||||
|
@ -210,11 +220,11 @@ while not game_over:
|
||||||
# Randomly spawn an object (cupcake, football, or trollface)
|
# Randomly spawn an object (cupcake, football, or trollface)
|
||||||
spawn_type = random.choice(["cupcake", "football", "trollface"])
|
spawn_type = random.choice(["cupcake", "football", "trollface"])
|
||||||
if spawn_type == "cupcake":
|
if spawn_type == "cupcake":
|
||||||
falling_cupcakes.append(Cupcake())
|
falling_cupcakes.append(FallingObject(cupcake_image, CUPCAKE_WIDTH, CUPCAKE_HEIGHT, 5))
|
||||||
elif spawn_type == "football":
|
elif spawn_type == "football":
|
||||||
falling_footballs.append(Football())
|
falling_footballs.append(FallingObject(football_image, FOOTBALL_WIDTH, FOOTBALL_HEIGHT, 5))
|
||||||
else:
|
else:
|
||||||
falling_trollfaces.append(Trollface())
|
falling_trollfaces.append(FallingObject(trollface_image, TROLLFACE_WIDTH, TROLLFACE_HEIGHT, 5))
|
||||||
|
|
||||||
# Move the paddle based on flags
|
# Move the paddle based on flags
|
||||||
if move_left and paddle.left > 0:
|
if move_left and paddle.left > 0:
|
||||||
|
@ -222,6 +232,10 @@ while not game_over:
|
||||||
if move_right and paddle.right < WIDTH:
|
if move_right and paddle.right < WIDTH:
|
||||||
paddle.x += PADDLE_SPEED
|
paddle.x += PADDLE_SPEED
|
||||||
|
|
||||||
|
# Update cat position based on speed
|
||||||
|
cat_rect.x += cat_speed[0]
|
||||||
|
cat_rect.y += cat_speed[1]
|
||||||
|
|
||||||
# Check for collision with walls
|
# Check for collision with walls
|
||||||
if cat_rect.left <= 0 or cat_rect.right >= WIDTH:
|
if cat_rect.left <= 0 or cat_rect.right >= WIDTH:
|
||||||
cat_speed[0] = -cat_speed[0]
|
cat_speed[0] = -cat_speed[0]
|
||||||
|
|
Loading…
Reference in New Issue