实现倭瓜、地刺范围伤害

This commit is contained in:
星外之神 2022-04-06 23:14:06 +08:00
parent 1aabacdd92
commit 2c3abb8800
4 changed files with 30 additions and 13 deletions

View File

@ -84,7 +84,6 @@ nuitka --mingw --standalone --onefile --show-progress --show-memory --output-dir
* 冷冻的僵尸未用蓝色滤镜标识 * 冷冻的僵尸未用蓝色滤镜标识
* 魅惑的僵尸未用红色滤镜标识 * 魅惑的僵尸未用红色滤镜标识
* 暂停游戏时僵尸与阳光的生成仍在计时 * 暂停游戏时僵尸与阳光的生成仍在计时
* 倭瓜、地刺无范围伤害
**欢迎提供[Pull requests](https://github.com/wszqkzqk/pypvz/pulls)或修复方法建议** **欢迎提供[Pull requests](https://github.com/wszqkzqk/pypvz/pulls)或修复方法建议**

View File

@ -1,8 +1,13 @@
{ {
"background_type":0, "background_type":0,
"init_sun_value":500, "init_sun_value":5000,
"shovel":1, "shovel":1,
"zombie_list":[ "zombie_list":[
{"time":1000, "map_y":2, "name":"BucketheadZombie"},
{"time":1000, "map_y":2, "name":"BucketheadZombie"},
{"time":1000, "map_y":2, "name":"Zombie"},
{"time":1000, "map_y":2, "name":"Zombie"},
{"time":1000, "map_y":2, "name":"Zombie"},
{"time":1000, "map_y":2, "name":"Zombie"} {"time":1000, "map_y":2, "name":"Zombie"}
] ]
} }

View File

@ -281,7 +281,7 @@ class PeaShooter(Plant):
self.shoot_timer = 0 self.shoot_timer = 0
def attacking(self): def attacking(self):
if (self.current_time - self.shoot_timer) > 2000: if (self.current_time - self.shoot_timer) > 1400:
self.bullet_group.add(Bullet(self.rect.right, self.rect.y, self.rect.y, self.bullet_group.add(Bullet(self.rect.right, self.rect.y, self.rect.y,
c.BULLET_PEA, c.BULLET_DAMAGE_NORMAL, False)) c.BULLET_PEA, c.BULLET_DAMAGE_NORMAL, False))
self.shoot_timer = self.current_time self.shoot_timer = self.current_time
@ -293,7 +293,7 @@ class RepeaterPea(Plant):
self.shoot_timer = 0 self.shoot_timer = 0
def attacking(self): def attacking(self):
if (self.current_time - self.shoot_timer) > 2000: if (self.current_time - self.shoot_timer) > 1400:
self.bullet_group.add(Bullet(self.rect.right, self.rect.y, self.rect.y, self.bullet_group.add(Bullet(self.rect.right, self.rect.y, self.rect.y,
c.BULLET_PEA, c.BULLET_DAMAGE_NORMAL, False)) c.BULLET_PEA, c.BULLET_DAMAGE_NORMAL, False))
self.bullet_group.add(Bullet(self.rect.right + 40, self.rect.y, self.rect.y, self.bullet_group.add(Bullet(self.rect.right + 40, self.rect.y, self.rect.y,
@ -309,7 +309,7 @@ class ThreePeaShooter(Plant):
self.bullet_groups = bullet_groups self.bullet_groups = bullet_groups
def attacking(self): def attacking(self):
if (self.current_time - self.shoot_timer) > 2000: 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)
@ -327,7 +327,7 @@ class SnowPeaShooter(Plant):
self.shoot_timer = 0 self.shoot_timer = 0
def attacking(self): def attacking(self):
if (self.current_time - self.shoot_timer) > 2000: if (self.current_time - self.shoot_timer) > 1400:
self.bullet_group.add(Bullet(self.rect.right, self.rect.y, self.rect.y, self.bullet_group.add(Bullet(self.rect.right, self.rect.y, self.rect.y,
c.BULLET_PEA_ICE, c.BULLET_DAMAGE_NORMAL, True)) c.BULLET_PEA_ICE, c.BULLET_DAMAGE_NORMAL, True))
self.shoot_timer = self.current_time self.shoot_timer = self.current_time
@ -484,7 +484,7 @@ 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) > 3000: if (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, True)) c.BULLET_MUSHROOM, c.BULLET_DAMAGE_NORMAL, True))
self.shoot_timer = self.current_time self.shoot_timer = self.current_time
@ -570,22 +570,35 @@ class Squash(Plant):
self.frames = self.idle_frames self.frames = self.idle_frames
def canAttack(self, zombie): def canAttack(self, zombie):
# 普通状态
if (self.state == c.IDLE and self.rect.x <= zombie.rect.right and if (self.state == c.IDLE and self.rect.x <= zombie.rect.right and
(self.rect.right + c.GRID_X_SIZE >= zombie.rect.x)): (self.rect.right + c.GRID_X_SIZE >= zombie.rect.x)):
return True return True
# 攻击状态
elif (self.state == c.ATTACK) and (self.rect.left <= zombie.rect.right or self.rect.right >= zombie.rect.left):
return True
return False return False
def setAttack(self, zombie, zombie_group): def setAttack(self, zombie, zombie_group):
self.attack_zombie = zombie self.attack_zombie = zombie
self.zombie_group = zombie_group self.zombie_group = zombie_group
self.state = c.ATTACK self.state = c.ATTACK
# 攻击状态下生命值无敌
self.health = float('inf')
def attacking(self): def attacking(self):
if self.squashing: if self.squashing:
if self.frame_index == 2: '''
self.zombie_group.remove(self.attack_zombie)
for zombie in self.zombie_group:
if self.canAttack(zombie):
zombie.setDamage(1800, False)
'''
if (self.frame_index + 1) == self.frame_num: if (self.frame_index + 1) == self.frame_num:
self.attack_zombie.kill() self.attack_zombie.kill()
for zombie in self.zombie_group:
if self.canAttack(zombie):
zombie.setDamage(1800, False)
self.health = 0 self.health = 0
elif self.aim_timer == 0: elif self.aim_timer == 0:
self.aim_timer = self.current_time self.aim_timer = self.current_time
@ -626,11 +639,11 @@ class Spikeweed(Plant):
self.state = c.ATTACK self.state = c.ATTACK
def attacking(self): def attacking(self):
if (self.current_time - self.attack_timer) > 2000: if (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):
zombie.setDamage(1, False) zombie.setDamage(10, False)
class Jalapeno(Plant): class Jalapeno(Plant):
@ -719,7 +732,7 @@ class ScaredyShroom(Plant):
self.changeFrames(self.idle_frames) self.changeFrames(self.idle_frames)
def attacking(self): def attacking(self):
if (self.current_time - self.shoot_timer) > 2000: if (self.current_time - self.shoot_timer) > 1400:
self.bullet_group.add(Bullet(self.rect.right, self.rect.y + 40, self.rect.y + 40, self.bullet_group.add(Bullet(self.rect.right, self.rect.y + 40, self.rect.y + 40,
c.BULLET_MUSHROOM, c.BULLET_DAMAGE_NORMAL, True)) c.BULLET_MUSHROOM, c.BULLET_DAMAGE_NORMAL, True))
self.shoot_timer = self.current_time self.shoot_timer = self.current_time

View File

@ -172,7 +172,7 @@ BUCKETHEAD_HEALTH = 1100
NEWSPAPER_HEALTH = 200 NEWSPAPER_HEALTH = 200
ATTACK_INTERVAL = 500 ATTACK_INTERVAL = 500
ZOMBIE_WALK_INTERVAL = 100 ZOMBIE_WALK_INTERVAL = 60 # 僵尸步行间隔
ZOMBIE_START_X = SCREEN_WIDTH + 50 ZOMBIE_START_X = SCREEN_WIDTH + 50