diff --git a/resources/data/map/level_0.json b/resources/data/map/level_0.json index 1bc5e1e..4067036 100644 --- a/resources/data/map/level_0.json +++ b/resources/data/map/level_0.json @@ -1,5 +1,5 @@ { - "background_type":1, + "background_type":2, "init_sun_value":5000, "shovel":1, "zombie_list":[ diff --git a/source/component/map.py b/source/component/map.py index c57db74..33df184 100755 --- a/source/component/map.py +++ b/source/component/map.py @@ -63,7 +63,7 @@ class Map(): return False else: return False - else: # 水里 + elif self.map[map_y][map_x][c.MAP_PLOT_TYPE] == c.MAP_WATER: # 水里 if plantName in {c.LILYPAD, '海蘑菇(未实现)', '缠绕水草(未实现)'}: # 是水生植物 if not self.map[map_y][map_x][c.MAP_PLANT]: # 只有无植物时才能在水里种植水生植物 return True @@ -71,9 +71,9 @@ class Map(): return False else: # 非水生植物,依赖睡莲 if c.LILYPAD in self.map[map_y][map_x][c.MAP_PLANT]: - if ((self.map[map_y][map_x][c.MAP_PLANT] | {c.LILYPAD, '花盆(未实现)', '南瓜头(未实现)'} == {c.LILYPAD, '花盆(未实现)', '南瓜头(未实现)'}) + if ((self.map[map_y][map_x][c.MAP_PLANT] | {c.LILYPAD, '南瓜头(未实现)'} == {c.LILYPAD, '南瓜头(未实现)'}) and (plantName not in self.map[map_y][map_x][c.MAP_PLANT])): # 例外植物:集合中填花盆和南瓜头,只要这里没有这种植物就能种植;判断方法:并集 - if plantName in {c.SPIKEWEED}: # 不能在睡莲上种植的植物 + if plantName in {c.SPIKEWEED, '花盆(未实现)'}: # 不能在睡莲上种植的植物 return False else: return True @@ -81,6 +81,8 @@ class Map(): return False else: return False + else: # 不可种植区域 + return False def getMapIndex(self, x, y): # 引入新地图后需要增加这里的内容 diff --git a/source/component/plant.py b/source/component/plant.py index 77d2c59..dd4d0d5 100755 --- a/source/component/plant.py +++ b/source/component/plant.py @@ -107,6 +107,7 @@ class Bullet(pg.sprite.Sprite): def draw(self, surface): surface.blit(self.image, self.rect) +# 暂时是杨桃的子弹,以后可以扩展到非定行飞行的子弹 class StarBullet(Bullet): def __init__(self, x, y, name): self.name = name diff --git a/source/component/zombie.py b/source/component/zombie.py index f7b1f29..a486839 100755 --- a/source/component/zombie.py +++ b/source/component/zombie.py @@ -299,6 +299,7 @@ class Zombie(pg.sprite.Sprite): def setAttack(self, prey, is_plant=True): self.prey = prey # prey can be plant or other zombies + print(self.prey) self.prey_is_plant = is_plant self.state = c.ATTACK self.attack_timer = self.current_time diff --git a/source/constants.py b/source/constants.py index a8f8441..99c37a9 100755 --- a/source/constants.py +++ b/source/constants.py @@ -1,4 +1,4 @@ -START_LEVEL_NUM = 1 +START_LEVEL_NUM = 0 START_LITTLE_GAME_NUM = 1 ORIGINAL_CAPTION = 'pypvz' @@ -98,6 +98,7 @@ MAP_PLOT_TYPE = 'plotType' MAP_GRASS = 'grass' MAP_WATER = 'water' MAP_TILE = 'tile' # 指屋顶上的瓦片 +MAP_DAMAGED = 'damaged' MAP_STATE_EMPTY = {MAP_PLANT:set(), MAP_SLEEP:False, MAP_PLOT_TYPE:MAP_GRASS} # 由于同一格显然不可能种两个相同的植物,所以用集合 MAP_STATE_WATER = {MAP_PLANT:set(), MAP_SLEEP:False, MAP_PLOT_TYPE:MAP_WATER} MAP_STATE_TILE = {MAP_PLANT:set(), MAP_SLEEP:False, MAP_PLOT_TYPE:MAP_TILE} diff --git a/source/state/level.py b/source/state/level.py index 0dd0d46..75db34d 100644 --- a/source/state/level.py +++ b/source/state/level.py @@ -185,6 +185,10 @@ class Level(tool.State): self.hint_image = None self.hint_plant = False + + # 种植植物后应当刷新僵尸的攻击对象,当然,默认初始时不用刷新 + self.refreshZombieAttack = False + # 0:白天 1:夜晚 2:泳池 3:浓雾 4:屋顶 5:月夜 6:坚果保龄球 # 还准备加入 7:单行草皮 8:三行草皮 但是目前没有找到图( if self.background_type in {0, 2, 4, 7, 8} and self.bar_type == c.CHOOSEBAR_STATIC: @@ -285,6 +289,14 @@ class Level(tool.State): for i in self.plant_groups[map_y]: if (x >= i.rect.x and x <= i.rect.right and y >= i.rect.y and y <= i.rect.bottom): + # 优先移除花盆、睡莲上的植物而非花盆、睡莲本身 + if len(self.map.map[map_y][map_x][c.MAP_PLANT]) >= 2: + if c.LILYPAD in self.map.map[map_y][map_x][c.MAP_PLANT]: + if i.name == c.LILYPAD: + continue + elif '花盆(未实现)' in self.map.map[map_y][map_x][c.MAP_PLANT]: + if i.name == '花盆(未实现)': + continue self.killPlant(i, shovel=True) # 使用后默认铲子复原 self.drag_shovel = not self.drag_shovel @@ -526,6 +538,8 @@ class Level(tool.State): else: mushroomSleep = False self.plant_groups[map_y].add(new_plant) + # 种植植物后应当刷新僵尸的攻击对象 + self.refreshZombieAttack = True if self.bar_type == c.CHOOSEBAR_STATIC: self.menubar.decreaseSunValue(self.select_plant.sun_cost) self.menubar.setCardFrozenTime(self.plant_name) @@ -618,7 +632,8 @@ class Level(tool.State): hypo_zombies = [] for zombie in self.zombie_groups[i]: if zombie.state != c.WALK: - continue + if not self.refreshZombieAttack: + continue plant = pg.sprite.spritecollideany(zombie, self.plant_groups[i], collided_func) if plant: if plant.name == c.WALLNUTBOWLING: @@ -630,8 +645,23 @@ class Level(tool.State): elif plant.name == c.REDWALLNUTBOWLING: if plant.state == c.IDLE: plant.setAttack() - elif plant.name != c.SPIKEWEED: - zombie.setAttack(plant) + elif plant.name == c.SPIKEWEED: + continue + # 在睡莲、花盆上有植物时应当优先攻击其上的植物 + # 这一段代码目前未能生效 + elif plant.name in {c.LILYPAD, '花盆(未实现)'}: + map_x, map_y = self.map.getMapIndex(plant.rect.centerx, plant.rect.bottom) + if len(self.map.map[map_y][map_x][c.MAP_PLANT]) >= 2: + # 这里暂时没有南瓜头优先攻击逻辑,这整个模块都没有对南瓜头的设计 + for actualTargetPlant in self.plant_groups[i]: + # 检测同一格的其他植物 + if self.map.getMapIndex(actualTargetPlant.rect.centerx, actualTargetPlant.rect.bottom) == (map_x, map_y): + if actualTargetPlant.name != c.LILYPAD: + zombie.setAttack(actualTargetPlant) + continue + zombie.setAttack(plant) + else: + self.refreshZombieAttack = False # 生效后需要解除刷新设置 for hypno_zombie in self.hypno_zombie_groups[i]: if hypno_zombie.health <= 0: @@ -846,6 +876,14 @@ class Level(tool.State): for i in self.plant_groups[map_y]: if (x >= i.rect.x and x <= i.rect.right and y >= i.rect.y and y <= i.rect.bottom): + # 优先选中睡莲、花盆上的植物 + if len(self.map.map[map_y][map_x][c.MAP_PLANT]) >= 2: + if c.LILYPAD in self.map.map[map_y][map_x][c.MAP_PLANT]: + if i.name == c.LILYPAD: + continue + elif '花盆(未实现)' in self.map.map[map_y][map_x][c.MAP_PLANT]: + if i.name == '花盆(未实现)': + continue i.highlightTime = self.current_time return