Skip to content

Commit

Permalink
修复选卡模式下点击菜单会闪退的bug;更改封装
Browse files Browse the repository at this point in the history
  • Loading branch information
wszqkzqk committed Jul 28, 2022
1 parent be5309f commit 7164dd3
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 24 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
16 changes: 6 additions & 10 deletions source/component/plant.py
Original file line number Diff line number Diff line change
Expand Up @@ -548,7 +548,7 @@ def __init__(self, x, y):
self.explode_x_range = c.GRID_X_SIZE * 1.5

def setBoom(self):
frame = tool.GFX[c.CHERRY_BOOM_IMAGE]
frame = tool.GFX[c.BOOM_IMAGE]
rect = frame.get_rect()
width, height = rect.w, rect.h

Expand Down Expand Up @@ -1232,16 +1232,12 @@ def __init__(self, x, y):

def loadImages(self, name, scale):
self.idle_frames = []
self.explode_frames = []

idle_name = name
explode_name = name + 'Explode'
self.loadFrames(self.idle_frames, name, 1)

frame_list = [self.idle_frames, self.explode_frames]
name_list = [idle_name, explode_name]

for i, name in enumerate(name_list):
self.loadFrames(frame_list[i], name, 1, c.WHITE)
frame = tool.GFX[c.BOOM_IMAGE]
rect = frame.get_rect()
image = tool.get_image(frame, 0, 0, rect.w, rect.h)
self.explode_frames = (image, )

self.frames = self.idle_frames

Expand Down
3 changes: 2 additions & 1 deletion source/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@ def INIT_MAP_GRID(PLOT_TYPE):

# 植物相关信息
PLANT_IMAGE_RECT = 'plant_image_rect'
BOOM_IMAGE = 'Boom'

# 植物卡片信息汇总(包括植物名称, 卡片名称, 阳光, 冷却时间)
PLANT_CARD_INFO = (# 元组 (植物名称, 卡片名称, 阳光, 冷却时间)
Expand Down Expand Up @@ -420,7 +421,7 @@ def INIT_MAP_GRID(PLOT_TYPE):
JALAPENO, SCAREDYSHROOM,
SUNSHROOM, ICESHROOM,
HYPNOSHROOM, SQUASH,
WALLNUTBOWLING, REDWALLNUTBOWLING,
WALLNUTBOWLING,
}

# 直接水生植物
Expand Down
25 changes: 12 additions & 13 deletions source/state/level.py
Original file line number Diff line number Diff line change
Expand Up @@ -1506,7 +1506,16 @@ def showLevelProgress(self, surface):
# 画僵尸头
surface.blit(self.level_progress_zombie_head_image, self.level_progress_zombie_head_image_rect)

def showCurrentVolumeImage(self, surface):
def showAllContentOfMenu(self, surface):
# 绘制不可变内容
surface.blit(self.big_menu, self.big_menu_rect)
surface.blit(self.return_button, self.return_button_rect)
surface.blit(self.restart_button, self.restart_button_rect)
surface.blit(self.mainMenu_button, self.mainMenu_button_rect)
surface.blit(self.sound_volume_minus_button, self.sound_volume_minus_button_rect)
surface.blit(self.sound_volume_plus_button, self.sound_volume_plus_button_rect)

# 显示当前音量
# 由于音量可变,因此这一内容不能在一开始就结束加载,而应当不断刷新不断显示
font = pg.font.Font(c.FONT_PATH, 30)
volume_tips = font.render(f"音量:{round(self.game_info[c.SOUND_VOLUME]*100):3}%", True, c.LIGHTGRAY)
Expand All @@ -1523,11 +1532,7 @@ def draw(self, surface):
# 画小菜单
surface.blit(self.little_menu, self.little_menu_rect)
if self.showLittleMenu:
surface.blit(self.big_menu, self.big_menu_rect)
surface.blit(self.return_button, self.return_button_rect)
surface.blit(self.restart_button, self.restart_button_rect)
surface.blit(self.mainMenu_button, self.mainMenu_button_rect)
self.showCurrentVolumeImage()
self.showAllContentOfMenu(surface)
# 以后可能需要插入一个预备的状态(预览显示僵尸、返回战场)
elif self.state == c.PLAY:
if self.hasShovel:
Expand Down Expand Up @@ -1556,13 +1561,7 @@ def draw(self, surface):
self.drawMouseShowPlus(surface)

if self.showLittleMenu:
surface.blit(self.big_menu, self.big_menu_rect)
surface.blit(self.return_button, self.return_button_rect)
surface.blit(self.restart_button, self.restart_button_rect)
surface.blit(self.mainMenu_button, self.mainMenu_button_rect)
surface.blit(self.sound_volume_minus_button, self.sound_volume_minus_button_rect)
surface.blit(self.sound_volume_plus_button, self.sound_volume_plus_button_rect)
self.showCurrentVolumeImage(surface)
self.showAllContentOfMenu(surface)

if self.map_data[c.SPAWN_ZOMBIES] == c.SPAWN_ZOMBIES_AUTO:
self.showLevelProgress(surface)
Expand Down

0 comments on commit 7164dd3

Please sign in to comment.