统一命名规则:function、method用驼峰命名法变量用下划线命名法

This commit is contained in:
星外之神 2022-08-01 14:37:39 +08:00
parent 93259a2380
commit 7c2b72152d
3 changed files with 493 additions and 488 deletions

View File

@ -37,7 +37,9 @@ class Car(pg.sprite.Sprite):
# 豌豆及孢子类普通子弹 # 豌豆及孢子类普通子弹
class Bullet(pg.sprite.Sprite): class Bullet(pg.sprite.Sprite):
def __init__(self, x, start_y, dest_y, name, damage, effect=None, passedTorchWood=None, damageType=c.ZOMBIE_DEAFULT_DAMAGE): def __init__( self, x, start_y, dest_y, name, damage,
effect=None, passed_torchwood_x=None,
damageType=c.ZOMBIE_DEAFULT_DAMAGE):
pg.sprite.Sprite.__init__(self) pg.sprite.Sprite.__init__(self)
self.name = name self.name = name
@ -60,7 +62,7 @@ class Bullet(pg.sprite.Sprite):
self.current_time = 0 self.current_time = 0
self.animate_timer = 0 self.animate_timer = 0
self.animate_interval = 70 self.animate_interval = 70
self.passedTorchWood = passedTorchWood # 记录最近通过的火炬树横坐标如果没有缺省为None self.passed_torchwood_x = passed_torchwood_x # 记录最近通过的火炬树横坐标如果没有缺省为None
def loadFrames(self, frames, name): def loadFrames(self, frames, name):
frame_list = tool.GFX[name] frame_list = tool.GFX[name]
@ -248,7 +250,7 @@ class Plant(pg.sprite.Sprite):
self.animate_interval = 70 # 帧播放间隔 self.animate_interval = 70 # 帧播放间隔
self.hit_timer = 0 self.hit_timer = 0
# 被铲子指向时间 # 被铲子指向时间
self.highlightTime = 0 self.highlight_time = 0
def loadFrames(self, frames, name, scale=1, color=c.BLACK): def loadFrames(self, frames, name, scale=1, color=c.BLACK):
frame_list = tool.GFX[name] frame_list = tool.GFX[name]
@ -267,7 +269,7 @@ class Plant(pg.sprite.Sprite):
self.loadFrames(self.frames, name, scale) self.loadFrames(self.frames, name, scale)
def changeFrames(self, frames): def changeFrames(self, frames):
"""change image frames and modify rect position""" # change image frames and modify rect position
self.frames = frames self.frames = frames
self.frame_num = len(self.frames) self.frame_num = len(self.frames)
self.frame_index = 0 self.frame_index = 0
@ -311,7 +313,7 @@ class Plant(pg.sprite.Sprite):
self.image = self.frames[self.frame_index] self.image = self.frames[self.frame_index]
self.mask = pg.mask.from_surface(self.image) self.mask = pg.mask.from_surface(self.image)
if (self.current_time - self.highlightTime < 100): if (self.current_time - self.highlight_time < 100):
self.image.set_alpha(150) self.image.set_alpha(150)
elif ((self.current_time - self.hit_timer) < 200): elif ((self.current_time - self.hit_timer) < 200):
self.image.set_alpha(192) self.image.set_alpha(192)
@ -338,7 +340,7 @@ class Plant(pg.sprite.Sprite):
self.changeFrames(self.sleep_frames) self.changeFrames(self.sleep_frames)
def setDamage(self, damage, zombie): def setDamage(self, damage, zombie):
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 if ((self.name == c.HYPNOSHROOM) and
@ -429,20 +431,20 @@ class RepeaterPea(Plant):
self.shoot_timer = 0 self.shoot_timer = 0
# 是否发射第一颗 # 是否发射第一颗
self.firstShot = False self.first_shot = False
def attacking(self): def attacking(self):
if self.shoot_timer == 0: if self.shoot_timer == 0:
self.shoot_timer = self.current_time - 700 self.shoot_timer = self.current_time - 700
elif (self.current_time - self.shoot_timer >= 1400): elif (self.current_time - self.shoot_timer >= 1400):
self.firstShot = True self.first_shot = True
self.bullet_group.add(Bullet(self.rect.right - 15, self.rect.y, self.rect.y, self.bullet_group.add(Bullet(self.rect.right - 15, self.rect.y, self.rect.y,
c.BULLET_PEA, c.BULLET_DAMAGE_NORMAL, effect=None)) c.BULLET_PEA, c.BULLET_DAMAGE_NORMAL, effect=None))
self.shoot_timer = self.current_time self.shoot_timer = self.current_time
# 播放发射音效 # 播放发射音效
c.SOUND_SHOOT.play() c.SOUND_SHOOT.play()
elif self.firstShot and (self.current_time - self.shoot_timer) > 100: elif self.first_shot and (self.current_time - self.shoot_timer) > 100:
self.firstShot = False self.first_shot = False
self.bullet_group.add(Bullet(self.rect.right - 15, self.rect.y, self.rect.y, self.bullet_group.add(Bullet(self.rect.right - 15, self.rect.y, self.rect.y,
c.BULLET_PEA, c.BULLET_DAMAGE_NORMAL, effect=None)) c.BULLET_PEA, c.BULLET_DAMAGE_NORMAL, effect=None))
# 播放发射音效 # 播放发射音效
@ -580,7 +582,7 @@ class CherryBomb(Plant):
self.image = self.frames[self.frame_index] self.image = self.frames[self.frame_index]
self.mask = pg.mask.from_surface(self.image) self.mask = pg.mask.from_surface(self.image)
if (self.current_time - self.highlightTime < 100): if (self.current_time - self.highlight_time < 100):
self.image.set_alpha(150) self.image.set_alpha(150)
elif ((self.current_time - self.hit_timer) < 200): elif ((self.current_time - self.hit_timer) < 200):
self.image.set_alpha(192) self.image.set_alpha(192)
@ -596,7 +598,7 @@ class Chomper(Plant):
self.digest_interval = 15000 self.digest_interval = 15000
self.attack_zombie = None self.attack_zombie = None
self.zombie_group = None self.zombie_group = None
self.shouldDiggest = False self.should_diggest = False
def loadImages(self, name, scale): def loadImages(self, name, scale):
self.idle_frames = [] self.idle_frames = []
@ -624,7 +626,7 @@ class Chomper(Plant):
if (zombie.name == c.SNORKELZOMBIE) and (zombie.frames == zombie.swim_frames): if (zombie.name == c.SNORKELZOMBIE) and (zombie.frames == zombie.swim_frames):
return False return False
elif (self.state == c.IDLE and zombie.state != c.DIGEST and elif (self.state == c.IDLE and zombie.state != c.DIGEST and
self.rect.x <= zombie.rect.centerx and (not zombie.lostHead) and self.rect.x <= zombie.rect.centerx and (not zombie.losthead) and
(self.rect.x + c.GRID_X_SIZE*2.7 >= zombie.rect.centerx)): (self.rect.x + c.GRID_X_SIZE*2.7 >= zombie.rect.centerx)):
return True return True
return False return False
@ -648,12 +650,12 @@ class Chomper(Plant):
# 播放吞的音效 # 播放吞的音效
c.SOUND_BIGCHOMP.play() c.SOUND_BIGCHOMP.play()
if self.attack_zombie.alive(): if self.attack_zombie.alive():
self.shouldDiggest = True self.should_diggest = True
self.attack_zombie.kill() self.attack_zombie.kill()
if (self.frame_index + 1) == self.frame_num: if (self.frame_index + 1) == self.frame_num:
if self.shouldDiggest: if self.should_diggest:
self.setDigest() self.setDigest()
self.shouldDiggest = False self.should_diggest = False
else: else:
self.setIdle() self.setIdle()
@ -751,7 +753,7 @@ class PotatoMine(Plant):
return False return False
# 这里碰撞应当比碰撞一般更容易就设置成圆形或矩形模式不宜采用mask # 这里碰撞应当比碰撞一般更容易就设置成圆形或矩形模式不宜采用mask
elif (pg.sprite.collide_circle_ratio(0.7)(zombie, self) and elif (pg.sprite.collide_circle_ratio(0.7)(zombie, self) and
(not self.is_init) and (not zombie.lostHead)): (not self.is_init) and (not zombie.losthead)):
return True return True
return False return False
@ -767,12 +769,12 @@ class PotatoMine(Plant):
class Squash(Plant): class Squash(Plant):
def __init__(self, x, y, mapPlantsSet): def __init__(self, x, y, map_plant_set):
Plant.__init__(self, x, y, c.SQUASH, c.PLANT_HEALTH, None) Plant.__init__(self, x, y, c.SQUASH, c.PLANT_HEALTH, None)
self.orig_pos = (x, y) self.orig_pos = (x, y)
self.aim_timer = 0 self.aim_timer = 0
self.start_boom = False # 和灰烬等植物统一变量名,在这里表示倭瓜是否跳起 self.start_boom = False # 和灰烬等植物统一变量名,在这里表示倭瓜是否跳起
self.mapPlantsSet = mapPlantsSet self.map_plant_set = map_plant_set
def loadImages(self, name, scale): def loadImages(self, name, scale):
self.idle_frames = [] self.idle_frames = []
@ -816,7 +818,7 @@ class Squash(Plant):
if self.canAttack(zombie): if self.canAttack(zombie):
zombie.setDamage(1800, damageType=c.ZOMBIE_RANGE_DAMAGE) zombie.setDamage(1800, damageType=c.ZOMBIE_RANGE_DAMAGE)
self.health = 0 # 避免僵尸在原位啃食 self.health = 0 # 避免僵尸在原位啃食
self.mapPlantsSet.remove(c.SQUASH) self.map_plant_set.remove(c.SQUASH)
self.kill() self.kill()
# 播放碾压音效 # 播放碾压音效
c.SOUND_SQUASHING.play() c.SOUND_SQUASHING.play()
@ -870,7 +872,7 @@ class Spikeweed(Plant):
if self.canAttack(zombie): if self.canAttack(zombie):
# 有车的僵尸 # 有车的僵尸
if zombie.name in {c.ZOMBONI}: if zombie.name in {c.ZOMBONI}:
zombie.health = zombie.lostHeadHealth zombie.health = zombie.losthead_health
killSelf = True killSelf = True
else: else:
zombie.setDamage(20, damageType=c.ZOMBIE_COMMON_DAMAGE) zombie.setDamage(20, damageType=c.ZOMBIE_COMMON_DAMAGE)
@ -924,7 +926,7 @@ class Jalapeno(Plant):
self.image = self.frames[self.frame_index] self.image = self.frames[self.frame_index]
self.mask = pg.mask.from_surface(self.image) self.mask = pg.mask.from_surface(self.image)
if (self.current_time - self.highlightTime < 100): if (self.current_time - self.highlight_time < 100):
self.image.set_alpha(150) self.image.set_alpha(150)
elif ((self.current_time - self.hit_timer) < 200): elif ((self.current_time - self.hit_timer) < 200):
self.image.set_alpha(192) self.image.set_alpha(192)
@ -1091,7 +1093,7 @@ class IceShroom(Plant):
self.image = self.frames[self.frame_index] self.image = self.frames[self.frame_index]
self.mask = pg.mask.from_surface(self.image) self.mask = pg.mask.from_surface(self.image)
if (self.current_time - self.highlightTime < 100): if (self.current_time - self.highlight_time < 100):
self.image.set_alpha(150) self.image.set_alpha(150)
elif ((self.current_time - self.hit_timer) < 200): elif ((self.current_time - self.hit_timer) < 200):
self.image.set_alpha(192) self.image.set_alpha(192)
@ -1288,16 +1290,16 @@ class TorchWood(Plant):
def idling(self): def idling(self):
for i in self.bullet_group: for i in self.bullet_group:
if i.name == c.BULLET_PEA: if i.name == c.BULLET_PEA:
if i.passedTorchWood != self.rect.centerx: if i.passed_torchwood_x != 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.dest_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, passed_torchwood_x=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.passed_torchwood_x != 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.dest_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, passed_torchwood_x=self.rect.centerx))
i.kill() i.kill()
class StarFruit(Plant): class StarFruit(Plant):
@ -1311,8 +1313,8 @@ class StarFruit(Plant):
if (zombie.name == c.SNORKELZOMBIE) and (zombie.frames == zombie.swim_frames): if (zombie.name == c.SNORKELZOMBIE) and (zombie.frames == zombie.swim_frames):
return False return False
if zombie.state != c.DIE: if zombie.state != c.DIE:
zombieMapY = self.level.map.getMapIndex(zombie.rect.centerx, zombie.rect.bottom)[1] zombie_map_y = self.level.map.getMapIndex(zombie.rect.centerx, zombie.rect.bottom)[1]
if (self.rect.x >= zombie.rect.x) and (self.map_y == zombieMapY): # 对于同行且在杨桃后的僵尸 if (self.rect.x >= zombie.rect.x) and (self.map_y == zombie_map_y): # 对于同行且在杨桃后的僵尸
return True return True
# 斜向上理想直线方程为f(zombie.rect.x) = -0.75*(zombie.rect.x - (self.rect.right - 5)) + self.rect.y - 10 # 斜向上理想直线方程为f(zombie.rect.x) = -0.75*(zombie.rect.x - (self.rect.right - 5)) + self.rect.y - 10
# 注意实际上为射线 # 注意实际上为射线
@ -1348,10 +1350,10 @@ class StarFruit(Plant):
class CoffeeBean(Plant): class CoffeeBean(Plant):
def __init__(self, x, y, plant_group, mapContent, map, map_x): def __init__(self, x, y, plant_group, map_content, map, map_x):
Plant.__init__(self, x, y, c.COFFEEBEAN, c.PLANT_HEALTH, None) Plant.__init__(self, x, y, c.COFFEEBEAN, c.PLANT_HEALTH, None)
self.plant_group = plant_group self.plant_group = plant_group
self.mapContent = mapContent self.map_content = map_content
self.map = map self.map = map
self.map_x = map_x self.map_x = map_x
@ -1360,7 +1362,7 @@ class CoffeeBean(Plant):
self.frame_index += 1 self.frame_index += 1
if self.frame_index >= self.frame_num: if self.frame_index >= self.frame_num:
self.mapContent[c.MAP_SLEEP] = False self.map_content[c.MAP_SLEEP] = False
for plant in self.plant_group: for plant in self.plant_group:
if plant.can_sleep: if plant.can_sleep:
if plant.state == c.SLEEP: if plant.state == c.SLEEP:
@ -1371,7 +1373,7 @@ class CoffeeBean(Plant):
plant.changeFrames(plant.idle_frames) plant.changeFrames(plant.idle_frames)
# 播放唤醒音效 # 播放唤醒音效
c.SOUND_MUSHROOM_WAKEUP.play() c.SOUND_MUSHROOM_WAKEUP.play()
self.mapContent[c.MAP_PLANT].remove(self.name) self.map_content[c.MAP_PLANT].remove(self.name)
self.kill() self.kill()
self.frame_index = self.frame_num - 1 self.frame_index = self.frame_num - 1
@ -1379,7 +1381,7 @@ class CoffeeBean(Plant):
self.image = self.frames[self.frame_index] self.image = self.frames[self.frame_index]
self.mask = pg.mask.from_surface(self.image) self.mask = pg.mask.from_surface(self.image)
if (self.current_time - self.highlightTime < 100): if (self.current_time - self.highlight_time < 100):
self.image.set_alpha(150) self.image.set_alpha(150)
elif ((self.current_time - self.hit_timer) < 200): elif ((self.current_time - self.hit_timer) < 200):
self.image.set_alpha(192) self.image.set_alpha(192)
@ -1480,7 +1482,7 @@ class TangleKlep(Plant):
self.frames = self.idle_frames self.frames = self.idle_frames
def canAttack(self, zombie): def canAttack(self, zombie):
if zombie.state != c.DIE and (not zombie.lostHead): if zombie.state != c.DIE and (not zombie.losthead):
# 这里碰撞应当比碰撞一般更容易就设置成圆形或矩形模式不宜采用mask # 这里碰撞应当比碰撞一般更容易就设置成圆形或矩形模式不宜采用mask
if pg.sprite.collide_circle_ratio(0.7)(zombie, self): if pg.sprite.collide_circle_ratio(0.7)(zombie, self):
return True return True
@ -1510,17 +1512,17 @@ class TangleKlep(Plant):
# 坑形态的毁灭菇同地刺一样不可以被啃食 # 坑形态的毁灭菇同地刺一样不可以被啃食
# 爆炸时杀死同一格的所有植物 # 爆炸时杀死同一格的所有植物
class DoomShroom(Plant): class DoomShroom(Plant):
def __init__(self, x, y, mapPlantsSet, explode_y_range): def __init__(self, x, y, map_plant_set, explode_y_range):
Plant.__init__(self, x, y, c.DOOMSHROOM, c.PLANT_HEALTH, None) Plant.__init__(self, x, y, c.DOOMSHROOM, c.PLANT_HEALTH, None)
self.can_sleep = True self.can_sleep = True
self.mapPlantSet = mapPlantsSet self.map_plant_set = map_plant_set
self.bomb_timer = 0 self.bomb_timer = 0
self.explode_y_range = explode_y_range self.explode_y_range = explode_y_range
self.explode_x_range = 250 self.explode_x_range = 250
self.start_boom = False self.start_boom = False
self.boomed = False self.boomed = False
self.originalX = x self.original_x = x
self.originalY = y self.original_y = y
def loadImages(self, name, scale): def loadImages(self, name, scale):
self.idle_frames = [] self.idle_frames = []
@ -1556,7 +1558,7 @@ class DoomShroom(Plant):
if self.frame_index >= self.frame_num: if self.frame_index >= self.frame_num:
self.health = 0 self.health = 0
self.frame_index = self.frame_num - 1 self.frame_index = self.frame_num - 1
self.mapPlantSet.add(c.HOLE) self.map_plant_set.add(c.HOLE)
# 睡觉状态 # 睡觉状态
elif self.state == c.SLEEP: elif self.state == c.SLEEP:
if (self.current_time - self.animate_timer) > self.animate_interval: if (self.current_time - self.animate_timer) > self.animate_interval:
@ -1576,7 +1578,7 @@ class DoomShroom(Plant):
self.image = self.frames[self.frame_index] self.image = self.frames[self.frame_index]
self.mask = pg.mask.from_surface(self.image) self.mask = pg.mask.from_surface(self.image)
if (self.current_time - self.highlightTime < 100): if (self.current_time - self.highlight_time < 100):
self.image.set_alpha(150) self.image.set_alpha(150)
elif ((self.current_time - self.hit_timer) < 200): elif ((self.current_time - self.hit_timer) < 200):
self.image.set_alpha(192) self.image.set_alpha(192)
@ -1668,8 +1670,8 @@ class GraveBuster(Plant):
self.frame_index = self.frame_num - 1 self.frame_index = self.frame_num - 1
for item in self.plant_group: for item in self.plant_group:
if item.name == c.GRAVE: if item.name == c.GRAVE:
itemMapX, _ = self.map.getMapIndex(item.rect.centerx, item.rect.bottom) item_map_x, _ = self.map.getMapIndex(item.rect.centerx, item.rect.bottom)
if itemMapX == self.map_x: if item_map_x == self.map_x:
item.health = 0 item.health = 0
self.health = 0 self.health = 0
self.animate_timer = self.current_time self.animate_timer = self.current_time
@ -1677,7 +1679,7 @@ class GraveBuster(Plant):
self.image = self.frames[self.frame_index] self.image = self.frames[self.frame_index]
self.mask = pg.mask.from_surface(self.image) self.mask = pg.mask.from_surface(self.image)
if (self.current_time - self.highlightTime < 100): if (self.current_time - self.highlight_time < 100):
self.image.set_alpha(150) self.image.set_alpha(150)
elif ((self.current_time - self.hit_timer) < 200): elif ((self.current_time - self.hit_timer) < 200):
self.image.set_alpha(192) self.image.set_alpha(192)
@ -1689,7 +1691,7 @@ class FumeShroom(Plant):
Plant.__init__(self, x, y, c.FUMESHROOM, c.PLANT_HEALTH, bullet_group) Plant.__init__(self, x, y, c.FUMESHROOM, c.PLANT_HEALTH, bullet_group)
self.can_sleep = True self.can_sleep = True
self.shoot_timer = 0 self.shoot_timer = 0
self.showAttackFrames = True self.show_attack_frames = True
self.zombie_group = zombie_group self.zombie_group = zombie_group
def loadImages(self, name, scale): def loadImages(self, name, scale):
@ -1726,18 +1728,18 @@ class FumeShroom(Plant):
if self.shoot_timer == 0: if self.shoot_timer == 0:
self.shoot_timer = self.current_time - 700 self.shoot_timer = self.current_time - 700
elif self.current_time - self.shoot_timer >= 1100: elif self.current_time - self.shoot_timer >= 1100:
if self.showAttackFrames: if self.show_attack_frames:
self.showAttackFrames = False self.show_attack_frames = False
self.changeFrames(self.attack_frames) self.changeFrames(self.attack_frames)
if self.current_time - self.shoot_timer >= 1400: if self.current_time - self.shoot_timer >= 1400:
self.bullet_group.add(Fume(self.rect.right - 35, self.rect.y)) self.bullet_group.add(Fume(self.rect.right - 35, self.rect.y))
# 烟雾只是个动画,实际伤害由本身完成 # 烟雾只是个动画,实际伤害由本身完成
for targetZombie in self.zombie_group: for target_zombie in self.zombie_group:
if self.canAttack(targetZombie): if self.canAttack(target_zombie):
targetZombie.setDamage(c.BULLET_DAMAGE_NORMAL, damageType=c.ZOMBIE_RANGE_DAMAGE) target_zombie.setDamage(c.BULLET_DAMAGE_NORMAL, damageType=c.ZOMBIE_RANGE_DAMAGE)
self.shoot_timer = self.current_time self.shoot_timer = self.current_time
self.showAttackFrames = True self.show_attack_frames = True
# 播放发射音效 # 播放发射音效
c.SOUND_FUME.play() c.SOUND_FUME.play()
@ -1754,7 +1756,7 @@ class FumeShroom(Plant):
self.image = self.frames[self.frame_index] self.image = self.frames[self.frame_index]
self.mask = pg.mask.from_surface(self.image) self.mask = pg.mask.from_surface(self.image)
if (self.current_time - self.highlightTime < 100): if (self.current_time - self.highlight_time < 100):
self.image.set_alpha(150) self.image.set_alpha(150)
elif ((self.current_time - self.hit_timer) < 200): elif ((self.current_time - self.hit_timer) < 200):
self.image.set_alpha(192) self.image.set_alpha(192)

View File

@ -5,7 +5,10 @@ from .. import constants as c
class Zombie(pg.sprite.Sprite): class Zombie(pg.sprite.Sprite):
def __init__(self, x, y, name, head_group=None, helmetHealth=0, helmetType2Health=0, bodyHealth=c.NORMAL_HEALTH, lostHeadHealth=c.LOSTHEAD_HEALTH, damage=c.ZOMBIE_ATTACK_DAMAGE, canSwim=False): def __init__( self, x, y, name, head_group=None,
helmet_health=0, helmet_type2_health=0,
body_health=c.NORMAL_HEALTH, losthead_health=c.LOSTHEAD_HEALTH,
damage=c.ZOMBIE_ATTACK_DAMAGE, can_swim=False):
pg.sprite.Sprite.__init__(self) pg.sprite.Sprite.__init__(self)
self.name = name self.name = name
@ -20,21 +23,21 @@ class Zombie(pg.sprite.Sprite):
self.rect.x = x self.rect.x = x
self.rect.bottom = y self.rect.bottom = y
# 大蒜换行移动像素值,< 0时向上= 0时不变> 0时向上 # 大蒜换行移动像素值,< 0时向上= 0时不变> 0时向上
self.targetYChange = 0 self.target_y_change = 0
self.originalY = y self.original_y = y
self.toChangeGroup = False self.to_change_group = False
self.helmetHealth = helmetHealth self.helmet_health = helmet_health
self.helmetType2Health = helmetType2Health self.helmet_type2_health = helmet_type2_health
self.health = bodyHealth + lostHeadHealth self.health = body_health + losthead_health
self.lostHeadHealth = lostHeadHealth self.losthead_health = losthead_health
self.damage = damage self.damage = damage
self.dead = False self.dead = False
self.lostHead = False self.losthead = False
self.canSwim = canSwim self.can_swim = can_swim
self.swimming = False self.swimming = False
self.helmet = (self.helmetHealth > 0) self.helmet = (self.helmet_health > 0)
self.helmetType2 = (self.helmetType2Health > 0) self.helmet_type2 = (self.helmet_type2_health > 0)
self.head_group = head_group self.head_group = head_group
self.walk_timer = 0 self.walk_timer = 0
@ -44,7 +47,7 @@ class Zombie(pg.sprite.Sprite):
self.animate_interval = 150 self.animate_interval = 150
self.walk_animate_interval = 180 self.walk_animate_interval = 180
self.attack_animate_interval = 100 self.attack_animate_interval = 100
self.lostHead_animate_interval = 180 self.losthead_animate_interval = 180
self.die_animate_interval = 50 self.die_animate_interval = 50
self.boomDie_animate_interval = 100 self.boomDie_animate_interval = 100
self.ice_slow_ratio = 1 self.ice_slow_ratio = 1
@ -88,8 +91,8 @@ class Zombie(pg.sprite.Sprite):
if self.health <= 0: if self.health <= 0:
self.setDie() self.setDie()
return True return True
elif self.health <= self.lostHeadHealth: elif self.health <= self.losthead_health:
if not self.lostHead: if not self.losthead:
self.changeFrames(framesKind) self.changeFrames(framesKind)
self.setLostHead() self.setLostHead()
return True return True
@ -105,7 +108,7 @@ class Zombie(pg.sprite.Sprite):
return return
# 能游泳的僵尸 # 能游泳的僵尸
if self.canSwim: if self.can_swim:
# 在水池范围内 # 在水池范围内
# 在右侧岸左 # 在右侧岸左
if self.rect.right <= c.MAP_POOL_FRONT_X: if self.rect.right <= c.MAP_POOL_FRONT_X:
@ -119,25 +122,25 @@ class Zombie(pg.sprite.Sprite):
c.SOUND_ZOMBIE_ENTERING_WATER.play() c.SOUND_ZOMBIE_ENTERING_WATER.play()
# 同样没有兼容双防具 # 同样没有兼容双防具
if self.helmet: if self.helmet:
if self.helmetHealth <= 0: if self.helmet_health <= 0:
self.helmet = False self.helmet = False
else: else:
self.changeFrames(self.helmet_swim_frames) self.changeFrames(self.helmet_swim_frames)
if self.helmetType2: if self.helmet_type2:
if self.helmetType2Health <= 0: if self.helmet_type2_health <= 0:
self.helmetType2 = False self.helmet_type2 = False
else: else:
self.changeFrames(self.helmet_swim_frames) self.changeFrames(self.helmet_swim_frames)
# 已经进入游泳状态 # 已经进入游泳状态
else: else:
if self.helmet: if self.helmet:
if self.helmetHealth <= 0: if self.helmet_health <= 0:
self.changeFrames(self.swim_frames) self.changeFrames(self.swim_frames)
self.helmet = False self.helmet = False
if self.helmetType2: if self.helmet_type2:
if self.helmetType2Health <= 0: if self.helmet_type2_health <= 0:
self.changeFrames(self.swim_frames) self.changeFrames(self.swim_frames)
self.helmetType2 = False self.helmet_type2 = False
# 水生僵尸已经接近家门口并且上岸 # 水生僵尸已经接近家门口并且上岸
else: else:
if self.swimming: if self.swimming:
@ -145,55 +148,55 @@ class Zombie(pg.sprite.Sprite):
self.swimming = False self.swimming = False
# 同样没有兼容双防具 # 同样没有兼容双防具
if self.helmet: if self.helmet:
if self.helmetHealth <= 0: if self.helmet_health <= 0:
self.helmet = False self.helmet = False
else: else:
self.changeFrames(self.helmet_walk_frames) self.changeFrames(self.helmet_walk_frames)
if self.helmetType2: if self.helmet_type2:
if self.helmetType2Health <= 0: if self.helmet_type2_health <= 0:
self.helmetType2 = False self.helmet_type2 = False
else: else:
self.changeFrames(self.helmet_walk_frames) self.changeFrames(self.helmet_walk_frames)
if self.helmet: if self.helmet:
if self.helmetHealth <= 0: if self.helmet_health <= 0:
self.helmet = False self.helmet = False
self.changeFrames(self.walk_frames) self.changeFrames(self.walk_frames)
if self.helmetType2: if self.helmet_type2:
if self.helmetType2Health <= 0: if self.helmet_type2_health <= 0:
self.helmetType2 = False self.helmet_type2 = False
self.changeFrames(self.walk_frames) self.changeFrames(self.walk_frames)
elif self.is_hypno and self.rect.right > c.MAP_POOL_FRONT_X + 55: # 常数拟合暂时缺乏检验 elif self.is_hypno and self.rect.right > c.MAP_POOL_FRONT_X + 55: # 常数拟合暂时缺乏检验
if self.swimming: if self.swimming:
self.changeFrames(self.walk_frames) self.changeFrames(self.walk_frames)
if self.helmet: if self.helmet:
if self.helmetHealth <= 0: if self.helmet_health <= 0:
self.changeFrames(self.walk_frames) self.changeFrames(self.walk_frames)
self.helmet = False self.helmet = False
elif self.swimming: # 游泳状态需要改为步行 elif self.swimming: # 游泳状态需要改为步行
self.changeFrames(self.helmet_walk_frames) self.changeFrames(self.helmet_walk_frames)
if self.helmetType2: if self.helmet_type2:
if self.helmetType2Health <= 0: if self.helmet_type2_health <= 0:
self.changeFrames(self.walk_frames) self.changeFrames(self.walk_frames)
self.helmetType2 = False self.helmet_type2 = False
elif self.swimming: # 游泳状态需要改为步行 elif self.swimming: # 游泳状态需要改为步行
self.changeFrames(self.helmet_walk_frames) self.changeFrames(self.helmet_walk_frames)
self.swimming = False self.swimming = False
# 尚未进入水池 # 尚未进入水池
else: else:
if self.helmetHealth <= 0 and self.helmet: if self.helmet_health <= 0 and self.helmet:
self.changeFrames(self.walk_frames) self.changeFrames(self.walk_frames)
self.helmet = False self.helmet = False
if self.helmetType2Health <= 0 and self.helmetType2: if self.helmet_type2_health <= 0 and self.helmet_type2:
self.changeFrames(self.walk_frames) self.changeFrames(self.walk_frames)
self.helmetType2 = False self.helmet_type2 = False
# 不能游泳的一般僵尸 # 不能游泳的一般僵尸
else: else:
if self.helmetHealth <= 0 and self.helmet: if self.helmet_health <= 0 and self.helmet:
self.changeFrames(self.walk_frames) self.changeFrames(self.walk_frames)
self.helmet = False self.helmet = False
if self.helmetType2Health <= 0 and self.helmetType2: if self.helmet_type2_health <= 0 and self.helmet_type2:
self.changeFrames(self.walk_frames) self.changeFrames(self.walk_frames)
self.helmetType2 = False self.helmet_type2 = 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()):
self.handleGarlicYChange() self.handleGarlicYChange()
@ -204,48 +207,48 @@ class Zombie(pg.sprite.Sprite):
self.rect.x -= 1 self.rect.x -= 1
def handleGarlicYChange(self): def handleGarlicYChange(self):
if self.targetYChange < 0: if self.target_y_change < 0:
if self.rect.bottom > self.originalY + self.targetYChange: # 注意这里加的是负数 if self.rect.bottom > self.original_y + self.target_y_change: # 注意这里加的是负数
self.rect.bottom -= 3 self.rect.bottom -= 3
# 过半时换行 # 过半时换行
if ((self.toChangeGroup) and if ((self.to_change_group) and
(self.rect.bottom >= self.originalY + 0.5*self.targetYChange)): (self.rect.bottom >= self.original_y + 0.5*self.target_y_change)):
self.level.zombie_groups[self.mapY].remove(self) self.level.zombie_groups[self.map_y].remove(self)
self.level.zombie_groups[self.targetMapY].add(self) self.level.zombie_groups[self.target_map_y].add(self)
self.toChangeGroup = False self.to_change_group = False
else: else:
self.rect.bottom = self.originalY + self.targetYChange self.rect.bottom = self.original_y + self.target_y_change
self.originalY = self.rect.bottom self.original_y = self.rect.bottom
self.targetYChange = 0 self.target_y_change = 0
elif self.targetYChange > 0: elif self.target_y_change > 0:
if self.rect.bottom < self.originalY + self.targetYChange: # 注意这里加的是负数 if self.rect.bottom < self.original_y + self.target_y_change: # 注意这里加的是负数
self.rect.bottom += 3 self.rect.bottom += 3
# 过半时换行 # 过半时换行
if ((self.toChangeGroup) and if ((self.to_change_group) and
(self.rect.bottom <= self.originalY + 0.5*self.targetYChange)): (self.rect.bottom <= self.original_y + 0.5*self.target_y_change)):
self.level.zombie_groups[self.mapY].remove(self) self.level.zombie_groups[self.map_y].remove(self)
self.level.zombie_groups[self.targetMapY].add(self) self.level.zombie_groups[self.target_map_y].add(self)
self.toChangeGroup = False self.to_change_group = False
else: else:
self.rect.bottom = self.originalY + self.targetYChange self.rect.bottom = self.original_y + self.target_y_change
self.originalY = self.rect.bottom self.original_y = self.rect.bottom
self.targetYChange = 0 self.target_y_change = 0
def attacking(self): def attacking(self):
if self.checkToDie(self.losthead_attack_frames): if self.checkToDie(self.losthead_attack_frames):
return return
if self.helmetHealth <= 0 and self.helmet: if self.helmet_health <= 0 and self.helmet:
self.changeFrames(self.attack_frames) self.changeFrames(self.attack_frames)
self.helmet = False self.helmet = False
if self.helmetType2Health <= 0 and self.helmetType2: if self.helmet_type2_health <= 0 and self.helmet_type2:
self.changeFrames(self.attack_frames) self.changeFrames(self.attack_frames)
self.helmetType2 = False self.helmet_type2 = False
if self.name == c.NEWSPAPER_ZOMBIE: if self.name == c.NEWSPAPER_ZOMBIE:
self.speed = 2.65 self.speed = 2.65
self.walk_animate_interval = 300 self.walk_animate_interval = 300
if (((self.current_time - self.attack_timer) > (c.ATTACK_INTERVAL * self.getAttackTimeRatio())) if (((self.current_time - self.attack_timer) > (c.ATTACK_INTERVAL * self.getAttackTimeRatio()))
and (not self.lostHead)): and (not self.losthead)):
if self.prey.health > 0: if self.prey.health > 0:
if self.prey_is_plant: if self.prey_is_plant:
self.prey.setDamage(self.damage, self) self.prey.setDamage(self.damage, self)
@ -281,8 +284,8 @@ class Zombie(pg.sprite.Sprite):
def setLostHead(self): def setLostHead(self):
self.losthead_timer = self.current_time self.losthead_timer = self.current_time
self.lostHead = True self.losthead = True
self.animate_interval = self.lostHead_animate_interval self.animate_interval = self.losthead_animate_interval
if self.head_group is not None: if self.head_group is not None:
self.head_group.add(ZombieHead(self.rect.centerx, self.rect.bottom)) self.head_group.add(ZombieHead(self.rect.centerx, self.rect.bottom))
@ -347,87 +350,87 @@ class Zombie(pg.sprite.Sprite):
# 冰冻减速效果 # 冰冻减速效果
if effect == c.BULLET_EFFECT_ICE: if effect == c.BULLET_EFFECT_ICE:
if damageType == c.ZOMBIE_DEAFULT_DAMAGE: # 寒冰射手不能穿透二类防具进行减速 if damageType == c.ZOMBIE_DEAFULT_DAMAGE: # 寒冰射手不能穿透二类防具进行减速
if not self.helmetType2: if not self.helmet_type2:
self.setIceSlow() self.setIceSlow()
else: else:
self.setIceSlow() self.setIceSlow()
# 解冻 # 解冻
elif effect == c.BULLET_EFFECT_UNICE: elif effect == c.BULLET_EFFECT_UNICE:
if damageType == c.ZOMBIE_DEAFULT_DAMAGE: # 寒冰射手不能穿透二类防具进行减速 if damageType == c.ZOMBIE_DEAFULT_DAMAGE: # 寒冰射手不能穿透二类防具进行减速
if not self.helmetType2: if not self.helmet_type2:
self.ice_slow_ratio = 1 self.ice_slow_ratio = 1
else: else:
self.ice_slow_ratio = 1 self.ice_slow_ratio = 1
if damageType == c.ZOMBIE_DEAFULT_DAMAGE: # 不穿透二类防具的攻击 if damageType == c.ZOMBIE_DEAFULT_DAMAGE: # 不穿透二类防具的攻击
# 从第二类防具开始逐级传递 # 从第二类防具开始逐级传递
if self.helmetType2: if self.helmet_type2:
self.helmetType2Health -= damage self.helmet_type2_health -= damage
if self.helmetType2Health <= 0: if self.helmet_type2_health <= 0:
if self.helmet: if self.helmet:
self.helmetHealth += self.helmetType2Health # 注意self.helmetType2Health已经带有正负 self.helmet_health += self.helmet_type2_health # 注意self.helmet_type2_health已经带有正负
self.helmetType2Health = 0 # 注意合并后清零 self.helmet_type2_health = 0 # 注意合并后清零
if self.helmetHealth <= 0: if self.helmet_health <= 0:
self.health += self.helmetHealth self.health += self.helmet_health
self.helmetHealth = 0 # 注意合并后清零 self.helmet_health = 0 # 注意合并后清零
else: else:
self.health += self.helmetType2Health self.health += self.helmet_type2_health
self.helmetType2Health = 0 self.helmet_type2_health = 0
elif self.helmet: # 不存在二类防具,但是存在一类防具 elif self.helmet: # 不存在二类防具,但是存在一类防具
self.helmetHealth -= damage self.helmet_health -= damage
if self.helmetHealth <= 0: if self.helmet_health <= 0:
self.health += self.helmetHealth self.health += self.helmet_health
self.helmetHealth = 0 # 注意合并后清零 self.helmet_health = 0 # 注意合并后清零
else: # 没有防具 else: # 没有防具
self.health -= damage self.health -= damage
elif damageType == c.ZOMBIE_COMMON_DAMAGE: # 无视二类防具,将攻击一类防具与本体视为整体的攻击 elif damageType == c.ZOMBIE_COMMON_DAMAGE: # 无视二类防具,将攻击一类防具与本体视为整体的攻击
if self.helmet: # 存在一类防具 if self.helmet: # 存在一类防具
self.helmetHealth -= damage self.helmet_health -= damage
if self.helmetHealth <= 0: if self.helmet_health <= 0:
self.health += self.helmetHealth self.health += self.helmet_health
self.helmetHealth = 0 # 注意合并后清零 self.helmet_health = 0 # 注意合并后清零
else: # 没有一类防具 else: # 没有一类防具
self.health -= damage self.health -= damage
elif damageType == c.ZOMBIE_RANGE_DAMAGE: elif damageType == c.ZOMBIE_RANGE_DAMAGE:
# 从第二类防具开始逐级传递 # 从第二类防具开始逐级传递
if self.helmetType2: if self.helmet_type2:
self.helmetType2Health -= damage self.helmet_type2_health -= damage
if self.helmetType2Health <= 0: if self.helmet_type2_health <= 0:
if self.helmet: if self.helmet:
self.helmetHealth -= damage # 注意范围伤害中这里还有一个攻击 self.helmet_health -= damage # 注意范围伤害中这里还有一个攻击
self.helmetHealth += self.helmetType2Health # 注意self.helmetType2Health已经带有正负 self.helmet_health += self.helmet_type2_health # 注意self.helmet_type2_health已经带有正负
self.helmetType2Health = 0 # 注意合并后清零 self.helmet_type2_health = 0 # 注意合并后清零
if self.helmetHealth <= 0: if self.helmet_health <= 0:
self.health += self.helmetHealth self.health += self.helmet_health
self.helmetHealth = 0 # 注意合并后清零 self.helmet_health = 0 # 注意合并后清零
else: else:
self.health -= damage # 注意范围伤害中这里还有一个攻击 self.health -= damage # 注意范围伤害中这里还有一个攻击
self.health += self.helmetType2Health self.health += self.helmet_type2_health
self.helmetType2Health = 0 self.helmet_type2_health = 0
else: else:
if self.helmet: if self.helmet:
self.helmetHealth -= damage self.helmet_health -= damage
if self.helmetHealth <= 0: if self.helmet_health <= 0:
self.health += self.helmetHealth self.health += self.helmet_health
self.helmetHealth = 0 # 注意合并后清零 self.helmet_health = 0 # 注意合并后清零
else: else:
self.health -= damage self.health -= damage
elif self.helmet: # 不存在二类防具,但是存在一类防具 elif self.helmet: # 不存在二类防具,但是存在一类防具
self.helmetHealth -= damage self.helmet_health -= damage
if self.helmetHealth <= 0: if self.helmet_health <= 0:
self.health += self.helmetHealth self.health += self.helmet_health
self.helmetHealth = 0 # 注意合并后清零 self.helmet_health = 0 # 注意合并后清零
else: # 没有防具 else: # 没有防具
self.health -= damage self.health -= damage
elif damageType == c.ZOMBIE_ASH_DAMAGE: elif damageType == c.ZOMBIE_ASH_DAMAGE:
self.health -= damage # 无视任何防具 self.health -= damage # 无视任何防具
elif damageType == c.ZOMBIE_WALLNUT_BOWLING_DANMAGE: elif damageType == c.ZOMBIE_WALLNUT_BOWLING_DANMAGE:
# 逻辑:对防具的多余伤害不传递 # 逻辑:对防具的多余伤害不传递
if self.helmetType2: if self.helmet_type2:
# 对二类防具伤害较一般情况低拟合铁门需要砸3次的设定 # 对二类防具伤害较一般情况低拟合铁门需要砸3次的设定
self.helmetType2Health -= int(damage * 0.8) self.helmet_type2_health -= int(damage * 0.8)
elif self.helmet: # 不存在二类防具,但是存在一类防具 elif self.helmet: # 不存在二类防具,但是存在一类防具
self.helmetHealth -= damage self.helmet_health -= damage
else: # 没有防具 else: # 没有防具
self.health -= damage self.health -= damage
else: else:
@ -441,28 +444,28 @@ class Zombie(pg.sprite.Sprite):
self.state = c.WALK self.state = c.WALK
self.animate_interval = self.walk_animate_interval self.animate_interval = self.walk_animate_interval
if self.helmet or self.helmetType2: # 这里暂时没有考虑同时有两种防具的僵尸 if self.helmet or self.helmet_type2: # 这里暂时没有考虑同时有两种防具的僵尸
self.changeFrames(self.helmet_walk_frames) self.changeFrames(self.helmet_walk_frames)
elif self.lostHead: elif self.losthead:
self.changeFrames(self.losthead_walk_frames) self.changeFrames(self.losthead_walk_frames)
else: else:
self.changeFrames(self.walk_frames) self.changeFrames(self.walk_frames)
if self.canSwim: if self.can_swim:
if self.rect.right <= c.MAP_POOL_FRONT_X: if self.rect.right <= c.MAP_POOL_FRONT_X:
self.swimming = True self.swimming = True
self.changeFrames(self.swim_frames) self.changeFrames(self.swim_frames)
# 同样没有兼容双防具 # 同样没有兼容双防具
if self.helmet: if self.helmet:
if self.helmetHealth <= 0: if self.helmet_health <= 0:
self.changeFrames(self.swim_frames) self.changeFrames(self.swim_frames)
self.helmet = False self.helmet = False
else: else:
self.changeFrames(self.helmet_swim_frames) self.changeFrames(self.helmet_swim_frames)
if self.helmetType2: if self.helmet_type2:
if self.helmetType2Health <= 0: if self.helmet_type2_health <= 0:
self.changeFrames(self.swim_frames) self.changeFrames(self.swim_frames)
self.helmetType2 = False self.helmet_type2 = False
else: else:
self.changeFrames(self.helmet_swim_frames) self.changeFrames(self.helmet_swim_frames)
@ -473,9 +476,9 @@ class Zombie(pg.sprite.Sprite):
self.attack_timer = self.current_time self.attack_timer = self.current_time
self.animate_interval = self.attack_animate_interval self.animate_interval = self.attack_animate_interval
if self.helmet or self.helmetType2: # 这里暂时没有考虑同时有两种防具的僵尸 if self.helmet or self.helmet_type2: # 这里暂时没有考虑同时有两种防具的僵尸
self.changeFrames(self.helmet_attack_frames) self.changeFrames(self.helmet_attack_frames)
elif self.lostHead: elif self.losthead:
self.changeFrames(self.losthead_attack_frames) self.changeFrames(self.losthead_attack_frames)
else: else:
self.changeFrames(self.attack_frames) self.changeFrames(self.attack_frames)
@ -558,7 +561,7 @@ class NormalZombie(Zombie):
# 路障僵尸 # 路障僵尸
class ConeHeadZombie(Zombie): class ConeHeadZombie(Zombie):
def __init__(self, x, y, head_group): def __init__(self, x, y, head_group):
Zombie.__init__(self, x, y, c.CONEHEAD_ZOMBIE, head_group, helmetHealth=c.CONEHEAD_HEALTH) Zombie.__init__(self, x, y, c.CONEHEAD_ZOMBIE, head_group, helmet_health=c.CONEHEAD_HEALTH)
def loadImages(self): def loadImages(self):
self.helmet_walk_frames = [] self.helmet_walk_frames = []
@ -594,7 +597,7 @@ class ConeHeadZombie(Zombie):
class BucketHeadZombie(Zombie): class BucketHeadZombie(Zombie):
def __init__(self, x, y, head_group): def __init__(self, x, y, head_group):
Zombie.__init__(self, x, y, c.BUCKETHEAD_ZOMBIE, head_group, helmetHealth=c.BUCKETHEAD_HEALTH) Zombie.__init__(self, x, y, c.BUCKETHEAD_ZOMBIE, head_group, helmet_health=c.BUCKETHEAD_HEALTH)
def loadImages(self): def loadImages(self):
self.helmet_walk_frames = [] self.helmet_walk_frames = []
@ -661,8 +664,8 @@ class FlagZombie(Zombie):
class NewspaperZombie(Zombie): class NewspaperZombie(Zombie):
def __init__(self, x, y, head_group): def __init__(self, x, y, head_group):
Zombie.__init__(self, x, y, c.NEWSPAPER_ZOMBIE, head_group, helmetType2Health=c.NEWSPAPER_HEALTH) Zombie.__init__(self, x, y, c.NEWSPAPER_ZOMBIE, head_group, helmet_type2_health=c.NEWSPAPER_HEALTH)
self.speedUp = False self.speed_up = False
def loadImages(self): def loadImages(self):
self.helmet_walk_frames = [] self.helmet_walk_frames = []
@ -707,9 +710,9 @@ class NewspaperZombie(Zombie):
if self.checkToDie(self.losthead_walk_frames): if self.checkToDie(self.losthead_walk_frames):
return return
if self.helmetType2Health <= 0 and self.helmetType2: if self.helmet_type2_health <= 0 and self.helmet_type2:
self.changeFrames(self.lostnewspaper_frames) self.changeFrames(self.lostnewspaper_frames)
self.helmetType2 = False self.helmet_type2 = False
# 触发报纸撕裂音效 # 触发报纸撕裂音效
c.SOUND_NEWSPAPER_RIP.play() c.SOUND_NEWSPAPER_RIP.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())):
@ -733,9 +736,9 @@ class NewspaperZombie(Zombie):
if self.state == c.DIE: if self.state == c.DIE:
self.kill() self.kill()
return return
elif self.frames == self.lostnewspaper_frames and (not self.speedUp): elif self.frames == self.lostnewspaper_frames and (not self.speed_up):
self.changeFrames(self.walk_frames) self.changeFrames(self.walk_frames)
self.speedUp = True self.speed_up = True
self.speed = 2.65 self.speed = 2.65
self.walk_animate_interval = 300 self.walk_animate_interval = 300
# 触发报纸僵尸暴走音效 # 触发报纸僵尸暴走音效
@ -755,12 +758,12 @@ class NewspaperZombie(Zombie):
class FootballZombie(Zombie): class FootballZombie(Zombie):
def __init__(self, x, y, head_group): def __init__(self, x, y, head_group):
Zombie.__init__(self, x, y, c.FOOTBALL_ZOMBIE, head_group, helmetHealth=c.FOOTBALL_HELMET_HEALTH) Zombie.__init__(self, x, y, c.FOOTBALL_ZOMBIE, head_group, helmet_health=c.FOOTBALL_HELMET_HEALTH)
self.speed = 1.88 self.speed = 1.88
self.animate_interval = 50 self.animate_interval = 50
self.walk_animate_interval = 50 self.walk_animate_interval = 50
self.attack_animate_interval = 60 self.attack_animate_interval = 60
self.lostHead_animate_interval = 180 self.losthead_animate_interval = 180
self.die_animate_interval = 150 self.die_animate_interval = 150
def loadImages(self): def loadImages(self):
@ -796,7 +799,7 @@ class FootballZombie(Zombie):
class DuckyTubeZombie(Zombie): class DuckyTubeZombie(Zombie):
def __init__(self, x, y, head_group): def __init__(self, x, y, head_group):
Zombie.__init__(self, x, y, c.DUCKY_TUBE_ZOMBIE, head_group, canSwim=True) Zombie.__init__(self, x, y, c.DUCKY_TUBE_ZOMBIE, head_group, can_swim=True)
def loadImages(self): def loadImages(self):
self.walk_frames = [] self.walk_frames = []
@ -827,7 +830,7 @@ class DuckyTubeZombie(Zombie):
class ConeHeadDuckyTubeZombie(Zombie): class ConeHeadDuckyTubeZombie(Zombie):
def __init__(self, x, y, head_group): def __init__(self, x, y, head_group):
Zombie.__init__(self, x, y, c.CONEHEAD_DUCKY_TUBE_ZOMBIE, head_group, helmetHealth=c.CONEHEAD_HEALTH ,canSwim=True) Zombie.__init__(self, x, y, c.CONEHEAD_DUCKY_TUBE_ZOMBIE, head_group, helmet_health=c.CONEHEAD_HEALTH ,can_swim=True)
def loadImages(self): def loadImages(self):
self.helmet_walk_frames = [] self.helmet_walk_frames = []
@ -865,7 +868,7 @@ class ConeHeadDuckyTubeZombie(Zombie):
class BucketHeadDuckyTubeZombie(Zombie): class BucketHeadDuckyTubeZombie(Zombie):
def __init__(self, x, y, head_group): def __init__(self, x, y, head_group):
Zombie.__init__(self, x, y, c.BUCKETHEAD_DUCKY_TUBE_ZOMBIE, head_group, helmetHealth=c.BUCKETHEAD_HEALTH ,canSwim=True) Zombie.__init__(self, x, y, c.BUCKETHEAD_DUCKY_TUBE_ZOMBIE, head_group, helmet_health=c.BUCKETHEAD_HEALTH ,can_swim=True)
def loadImages(self): def loadImages(self):
self.helmet_walk_frames = [] self.helmet_walk_frames = []
@ -903,7 +906,7 @@ class BucketHeadDuckyTubeZombie(Zombie):
class ScreenDoorZombie(Zombie): class ScreenDoorZombie(Zombie):
def __init__(self, x, y, head_group): def __init__(self, x, y, head_group):
Zombie.__init__(self, x, y, c.SCREEN_DOOR_ZOMBIE, head_group, helmetType2Health=c.SCREEN_DOOR_HEALTH) Zombie.__init__(self, x, y, c.SCREEN_DOOR_ZOMBIE, head_group, helmet_type2_health=c.SCREEN_DOOR_HEALTH)
def loadImages(self): def loadImages(self):
self.helmet_walk_frames = [] self.helmet_walk_frames = []
@ -939,7 +942,7 @@ class ScreenDoorZombie(Zombie):
class PoleVaultingZombie(Zombie): class PoleVaultingZombie(Zombie):
def __init__(self, x, y, head_group): def __init__(self, x, y, head_group):
Zombie.__init__(self, x, y, c.POLE_VAULTING_ZOMBIE, head_group=head_group, bodyHealth=c.POLE_VAULTING_HEALTH, lostHeadHealth=c.POLE_VAULTING_LOSTHEAD_HEALTH) Zombie.__init__(self, x, y, c.POLE_VAULTING_ZOMBIE, head_group=head_group, body_health=c.POLE_VAULTING_HEALTH, losthead_health=c.POLE_VAULTING_LOSTHEAD_HEALTH)
self.speed = 1.88 self.speed = 1.88
self.jumped = False self.jumped = False
self.jumping = False self.jumping = False
@ -975,12 +978,12 @@ class PoleVaultingZombie(Zombie):
self.frames = self.walk_before_jump_frames self.frames = self.walk_before_jump_frames
def setJump(self, successfullyJumped, jumpX): def setJump(self, successfullyJumped, jump_x):
if not self.jumping: if not self.jumping:
self.jumping = True self.jumping = True
self.changeFrames(self.jump_frames) self.changeFrames(self.jump_frames)
self.successfullyJumped = successfullyJumped self.successfullyJumped = successfullyJumped
self.jumpX = jumpX self.jump_x = jump_x
# 播放跳跃音效 # 播放跳跃音效
c.SOUND_POLEVAULT_JUMP.play() c.SOUND_POLEVAULT_JUMP.play()
@ -1005,7 +1008,7 @@ class PoleVaultingZombie(Zombie):
if self.jumping and (not self.jumped): if self.jumping and (not self.jumped):
self.changeFrames(self.walk_frames) self.changeFrames(self.walk_frames)
if self.successfullyJumped: if self.successfullyJumped:
self.rect.centerx = self.jumpX self.rect.centerx = self.jump_x
self.jumped = True self.jumped = True
self.speed = 1.04 self.speed = 1.04
self.animate_timer = self.current_time self.animate_timer = self.current_time
@ -1043,7 +1046,7 @@ class PoleVaultingZombie(Zombie):
# 注意:冰车僵尸移动变速 # 注意:冰车僵尸移动变速
class Zomboni(Zombie): class Zomboni(Zombie):
def __init__(self, x, y, plant_group, map, IceFrozenPlot): def __init__(self, x, y, plant_group, map, IceFrozenPlot):
Zombie.__init__(self, x, y, c.ZOMBONI, bodyHealth=c.ZOMBONI_HEALTH) Zombie.__init__(self, x, y, c.ZOMBONI, body_health=c.ZOMBONI_HEALTH)
self.plant_group = plant_group self.plant_group = plant_group
self.map = map self.map = map
self.IceFrozenPlot = IceFrozenPlot self.IceFrozenPlot = IceFrozenPlot
@ -1095,7 +1098,7 @@ class Zomboni(Zombie):
elif self.health <= c.ZOMBONI_DAMAGED1_HEALTH: elif self.health <= c.ZOMBONI_DAMAGED1_HEALTH:
self.changeFrames(self.walk_damaged1_frames) self.changeFrames(self.walk_damaged1_frames)
if (self.current_time - self.walk_timer) > (c.ZOMBIE_WALK_INTERVAL * self.getTimeRatio()) and (not self.lostHead): if (self.current_time - self.walk_timer) > (c.ZOMBIE_WALK_INTERVAL * self.getTimeRatio()) and (not self.losthead):
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
@ -1111,14 +1114,14 @@ class Zomboni(Zombie):
plant.health -= 8000 plant.health -= 8000
# 造冰 # 造冰
mapX, mapY = self.map.getMapIndex(self.rect.right - 40, self.rect.bottom) map_x, map_y = self.map.getMapIndex(self.rect.right - 40, self.rect.bottom)
if 0 <= mapX < c.GRID_X_LEN: if 0 <= map_x < c.GRID_X_LEN:
if c.ICEFROZENPLOT not in self.map.map[mapY][mapX]: if c.ICEFROZENPLOT not in self.map.map[map_y][map_x]:
x, y = self.map.getMapGridPos(mapX, mapY) x, y = self.map.getMapGridPos(map_x, map_y)
self.plant_group.add(self.IceFrozenPlot(x, y)) self.plant_group.add(self.IceFrozenPlot(x, y))
self.map.map[mapY][mapX][c.MAP_PLANT].add(c.ICEFROZENPLOT) self.map.map[map_y][map_x][c.MAP_PLANT].add(c.ICEFROZENPLOT)
self.speed = max(0.6, 1.5 - (c.GRID_X_LEN + 1 - mapX)*0.225) self.speed = max(0.6, 1.5 - (c.GRID_X_LEN + 1 - map_x)*0.225)
def setDie(self): def setDie(self):
self.state = c.DIE self.state = c.DIE
@ -1130,7 +1133,7 @@ class Zomboni(Zombie):
class SnorkelZombie(Zombie): class SnorkelZombie(Zombie):
def __init__(self, x, y, head_group): def __init__(self, x, y, head_group):
Zombie.__init__(self, x, y, c.SNORKELZOMBIE, canSwim=True) Zombie.__init__(self, x, y, c.SNORKELZOMBIE, can_swim=True)
self.speed = 1.175 self.speed = 1.175
self.walk_animate_interval = 60 self.walk_animate_interval = 60
self.canSetAttack = True self.canSetAttack = True
@ -1250,7 +1253,7 @@ class SnorkelZombie(Zombie):
self.prey_is_plant = is_plant self.prey_is_plant = is_plant
self.animate_interval = self.attack_animate_interval self.animate_interval = self.attack_animate_interval
if self.lostHead: if self.losthead:
self.changeFrames(self.losthead_attack_frames) self.changeFrames(self.losthead_attack_frames)
elif self.canSetAttack: elif self.canSetAttack:
self.changeFrames(self.float_frames) self.changeFrames(self.float_frames)

File diff suppressed because it is too large Load Diff