diff --git a/source/component/menubar.py b/source/component/menubar.py index d516662..808cff4 100755 --- a/source/component/menubar.py +++ b/source/component/menubar.py @@ -4,7 +4,7 @@ import pygame as pg from .. import tool from .. import constants as c -plantInfo = (#元组 (植物名称, 卡片名称, 阳光, 冷却时间) +plantInfo = (# 元组 (植物名称, 卡片名称, 阳光, 冷却时间) (c.PEASHOOTER, c.CARD_PEASHOOTER, 100, diff --git a/source/component/plant.py b/source/component/plant.py index 6d60b92..2a1ed53 100755 --- a/source/component/plant.py +++ b/source/component/plant.py @@ -111,10 +111,11 @@ class Bullet(pg.sprite.Sprite): # 杨桃的子弹 class StarBullet(Bullet): - def __init__(self, x, start_y, damage, direction): # direction指星星飞行方向 + def __init__(self, x, start_y, damage, direction, level): # direction指星星飞行方向 pg.sprite.Sprite.__init__(self) self.name = c.BULLET_STAR + self.level = level self.frames = [] self.effect = False self.frame_index = 0 @@ -186,11 +187,10 @@ class StarBullet(Bullet): def draw(self, surface): surface.blit(self.image, self.rect) - # 这里可以用坚果保龄球的代码改一下 + # 这里用的是坚果保龄球的代码改一下,实现子弹换行 def handleMapYPosition(self): _, map_y1 = self.level.map.getMapIndex(self.rect.x, self.rect.centery) - if self.map_y != map_y1: - # 换行 + 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[map_y1].add(self) self.map_y = map_y1 @@ -1136,9 +1136,10 @@ class TorchWood(Plant): i.kill() class StarFruit(Plant): - def __init__(self, x, y, bullet_group): + def __init__(self, x, y, bullet_group, level): Plant.__init__(self, x, y, c.STARFRUIT, c.PLANT_HEALTH, bullet_group) self.shoot_timer = 0 + self.level = level def canAttack(self, zombie): if zombie.state != c.DIE: @@ -1152,10 +1153,10 @@ class StarFruit(Plant): 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.bullet_group.add(StarBullet(self.rect.centerx, self.rect.bottom - self.rect.h + 5, c.BULLET_DAMAGE_NORMAL, c.STAR_UPWARD)) - self.bullet_group.add(StarBullet(self.rect.centerx, self.rect.bottom - 5, c.BULLET_DAMAGE_NORMAL, c.STAR_DOWNWARD)) - self.bullet_group.add(StarBullet(self.rect.left + 5, self.rect.y + 10, c.BULLET_DAMAGE_NORMAL, c.STAR_FORWARD_DOWN)) - self.bullet_group.add(StarBullet(self.rect.left + 5, self.rect.y - 10, c.BULLET_DAMAGE_NORMAL, c.STAR_FORWARD_UP)) + self.bullet_group.add(StarBullet(self.rect.left + 10, self.rect.y, c.BULLET_DAMAGE_NORMAL, c.STAR_BACKWARD, self.level)) + self.bullet_group.add(StarBullet(self.rect.centerx - 20, self.rect.bottom - self.rect.h + 5, 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.right - 5, self.rect.bottom - 20, c.BULLET_DAMAGE_NORMAL, c.STAR_FORWARD_DOWN, self.level)) + self.bullet_group.add(StarBullet(self.rect.right - 5, self.rect.y - 10, c.BULLET_DAMAGE_NORMAL, c.STAR_FORWARD_UP, self.level)) self.shoot_timer = self.current_time diff --git a/source/state/level.py b/source/state/level.py index 30db6ef..a93a563 100644 --- a/source/state/level.py +++ b/source/state/level.py @@ -536,7 +536,7 @@ class Level(tool.State): 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]) + new_plant = plant.StarFruit(x, y, self.bullet_groups[map_y], self) 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() @@ -618,9 +618,12 @@ class Level(tool.State): self.shovel_rect.y = self.shovel_positon[1] def checkBulletCollisions(self): - collided_func = pg.sprite.collide_circle_ratio(0.7) for i in range(self.map_y_len): for bullet in self.bullet_groups[i]: + if bullet.name == c.BULLET_STAR: + collided_func = pg.sprite.collide_circle_ratio(1) + else: + collided_func = pg.sprite.collide_circle_ratio(0.7) if bullet.state == c.FLY: zombie = pg.sprite.spritecollideany(bullet, self.zombie_groups[i], collided_func) if zombie and zombie.state != c.DIE: