增加植物初始攻击间隔,修复咖啡豆bug
This commit is contained in:
parent
9cb27a7d86
commit
1d35afd649
@ -90,7 +90,6 @@ nuitka --mingw64 --standalone --onefile --show-progress --show-memory --output-d
|
|||||||
## 已知bug
|
## 已知bug
|
||||||
|
|
||||||
以下问题囿于个人目前的能力与精力,没有修复:
|
以下问题囿于个人目前的能力与精力,没有修复:
|
||||||
* 植物刚刚种植会立刻攻击,而非像原版一样有间歇时间
|
|
||||||
* 冷冻的僵尸未用蓝色滤镜标识
|
* 冷冻的僵尸未用蓝色滤镜标识
|
||||||
* 这个想不到很好的实现方法,可能会想一种替代方案
|
* 这个想不到很好的实现方法,可能会想一种替代方案
|
||||||
* 魅惑的僵尸未用红色滤镜标识
|
* 魅惑的僵尸未用红色滤镜标识
|
||||||
|
|||||||
@ -157,7 +157,10 @@ class StarBullet(Bullet):
|
|||||||
|
|
||||||
# 这里用的是坚果保龄球的代码改一下,实现子弹换行
|
# 这里用的是坚果保龄球的代码改一下,实现子弹换行
|
||||||
def handleMapYPosition(self):
|
def handleMapYPosition(self):
|
||||||
_, map_y1 = self.level.map.getMapIndex(self.rect.x, self.rect.centery +20)
|
if self.direction == c.STAR_UPWARD:
|
||||||
|
_, map_y1 = self.level.map.getMapIndex(self.rect.x, self.rect.centery + 40)
|
||||||
|
else:
|
||||||
|
_, map_y1 = self.level.map.getMapIndex(self.rect.x, self.rect.centery + 20)
|
||||||
# _, map_y2 = self.level.map.getMapIndex(self.rect.x, self.rect.bottom +20)
|
# _, map_y2 = self.level.map.getMapIndex(self.rect.x, self.rect.bottom +20)
|
||||||
if (self.map_y != map_y1) and (0 <= map_y1 <= self.level.map_y_len-1): # 换行
|
if (self.map_y != map_y1) and (0 <= map_y1 <= self.level.map_y_len-1): # 换行
|
||||||
self.level.bullet_groups[self.map_y].remove(self)
|
self.level.bullet_groups[self.map_y].remove(self)
|
||||||
@ -344,13 +347,19 @@ class PeaShooter(Plant):
|
|||||||
self.shoot_timer = 0
|
self.shoot_timer = 0
|
||||||
|
|
||||||
def attacking(self):
|
def attacking(self):
|
||||||
if (self.current_time - self.shoot_timer) >= 1400:
|
if self.shoot_timer == 0:
|
||||||
|
self.shoot_timer = self.current_time - 700
|
||||||
|
elif (self.current_time - self.shoot_timer) >= 1400:
|
||||||
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=False))
|
c.BULLET_PEA, c.BULLET_DAMAGE_NORMAL, effect=False))
|
||||||
self.shoot_timer = self.current_time
|
self.shoot_timer = self.current_time
|
||||||
# 播放发射音效
|
# 播放发射音效
|
||||||
pg.mixer.Sound(os.path.join(os.path.dirname(os.path.dirname(os.path.dirname(__file__))) ,"resources", "sound", "shoot.ogg")).play()
|
pg.mixer.Sound(os.path.join(os.path.dirname(os.path.dirname(os.path.dirname(__file__))) ,"resources", "sound", "shoot.ogg")).play()
|
||||||
|
|
||||||
|
def setAttack(self):
|
||||||
|
self.state = c.ATTACK
|
||||||
|
if self.shoot_timer != 0:
|
||||||
|
self.shoot_timer = self.current_time - 700
|
||||||
|
|
||||||
class RepeaterPea(Plant):
|
class RepeaterPea(Plant):
|
||||||
def __init__(self, x, y, bullet_group):
|
def __init__(self, x, y, bullet_group):
|
||||||
@ -361,7 +370,9 @@ class RepeaterPea(Plant):
|
|||||||
self.firstShot = False
|
self.firstShot = False
|
||||||
|
|
||||||
def attacking(self):
|
def attacking(self):
|
||||||
if (self.current_time - self.shoot_timer >= 1400):
|
if self.shoot_timer == 0:
|
||||||
|
self.shoot_timer = self.current_time - 700
|
||||||
|
elif (self.current_time - self.shoot_timer >= 1400):
|
||||||
self.firstShot = True
|
self.firstShot = 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=False))
|
c.BULLET_PEA, c.BULLET_DAMAGE_NORMAL, effect=False))
|
||||||
@ -375,6 +386,10 @@ class RepeaterPea(Plant):
|
|||||||
# 播放发射音效
|
# 播放发射音效
|
||||||
pg.mixer.Sound(os.path.join(os.path.dirname(os.path.dirname(os.path.dirname(__file__))) ,"resources", "sound", "shoot.ogg")).play()
|
pg.mixer.Sound(os.path.join(os.path.dirname(os.path.dirname(os.path.dirname(__file__))) ,"resources", "sound", "shoot.ogg")).play()
|
||||||
|
|
||||||
|
def setAttack(self):
|
||||||
|
self.state = c.ATTACK
|
||||||
|
if self.shoot_timer != 0:
|
||||||
|
self.shoot_timer = self.current_time - 700
|
||||||
|
|
||||||
class ThreePeaShooter(Plant):
|
class ThreePeaShooter(Plant):
|
||||||
def __init__(self, x, y, bullet_groups, map_y, background_type):
|
def __init__(self, x, y, bullet_groups, map_y, background_type):
|
||||||
@ -385,10 +400,16 @@ class ThreePeaShooter(Plant):
|
|||||||
self.background_type = background_type
|
self.background_type = background_type
|
||||||
|
|
||||||
def attacking(self):
|
def attacking(self):
|
||||||
|
if self.shoot_timer == 0:
|
||||||
|
self.shoot_timer = self.current_time - 700
|
||||||
if (self.current_time - self.shoot_timer) >= 1400:
|
if (self.current_time - self.shoot_timer) >= 1400:
|
||||||
offset_y = 9 # modify bullet in the same y position with bullets of other plants
|
offset_y = 9 # modify bullet in the same y position with bullets of other plants
|
||||||
for i in range(3):
|
for i in range(3):
|
||||||
tmp_y = self.map_y + (i - 1)
|
tmp_y = self.map_y + (i - 1)
|
||||||
|
if self.background_type in {c.BACKGROUND_POOL, c.BACKGROUND_FOG}:
|
||||||
|
if tmp_y < 0 or tmp_y >= c.GRID_POOL_Y_LEN:
|
||||||
|
continue
|
||||||
|
else:
|
||||||
if tmp_y < 0 or tmp_y >= c.GRID_Y_LEN:
|
if tmp_y < 0 or tmp_y >= c.GRID_Y_LEN:
|
||||||
continue
|
continue
|
||||||
if self.background_type in {c.BACKGROUND_POOL, c.BACKGROUND_FOG, c.BACKGROUND_ROOF, c.BACKGROUND_ROOFNIGHT}:
|
if self.background_type in {c.BACKGROUND_POOL, c.BACKGROUND_FOG, c.BACKGROUND_ROOF, c.BACKGROUND_ROOFNIGHT}:
|
||||||
@ -401,6 +422,10 @@ class ThreePeaShooter(Plant):
|
|||||||
# 播放发射音效
|
# 播放发射音效
|
||||||
pg.mixer.Sound(os.path.join(os.path.dirname(os.path.dirname(os.path.dirname(__file__))) ,"resources", "sound", "shoot.ogg")).play()
|
pg.mixer.Sound(os.path.join(os.path.dirname(os.path.dirname(os.path.dirname(__file__))) ,"resources", "sound", "shoot.ogg")).play()
|
||||||
|
|
||||||
|
def setAttack(self):
|
||||||
|
self.state = c.ATTACK
|
||||||
|
if self.shoot_timer != 0:
|
||||||
|
self.shoot_timer = self.current_time - 700
|
||||||
|
|
||||||
class SnowPeaShooter(Plant):
|
class SnowPeaShooter(Plant):
|
||||||
def __init__(self, x, y, bullet_group):
|
def __init__(self, x, y, bullet_group):
|
||||||
@ -408,7 +433,9 @@ class SnowPeaShooter(Plant):
|
|||||||
self.shoot_timer = 0
|
self.shoot_timer = 0
|
||||||
|
|
||||||
def attacking(self):
|
def attacking(self):
|
||||||
if (self.current_time - self.shoot_timer) >= 1400:
|
if self.shoot_timer == 0:
|
||||||
|
self.shoot_timer = self.current_time - 700
|
||||||
|
elif (self.current_time - self.shoot_timer) >= 1400:
|
||||||
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_ICE, c.BULLET_DAMAGE_NORMAL, effect=c.BULLET_EFFECT_ICE))
|
c.BULLET_PEA_ICE, c.BULLET_DAMAGE_NORMAL, effect=c.BULLET_EFFECT_ICE))
|
||||||
self.shoot_timer = self.current_time
|
self.shoot_timer = self.current_time
|
||||||
@ -417,6 +444,10 @@ class SnowPeaShooter(Plant):
|
|||||||
# 播放冰子弹音效
|
# 播放冰子弹音效
|
||||||
pg.mixer.Sound(os.path.join(os.path.dirname(os.path.dirname(os.path.dirname(__file__))) ,"resources", "sound", "snowPeaSparkles.ogg")).play()
|
pg.mixer.Sound(os.path.join(os.path.dirname(os.path.dirname(os.path.dirname(__file__))) ,"resources", "sound", "snowPeaSparkles.ogg")).play()
|
||||||
|
|
||||||
|
def setAttack(self):
|
||||||
|
self.state = c.ATTACK
|
||||||
|
if self.shoot_timer != 0:
|
||||||
|
self.shoot_timer = self.current_time - 700
|
||||||
|
|
||||||
class WallNut(Plant):
|
class WallNut(Plant):
|
||||||
def __init__(self, x, y):
|
def __init__(self, x, y):
|
||||||
@ -574,7 +605,9 @@ class PuffShroom(Plant):
|
|||||||
self.frames = self.idle_frames
|
self.frames = self.idle_frames
|
||||||
|
|
||||||
def attacking(self):
|
def attacking(self):
|
||||||
if (self.current_time - self.shoot_timer) >= 1400:
|
if self.shoot_timer == 0:
|
||||||
|
self.shoot_timer = self.current_time - 700
|
||||||
|
elif (self.current_time - self.shoot_timer) >= 1400:
|
||||||
self.bullet_group.add(Bullet(self.rect.right, self.rect.y + 10, self.rect.y + 10,
|
self.bullet_group.add(Bullet(self.rect.right, self.rect.y + 10, self.rect.y + 10,
|
||||||
c.BULLET_MUSHROOM, c.BULLET_DAMAGE_NORMAL, effect=False))
|
c.BULLET_MUSHROOM, c.BULLET_DAMAGE_NORMAL, effect=False))
|
||||||
self.shoot_timer = self.current_time
|
self.shoot_timer = self.current_time
|
||||||
@ -587,6 +620,11 @@ class PuffShroom(Plant):
|
|||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
def setAttack(self):
|
||||||
|
self.state = c.ATTACK
|
||||||
|
if self.shoot_timer != 0:
|
||||||
|
self.shoot_timer = self.current_time - 700
|
||||||
|
|
||||||
|
|
||||||
class PotatoMine(Plant):
|
class PotatoMine(Plant):
|
||||||
def __init__(self, x, y):
|
def __init__(self, x, y):
|
||||||
@ -729,9 +767,13 @@ class Spikeweed(Plant):
|
|||||||
self.zombie_group = zombie_group
|
self.zombie_group = zombie_group
|
||||||
self.animate_interval = 35
|
self.animate_interval = 35
|
||||||
self.state = c.ATTACK
|
self.state = c.ATTACK
|
||||||
|
if self.hit_timer != 0:
|
||||||
|
self.hit_timer = self.current_time - 500
|
||||||
|
|
||||||
def attacking(self):
|
def attacking(self):
|
||||||
if (self.current_time - self.attack_timer) >= 700:
|
if self.hit_timer == 0:
|
||||||
|
self.hit_timer = self.current_time - 500
|
||||||
|
elif (self.current_time - self.attack_timer) >= 700:
|
||||||
self.attack_timer = self.current_time
|
self.attack_timer = self.current_time
|
||||||
for zombie in self.zombie_group:
|
for zombie in self.zombie_group:
|
||||||
if self.canAttack(zombie):
|
if self.canAttack(zombie):
|
||||||
@ -822,13 +864,17 @@ class ScaredyShroom(Plant):
|
|||||||
def setAttack(self):
|
def setAttack(self):
|
||||||
self.state = c.ATTACK
|
self.state = c.ATTACK
|
||||||
self.changeFrames(self.idle_frames)
|
self.changeFrames(self.idle_frames)
|
||||||
|
if self.shoot_timer != 0:
|
||||||
|
self.shoot_timer = self.current_time - 700
|
||||||
|
|
||||||
def setIdle(self):
|
def setIdle(self):
|
||||||
self.state = c.IDLE
|
self.state = c.IDLE
|
||||||
self.changeFrames(self.idle_frames)
|
self.changeFrames(self.idle_frames)
|
||||||
|
|
||||||
def attacking(self):
|
def attacking(self):
|
||||||
if (self.current_time - self.shoot_timer) >= 1400:
|
if self.shoot_timer == 0:
|
||||||
|
self.shoot_timer = self.current_time - 700
|
||||||
|
elif (self.current_time - self.shoot_timer) >= 1400:
|
||||||
self.bullet_group.add(Bullet(self.rect.right - 15, self.rect.y + 40, self.rect.y + 40,
|
self.bullet_group.add(Bullet(self.rect.right - 15, self.rect.y + 40, self.rect.y + 40,
|
||||||
c.BULLET_MUSHROOM, c.BULLET_DAMAGE_NORMAL, effect=False))
|
c.BULLET_MUSHROOM, c.BULLET_DAMAGE_NORMAL, effect=False))
|
||||||
self.shoot_timer = self.current_time
|
self.shoot_timer = self.current_time
|
||||||
@ -1161,7 +1207,9 @@ class StarFruit(Plant):
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
def attacking(self):
|
def attacking(self):
|
||||||
if (self.current_time - self.shoot_timer) >= 1400:
|
if self.shoot_timer == 0:
|
||||||
|
self.shoot_timer = self.current_time - 700
|
||||||
|
elif (self.current_time - self.shoot_timer) >= 1400:
|
||||||
self.bullet_group.add(StarBullet(self.rect.left - 10, self.rect.y + 15, c.BULLET_DAMAGE_NORMAL, c.STAR_BACKWARD, self.level))
|
self.bullet_group.add(StarBullet(self.rect.left - 10, self.rect.y + 15, c.BULLET_DAMAGE_NORMAL, c.STAR_BACKWARD, self.level))
|
||||||
self.bullet_group.add(StarBullet(self.rect.centerx - 20, self.rect.bottom - self.rect.h - 15, c.BULLET_DAMAGE_NORMAL, c.STAR_UPWARD, self.level))
|
self.bullet_group.add(StarBullet(self.rect.centerx - 20, self.rect.bottom - self.rect.h - 15, c.BULLET_DAMAGE_NORMAL, c.STAR_UPWARD, self.level))
|
||||||
self.bullet_group.add(StarBullet(self.rect.centerx - 20, self.rect.bottom - 5, c.BULLET_DAMAGE_NORMAL, c.STAR_DOWNWARD, self.level))
|
self.bullet_group.add(StarBullet(self.rect.centerx - 20, self.rect.bottom - 5, c.BULLET_DAMAGE_NORMAL, c.STAR_DOWNWARD, self.level))
|
||||||
@ -1171,6 +1219,11 @@ class StarFruit(Plant):
|
|||||||
# 播放发射音效
|
# 播放发射音效
|
||||||
pg.mixer.Sound(os.path.join(os.path.dirname(os.path.dirname(os.path.dirname(__file__))) ,"resources", "sound", "shoot.ogg")).play()
|
pg.mixer.Sound(os.path.join(os.path.dirname(os.path.dirname(os.path.dirname(__file__))) ,"resources", "sound", "shoot.ogg")).play()
|
||||||
|
|
||||||
|
def setAttack(self):
|
||||||
|
self.state = c.ATTACK
|
||||||
|
if self.shoot_timer != 0:
|
||||||
|
self.shoot_timer = self.current_time - 700
|
||||||
|
|
||||||
|
|
||||||
class CoffeeBean(Plant):
|
class CoffeeBean(Plant):
|
||||||
def __init__(self, x, y, plant_group, mapContent, map, map_x):
|
def __init__(self, x, y, plant_group, mapContent, map, map_x):
|
||||||
@ -1180,8 +1233,11 @@ class CoffeeBean(Plant):
|
|||||||
self.map = map
|
self.map = map
|
||||||
self.map_x = map_x
|
self.map_x = map_x
|
||||||
|
|
||||||
def idling(self):
|
def animation(self):
|
||||||
if (self.frame_index + 1) == self.frame_num:
|
if (self.current_time - self.animate_timer) > self.animate_interval:
|
||||||
|
self.frame_index += 1
|
||||||
|
|
||||||
|
if self.frame_index >= self.frame_num:
|
||||||
self.mapContent[c.MAP_SLEEP] = False
|
self.mapContent[c.MAP_SLEEP] = False
|
||||||
for plant in self.plant_group:
|
for plant in self.plant_group:
|
||||||
if plant.can_sleep:
|
if plant.can_sleep:
|
||||||
@ -1195,6 +1251,18 @@ class CoffeeBean(Plant):
|
|||||||
pg.mixer.Sound(os.path.join(os.path.dirname(os.path.dirname(os.path.dirname(__file__))) ,"resources", "sound", "mushroomWakeup.ogg")).play()
|
pg.mixer.Sound(os.path.join(os.path.dirname(os.path.dirname(os.path.dirname(__file__))) ,"resources", "sound", "mushroomWakeup.ogg")).play()
|
||||||
self.mapContent[c.MAP_PLANT].remove(self.name)
|
self.mapContent[c.MAP_PLANT].remove(self.name)
|
||||||
self.kill()
|
self.kill()
|
||||||
|
self.frame_index = self.frame_num - 1
|
||||||
|
|
||||||
|
self.animate_timer = self.current_time
|
||||||
|
|
||||||
|
self.image = self.frames[self.frame_index]
|
||||||
|
if (self.current_time - self.highlightTime < 200):
|
||||||
|
self.image.set_alpha(150)
|
||||||
|
elif ((self.current_time - self.hit_timer) < 200):
|
||||||
|
self.image.set_alpha(192)
|
||||||
|
else:
|
||||||
|
self.image.set_alpha(255)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class SeaShroom(Plant):
|
class SeaShroom(Plant):
|
||||||
@ -1219,7 +1287,9 @@ class SeaShroom(Plant):
|
|||||||
self.frames = self.idle_frames
|
self.frames = self.idle_frames
|
||||||
|
|
||||||
def attacking(self):
|
def attacking(self):
|
||||||
if (self.current_time - self.shoot_timer) >= 1400:
|
if self.shoot_timer == 0:
|
||||||
|
self.shoot_timer = self.current_time - 700
|
||||||
|
elif (self.current_time - self.shoot_timer) >= 1400:
|
||||||
self.bullet_group.add(Bullet(self.rect.right, self.rect.y + 50, self.rect.y + 50,
|
self.bullet_group.add(Bullet(self.rect.right, self.rect.y + 50, self.rect.y + 50,
|
||||||
c.BULLET_SEASHROOM, c.BULLET_DAMAGE_NORMAL, effect=False))
|
c.BULLET_SEASHROOM, c.BULLET_DAMAGE_NORMAL, effect=False))
|
||||||
self.shoot_timer = self.current_time
|
self.shoot_timer = self.current_time
|
||||||
@ -1232,6 +1302,11 @@ class SeaShroom(Plant):
|
|||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
def setAttack(self):
|
||||||
|
self.state = c.ATTACK
|
||||||
|
if self.shoot_timer != 0:
|
||||||
|
self.shoot_timer = self.current_time - 700
|
||||||
|
|
||||||
|
|
||||||
class TallNut(Plant):
|
class TallNut(Plant):
|
||||||
def __init__(self, x, y):
|
def __init__(self, x, y):
|
||||||
@ -1503,3 +1578,12 @@ class FumeShroom(Plant):
|
|||||||
(self.rect.x + c.GRID_X_SIZE * 4.5 >= zombie.rect.x) and (zombie.rect.left <= c.SCREEN_WIDTH + 10)):
|
(self.rect.x + c.GRID_X_SIZE * 4.5 >= zombie.rect.x) and (zombie.rect.left <= c.SCREEN_WIDTH + 10)):
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
def setAttack(self):
|
||||||
|
self.state = c.ATTACK
|
||||||
|
self.changeFrames(self.attack_frames)
|
||||||
|
if self.shoot_timer != 0:
|
||||||
|
self.shoot_timer = self.current_time - 700
|
||||||
|
|
||||||
|
def attacking(self):
|
||||||
|
''
|
||||||
@ -1,5 +1,5 @@
|
|||||||
# 冒险模式起始关卡
|
# 冒险模式起始关卡
|
||||||
START_LEVEL_NUM = 0
|
START_LEVEL_NUM = 1
|
||||||
# 小游戏模式起始关卡
|
# 小游戏模式起始关卡
|
||||||
START_LITTLE_GAME_NUM = 1
|
START_LITTLE_GAME_NUM = 1
|
||||||
|
|
||||||
|
|||||||
@ -1248,7 +1248,6 @@ class Level(tool.State):
|
|||||||
plant.setIdle()
|
plant.setIdle()
|
||||||
elif plant.name == c.STARFRUIT:
|
elif plant.name == c.STARFRUIT:
|
||||||
can_attack = False
|
can_attack = False
|
||||||
if (plant.state == c.IDLE):
|
|
||||||
for zombie_group in self.zombie_groups: # 遍历循环所有僵尸
|
for zombie_group in self.zombie_groups: # 遍历循环所有僵尸
|
||||||
for zombie in zombie_group:
|
for zombie in zombie_group:
|
||||||
if plant.canAttack(zombie):
|
if plant.canAttack(zombie):
|
||||||
@ -1267,14 +1266,14 @@ class Level(tool.State):
|
|||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
can_attack = False
|
can_attack = False
|
||||||
if (plant.state == c.IDLE and zombie_len > 0):
|
if (zombie_len > 0):
|
||||||
for zombie in self.zombie_groups[i]:
|
for zombie in self.zombie_groups[i]:
|
||||||
if plant.canAttack(zombie):
|
if plant.canAttack(zombie):
|
||||||
can_attack = True
|
can_attack = True
|
||||||
break
|
break
|
||||||
if plant.state == c.IDLE and can_attack:
|
if plant.state == c.IDLE and can_attack:
|
||||||
plant.setAttack()
|
plant.setAttack()
|
||||||
elif (plant.state == c.ATTACK and not can_attack):
|
elif (plant.state == c.ATTACK and (not can_attack)):
|
||||||
plant.setIdle()
|
plant.setIdle()
|
||||||
|
|
||||||
def checkPlants(self):
|
def checkPlants(self):
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user