-
Notifications
You must be signed in to change notification settings - Fork 0
/
mudskipper_screen_2.py
259 lines (223 loc) · 14.2 KB
/
mudskipper_screen_2.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
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
from game_util import PetConfig as config, scene_items as scene_item, music_player as MP
from pet_selection import PetSelection
from game_over import GameOver
from game_util.sprite_sheet import SpriteSheet
from game_config import GameConfig as gc
import os
class MudskipperHouse:
def __init__(self,screen,game_menu,music):
self.house_screen = screen
self.screen = screen
self.gm = game_menu
self.score_board = scene_item.Score(pygame=pygame, screen=screen)
self.player_name = gc.SAVED_PET_NAMES[0] if len(gc.SAVED_PET_NAMES) > 0 else ''
self.player_board = scene_item.PlayerName(pygame=pygame, screen=screen, player_name=self.player_name)
self.kill_pet_button = scene_item.Buttons(self.screen,[50,100],"Kill",button_text_color=config.RED)
self.pet_stats = scene_item.PetStats()
self.pet_stats_bar_icon = scene_item.RaccoonIcons(pygame, self.screen)
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.main_music= music
self.last_update = pygame.time.get_ticks()
self.animation_cooldown = 100
self.my_mudskipper = PetMudskipper(pygame, self.screen)
self.my_mudskipper.set_location(50, 50) #900 1100
self.my_mudskipper.set_current_animation(config.MudskipperActions.idle.value)
self.x_location = config.SCREEN_WIDTH // 2 - self.my_mudskipper.get_current_frame().get_width() // 2
self.y_location = config.SCREEN_HEIGHT // 2 + self.my_mudskipper.get_current_frame().get_height() // 3
self.broccoli = self.sprite_sheet.get_image(0,384,96,96,1,config.BG_BLACK)
self.broccoli_location = [475, 250]
self.broccoli_item = scene_item.Item(config.ItemID.broccoli, pygame, self.screen, self.broccoli,self.my_mudskipper, self.broccoli_location[0], self.broccoli_location[1])
self.gray_cloud = self.sprite_sheet.get_image(0, 1440, 96, 96, 2, config.BG_BLACK)
self.gray_cloud_location = [480,0]
self.ball = self.sprite_sheet.get_image(0,1248, 96, 96, 2, config.BG_BLACK)
self.ball_location = [300,400]
self.ball_item = scene_item.Item( config.ItemID.ball,pygame, self.screen, self.ball,self.my_mudskipper, self.ball_location[0], self.ball_location[1])
self.gray_cloud_item = scene_item.Item(config.ItemID.gray_cloud, pygame, self.screen, self.gray_cloud, self.my_mudskipper, self.gray_cloud_location[0], self.gray_cloud_location[1])
self.bed = self.sprite_sheet.get_image(0,1056,96,96,2,config.BG_BLACK)
self.bed_location = [1100, 600]
self.bed_item = scene_item.Item(config.ItemID.bed, pygame, self.screen,self.bed,self.my_mudskipper, self.bed_location[0],self.bed_location[1],False)
self.flower_location = [700, 300]
self.flower = Table.Table(pygame, self.screen, self.flower_location[0], self.flower_location[1])
self.flower.set_current_selected_animation(config.TableActions.spray_flower_pink.value)
self.full_cup = self.sprite_sheet.get_image(0,864,96,96,2, config.BG_BLACK)
self.cup_item_location = [70, 400]
self.full_cup_item = scene_item.Item(config.ItemID.full_cup, pygame, self.screen, self.full_cup, self.my_mudskipper, self.cup_item_location[0], self.cup_item_location[1])
self.list_of_items = [self.broccoli_item, self.ball_item, self.gray_cloud_item, self.full_cup_item]
# Pet Timer
self.started_game_time = pygame.time.get_ticks()
self.dirtiness_start = pygame.time.get_ticks()
self.not_interacted = False
self.mudskipper_misbehaving_time = 10 #seconds time before raccoon misbehaves
self.dirtiness_time = 30 #seconds time before raccoon starts getting dirty
self.sleep_start = pygame.time.get_ticks()
self.sleep_time = 10
self.game_over = GameOver(pygame, self.screen, self.gm, self.my_mudskipper)
# Thought bubble
self.mudskipper_thought = scene_item.ThoughtBubble(self.pet_stats)
self.mudskipper_made_a_mess = False
self.pet_died = False
self.is_mudskipper_dirty = False
self.is_hungry = False
self.is_thirsty = False
self.is_sad = False
self.is_sleeping = False
self.locationset = False
self.has_touched_flower = False
def reset(self):
self.my_mudskipper.set_current_animation(config.MudskipperActions.idle.value)
self.not_interacted = False
self.started_game_time = pygame.time.get_ticks()
self.dirtiness_start = pygame.time.get_ticks()
self.pet_stats.reset()
self.pet_died = False
gc.DISPLAY_KILL_BUTTON = False
def initialize_house(self):
self.house_screen.fill(config.BLACK)
screen_background = pygame.image.load(config.MUDSKIPPER_BACKGROUND)
screen_background = pygame.transform.scale(screen_background, (config.SCREEN_WIDTH, config.SCREEN_HEIGHT))
self.house_screen.blit(screen_background, (0, 0))
if gc.DISPLAY_KILL_BUTTON == True:
self.kill_pet_button.draw()
def handle_event(self, is_mudskipper_dirty):
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
if event.type == pygame.MOUSEBUTTONDOWN:
mouse_pos = pygame.mouse.get_pos()
if self.kill_pet_button.is_mouse_selection(mouse_pos):
self.pet_stats.health_bar.drain_health_fully()
if event.type == pygame.KEYDOWN and event.key == pygame.K_ESCAPE:
gc.DISPLAY_KILL_BUTTON = True
if not is_mudskipper_dirty:
self.broccoli_item.handle_event(event,self.broccoli_location, is_mudskipper_dirty)
self.bed_item.handle_event(event, self.bed_location, is_mudskipper_dirty)
self.full_cup_item.handle_event(event, self.cup_item_location, is_mudskipper_dirty)
self.ball_item.handle_event(event,self.ball_location,is_mudskipper_dirty)
self.gray_cloud_item.handle_event(event, self.gray_cloud_location, is_mudskipper_dirty)
if(self.my_mudskipper.did_overlap_with(self.gray_cloud_item)):
self.my_mudskipper.set_current_animation(Config.MudskipperActions.clean.value, True)
self.not_interacted = False
self.is_mudskipper_dirty = False
self.started_game_time = pygame.time.get_ticks()
elif(self.my_mudskipper.did_overlap_with(self.broccoli_item) and not self.is_mudskipper_dirty):
self.started_game_time = pygame.time.get_ticks()
self.my_mudskipper.set_current_animation(Config.MudskipperActions.eating.value, True)
self.pet_stats.fill_hunger()
elif(self.my_mudskipper.did_overlap_with(self.ball_item) and not self.is_mudskipper_dirty):
self.started_game_time = pygame.time.get_ticks()
self.my_mudskipper.set_current_animation(Config.MudskipperActions.playing.value, True)
self.pet_stats.fill_happiness()
elif(self.my_mudskipper.did_overlap_with(self.bed_item) and not self.is_mudskipper_dirty):
self.is_sleeping = True
self.started_game_time = pygame.time.get_ticks()
elif(self.my_mudskipper.did_overlap_with(self.full_cup_item) and not self.is_mudskipper_dirty):
self.started_game_time = pygame.time.get_ticks()
self.my_mudskipper.set_current_animation(Config.MudskipperActions.drinking.value, True)
self.pet_stats.fill_thirst()
if(self.my_mudskipper.current_selected_animation == config.MudskipperActions.clean.value and self.my_mudskipper.has_animation_ended()):
self.my_mudskipper.set_current_animation(Config.MudskipperActions.idle.value)
self.my_mudskipper.set_location(500, 500)
self.is_mudskipper_dirty = False
self.not_interacted = False
self.started_game_time = pygame.time.get_ticks()
self.dirtiness_start = pygame.time.get_ticks()
if (self.is_sleeping == True) and self.sleep_start + self.sleep_time * 1000 < pygame.time.get_ticks():
self.my_mudskipper.set_location(self.x_location, self.y_location)
self.my_mudskipper.set_current_animation(Config.MudskipperActions.idle.value, False)
self.sleep_start = pygame.time.get_ticks()
self.started_game_time = pygame.time.get_ticks()
self.is_sleeping = False
def fixlocation(self):
self.my_mudskipper.set_location(500, 500)
def update_pet_stats(self):
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
def draw_pet_thought(self):
if self.is_mudskipper_dirty == True:
self.mudskipper_thought.draw_thought_bubble(self.screen, self.my_mudskipper.get_location(),self.pet_stats_bar_icon.get_gray_cloud_icon())
if self.is_mudskipper_dirty == False and self.is_hungry == True:
self.mudskipper_thought.draw_thought_bubble(self.screen, self.my_mudskipper.get_location(),self.pet_stats_bar_icon.get_broccoli_icon())
if self.is_mudskipper_dirty == False and self.is_hungry == False and self.is_thirsty == True:
self.mudskipper_thought.draw_thought_bubble(self.screen, self.my_mudskipper.get_location(), self.pet_stats_bar_icon.get_full_cup_icon())
if self.is_mudskipper_dirty == False and self.is_hungry == False and self.is_thirsty == False and self.is_sad == True:
self.mudskipper_thought.draw_thought_bubble(self.screen, self.my_mudskipper.get_location(), self.pet_stats_bar_icon.get_ball_icon())
def display_house_to_screen(self):
self.screen.blit(self.my_mudskipper.get_current_frame(), self.my_mudskipper.get_location())
self.screen.blit(self.flower.get_current_frame(), self.flower.get_location())
for item in self.list_of_items:
if not self.my_mudskipper.did_overlap_with(item):
self.screen.blit(item.image, item.get_item_location())
self.screen.blit(self.bed, self.bed_item.get_item_location())
def manage_pet_dirtiness(self):
if (self.not_interacted and not self.is_mudskipper_dirty) and self.my_mudskipper.get_location()[0] < 1100:
self.my_mudskipper.set_location(self.my_mudskipper.get_location()[0]+30, self.my_mudskipper.get_location()[1])
elif (self.not_interacted and not self.is_mudskipper_dirty) and self.my_mudskipper.get_location()[0] >= 1100:
self.my_mudskipper.set_current_animation(Config.MudskipperActions.dirty.value, False)
self.is_mudskipper_dirty = True
if not self.is_mudskipper_dirty and self.dirtiness_start + self.dirtiness_time * 1000 < pygame.time.get_ticks():
self.my_mudskipper.set_current_animation(Config.MudskipperActions.dirty.value, False)
self.is_mudskipper_dirty = True
self.dirtiness_start = pygame.time.get_ticks() + (self.dirtiness_time*1000)
if self.flower.did_overlap_with(self.my_mudskipper):
# self.broken_vase.update()
self.has_touched_flower = True
if self.has_touched_flower and self.flower.get_location()[1] < 350:
self.flower.set_location(self.flower.get_location()[0],self.flower.get_location()[1]+10)
self.flower.update()
if not self.is_mudskipper_dirty and self.started_game_time + self.mudskipper_misbehaving_time * 1000 < pygame.time.get_ticks():
self.my_mudskipper.set_location(700, 300)
self.my_mudskipper.set_current_animation(Config.MudskipperActions.dirty.value, True)
self.started_game_time = pygame.time.get_ticks() + (self.mudskipper_misbehaving_time*1000)
self.not_interacted = True
def main_frames(self):
if self.pet_stats.get_pet_health() == 0 and not self.pet_died:
self.my_mudskipper.set_current_animation(Config.MudskipperActions.dying.value)
x_location = config.SCREEN_WIDTH // 2 - self.my_mudskipper.get_current_frame().get_width() // 2
y_location = config.SCREEN_HEIGHT // 2 + self.my_mudskipper.get_current_frame().get_height() // 3
self.my_mudskipper.set_location(x_location, y_location )
self.pet_died = True
self.main_music.load_track(config.game_over)
if gc.IS_SOUND_ON:
self.main_music.play(True)
else:
self.main_music.stop()
if not self.pet_died:
if self.locationset == False:
self.fixlocation()
self.locationset = True
self.initialize_house()
self.pet_stats_bar_icon.draw_mudskipper_icons()
if self.is_sleeping == False:
self.pet_stats.update()
self.pet_stats.draw(self.screen)
self.display_house_to_screen()
self.update_pet_stats()
self.draw_pet_thought()
self.manage_pet_dirtiness()
self.my_mudskipper.updated_frame()
self.handle_event(self.is_mudskipper_dirty)
self.score_board.draw_score_text()
self.score_board.add_score()
if self.player_name != '':
self.player_board.draw_player_name_text()
pygame.display.flip()
else:
score = self.score_board.score_value
self.game_over.main_frames(score)
pygame.display.update()