将车改为按行绘制;豌豆通过火炬树桩继承之前的移动轨迹

This commit is contained in:
星外之神 2022-05-14 19:54:58 +08:00
parent ada7d690eb
commit 3a53f772ce
4 changed files with 27 additions and 22 deletions

View File

@ -17,6 +17,6 @@
{"time":0, "map_y":0, "name":"PoleVaultingZombie"}, {"time":0, "map_y":0, "name":"PoleVaultingZombie"},
{"time":6000, "map_y":0, "name":"FootballZombie"}, {"time":6000, "map_y":0, "name":"FootballZombie"},
{"time":0, "map_y":2, "name":"ConeheadDuckyTubeZombie"}, {"time":0, "map_y":2, "name":"ConeheadDuckyTubeZombie"},
{"time":80000, "map_y":2, "name":"ConeheadDuckyTubeZombie"} {"time":90000, "map_y":2, "name":"ConeheadDuckyTubeZombie"}
] ]
} }

View File

@ -340,7 +340,9 @@ class Plant(pg.sprite.Sprite):
if not zombie.lostHead: if not zombie.lostHead:
self.health -= damage self.health -= damage
self.hit_timer = self.current_time self.hit_timer = self.current_time
if (self.name == c.HYPNOSHROOM) and (self.state != c.SLEEP) and (zombie.name not in {"投石车僵尸(未实现)"}): if ((self.name == c.HYPNOSHROOM) and
(self.state != c.SLEEP) and
(zombie.name not in {c.ZOMBONI, "投石车僵尸(未实现)", "加刚特尔(未实现)"})):
self.zombie_to_hypno = zombie self.zombie_to_hypno = zombie
def getPosition(self): def getPosition(self):
@ -1254,13 +1256,13 @@ class TorchWood(Plant):
if i.name == c.BULLET_PEA: if i.name == c.BULLET_PEA:
if i.passedTorchWood != self.rect.centerx: if i.passedTorchWood != self.rect.centerx:
if abs(i.rect.centerx - self.rect.centerx) <= 20: if abs(i.rect.centerx - self.rect.centerx) <= 20:
self.bullet_group.add(Bullet(i.rect.x, i.rect.y, i.rect.y, self.bullet_group.add(Bullet(i.rect.x, i.rect.y, i.dest_y,
c.BULLET_FIREBALL, c.BULLET_DAMAGE_FIREBALL_BODY, effect=c.BULLET_EFFECT_UNICE, passedTorchWood=self.rect.centerx)) c.BULLET_FIREBALL, c.BULLET_DAMAGE_FIREBALL_BODY, effect=c.BULLET_EFFECT_UNICE, passedTorchWood=self.rect.centerx))
i.kill() i.kill()
elif i.name == c.BULLET_PEA_ICE: elif i.name == c.BULLET_PEA_ICE:
if i.passedTorchWood != self.rect.centerx: if i.passedTorchWood != self.rect.centerx:
if abs(i.rect.centerx - self.rect.centerx) <= 20: if abs(i.rect.centerx - self.rect.centerx) <= 20:
self.bullet_group.add(Bullet(i.rect.x, i.rect.y, i.rect.y, self.bullet_group.add(Bullet(i.rect.x, i.rect.y, i.dest_y,
c.BULLET_PEA, c.BULLET_DAMAGE_NORMAL, effect=None, passedTorchWood=self.rect.centerx)) c.BULLET_PEA, c.BULLET_DAMAGE_NORMAL, effect=None, passedTorchWood=self.rect.centerx))
i.kill() i.kill()

View File

@ -1001,7 +1001,7 @@ class Zomboni(Zombie):
if ((plant.name not in {c.SPIKEWEED}) if ((plant.name not in {c.SPIKEWEED})
and (self.rect.centerx <= plant.rect.right <= self.rect.right)): and (self.rect.centerx <= plant.rect.right <= self.rect.right)):
# 扣除生命值为可能的最大有限生命值 # 扣除生命值为可能的最大有限生命值
plant.setDamage(8000, self) plant.health -= 8000
# 造冰 # 造冰
mapX, mapY = self.map.getMapIndex(self.rect.right - 20, self.rect.bottom) mapX, mapY = self.map.getMapIndex(self.rect.right - 20, self.rect.bottom)

View File

@ -771,7 +771,8 @@ class Level(tool.State):
self.shovelRemovePlant(mouse_pos) self.shovelRemovePlant(mouse_pos)
for car in self.cars: for car in self.cars:
car.update(self.game_info) if car:
car.update(self.game_info)
self.menubar.update(self.current_time) self.menubar.update(self.current_time)
@ -1154,15 +1155,16 @@ class Level(tool.State):
self.newPlantAndPositon = None # 生效后需要解除刷新设置 self.newPlantAndPositon = None # 生效后需要解除刷新设置
def checkCarCollisions(self): def checkCarCollisions(self):
for car in self.cars: for i in range(len(self.cars)):
for zombie in self.zombie_groups[car.map_y]: if self.cars[i]:
if zombie and zombie.state != c.DIE and (not zombie.lostHead) and (zombie.rect.centerx <= 0): for zombie in self.zombie_groups[i]:
car.setWalk() if zombie and zombie.state != c.DIE and (not zombie.lostHead) and (zombie.rect.centerx <= 0):
if zombie.rect.centerx <= car.rect.x: self.cars[i].setWalk()
zombie.health = 0 if zombie.rect.centerx <= self.cars[i].rect.x:
zombie.kill() zombie.health = 0
if car.dead: zombie.kill()
self.cars.remove(car) if self.cars[i].dead:
self.cars[i] = None
def boomZombies(self, x, map_y, y_range, x_range, effect=None): def boomZombies(self, x, map_y, y_range, x_range, effect=None):
for i in range(self.map_y_len): for i in range(self.map_y_len):
@ -1217,11 +1219,12 @@ class Level(tool.State):
elif targetPlant.name == c.ICESHROOM and targetPlant.state != c.SLEEP: elif targetPlant.name == c.ICESHROOM and targetPlant.state != c.SLEEP:
self.freezeZombies(targetPlant) self.freezeZombies(targetPlant)
elif targetPlant.name == c.HYPNOSHROOM and targetPlant.state != c.SLEEP: elif targetPlant.name == c.HYPNOSHROOM and targetPlant.state != c.SLEEP:
zombie = targetPlant.zombie_to_hypno if targetPlant.zombie_to_hypno:
zombie.setHypno() zombie = targetPlant.zombie_to_hypno
_, map_y = self.map.getMapIndex(zombie.rect.centerx, zombie.rect.bottom) zombie.setHypno()
self.zombie_groups[map_y].remove(zombie) _, map_y = self.map.getMapIndex(zombie.rect.centerx, zombie.rect.bottom)
self.hypno_zombie_groups[map_y].add(zombie) self.zombie_groups[map_y].remove(zombie)
self.hypno_zombie_groups[map_y].add(zombie)
elif (targetPlant.name == c.POTATOMINE and not targetPlant.is_init): # 土豆雷不是灰烬植物不能用Boom elif (targetPlant.name == c.POTATOMINE and not targetPlant.is_init): # 土豆雷不是灰烬植物不能用Boom
for zombie in self.zombie_groups[map_y]: for zombie in self.zombie_groups[map_y]:
# 双判断:发生碰撞或在攻击范围内 # 双判断:发生碰撞或在攻击范围内
@ -1488,14 +1491,14 @@ class Level(tool.State):
surface.blit(self.little_menu, self.little_menu_rect) surface.blit(self.little_menu, self.little_menu_rect)
self.menubar.draw(surface) self.menubar.draw(surface)
for car in self.cars:
car.draw(surface)
for i in range(self.map_y_len): for i in range(self.map_y_len):
self.plant_groups[i].draw(surface) self.plant_groups[i].draw(surface)
self.zombie_groups[i].draw(surface) self.zombie_groups[i].draw(surface)
self.hypno_zombie_groups[i].draw(surface) self.hypno_zombie_groups[i].draw(surface)
self.bullet_groups[i].draw(surface) self.bullet_groups[i].draw(surface)
self.drawZombieFreezeTrap(i, surface) self.drawZombieFreezeTrap(i, surface)
if self.cars[i]:
self.cars[i].draw(surface)
self.head_group.draw(surface) self.head_group.draw(surface)
self.sun_group.draw(surface) self.sun_group.draw(surface)