写了个有一堆bug的杨桃

This commit is contained in:
星外之神 2022-04-24 00:23:36 +08:00
parent 6a218c042e
commit cbfa280893
20 changed files with 91 additions and 10 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 38 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.2 KiB

After

Width:  |  Height:  |  Size: 2.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.3 KiB

After

Width:  |  Height:  |  Size: 2.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.3 KiB

After

Width:  |  Height:  |  Size: 2.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.2 KiB

After

Width:  |  Height:  |  Size: 2.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.2 KiB

After

Width:  |  Height:  |  Size: 2.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.1 KiB

After

Width:  |  Height:  |  Size: 2.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.1 KiB

After

Width:  |  Height:  |  Size: 2.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.0 KiB

After

Width:  |  Height:  |  Size: 2.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.1 KiB

After

Width:  |  Height:  |  Size: 2.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.1 KiB

After

Width:  |  Height:  |  Size: 2.1 KiB

View File

@ -81,6 +81,10 @@ plantInfo = (#元组 (植物名称, 卡片名称, 阳光, 冷却时间)
c.CARD_TORCHWOOD,
175,
7500),
(c.STARFRUIT,
c.CARD_STARFRUIT,
125,
7500),
# 应当保证这两个在一般模式下不可选的特殊植物恒在最后
(c.WALLNUTBOWLING,
c.CARD_WALLNUT,
@ -349,7 +353,7 @@ class Panel():
self.selected_cards.remove(delete_card)
self.selected_num -= 1
if self.selected_num >= c.BAR_CARD_X_INTERNAL:
if self.selected_num >= c.CARD_MAX_NUM:
return
for card in self.card_list:

View File

@ -109,10 +109,10 @@ class Bullet(pg.sprite.Sprite):
# 杨桃的子弹
class StarBullet(Bullet):
def __init__(self, x, start_y, name, damage, direction): # direction指星星飞行方向
def __init__(self, x, start_y, damage, direction): # direction指星星飞行方向
pg.sprite.Sprite.__init__(self)
self.name = name
self.name = c.BULLET_STAR
self.frames = []
self.frame_index = 0
self.load_images()
@ -143,7 +143,7 @@ class StarBullet(Bullet):
self.explode_frames = []
fly_name = self.name
explode_name = 'PeaNormalExplode'
explode_name = 'StarBulletExplode'
self.loadFrames(self.fly_frames, fly_name)
self.loadFrames(self.explode_frames, explode_name)
@ -153,12 +153,20 @@ class StarBullet(Bullet):
def update(self, game_info):
self.current_time = game_info[c.CURRENT_TIME]
if self.state == c.FLY:
if self.rect.y != self.dest_y:
self.rect.y += self.y_vel
if self.y_vel * (self.dest_y - self.rect.y) < 0:
self.rect.y = self.dest_y
self.rect.x += self.x_vel
if self.rect.x > c.SCREEN_WIDTH:
if self.direction == c.STAR_FORWARD_UP:
self.rect.x += 7
self.rect.y -= 7
elif self.direction == c.STAR_FORWARD_DOWN:
self.rect.x += 7
self.rect.y += 7
elif self.direction == c.STAR_UPWARD:
self.rect.y -= 10
elif self.direction == c.STAR_DOWNWARD:
self.rect.y += 10
else:
self.rect.x -= 10
if ((self.rect.x > c.SCREEN_WIDTH) or (self.rect.x < 0)
or (self.rect.y > c.SCREEN_HEIGHT) or (self.rect.y < 0)):
self.kill()
elif self.state == c.EXPLODE:
if (self.current_time - self.explode_timer) > 250:
@ -1112,3 +1120,29 @@ class TorchWood(Plant):
self.bullet_group.add(Bullet(i.rect.x, i.rect.y, i.rect.y,
c.BULLET_PEA, c.BULLET_DAMAGE_NORMAL, effect=False, passedTorchWood=self.rect.x))
i.kill()
class StarFruit(Plant):
def __init__(self, x, y, bullet_group, global_bullet_group):
Plant.__init__(self, x, y, c.STARFRUIT, c.PLANT_HEALTH, bullet_group)
self.global_bullet_group = global_bullet_group
self.shoot_timer = 0
def canAttack(self, zombie):
if zombie.state != c.DIE:
if (self.rect.x >= zombie.rect.x) and abs(zombie.rect.bottom - self.rect.bottom) <= 30: # 对于同行且在杨桃后的僵尸
return True
elif 0.9*abs(zombie.rect.y - self.rect.y) <= abs(zombie.rect.x - self.rect.x) <= 1.1*abs(zombie.rect.y - self.rect.y):
return True
elif zombie.rect.left <= self.rect.x <= zombie.rect.right:
return True
return False
def attacking(self):
if (self.current_time - self.shoot_timer) > 1400:
self.bullet_group.add(StarBullet(self.rect.left + 10, self.rect.y, c.BULLET_DAMAGE_NORMAL, c.STAR_BACKWARD))
self.global_bullet_group.add(StarBullet(self.rect.centerx, self.rect.bottom - self.rect.h + 5, c.BULLET_DAMAGE_NORMAL, c.STAR_UPWARD))
self.global_bullet_group.add(StarBullet(self.rect.centerx, self.rect.bottom - 5, c.BULLET_DAMAGE_NORMAL, c.STAR_DOWNWARD))
self.global_bullet_group.add(StarBullet(self.rect.left + 5, self.rect.y + 10, c.BULLET_DAMAGE_NORMAL, c.STAR_FORWARD_DOWN))
self.global_bullet_group.add(StarBullet(self.rect.left + 5, self.rect.y - 10, c.BULLET_DAMAGE_NORMAL, c.STAR_FORWARD_UP))
self.shoot_timer = self.current_time

View File

@ -202,6 +202,7 @@ class Zombie(pg.sprite.Sprite):
def setDamage(self, damage, effect=False, damageType=c.ZOMBIE_COMMON_DAMAGE):
# 冰冻减速效果
print(damage, effect, damageType)
if effect == c.BULLET_EFFECT_ICE:
if damageType == c.ZOMBIE_DEAFULT_DAMAGE: # 寒冰射手不能穿透二类防具进行减速
if not self.helmetType2:

View File

@ -181,6 +181,7 @@ WALLNUTBOWLING = 'WallNutBowling'
REDWALLNUTBOWLING = 'RedWallNutBowling'
LILYPAD = 'LilyPad'
TORCHWOOD = 'TorchWood'
STARFRUIT = 'StarFruit'
# 植物生命值
PLANT_HEALTH = 300
@ -222,6 +223,7 @@ CARD_HYPNOSHROOM = 'card_hypnoshroom'
CARD_REDWALLNUT = 'card_redwallnut'
CARD_LILYPAD = 'card_lilypad'
CARD_TORCHWOOD = 'card_torchwood'
CARD_STARFRUIT = 'card_starfruit'
# 子弹信息
# 子弹类型
@ -237,7 +239,10 @@ BULLET_DAMAGE_FIREBALL_RANGE = 13
BULLET_EFFECT_ICE = 'ice'
BULLET_EFFECT_UNICE = 'unice'
# 特殊子弹
# 杨桃子弹
# 子弹名称
BULLET_STAR = 'StarBullet'
# 子弹方向
STAR_FORWARD_UP = 'forwardUp' # 向前上方
STAR_FORWARD_DOWN = 'forwardDown' #向前下方

View File

@ -97,6 +97,7 @@ class Level(tool.State):
self.zombie_groups = []
self.hypno_zombie_groups = [] #zombies who are hypno after eating hypnoshroom
self.bullet_groups = []
self.global_bullet_group = pg.sprite.Group() # 全局可用的子弹
for i in range(self.map_y_len):
self.plant_groups.append(pg.sprite.Group())
self.zombie_groups.append(pg.sprite.Group())
@ -360,6 +361,7 @@ class Level(tool.State):
self.createZombie(data[1])
self.zombie_list.remove(data)
self.global_bullet_group.update((self.game_info))
for i in range(self.map_y_len):
self.bullet_groups[i].update(self.game_info)
self.plant_groups[i].update(self.game_info)
@ -434,6 +436,7 @@ class Level(tool.State):
# 检查碰撞啥的
self.checkBulletCollisions()
self.checkGlobalBulletCollision()
self.checkZombieCollisions()
self.checkPlants()
self.checkCarCollisions()
@ -535,6 +538,8 @@ class Level(tool.State):
new_plant = plant.LilyPad(x, y)
elif self.plant_name == c.TORCHWOOD:
new_plant = plant.TorchWood(x, y, self.bullet_groups[map_y])
elif self.plant_name == c.STARFRUIT:
new_plant = plant.StarFruit(x, y, self.bullet_groups[map_y], self.global_bullet_group)
if new_plant.can_sleep and self.background_type in {c.BACKGROUND_DAY, c.BACKGROUND_POOL, c.BACKGROUND_ROOF, c.BACKGROUND_WALLNUTBOWLING, c.BACKGROUND_SINGLE, c.BACKGROUND_TRIPLE}:
new_plant.setSleep()
@ -631,6 +636,19 @@ class Level(tool.State):
if abs(rangeZombie.rect.x - bullet.rect.x) <= (c.GRID_X_SIZE // 2):
rangeZombie.setDamage(c.BULLET_DAMAGE_FIREBALL_RANGE, effect=False, damageType=c.ZOMBIE_DEAFULT_DAMAGE)
def checkGlobalBulletCollision(self):
collided_func = pg.sprite.collide_circle_ratio(0.7)
for i in range(self.map_y_len):
for globalBullet in self.global_bullet_group:
if globalBullet.state == c.FLY:
zombie = pg.sprite.spritecollideany(globalBullet, self.zombie_groups[i], collided_func)
if zombie and zombie.state != c.DIE:
# 这里生效代表已经发生了碰撞
zombie.setDamage(globalBullet.damage, damageType=c.ZOMBIE_COMMON_DAMAGE) # 这里设定刻意与原版不同:逻辑上,杨桃是斜着打的,伤害应当可用穿透二类防具
globalBullet.setExplode()
def checkZombieCollisions(self):
if self.bar_type == c.CHOSSEBAR_BOWLING:
ratio = 0.6
@ -820,6 +838,24 @@ class Level(tool.State):
plant.setAttack()
elif plant.state != c.IDLE:
plant.setIdle()
elif plant.name == c.STARFRUIT:
can_attack = False
if (plant.state == c.IDLE):
'''
totalZombie = 0
for zombieColumn in range(self.map_y_len):
totalZombie += len(self.zombie_groups[zombieColumn])
if totalZombie > 0: # 只要场上有僵尸就需要判断
'''
for zombie_group in self.zombie_groups: # 遍历循环所有僵尸
for zombie in zombie_group:
if plant.canAttack(zombie):
can_attack = True
break
if plant.state == c.IDLE and can_attack:
plant.setAttack()
elif (plant.state == c.ATTACK and not can_attack):
plant.setIdle()
elif(plant.name == c.WALLNUTBOWLING or
plant.name == c.REDWALLNUTBOWLING):
pass
@ -920,6 +956,7 @@ class Level(tool.State):
self.menubar.draw(surface)
for car in self.cars:
car.draw(surface)
self.global_bullet_group.draw(surface)
for i in range(self.map_y_len):
self.plant_groups[i].draw(surface)
self.zombie_groups[i].draw(surface)