To compile with Nuitka bug of match-case

This commit is contained in:
星外之神 2022-07-20 14:12:30 +08:00
parent 42e67c0d26
commit 9fa2521396
2 changed files with 93 additions and 94 deletions

View File

@ -21,7 +21,7 @@
## 环境要求 ## 环境要求
* `Python` >= 3.10,最好使用最新版 * `Python` >= 3.7,最好使用最新版
* `Python-Pygame` >= 1.9,最好使用最新版 * `Python-Pygame` >= 1.9,最好使用最新版
## 开始游戏 ## 开始游戏

View File

@ -809,34 +809,34 @@ class Level(tool.State):
x, y = self.map.getMapGridPos(0, map_y) x, y = self.map.getMapGridPos(0, map_y)
# 新增的僵尸也需要在这里声明 # 新增的僵尸也需要在这里声明
match name: if name == c.NORMAL_ZOMBIE:
case c.NORMAL_ZOMBIE:
self.zombie_groups[map_y].add(zombie.NormalZombie(c.ZOMBIE_START_X + random.randint(-20, 20) + hugeWaveMove, y, self.head_group)) self.zombie_groups[map_y].add(zombie.NormalZombie(c.ZOMBIE_START_X + random.randint(-20, 20) + hugeWaveMove, y, self.head_group))
case c.CONEHEAD_ZOMBIE: elif name == c.CONEHEAD_ZOMBIE:
self.zombie_groups[map_y].add(zombie.ConeHeadZombie(c.ZOMBIE_START_X + random.randint(-20, 20) + hugeWaveMove, y, self.head_group)) self.zombie_groups[map_y].add(zombie.ConeHeadZombie(c.ZOMBIE_START_X + random.randint(-20, 20) + hugeWaveMove, y, self.head_group))
case c.BUCKETHEAD_ZOMBIE: elif name == c.BUCKETHEAD_ZOMBIE:
self.zombie_groups[map_y].add(zombie.BucketHeadZombie(c.ZOMBIE_START_X + random.randint(-20, 20) + hugeWaveMove, y, self.head_group)) self.zombie_groups[map_y].add(zombie.BucketHeadZombie(c.ZOMBIE_START_X + random.randint(-20, 20) + hugeWaveMove, y, self.head_group))
case c.FLAG_ZOMBIE: elif name == c.FLAG_ZOMBIE:
self.zombie_groups[map_y].add(zombie.FlagZombie(c.ZOMBIE_START_X, y, self.head_group)) self.zombie_groups[map_y].add(zombie.FlagZombie(c.ZOMBIE_START_X, y, self.head_group))
case c.NEWSPAPER_ZOMBIE: elif name == c.NEWSPAPER_ZOMBIE:
self.zombie_groups[map_y].add(zombie.NewspaperZombie(c.ZOMBIE_START_X + random.randint(-20, 20) + hugeWaveMove, y, self.head_group)) self.zombie_groups[map_y].add(zombie.NewspaperZombie(c.ZOMBIE_START_X + random.randint(-20, 20) + hugeWaveMove, y, self.head_group))
case c.FOOTBALL_ZOMBIE: elif name == c.FOOTBALL_ZOMBIE:
self.zombie_groups[map_y].add(zombie.FootballZombie(c.ZOMBIE_START_X + random.randint(-20, 20) + hugeWaveMove, y, self.head_group)) self.zombie_groups[map_y].add(zombie.FootballZombie(c.ZOMBIE_START_X + random.randint(-20, 20) + hugeWaveMove, y, self.head_group))
case c.DUCKY_TUBE_ZOMBIE: elif name == c.DUCKY_TUBE_ZOMBIE:
self.zombie_groups[map_y].add(zombie.DuckyTubeZombie(c.ZOMBIE_START_X + random.randint(-20, 20) + hugeWaveMove, y, self.head_group)) self.zombie_groups[map_y].add(zombie.DuckyTubeZombie(c.ZOMBIE_START_X + random.randint(-20, 20) + hugeWaveMove, y, self.head_group))
case c.CONEHEAD_DUCKY_TUBE_ZOMBIE: elif name == c.CONEHEAD_DUCKY_TUBE_ZOMBIE:
self.zombie_groups[map_y].add(zombie.ConeHeadDuckyTubeZombie(c.ZOMBIE_START_X + random.randint(-20, 20) + hugeWaveMove, y, self.head_group)) self.zombie_groups[map_y].add(zombie.ConeHeadDuckyTubeZombie(c.ZOMBIE_START_X + random.randint(-20, 20) + hugeWaveMove, y, self.head_group))
case c.BUCKETHEAD_DUCKY_TUBE_ZOMBIE: elif name == c.BUCKETHEAD_DUCKY_TUBE_ZOMBIE:
self.zombie_groups[map_y].add(zombie.BucketHeadDuckyTubeZombie(c.ZOMBIE_START_X + random.randint(-20, 20) + hugeWaveMove, y, self.head_group)) self.zombie_groups[map_y].add(zombie.BucketHeadDuckyTubeZombie(c.ZOMBIE_START_X + random.randint(-20, 20) + hugeWaveMove, y, self.head_group))
case c.SCREEN_DOOR_ZOMBIE: elif name == c.SCREEN_DOOR_ZOMBIE:
self.zombie_groups[map_y].add(zombie.ScreenDoorZombie(c.ZOMBIE_START_X + random.randint(-20, 20) + hugeWaveMove, y, self.head_group)) self.zombie_groups[map_y].add(zombie.ScreenDoorZombie(c.ZOMBIE_START_X + random.randint(-20, 20) + hugeWaveMove, y, self.head_group))
case c.POLE_VAULTING_ZOMBIE: elif name == c.POLE_VAULTING_ZOMBIE:
# 本来撑杆跳生成位置不同对齐左端可认为修正了一部分看作移动了70只需要相对修改即可 # 本来撑杆跳生成位置不同对齐左端可认为修正了一部分看作移动了70只需要相对修改即可
self.zombie_groups[map_y].add(zombie.PoleVaultingZombie(c.ZOMBIE_START_X + random.randint(0, 10) + hugeWaveMove, y, self.head_group)) self.zombie_groups[map_y].add(zombie.PoleVaultingZombie(c.ZOMBIE_START_X + random.randint(0, 10) + hugeWaveMove, y, self.head_group))
case c.ZOMBONI: elif name == c.ZOMBONI:
# 冰车僵尸生成位置不同 # 冰车僵尸生成位置不同
self.zombie_groups[map_y].add(zombie.Zomboni(c.ZOMBIE_START_X + random.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 + random.randint(0, 10) + hugeWaveMove, y, self.plant_groups[map_y], self.map, plant.IceFrozenPlot))
case c.SNORKELZOMBIE: elif name == c.SNORKELZOMBIE:
# 潜水僵尸生成位置不同
self.zombie_groups[map_y].add(zombie.SnorkelZombie(c.ZOMBIE_START_X + random.randint(0, 10) + hugeWaveMove, y, self.head_group)) self.zombie_groups[map_y].add(zombie.SnorkelZombie(c.ZOMBIE_START_X + random.randint(0, 10) + hugeWaveMove, y, self.head_group))
# 能否种植物的判断: # 能否种植物的判断:
@ -861,69 +861,68 @@ class Level(tool.State):
map_x, map_y = self.map.getMapIndex(x, y) map_x, map_y = self.map.getMapIndex(x, y)
# 新植物也需要在这里声明 # 新植物也需要在这里声明
match self.plant_name: if self.plant_name == c.SUNFLOWER:
case c.SUNFLOWER:
new_plant = plant.SunFlower(x, y, self.sun_group) new_plant = plant.SunFlower(x, y, self.sun_group)
case c.PEASHOOTER: elif self.plant_name == c.PEASHOOTER:
new_plant = plant.PeaShooter(x, y, self.bullet_groups[map_y]) new_plant = plant.PeaShooter(x, y, self.bullet_groups[map_y])
case c.SNOWPEASHOOTER: elif self.plant_name == c.SNOWPEASHOOTER:
new_plant = plant.SnowPeaShooter(x, y, self.bullet_groups[map_y]) new_plant = plant.SnowPeaShooter(x, y, self.bullet_groups[map_y])
case c.WALLNUT: elif self.plant_name == c.WALLNUT:
new_plant = plant.WallNut(x, y) new_plant = plant.WallNut(x, y)
case c.CHERRYBOMB: elif self.plant_name == c.CHERRYBOMB:
new_plant = plant.CherryBomb(x, y) new_plant = plant.CherryBomb(x, y)
case c.THREEPEASHOOTER: elif self.plant_name == c.THREEPEASHOOTER:
new_plant = plant.ThreePeaShooter(x, y, self.bullet_groups, map_y, self.map.background_type) new_plant = plant.ThreePeaShooter(x, y, self.bullet_groups, map_y, self.map.background_type)
case c.REPEATERPEA: elif self.plant_name == c.REPEATERPEA:
new_plant = plant.RepeaterPea(x, y, self.bullet_groups[map_y]) new_plant = plant.RepeaterPea(x, y, self.bullet_groups[map_y])
case c.CHOMPER: elif self.plant_name == c.CHOMPER:
new_plant = plant.Chomper(x, y) new_plant = plant.Chomper(x, y)
case c.PUFFSHROOM: elif self.plant_name == c.PUFFSHROOM:
new_plant = plant.PuffShroom(x, y, self.bullet_groups[map_y]) new_plant = plant.PuffShroom(x, y, self.bullet_groups[map_y])
case c.POTATOMINE: elif self.plant_name == c.POTATOMINE:
new_plant = plant.PotatoMine(x, y) new_plant = plant.PotatoMine(x, y)
case c.SQUASH: elif self.plant_name == c.SQUASH:
new_plant = plant.Squash(x, y, self.map.map[map_y][map_x][c.MAP_PLANT]) new_plant = plant.Squash(x, y, self.map.map[map_y][map_x][c.MAP_PLANT])
case c.SPIKEWEED: elif self.plant_name == c.SPIKEWEED:
new_plant = plant.Spikeweed(x, y) new_plant = plant.Spikeweed(x, y)
case c.JALAPENO: elif self.plant_name == c.JALAPENO:
new_plant = plant.Jalapeno(x, y) new_plant = plant.Jalapeno(x, y)
case c.SCAREDYSHROOM: elif self.plant_name == c.SCAREDYSHROOM:
new_plant = plant.ScaredyShroom(x, y, self.bullet_groups[map_y]) new_plant = plant.ScaredyShroom(x, y, self.bullet_groups[map_y])
case c.SUNSHROOM: elif self.plant_name == c.SUNSHROOM:
new_plant = plant.SunShroom(x, y, self.sun_group) new_plant = plant.SunShroom(x, y, self.sun_group)
case c.ICESHROOM: elif self.plant_name == c.ICESHROOM:
new_plant = plant.IceShroom(x, y) new_plant = plant.IceShroom(x, y)
case c.HYPNOSHROOM: elif self.plant_name == c.HYPNOSHROOM:
new_plant = plant.HypnoShroom(x, y) new_plant = plant.HypnoShroom(x, y)
case c.WALLNUTBOWLING: elif self.plant_name == c.WALLNUTBOWLING:
new_plant = plant.WallNutBowling(x, y, map_y, self) new_plant = plant.WallNutBowling(x, y, map_y, self)
case c.REDWALLNUTBOWLING: elif self.plant_name == c.REDWALLNUTBOWLING:
new_plant = plant.RedWallNutBowling(x, y) new_plant = plant.RedWallNutBowling(x, y)
case c.LILYPAD: elif self.plant_name == c.LILYPAD:
new_plant = plant.LilyPad(x, y) new_plant = plant.LilyPad(x, y)
case c.TORCHWOOD: elif self.plant_name == c.TORCHWOOD:
new_plant = plant.TorchWood(x, y, self.bullet_groups[map_y]) new_plant = plant.TorchWood(x, y, self.bullet_groups[map_y])
case c.STARFRUIT: elif self.plant_name == c.STARFRUIT:
new_plant = plant.StarFruit(x, y, self.bullet_groups[map_y], self) new_plant = plant.StarFruit(x, y, self.bullet_groups[map_y], self)
case c.COFFEEBEAN: elif self.plant_name == c.COFFEEBEAN:
new_plant = plant.CoffeeBean(x, y, self.plant_groups[map_y], self.map.map[map_y][map_x], self.map, map_x) new_plant = plant.CoffeeBean(x, y, self.plant_groups[map_y], self.map.map[map_y][map_x], self.map, map_x)
case c.SEASHROOM: elif self.plant_name == c.SEASHROOM:
new_plant = plant.SeaShroom(x, y, self.bullet_groups[map_y]) new_plant = plant.SeaShroom(x, y, self.bullet_groups[map_y])
case c.TALLNUT: elif self.plant_name == c.TALLNUT:
new_plant = plant.TallNut(x, y) new_plant = plant.TallNut(x, y)
case c.TANGLEKLEP: elif self.plant_name == c.TANGLEKLEP:
new_plant = plant.TangleKlep(x, y) new_plant = plant.TangleKlep(x, y)
case c.DOOMSHROOM: elif self.plant_name == c.DOOMSHROOM:
if self.map.gridHeightSize == c.GRID_Y_SIZE: if self.map.gridHeightSize == c.GRID_Y_SIZE:
new_plant = plant.DoomShroom(x, y, self.map.map[map_y][map_x][c.MAP_PLANT], explode_y_range=3)
else:
new_plant = plant.DoomShroom(x, y, self.map.map[map_y][map_x][c.MAP_PLANT], explode_y_range=2) new_plant = plant.DoomShroom(x, y, self.map.map[map_y][map_x][c.MAP_PLANT], explode_y_range=2)
case c.GRAVEBUSTER: else:
new_plant = plant.DoomShroom(x, y, self.map.map[map_y][map_x][c.MAP_PLANT], explode_y_range=3)
elif self.plant_name == c.GRAVEBUSTER:
new_plant = plant.GraveBuster(x, y, self.plant_groups[map_y], self.map, map_x) new_plant = plant.GraveBuster(x, y, self.plant_groups[map_y], self.map, map_x)
case c.FUMESHROOM: elif self.plant_name == c.FUMESHROOM:
new_plant = plant.FumeShroom(x, y, self.bullet_groups[map_y], self.zombie_groups[map_y]) new_plant = plant.FumeShroom(x, y, self.bullet_groups[map_y], self.zombie_groups[map_y])
case c.GARLIC: elif self.plant_name == c.GARLIC:
new_plant = plant.Garlic(x, y) new_plant = plant.Garlic(x, y)