修复撑杆跳生成位置过分靠后的bug

This commit is contained in:
星外之神 2022-05-16 18:07:19 +08:00
parent c37208bfb2
commit 8ed01975dc
2 changed files with 26 additions and 21 deletions

View File

@ -19,6 +19,12 @@ SCREEN_WIDTH = 800
SCREEN_HEIGHT = 600 SCREEN_HEIGHT = 600
SCREEN_SIZE = (SCREEN_WIDTH, SCREEN_HEIGHT) SCREEN_SIZE = (SCREEN_WIDTH, SCREEN_HEIGHT)
# 选卡数量
# 最大数量
CARD_MAX_NUM = 10 # 这里以后可以增加解锁功能从最初的6格逐渐解锁到10格
# 最小数量
CARD_LIST_NUM = CARD_MAX_NUM
# 方格数据 # 方格数据
# 一般 # 一般
GRID_X_LEN = 9 GRID_X_LEN = 9
@ -186,8 +192,6 @@ PANEL_X_START = 22
PANEL_Y_INTERNAL = 69 PANEL_Y_INTERNAL = 69
PANEL_X_INTERNAL = 53 PANEL_X_INTERNAL = 53
BAR_CARD_X_INTERNAL = 51 BAR_CARD_X_INTERNAL = 51
CARD_MAX_NUM = 10 # 这里以后可以增加解锁功能从最初的6格逐渐解锁到10格
CARD_LIST_NUM = CARD_MAX_NUM
# 所选植物信息索引 # 所选植物信息索引
PLANT_NAME_INDEX = 0 PLANT_NAME_INDEX = 0
@ -308,7 +312,8 @@ PLANT_NON_CHECK_ATTACK_STATE = ( # 这里运用了集合运算
ASH_PLANTS_AND_ICESHROOM = { ASH_PLANTS_AND_ICESHROOM = {
REDWALLNUTBOWLING, CHERRYBOMB, REDWALLNUTBOWLING, CHERRYBOMB,
JALAPENO, DOOMSHROOM, JALAPENO, DOOMSHROOM,
ICESHROOM,} ICESHROOM,
}
# 植物生命值 # 植物生命值

View File

@ -10,7 +10,7 @@ from ..component import map, plant, zombie, menubar
class Level(tool.State): class Level(tool.State):
def __init__(self): def __init__(self):
tool.State.__init__(self) tool.State.__init__(self)
def startup(self, current_time, persist): def startup(self, current_time, persist):
self.game_info = persist self.game_info = persist
self.persist = self.game_info self.persist = self.game_info
@ -22,7 +22,7 @@ class Level(tool.State):
# 默认显然不用显示菜单 # 默认显然不用显示菜单
self.showLittleMenu = False self.showLittleMenu = False
# 导入地图参数 # 导入地图参数
self.loadMap() self.loadMap()
self.map = map.Map(self.map_data[c.BACKGROUND_TYPE]) self.map = map.Map(self.map_data[c.BACKGROUND_TYPE])
@ -145,7 +145,7 @@ class Level(tool.State):
# 防止因为僵尸最小等级过大,使得总容量无法完全利用,造成死循环的检查机制 # 防止因为僵尸最小等级过大,使得总容量无法完全利用,造成死循环的检查机制
minCost = c.CREATE_ZOMBIE_DICT[min(useableZombies, key=lambda x:c.CREATE_ZOMBIE_DICT[x][0])][0] minCost = c.CREATE_ZOMBIE_DICT[min(useableZombies, key=lambda x:c.CREATE_ZOMBIE_DICT[x][0])][0]
while (volume >= minCost) and (len(zombieList) < 50): while (volume >= minCost) and (len(zombieList) < 50):
newZombie = choices(useableZombies, weights)[0] newZombie = choices(useableZombies, weights)[0]
# 普通僵尸、路障僵尸、铁桶僵尸有概率生成水中变种 # 普通僵尸、路障僵尸、铁桶僵尸有概率生成水中变种
@ -286,7 +286,7 @@ class Level(tool.State):
return return
elif ((current_time - self.waveTime >= 43000) or (self.bar_type != c.CHOOSEBAR_STATIC and current_time - self.waveTime >= 23000)): elif ((current_time - self.waveTime >= 43000) or (self.bar_type != c.CHOOSEBAR_STATIC and current_time - self.waveTime >= 23000)):
self.showHugeWaveApprochingTime = current_time self.showHugeWaveApprochingTime = current_time
numZombies = 0 numZombies = 0
for i in range(self.map_y_len): for i in range(self.map_y_len):
numZombies += len(self.zombie_groups[i]) numZombies += len(self.zombie_groups[i])
@ -319,7 +319,7 @@ class Level(tool.State):
for i in range(self.map_y_len): for i in range(self.map_y_len):
_, y = self.map.getMapGridPos(0, i) _, y = self.map.getMapGridPos(0, i)
self.cars.append(plant.Car(-40, y+20, i)) self.cars.append(plant.Car(-40, y+20, i))
# 更新函数每帧被调用,将鼠标事件传入给状态处理函数 # 更新函数每帧被调用,将鼠标事件传入给状态处理函数
def update(self, surface, current_time, mouse_pos, mouse_click): def update(self, surface, current_time, mouse_pos, mouse_click):
self.current_time = self.game_info[c.CURRENT_TIME] = self.pvzTime(current_time) self.current_time = self.game_info[c.CURRENT_TIME] = self.pvzTime(current_time)
@ -356,7 +356,7 @@ class Level(tool.State):
self.initPlay(card_pool) self.initPlay(card_pool)
if self.bar_type == c.CHOSSEBAR_BOWLING: if self.bar_type == c.CHOSSEBAR_BOWLING:
self.initBowlingMap() self.initBowlingMap()
self.setupLittleMenu() self.setupLittleMenu()
def initChoose(self): def initChoose(self):
@ -394,7 +394,7 @@ class Level(tool.State):
self.menubar = menubar.MenuBar(card_list, self.map_data[c.INIT_SUN_NAME]) self.menubar = menubar.MenuBar(card_list, self.map_data[c.INIT_SUN_NAME])
else: else:
self.menubar = menubar.MoveBar(card_list) self.menubar = menubar.MoveBar(card_list)
# 是否拖住植物或者铲子 # 是否拖住植物或者铲子
self.drag_plant = False self.drag_plant = False
self.drag_shovel = False self.drag_shovel = False
@ -449,7 +449,7 @@ class Level(tool.State):
self.shovel_rect.y = self.shovel_box_rect.y = self.shovel_positon[1] self.shovel_rect.y = self.shovel_box_rect.y = self.shovel_positon[1]
self.setupLevelProgressBarImage() self.setupLevelProgressBarImage()
self.setupHugeWaveApprochingImage() self.setupHugeWaveApprochingImage()
self.showHugeWaveApprochingTime = -2000 # 防止设置为0时刚刚打开游戏就已经启动红字 self.showHugeWaveApprochingTime = -2000 # 防止设置为0时刚刚打开游戏就已经启动红字
@ -461,7 +461,7 @@ class Level(tool.State):
# 缺省为少量墓碑 # 缺省为少量墓碑
else: else:
gradeGraves = 1 gradeGraves = 1
graveVolume = c.GRAVES_GRADE_INFO[gradeGraves] graveVolume = c.GRAVES_GRADE_INFO[gradeGraves]
self.graveSet = set() self.graveSet = set()
while len(self.graveSet) < graveVolume: while len(self.graveSet) < graveVolume:
@ -631,7 +631,7 @@ class Level(tool.State):
# 使用后默认铲子复原 # 使用后默认铲子复原
self.drag_shovel = not self.drag_shovel self.drag_shovel = not self.drag_shovel
self.removeMouseImagePlus() self.removeMouseImagePlus()
return return
# 检查小铲子的位置有没有被点击 # 检查小铲子的位置有没有被点击
# 方便放回去 # 方便放回去
@ -818,8 +818,8 @@ class Level(tool.State):
elif name == c.SCREEN_DOOR_ZOMBIE: elif name == c.SCREEN_DOOR_ZOMBIE:
self.zombie_groups[map_y].add(zombie.ScreenDoorZombie(c.ZOMBIE_START_X + randint(-20, 20) + hugeWaveMove, y, self.head_group)) self.zombie_groups[map_y].add(zombie.ScreenDoorZombie(c.ZOMBIE_START_X + randint(-20, 20) + hugeWaveMove, y, self.head_group))
elif name == c.POLE_VAULTING_ZOMBIE: elif name == c.POLE_VAULTING_ZOMBIE:
# 撑杆跳生成位置不同 # 本来撑杆跳生成位置不同对齐左端可认为修正了一部分看作移动了70只需要相对修改即可
self.zombie_groups[map_y].add(zombie.PoleVaultingZombie(c.ZOMBIE_START_X + randint(70, 80) + hugeWaveMove, y, self.head_group)) self.zombie_groups[map_y].add(zombie.PoleVaultingZombie(c.ZOMBIE_START_X + randint(0, 10) + hugeWaveMove, y, self.head_group))
elif name == c.ZOMBONI: elif name == c.ZOMBONI:
# 冰车僵尸生成位置不同 # 冰车僵尸生成位置不同
self.zombie_groups[map_y].add(zombie.Zomboni(c.ZOMBIE_START_X + randint(0, 10) + hugeWaveMove, y, self.plant_groups[map_y], self.map, plant.IceFrozenPlot)) self.zombie_groups[map_y].add(zombie.Zomboni(c.ZOMBIE_START_X + randint(0, 10) + hugeWaveMove, y, self.plant_groups[map_y], self.map, plant.IceFrozenPlot))
@ -830,7 +830,7 @@ class Level(tool.State):
def canSeedPlant(self, plantName): def canSeedPlant(self, plantName):
x, y = pg.mouse.get_pos() x, y = pg.mouse.get_pos()
return self.map.checkPlantToSeed(x, y, plantName) return self.map.checkPlantToSeed(x, y, plantName)
# 种植物 # 种植物
def addPlant(self): def addPlant(self):
pos = self.canSeedPlant(self.plant_name) pos = self.canSeedPlant(self.plant_name)
@ -1006,7 +1006,7 @@ class Level(tool.State):
if abs(rangeZombie.rect.x - bullet.rect.x) <= (c.GRID_X_SIZE // 2): if abs(rangeZombie.rect.x - bullet.rect.x) <= (c.GRID_X_SIZE // 2):
rangeZombie.setDamage(c.BULLET_DAMAGE_FIREBALL_RANGE, effect=None, damageType=c.ZOMBIE_DEAFULT_DAMAGE) rangeZombie.setDamage(c.BULLET_DAMAGE_FIREBALL_RANGE, effect=None, damageType=c.ZOMBIE_DEAFULT_DAMAGE)
break break
def checkZombieCollisions(self): def checkZombieCollisions(self):
for i in range(self.map_y_len): for i in range(self.map_y_len):
@ -1358,7 +1358,7 @@ class Level(tool.State):
if len(self.zombie_groups[i]) > 0: if len(self.zombie_groups[i]) > 0:
return False return False
return True return True
def checkLose(self): def checkLose(self):
for i in range(self.map_y_len): for i in range(self.map_y_len):
for zombie in self.zombie_groups[i]: for zombie in self.zombie_groups[i]:
@ -1390,7 +1390,7 @@ class Level(tool.State):
self.mouse_rect.centerx = x self.mouse_rect.centerx = x
self.mouse_rect.centery = y self.mouse_rect.centery = y
surface.blit(self.mouse_image, self.mouse_rect) surface.blit(self.mouse_image, self.mouse_rect)
def drawMouseShowPlus(self, surface): # 拖动铲子时的显示 def drawMouseShowPlus(self, surface): # 拖动铲子时的显示
x, y = pg.mouse.get_pos() x, y = pg.mouse.get_pos()
self.shovel_rect.centerx = x self.shovel_rect.centerx = x
@ -1445,7 +1445,7 @@ class Level(tool.State):
else: else:
self.level_progress_flag_rect.y = self.level_progress_bar_image_rect.y - 3 # 常数是猜的 self.level_progress_flag_rect.y = self.level_progress_bar_image_rect.y - 3 # 常数是猜的
surface.blit(self.level_progress_flag, self.level_progress_flag_rect) surface.blit(self.level_progress_flag, self.level_progress_flag_rect)
# 画僵尸头 # 画僵尸头
surface.blit(self.level_progress_zombie_head_image, self.level_progress_zombie_head_image_rect) surface.blit(self.level_progress_zombie_head_image, self.level_progress_zombie_head_image_rect)
@ -1485,7 +1485,7 @@ class Level(tool.State):
if self.drag_plant: if self.drag_plant:
self.drawMouseShow(surface) self.drawMouseShow(surface)
if self.hasShovel and self.drag_shovel: if self.hasShovel and self.drag_shovel:
self.drawMouseShowPlus(surface) self.drawMouseShowPlus(surface)