更新杨桃检测机制

This commit is contained in:
星外之神 2022-04-24 22:12:15 +08:00
parent 9b91d881d0
commit dca79c68d1
2 changed files with 11 additions and 5 deletions

View File

@ -190,7 +190,8 @@ class StarBullet(Bullet):
# 这里用的是坚果保龄球的代码改一下,实现子弹换行 # 这里用的是坚果保龄球的代码改一下,实现子弹换行
def handleMapYPosition(self): def handleMapYPosition(self):
_, map_y1 = self.level.map.getMapIndex(self.rect.x, self.rect.centery) _, map_y1 = self.level.map.getMapIndex(self.rect.x, self.rect.centery)
if (self.map_y != map_y1) and (0 <= map_y1 <= self.level.map_y_len-1): # 换行 _, map_y2 = self.level.map.getMapIndex(self.rect.x, self.rect.bottom)
if (self.map_y != map_y1) and (0 <= map_y1 <= self.level.map_y_len-1) and map_y1 == map_y2: # 换行
self.level.bullet_groups[self.map_y].remove(self) self.level.bullet_groups[self.map_y].remove(self)
self.level.bullet_groups[map_y1].add(self) self.level.bullet_groups[map_y1].add(self)
self.map_y = map_y1 self.map_y = map_y1
@ -1140,12 +1141,18 @@ class StarFruit(Plant):
Plant.__init__(self, x, y, c.STARFRUIT, c.PLANT_HEALTH, bullet_group) Plant.__init__(self, x, y, c.STARFRUIT, c.PLANT_HEALTH, bullet_group)
self.shoot_timer = 0 self.shoot_timer = 0
self.level = level self.level = level
self.map_x, self.map_y = self.level.map.getMapIndex(x, y)
def canAttack(self, zombie): def canAttack(self, zombie):
if zombie.state != c.DIE: if zombie.state != c.DIE:
if (self.rect.x >= zombie.rect.x) and abs(zombie.rect.bottom - self.rect.bottom) <= 30: # 对于同行且在杨桃后的僵尸 _, zombieMapY = self.level.map.getMapIndex(zombie.rect.centerx, zombie.rect.bottom)
if (self.rect.x >= zombie.rect.x) and (self.map_y == zombieMapY): # 对于同行且在杨桃后的僵尸
return True 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): # 斜向上理想直线方程为f(zombie.rect.x) = -zombie.rect.x + self.rect.y + self.rect.right - 15
elif abs(zombie.rect.y - (-zombie.rect.x + self.rect.y + self.rect.right - 15)) <= 60:
return True
# 斜向下理想直线方程为f(zombie.rect.x) = zombie.rect.x + self.rect.y - self.rect.right - 15
elif abs(zombie.rect.y - (zombie.rect.x + self.rect.y - self.rect.right - 15)) <= 60:
return True return True
elif zombie.rect.left <= self.rect.x <= zombie.rect.right: elif zombie.rect.left <= self.rect.x <= zombie.rect.right:
return True return True
@ -1153,7 +1160,7 @@ class StarFruit(Plant):
def attacking(self): def attacking(self):
if (self.current_time - self.shoot_timer) > 1400: 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.level)) self.bullet_group.add(StarBullet(self.rect.left + 10, self.rect.y + 20, 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 - 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.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.bottom - 20, c.BULLET_DAMAGE_NORMAL, c.STAR_FORWARD_DOWN, self.level))

View File

@ -148,7 +148,6 @@ class Level(tool.State):
self.map.setMapGridType(x, y, c.MAP_STATE_UNAVAILABLE) # 将坚果保龄球红线右侧设置为不可种植任何植物 self.map.setMapGridType(x, y, c.MAP_STATE_UNAVAILABLE) # 将坚果保龄球红线右侧设置为不可种植任何植物
def initState(self): def initState(self):
# 小游戏才有CHOOSEBAR_TYPE
if c.CHOOSEBAR_TYPE in self.map_data: if c.CHOOSEBAR_TYPE in self.map_data:
self.bar_type = self.map_data[c.CHOOSEBAR_TYPE] self.bar_type = self.map_data[c.CHOOSEBAR_TYPE]
else: else: