diff --git a/source/component/plant.py b/source/component/plant.py index 7a412e6..6d60b92 100755 --- a/source/component/plant.py +++ b/source/component/plant.py @@ -123,6 +123,7 @@ class StarBullet(Bullet): self.rect = self.image.get_rect() self.rect.x = x self.rect.y = start_y + _, self.map_y = self.level.map.getMapIndex(self.rect.x, self.rect.centery) self.direction = direction self.damage = damage self.state = c.FLY @@ -168,6 +169,7 @@ class StarBullet(Bullet): self.rect.y += 10 else: self.rect.x -= 10 + self.handleMapYPosition() 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() @@ -184,6 +186,15 @@ 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: + # 换行 + self.level.bullet_groups[self.map_y].remove(self) + self.level.bullet_groups[map_y1].add(self) + self.map_y = map_y1 + class Plant(pg.sprite.Sprite): def __init__(self, x, y, name, health, bullet_group, scale=1): @@ -1125,9 +1136,8 @@ class TorchWood(Plant): i.kill() class StarFruit(Plant): - def __init__(self, x, y, bullet_group, global_bullet_group): + def __init__(self, x, y, 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): @@ -1143,9 +1153,9 @@ 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.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.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.shoot_timer = self.current_time diff --git a/source/state/level.py b/source/state/level.py index d117b81..30db6ef 100644 --- a/source/state/level.py +++ b/source/state/level.py @@ -97,7 +97,6 @@ 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()) @@ -361,7 +360,6 @@ 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) @@ -436,7 +434,6 @@ class Level(tool.State): # 检查碰撞啥的 self.checkBulletCollisions() - self.checkGlobalBulletCollision() self.checkZombieCollisions() self.checkPlants() self.checkCarCollisions() @@ -539,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], self.global_bullet_group) + new_plant = plant.StarFruit(x, y, self.bullet_groups[map_y]) 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() @@ -636,19 +633,6 @@ 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.6) - 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 @@ -950,7 +934,6 @@ 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)