大蒜测试

This commit is contained in:
星外之神 2022-05-27 15:09:53 +08:00
parent 08b1c19fa2
commit cdf992095e
6 changed files with 69 additions and 6 deletions

View File

@ -49,6 +49,7 @@ python main.py
- 使用MSVC编译 - 使用MSVC编译
- 每次提交均会更新,保证更新及时 - 每次提交均会更新,保证更新及时
- 未进行任何测试存在bug的概率高于前者 - 未进行任何测试存在bug的概率高于前者
- 可看作本软件的测试版
- 还可以下载GitHub Workflow[自动利用Pyinstaller构建的版本点击跳转](https://github.com/wszqkzqk/pypvz/releases/tag/Current.Version.Built.with.Pyinstaller) - 还可以下载GitHub Workflow[自动利用Pyinstaller构建的版本点击跳转](https://github.com/wszqkzqk/pypvz/releases/tag/Current.Version.Built.with.Pyinstaller)
- 在程序闪退时有报错窗口弹出 - 在程序闪退时有报错窗口弹出
- 程序性能较差,不推荐 - 程序性能较差,不推荐

View File

@ -12,22 +12,27 @@ class Map():
if self.background_type in c.POOL_EQUIPPED_BACKGROUNDS: if self.background_type in c.POOL_EQUIPPED_BACKGROUNDS:
self.width = c.GRID_POOL_X_LEN self.width = c.GRID_POOL_X_LEN
self.height = c.GRID_POOL_Y_LEN self.height = c.GRID_POOL_Y_LEN
self.gridHeightSize = c.GRID_POOL_Y_SIZE
self.map = [[(deepcopy(c.MAP_STATE_EMPTY), deepcopy(c.MAP_STATE_WATER))[y in {2, 3}] for x in range(self.width)] for y in range(self.height)] self.map = [[(deepcopy(c.MAP_STATE_EMPTY), deepcopy(c.MAP_STATE_WATER))[y in {2, 3}] for x in range(self.width)] for y in range(self.height)]
elif self.background_type in c.ON_ROOF_BACKGROUNDS: elif self.background_type in c.ON_ROOF_BACKGROUNDS:
self.width = c.GRID_ROOF_X_LEN self.width = c.GRID_ROOF_X_LEN
self.height = c.GRID_ROOF_Y_LEN self.height = c.GRID_ROOF_Y_LEN
self.gridHeightSize = c.GRID_ROOF_Y_SIZE
self.map = [[deepcopy(c.MAP_STATE_TILE) for x in range(self.width)] for y in range(self.height)] self.map = [[deepcopy(c.MAP_STATE_TILE) for x in range(self.width)] for y in range(self.height)]
elif self.background_type == c.BACKGROUND_SINGLE: elif self.background_type == c.BACKGROUND_SINGLE:
self.width = c.GRID_X_LEN self.width = c.GRID_X_LEN
self.height = c.GRID_Y_LEN self.height = c.GRID_Y_LEN
self.gridHeightSize = c.GRID_Y_SIZE
self.map = [[(deepcopy(c.MAP_STATE_UNAVAILABLE), deepcopy(c.MAP_STATE_EMPTY))[y == 2] for x in range(self.width)] for y in range(self.height)] self.map = [[(deepcopy(c.MAP_STATE_UNAVAILABLE), deepcopy(c.MAP_STATE_EMPTY))[y == 2] for x in range(self.width)] for y in range(self.height)]
elif self.background_type == c.BACKGROUND_TRIPLE: elif self.background_type == c.BACKGROUND_TRIPLE:
self.width = c.GRID_X_LEN self.width = c.GRID_X_LEN
self.height = c.GRID_Y_LEN self.height = c.GRID_Y_LEN
self.gridHeightSize = c.GRID_Y_SIZE
self.map = [[(deepcopy(c.MAP_STATE_UNAVAILABLE), deepcopy(c.MAP_STATE_EMPTY))[y in {1, 2, 3}] for x in range(self.width)] for y in range(self.height)] self.map = [[(deepcopy(c.MAP_STATE_UNAVAILABLE), deepcopy(c.MAP_STATE_EMPTY))[y in {1, 2, 3}] for x in range(self.width)] for y in range(self.height)]
else: else:
self.width = c.GRID_X_LEN self.width = c.GRID_X_LEN
self.height = c.GRID_Y_LEN self.height = c.GRID_Y_LEN
self.gridHeightSize = c.GRID_Y_SIZE
self.map = [[deepcopy(c.MAP_STATE_EMPTY) for x in range(self.width)] for y in range(self.height)] self.map = [[deepcopy(c.MAP_STATE_EMPTY) for x in range(self.width)] for y in range(self.height)]
def isValid(self, map_x, map_y): def isValid(self, map_x, map_y):

View File

@ -113,6 +113,10 @@ plantInfo = (# 元组 (植物名称, 卡片名称, 阳光, 冷却时间)
c.CARD_COFFEEBEAN, c.CARD_COFFEEBEAN,
75, 75,
7500), 7500),
(c.GARLIC,
c.CARD_GARLIC,
50,
7500),
# 应当保证这两个在一般模式下不可选的特殊植物恒在最后 # 应当保证这两个在一般模式下不可选的特殊植物恒在最后
(c.WALLNUTBOWLING, (c.WALLNUTBOWLING,
c.CARD_WALLNUT, c.CARD_WALLNUT,

View File

@ -20,6 +20,10 @@ class Zombie(pg.sprite.Sprite):
self.rect = self.image.get_rect() self.rect = self.image.get_rect()
self.rect.x = x self.rect.x = x
self.rect.bottom = y self.rect.bottom = y
# 大蒜换行移动像素值,< 0时向上= 0时不变> 0时向上
self.targetYChange = 0
self.originalY = y
self.toChangeGroup = False
self.helmetHealth = helmetHealth self.helmetHealth = helmetHealth
self.helmetType2Health = helmetType2Health self.helmetType2Health = helmetType2Health
@ -191,13 +195,45 @@ class Zombie(pg.sprite.Sprite):
if self.helmetType2Health <= 0 and self.helmetType2: if self.helmetType2Health <= 0 and self.helmetType2:
self.changeFrames(self.walk_frames) self.changeFrames(self.walk_frames)
self.helmetType2 = False self.helmetType2 = False
if (self.current_time - self.walk_timer) > (c.ZOMBIE_WALK_INTERVAL * self.getTimeRatio()):
if ((self.current_time - self.walk_timer) > (c.ZOMBIE_WALK_INTERVAL * self.getTimeRatio())
and self.handleGarlicYChange()):
self.walk_timer = self.current_time self.walk_timer = self.current_time
if self.is_hypno: if self.is_hypno:
self.rect.x += 1 self.rect.x += 1
else: else:
self.rect.x -= 1 self.rect.x -= 1
def handleGarlicYChange(self):
if self.targetYChange < 0:
self.setWalk()
if self.rect.bottom > self.originalY + self.targetYChange: # 注意这里加的是负数
self.rect.bottom -= 3
# 过半时换行
if ((self.toChangeGroup) and
(self.rect.bottom >= self.originalY + 0.5*self.targetYChange)):
self.level.zombie_groups[self.mapY].remove(self)
self.level.zombie_groups[self.targetMapY].add(self)
else:
self.rect.bottom = self.originalY + self.targetYChange
self.targetYChange = 0
return None
elif self.targetYChange > 0:
self.setWalk()
if self.rect.bottom < self.originalY + self.targetYChange: # 注意这里加的是负数
self.rect.bottom += 3
# 过半时换行
if ((self.toChangeGroup) and
(self.rect.bottom <= self.originalY + 0.5*self.targetYChange)):
self.level.zombie_groups[self.mapY].remove(self)
self.level.zombie_groups[self.targetMapY].add(self)
else:
self.rect.bottom = self.originalY + self.targetYChange
self.targetYChange = 0
return None
else:
return True
def attacking(self): def attacking(self):
if self.checkToDie(self.losthead_attack_frames): if self.checkToDie(self.losthead_attack_frames):
return return
@ -676,7 +712,8 @@ class NewspaperZombie(Zombie):
self.helmetType2 = False self.helmetType2 = False
# 触发报纸撕裂音效 # 触发报纸撕裂音效
pg.mixer.Sound(os.path.join(os.path.dirname(os.path.dirname(os.path.dirname(__file__))) ,"resources", "sound", "newspaperRip.ogg")).play() pg.mixer.Sound(os.path.join(os.path.dirname(os.path.dirname(os.path.dirname(__file__))) ,"resources", "sound", "newspaperRip.ogg")).play()
if (self.current_time - self.walk_timer) > (c.ZOMBIE_WALK_INTERVAL * self.getTimeRatio()): if ((self.current_time - self.walk_timer) > (c.ZOMBIE_WALK_INTERVAL * self.getTimeRatio())
and self.handleGarlicYChange()):
self.walk_timer = self.current_time self.walk_timer = self.current_time
if self.frames == self.lostnewspaper_frames: if self.frames == self.lostnewspaper_frames:
pass pass
@ -1158,7 +1195,8 @@ class SnorkelZombie(Zombie):
if self.swimming: if self.swimming:
self.changeFrames(self.walk_frames) self.changeFrames(self.walk_frames)
self.swimming = False self.swimming = False
if (self.current_time - self.walk_timer) > (c.ZOMBIE_WALK_INTERVAL * self.getTimeRatio()): if ((self.current_time - self.walk_timer) > (c.ZOMBIE_WALK_INTERVAL * self.getTimeRatio())
and self.handleGarlicYChange()):
self.walk_timer = self.current_time self.walk_timer = self.current_time
# 正在上浮或者下潜不用移动 # 正在上浮或者下潜不用移动
if (self.frames == self.float_frames) or (self.frames == self.sink_frames): if (self.frames == self.float_frames) or (self.frames == self.sink_frames):

View File

@ -1,5 +1,5 @@
# 冒险模式起始关卡 # 冒险模式起始关卡
START_LEVEL_NUM = 1 START_LEVEL_NUM = 0
# 小游戏模式起始关卡 # 小游戏模式起始关卡
START_LITTLE_GAME_NUM = 1 START_LITTLE_GAME_NUM = 1
@ -23,7 +23,7 @@ SCREEN_SIZE = (SCREEN_WIDTH, SCREEN_HEIGHT)
# 最大数量 # 最大数量
CARD_MAX_NUM = 10 # 这里以后可以增加解锁功能从最初的6格逐渐解锁到10格 CARD_MAX_NUM = 10 # 这里以后可以增加解锁功能从最初的6格逐渐解锁到10格
# 最小数量 # 最小数量
CARD_LIST_NUM = CARD_MAX_NUM CARD_LIST_NUM = 0#CARD_MAX_NUM
# 方格数据 # 方格数据
# 一般 # 一般

View File

@ -1040,7 +1040,6 @@ class Level(tool.State):
# 被攻击对象是植物时才可能刷新 # 被攻击对象是植物时才可能刷新
if zombie.prey_is_plant: if zombie.prey_is_plant:
# 新植物种在被攻击植物同一格时才可能刷新 # 新植物种在被攻击植物同一格时才可能刷新
mapX, mapY = self.map.getMapIndex(zombie.prey.rect.centerx, zombie.prey.rect.centery)
if (mapX, mapY) == self.newPlantAndPositon[1]: if (mapX, mapY) == self.newPlantAndPositon[1]:
# 如果被攻击植物是睡莲和花盆,同一格种了植物必然刷新 # 如果被攻击植物是睡莲和花盆,同一格种了植物必然刷新
# 如果被攻击植物不是睡莲和花盆,同一格种了南瓜头才刷新 # 如果被攻击植物不是睡莲和花盆,同一格种了南瓜头才刷新
@ -1128,6 +1127,22 @@ class Level(tool.State):
elif targetPlant.name == c.REDWALLNUTBOWLING: elif targetPlant.name == c.REDWALLNUTBOWLING:
if targetPlant.state == c.IDLE: if targetPlant.state == c.IDLE:
targetPlant.setAttack() targetPlant.setAttack()
elif targetPlant.name == c.GARLIC:
zombie.setAttack(targetPlant)
# 向吃过大蒜的僵尸传入level
zombie.level = self
zombie.toChangeGroup = True
zombie.mapY = i
if i == 0:
_move = 1
elif i == self.map_y_len - 1:
_move = -1
else:
_move = randint(0, 1)*2 - 1
if self.map.map[i][0][c.MAP_PLOT_TYPE] != self.map.map[i + _move][0][c.MAP_PLOT_TYPE]:
_move = -_move
zombie.targetMapY = i + _move
zombie.targetYChange = _move * self.map.gridHeightSize
else: else:
zombie.setAttack(targetPlant) zombie.setAttack(targetPlant)