This commit is contained in:
星外之神 2022-06-05 15:53:44 +08:00
parent 0345119d34
commit ae58d15e18
3 changed files with 9 additions and 9 deletions

View File

@ -168,7 +168,7 @@ class MenuBar():
def checkMenuBarClick(self, mouse_pos): def checkMenuBarClick(self, mouse_pos):
x, y = mouse_pos x, y = mouse_pos
if(x >= self.rect.x and x <= self.rect.right and if (x >= self.rect.x and x <= self.rect.right and
y >= self.rect.y and y <= self.rect.bottom): y >= self.rect.y and y <= self.rect.bottom):
return True return True
return False return False

View File

@ -187,7 +187,7 @@ class StarBullet(Bullet):
Bullet.__init__(self, x, start_y, start_y, c.BULLET_STAR, damage, damageType = damageType) Bullet.__init__(self, x, start_y, start_y, c.BULLET_STAR, damage, damageType = damageType)
self.level = level self.level = level
_, self.map_y = self.level.map.getMapIndex(self.rect.x, self.rect.centery) self.map_y = self.level.map.getMapIndex(self.rect.x, self.rect.centery)[1]
self.direction = direction self.direction = direction
def update(self, game_info): def update(self, game_info):
@ -217,9 +217,9 @@ class StarBullet(Bullet):
# 这里用的是坚果保龄球的代码改一下,实现子弹换行 # 这里用的是坚果保龄球的代码改一下,实现子弹换行
def handleMapYPosition(self): def handleMapYPosition(self):
if self.direction == c.STAR_UPWARD: if self.direction == c.STAR_UPWARD:
_, map_y1 = self.level.map.getMapIndex(self.rect.x, self.rect.centery + 40) map_y1 = self.level.map.getMapIndex(self.rect.x, self.rect.centery + 40)[1]
else: else:
_, map_y1 = self.level.map.getMapIndex(self.rect.x, self.rect.centery + 20) map_y1 = self.level.map.getMapIndex(self.rect.x, self.rect.centery + 20)[1]
if (self.map_y != map_y1) and (0 <= map_y1 <= self.level.map_y_len-1): # 换行 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[self.map_y].remove(self)
self.level.bullet_groups[map_y1].add(self) self.level.bullet_groups[map_y1].add(self)
@ -1170,8 +1170,8 @@ class WallNutBowling(Plant):
return True return True
def handleMapYPosition(self): def handleMapYPosition(self):
_, map_y1 = self.level.map.getMapIndex(self.init_rect.x, self.init_rect.centery) map_y1 = self.level.map.getMapIndex(self.init_rect.x, self.init_rect.centery)[1]
_, map_y2 = self.level.map.getMapIndex(self.init_rect.x, self.init_rect.bottom) map_y2 = self.level.map.getMapIndex(self.init_rect.x, self.init_rect.bottom)[1]
if self.map_y != map_y1 and map_y1 == map_y2: if self.map_y != map_y1 and map_y1 == map_y2:
# wallnut bowls to another row, should modify which plant group it belongs to # wallnut bowls to another row, should modify which plant group it belongs to
self.level.plant_groups[self.map_y].remove(self) self.level.plant_groups[self.map_y].remove(self)
@ -1319,7 +1319,7 @@ class StarFruit(Plant):
if (zombie.name == c.SNORKELZOMBIE) and (zombie.frames == zombie.swim_frames): if (zombie.name == c.SNORKELZOMBIE) and (zombie.frames == zombie.swim_frames):
return False return False
if zombie.state != c.DIE: if zombie.state != c.DIE:
_, zombieMapY = self.level.map.getMapIndex(zombie.rect.centerx, zombie.rect.bottom) zombieMapY = self.level.map.getMapIndex(zombie.rect.centerx, zombie.rect.bottom)[1]
if (self.rect.x >= zombie.rect.x) and (self.map_y == zombieMapY): # 对于同行且在杨桃后的僵尸 if (self.rect.x >= zombie.rect.x) and (self.map_y == zombieMapY): # 对于同行且在杨桃后的僵尸
return True return True
# 斜向上理想直线方程为f(zombie.rect.x) = -0.75*(zombie.rect.x - (self.rect.right - 5)) + self.rect.y - 10 # 斜向上理想直线方程为f(zombie.rect.x) = -0.75*(zombie.rect.x - (self.rect.right - 5)) + self.rect.y - 10

View File

@ -320,7 +320,7 @@ class Level(tool.State):
def setupCars(self): def setupCars(self):
self.cars = [] self.cars = []
for i in range(self.map_y_len): for i in range(self.map_y_len):
_, y = self.map.getMapGridPos(0, i) y = self.map.getMapGridPos(0, i)[1]
self.cars.append(plant.Car(-40, y+20, i)) self.cars.append(plant.Car(-40, y+20, i))
# 更新函数每帧被调用,将鼠标事件传入给状态处理函数 # 更新函数每帧被调用,将鼠标事件传入给状态处理函数