From 3dd4595121032a3137d3fca37acb147ee00effa4 Mon Sep 17 00:00:00 2001 From: Donnyd88 <138402210+Donnyd88@users.noreply.github.com> Date: Mon, 31 Jul 2023 21:29:37 -0400 Subject: [PATCH] Thought bubbles (#122) * Thought Bubbles partially done Don Deal 7/27/2023 * Thought Bubbles but needs watering can to finish and to scale down some of the items Donald Deal 7/28/2023 * reversed an error Don Deal 7/28/2023 * fixed an error Donald Deal 7/28/2023 * more updates Donald Deal 7/28/2023 * Deleted duplicate status bars Donald Deal 7/29/2023 * items wont work when pet is dirty except the watering can * Fixed location varibles Donald Deal * changed shower animation fixed items going back to wrong location Donald Deal --- game_util/scene_items.py | 9 ++-- house_screen.py | 101 +++++++++++++++++++++++++++++++++------ main_menu.py | 4 +- status_bars.py | 74 ---------------------------- 4 files changed, 94 insertions(+), 94 deletions(-) delete mode 100644 status_bars.py diff --git a/game_util/scene_items.py b/game_util/scene_items.py index 65e963d..c766158 100644 --- a/game_util/scene_items.py +++ b/game_util/scene_items.py @@ -59,7 +59,7 @@ def get_pet_thirst(self): def get_pet_hunger(self): return self.hunger_bar.hp - def get_pet_happieness(self): + def get_pet_happiness(self): return self.happiness_bar.hp def fill_health(self): @@ -99,6 +99,7 @@ def __init__(self, item_id, pygame, screen, image, pet, x, y, is_movable = True) self.interacting_pet = pet self.item_location = [x,y] self.offset = (0, 0) + self.is_rock_dirty = False def is_mouse_selection(self, mouse_pos): item_location = self.item_location @@ -120,12 +121,12 @@ def get_collision_item(self): self.interacting_pet.set_current_animation(config.RockActions.drinking.value, True) return config.ItemID.full_cup elif self.item_id==config.ItemID.watering_can and self.rect.collidepoint(self.interacting_pet.get_location()): - self.interacting_pet.set_current_animation(config.RockActions.clean.value,True) + self.interacting_pet.set_current_animation(config.RockActions.very_dirty_shower.value,True) return config.ItemID.watering_can - def handle_event(self, event, item_loc): + def handle_event(self, event, item_loc, is_rock_dirty) : if self.is_movable: if event.type == pygame.MOUSEBUTTONDOWN: if self.rect.collidepoint(event.pos): @@ -145,6 +146,6 @@ def handle_event(self, event, item_loc): else: if event.type == pygame.MOUSEBUTTONDOWN: mouse_pos = self.pygame.mouse.get_pos() - if self.is_mouse_selection(mouse_pos): + if self.is_mouse_selection(mouse_pos) and is_rock_dirty == False: self.interacting_pet.set_location(self.item_location[0],self.item_location[1]+ self.rect.height/2.5) self.interacting_pet.set_current_animation(config.RockActions.sleeping.value, True) \ No newline at end of file diff --git a/house_screen.py b/house_screen.py index f864fdf..6ac0eb2 100644 --- a/house_screen.py +++ b/house_screen.py @@ -1,4 +1,5 @@ import pygame +from pygame.locals import * from game_util import PetConfig as Config from pets import PetRaccoon, PetRock, PetMudskipper from src import table as Table @@ -6,11 +7,15 @@ from pet_selection import PetSelection from game_over import GameOver from game_util.sprite_sheet import SpriteSheet +import os class HouseScreen: def __init__(self, screen): self.house_screen = screen + self.thought_bubble_radius = 40 + self.thought_bubble_color = (255, 255, 255) + def draw(self): self.house_screen.fill(config.BLACK) @@ -19,11 +24,12 @@ def draw(self): self.house_screen.blit(screen_background, (0, 0)) class RockHouse: - def __init__(self): - self.pygame = pygame.init() - + def __init__(self,screen): + self.house_screen = screen + self.thought_bubble_radius = 50 + self.thought_bubble_color = config.WHITE + - self.font = config.FONT self.screen = pygame.display.set_mode((config.SCREEN_WIDTH, config.SCREEN_HEIGHT)) self.house = HouseScreen(self.screen) self.pet_stats = scene_item.PetStats() @@ -31,7 +37,8 @@ def __init__(self): self.sprite_sheet_img = pygame.image.load(config.ITEM_PATH).convert_alpha() #SpriteSheet('../my_pet/assets/items_sheet.png') self.sprite_sheet = SpriteSheet(self.sprite_sheet_img) - self.last_update = pygame.time.get_ticks() + + self.last_update = pygame.time.get_ticks() self.animation_cooldown = 100 self.my_rock = PetRock(pygame, self.screen) @@ -61,23 +68,59 @@ def __init__(self): self.rock_misbehaving_time = 10 #seconds self.game_over = GameOver(pygame, self.screen, self.my_rock) + #scaled thought bubble objects + self.thought_of_watering_can = self.sprite_sheet.get_image(0, 288, 96, 96, 1, config.BG_BLACK) + self.thought_of_ball = self.sprite_sheet.get_image(2, 288, 96, 96, 1, config.BG_BLACK) + self.thought_of_full_cup = self.sprite_sheet.get_image(0,864,96,96,1, config.BG_BLACK) + + self.rock_made_a_mess = False self.pet_died = False self.is_rock_dirty = False + self.is_hungry = False + self.is_thirsty = False + self.is_sad = False + + def draw_thought_bubble(self, screen, pet_rock_location, image): + bubble_offset = (0, 50) # Offset for the first bubble (above the rock) + bubble_x = pet_rock_location[0] + bubble_offset[0] - self.thought_bubble_radius + bubble_y = pet_rock_location[1] + bubble_offset[1] - self.thought_bubble_radius + + # Draw the first bubble (above the rock) + pygame.draw.circle(screen, config.WHITE, (bubble_x + self.thought_bubble_radius, bubble_y + self.thought_bubble_radius), self.thought_bubble_radius//2) + + # Update the bubble_offset for the second bubble (below the first bubble) + bubble_offset = (0, -50) + bubble_x = pet_rock_location[0] + bubble_offset[0] - self.thought_bubble_radius + bubble_y = pet_rock_location[1] + bubble_offset[1] - self.thought_bubble_radius + + # Draw the second bubble (below the first bubble) + pygame.draw.circle(screen, config.WHITE, (bubble_x + self.thought_bubble_radius, bubble_y + self.thought_bubble_radius), self.thought_bubble_radius) + + # Draw the broccoli sprite inside the main thought bubble + item_x = bubble_x + (self.thought_bubble_radius - self.broccoli_item.rect.width // 2) + item_y = bubble_y + (self.thought_bubble_radius - self.broccoli_item.rect.height // 2) + screen.blit(image, (item_x, item_y)) - def handle_event(self): + + + + def handle_event(self, is_rock_dirty): for event in pygame.event.get(): if event.type == pygame.QUIT: pygame.quit() - self.watering_can_item.handle_event(event,self.watering_can_location) - self.broccoli_item.handle_event(event, self.broccoli_location) - self.ball_item.handle_event(event, self.ball_location) - self.bed_item.handle_event(event, self.bed_location) - self.full_cup_item.handle_event(event, self.cup_item_location) - + if is_rock_dirty == False: + self.broccoli_item.handle_event(event,self.broccoli_location, is_rock_dirty) + self.ball_item.handle_event(event, self.ball_location, is_rock_dirty) + self.bed_item.handle_event(event, self.bed_location, is_rock_dirty) + self.full_cup_item.handle_event(event, self.cup_item_location, is_rock_dirty) + + self.watering_can_item.handle_event(event, self.watering_can_location, is_rock_dirty) + if(self.watering_can_item.get_collision_item() == config.ItemID.watering_can): self.started_game_time = pygame.time.get_ticks() - # self.pet_stats.fill_thirst() + #self.is_rock_dirty = False + #self.pet_stats.fill_happiness() elif(self.broccoli_item.get_collision_item() == config.ItemID.broccoli): self.started_game_time = pygame.time.get_ticks() self.pet_stats.fill_hunger() @@ -118,11 +161,41 @@ def main_frames(self): self.screen.blit(self.bed, self.bed_item.rect.topleft) self.screen.blit(self.full_cup,self.full_cup_item.rect.topleft) self.screen.blit(self.lamp_table.get_current_frame(), self.lamp_table.get_location()) + self.current_frame = self.my_rock.get_current_frame() + self.my_rock_rect = self.current_frame.get_rect() + self.my_rock_rect.topleft = self.my_rock.get_location() + + if self.pet_stats.get_pet_hunger() < 50: + self.is_hungry = True + if self.pet_stats.get_pet_hunger() > 49: + self.is_hungry = False + if self.pet_stats.get_pet_thirst() < 50: + self.is_thirsty = True + if self.pet_stats.get_pet_thirst() > 49: + self.is_thirsty = False + if self.pet_stats.get_pet_happiness() < 50: + self.is_sad = True + if self.pet_stats.get_pet_happiness() > 49: + self.is_sad = False + + if self.is_rock_dirty == True: + self.draw_thought_bubble(self.screen, self.my_rock.get_location(),self.thought_of_watering_can) + if self.is_rock_dirty == False and self.is_hungry == True: + self.draw_thought_bubble(self.screen, self.my_rock.get_location(),self.broccoli_item.image) + if self.is_rock_dirty == False and self.is_hungry == False and self.is_thirsty == True: + self.draw_thought_bubble(self.screen, self.my_rock.get_location(), self.thought_of_full_cup) + if self.is_rock_dirty == False and self.is_hungry == False and self.is_thirsty == False and self.is_sad == True: + self.draw_thought_bubble(self.screen, self.my_rock.get_location(), self.thought_of_ball) + + if (self.not_interacted and not self.is_rock_dirty) and self.my_rock.get_location()[0] < 1100: self.my_rock.set_location(self.my_rock.get_location()[0]+30, self.my_rock.get_location()[1]) elif (self.not_interacted and not self.is_rock_dirty) and self.my_rock.get_location()[0] >= 1100: self.my_rock.set_current_animation(Config.RockActions.dirty.value, False) self.is_rock_dirty = True + + #elif self.my_rock.get_location()[0] >= 1100 and self.is_rock_dirty == False: + #pass self.my_rock.updated_frame() if self.rock_collide_table(): self.lamp_table.update() @@ -131,7 +204,7 @@ def main_frames(self): self.my_rock.set_current_animation(Config.RockActions.jumping.value, True) self.started_game_time = pygame.time.get_ticks() + (self.rock_misbehaving_time*1000) self.not_interacted = True - self.handle_event() + self.handle_event(self.is_rock_dirty) pygame.display.flip() else: diff --git a/main_menu.py b/main_menu.py index 86fa3dd..f352a33 100644 --- a/main_menu.py +++ b/main_menu.py @@ -115,7 +115,7 @@ def __init__(self): self.my_rock.set_location(x_location, y_location) self.game_over_screen = GameOver(pygame, screen, self.my_rock) self.current_screen = "start" - self.pet_rock_house = RockHouse() + self.pet_rock_house = None def run(self): running = True @@ -148,7 +148,7 @@ def run(self): scan_clicked_pet = self.my_pet_screen.handle_events() if scan_clicked_pet is not None and scan_clicked_pet.get_pet_id() == self.my_rock.get_pet_id(): self.current_screen = "rock_house" - self.pet_rock_house = RockHouse() + self.pet_rock_house = RockHouse(screen) elif self.current_screen == "rock_house": self.pet_rock_house.main_frames() else: diff --git a/status_bars.py b/status_bars.py deleted file mode 100644 index 178c526..0000000 --- a/status_bars.py +++ /dev/null @@ -1,74 +0,0 @@ -import pygame - -pygame.init() - -SCREEN_WIDTH = 1920 -SCREEN_HEIGHT = 1080 -RED = (255, 0, 0) -GREEN = (0, 255, 0) -INDIGO = (75, 0, 130) -BLUE = (0, 0, 255) -YELLOW = (255, 255, 0) -ORANGE = (255,165,0) - -hp_drain_time = 100 - -screen = pygame.display.set_mode((SCREEN_WIDTH, SCREEN_HEIGHT)) - -class StatusBar(): - def __init__(self, x, y, w, h, max_hp, color, bg_color): - self.x = x - self.y = y - self.w = w - self.h = h - self.hp = max_hp - self.max_hp = max_hp - self.color = color - self.bg_color = bg_color - - def draw(self, surface): - ratio = self.hp / self.max_hp - pygame.draw.rect(surface, self.bg_color, (self.x, self.y, self.w, self.h)) - pygame.draw.rect(surface, self.color, (self.x, self.y, self.w * ratio, self.h)) - - def bar_drain(self): - if self.hp > 0: - pygame.time.delay(hp_drain_time) - self.hp -= 1 - - -class PetStats(): - health_bar = StatusBar(100, 150, 300, 40, 1000, GREEN, RED) - thirst_bar = StatusBar(100, 100, 300, 40, 1000, BLUE, RED) - hunger_bar = StatusBar(100, 200, 300, 40, 1000, ORANGE, RED) - happiness_bar = StatusBar(100, 250,300,40,1000, YELLOW, RED) - - def draw(self, surface): - self.health_bar.draw(surface) - self.thirst_bar.draw(surface) - self.hunger_bar.draw(surface) - self.happiness_bar.draw(surface) - - def update(self): - self.thirst_bar.bar_drain() - self.hunger_bar.bar_drain() - self.happiness_bar.bar_drain() - if self.health_bar.hp == 0 or self.thirst_bar.hp == 0: - self.health_bar.bar_drain() - elif self.health_bar.hp == 0 and self.thirst_bar.hp == 0: - self.health_bar.bar_drain() - -pet_stats = PetStats() - -run = True -while run: - for event in pygame.event.get(): - if event.type == pygame.QUIT: - run = False - - screen.fill(INDIGO) - pet_stats.update() - pet_stats.draw(screen) - pygame.display.flip() - -pygame.quit() \ No newline at end of file