From c14283d818eb2c92820008f7927cbb83f85cb219 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=98=9F=E5=A4=96=E4=B9=8B=E7=A5=9E?= Date: Sun, 1 May 2022 21:25:57 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=80=E5=A4=A7=E6=B3=A2=E5=83=B5=E5=B0=B8?= =?UTF-8?q?=E6=9D=A5=E8=A2=AD=E6=97=B6=E5=A2=9E=E5=8A=A0=E6=8F=90=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/constants.py | 3 ++- source/state/level.py | 36 ++++++++++++++++++++++++++++-------- 2 files changed, 30 insertions(+), 9 deletions(-) diff --git a/source/constants.py b/source/constants.py index 2e2991e..7995d33 100755 --- a/source/constants.py +++ b/source/constants.py @@ -60,6 +60,8 @@ LITTLEGAME_BUTTON = 'littleGameButton' # 小铲子 SHOVEL = 'shovel' SHOVEL_BOX = 'shovelBox' +# 一大波僵尸来袭图片 +HUGE_WAVE_APPROCHING = 'Approching' # GAME INFO字典键值 @@ -167,7 +169,6 @@ CARD_MOVE_TIME = 60 # 其他显示物 CAR = 'car' SUN = 'Sun' -HUGE_WAVE_APPROCHING = 'Approching' # 植物相关信息 PLANT_IMAGE_RECT = 'plant_image_rect' # 植物名称 diff --git a/source/state/level.py b/source/state/level.py index e08571b..18564be 100644 --- a/source/state/level.py +++ b/source/state/level.py @@ -2,9 +2,7 @@ import os import json import sys import pygame as pg -from random import randint -from random import choices -from random import uniform +from random import randint, uniform, choices from .. import tool from .. import constants as c from ..component import map, plant, zombie, menubar @@ -154,6 +152,10 @@ class Level(tool.State): # 僵尸的刷新机制 def refreshWaves(self, current_time, survivalRounds=0): + + # 是否显示一大波僵尸即将来袭的红字 + self.showHugeWaveApproching = False + if self.waveNum >= self.map_data[c.NUM_FLAGS] * 10: return if (self.waveNum == 0): # 还未开始出现僵尸 @@ -187,14 +189,18 @@ class Level(tool.State): self.waveZombies = self.waves[self.waveNum - 1] self.numZombie = len(self.waveZombies) return + elif ((current_time - self.waveTime >= 43000) or (self.bar_type != c.CHOOSEBAR_STATIC and current_time - self.waveTime >= 23000)): + self.showHugeWaveApproching = True numZombies = 0 for i in range(self.map_y_len): numZombies += len(self.zombie_groups[i]) if numZombies / self.numZombie < uniform(0.15, 0.25): - self.waveNum += 1 - self.waveTime = current_time - self.waveZombies = self.waves[self.waveNum - 1] - return + # 当僵尸所剩无几时,改变时间记录,使得2000 ms后刷新僵尸(所以需要判断剩余时间是否大于2000 ms) + if current_time - self.waveTime > 2000: + if self.bar_type == c.CHOOSEBAR_STATIC: + self.waveTime = current_time - 43000 # 即倒计时2000 ms + else: + self.waveTime = current_time - 23000 # 即倒计时2000 ms @@ -338,6 +344,8 @@ class Level(tool.State): self.setupLittleMenu() + self.setupHugeWaveApprochingImage() + # 小菜单 def setupLittleMenu(self): @@ -372,6 +380,14 @@ class Level(tool.State): self.mainMenu_button_rect.x = 299 self.mainMenu_button_rect.y = 372 + # 一大波僵尸来袭图片显示 + def setupHugeWaveApprochingImage(self): + frame_rect = [0, 0, 492, 80] + self.huge_wave_approching_image = tool.get_image_menu(tool.GFX[c.HUGE_WAVE_APPROCHING], *frame_rect, c.BLACK, 1) + self.huge_wave_approching_image_rect = self.huge_wave_approching_image.get_rect() + self.huge_wave_approching_image_rect.x = 140 # 猜的 + self.huge_wave_approching_image_rect.y = 250 # 猜的 + # 检查小菜单有没有被点击 def checkLittleMenuClick(self, mouse_pos): x, y = mouse_pos @@ -1099,4 +1115,8 @@ class Level(tool.State): 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) \ No newline at end of file + surface.blit(self.mainMenu_button, self.mainMenu_button_rect) + + if not ((c.ZOMBIE_LIST in self.map_data.keys()) and self.map_data[c.SPAWN_ZOMBIES] == c.SPAWN_ZOMBIES_LIST): + if self.showHugeWaveApproching: + surface.blit(self.huge_wave_approching_image, self.huge_wave_approching_image_rect)