重构
This commit is contained in:
parent
0db90ba8c8
commit
0345119d34
@ -340,8 +340,8 @@ class MoveCard():
|
||||
|
||||
def checkMouseClick(self, mouse_pos):
|
||||
x, y = mouse_pos
|
||||
if(x >= self.rect.x and x <= self.rect.right and
|
||||
y >= self.rect.y and y <= self.rect.bottom):
|
||||
if (x >= self.rect.x and x <= self.rect.right and
|
||||
y >= self.rect.y and y <= self.rect.bottom):
|
||||
return True
|
||||
return False
|
||||
|
||||
@ -425,8 +425,8 @@ class MoveBar():
|
||||
|
||||
def checkMenuBarClick(self, mouse_pos):
|
||||
x, y = mouse_pos
|
||||
if(x >= self.rect.x and x <= self.rect.right and
|
||||
y >= self.rect.y and y <= self.rect.bottom):
|
||||
if (x >= self.rect.x and x <= self.rect.right and
|
||||
y >= self.rect.y and y <= self.rect.bottom):
|
||||
return True
|
||||
return False
|
||||
|
||||
|
||||
@ -211,7 +211,7 @@ class StarBullet(Bullet):
|
||||
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:
|
||||
if (self.current_time - self.explode_timer) >= 250:
|
||||
self.kill()
|
||||
|
||||
# 这里用的是坚果保龄球的代码改一下,实现子弹换行
|
||||
@ -220,7 +220,6 @@ class StarBullet(Bullet):
|
||||
_, map_y1 = self.level.map.getMapIndex(self.rect.x, self.rect.centery + 40)
|
||||
else:
|
||||
_, map_y1 = self.level.map.getMapIndex(self.rect.x, self.rect.centery + 20)
|
||||
# _, map_y2 = self.level.map.getMapIndex(self.rect.x, self.rect.bottom +20)
|
||||
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)
|
||||
@ -344,8 +343,8 @@ class Plant(pg.sprite.Sprite):
|
||||
self.health -= damage
|
||||
self.hit_timer = self.current_time
|
||||
if ((self.name == c.HYPNOSHROOM) and
|
||||
(self.state != c.SLEEP) and
|
||||
(zombie.name not in {c.ZOMBONI, "投石车僵尸(未实现)", "加刚特尔(未实现)"})):
|
||||
(self.state != c.SLEEP) and
|
||||
(zombie.name not in {c.ZOMBONI, "投石车僵尸(未实现)", "加刚特尔(未实现)"})):
|
||||
self.zombie_to_hypno = zombie
|
||||
|
||||
def getPosition(self):
|
||||
@ -383,7 +382,7 @@ class Sun(Plant):
|
||||
if self.state == c.DIE:
|
||||
return False
|
||||
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):
|
||||
self.state = c.DIE
|
||||
self.kill()
|
||||
return True
|
||||
@ -626,8 +625,8 @@ class Chomper(Plant):
|
||||
if (zombie.name == c.SNORKELZOMBIE) and (zombie.frames == zombie.swim_frames):
|
||||
return False
|
||||
elif (self.state == c.IDLE and zombie.state != c.DIGEST and
|
||||
self.rect.x <= zombie.rect.centerx and (not zombie.lostHead) and
|
||||
(self.rect.x + c.GRID_X_SIZE*2.7 >= zombie.rect.centerx)):
|
||||
self.rect.x <= zombie.rect.centerx and (not zombie.lostHead) and
|
||||
(self.rect.x + c.GRID_X_SIZE*2.7 >= zombie.rect.centerx)):
|
||||
return True
|
||||
return False
|
||||
|
||||
@ -702,7 +701,7 @@ class PuffShroom(Plant):
|
||||
if (zombie.name == c.SNORKELZOMBIE) and (zombie.frames == zombie.swim_frames):
|
||||
return False
|
||||
if (self.rect.x <= zombie.rect.right and
|
||||
(self.rect.x + c.GRID_X_SIZE * 4 >= zombie.rect.x) and (zombie.rect.left <= c.SCREEN_WIDTH + 10)):
|
||||
(self.rect.x + c.GRID_X_SIZE * 4 >= zombie.rect.x) and (zombie.rect.left <= c.SCREEN_WIDTH + 10)):
|
||||
return True
|
||||
return False
|
||||
|
||||
@ -796,7 +795,7 @@ class Squash(Plant):
|
||||
def canAttack(self, zombie):
|
||||
# 普通状态
|
||||
if (self.state == c.IDLE and self.rect.x <= zombie.rect.right and
|
||||
(self.rect.right + c.GRID_X_SIZE >= zombie.rect.x)):
|
||||
(self.rect.right + c.GRID_X_SIZE >= zombie.rect.x)):
|
||||
return True
|
||||
# 攻击状态
|
||||
elif (self.state == c.ATTACK):
|
||||
@ -1431,7 +1430,7 @@ class SeaShroom(Plant):
|
||||
if (zombie.name == c.SNORKELZOMBIE) and (zombie.frames == zombie.swim_frames):
|
||||
return False
|
||||
if (self.rect.x <= zombie.rect.right and
|
||||
(self.rect.x + c.GRID_X_SIZE * 4 >= zombie.rect.x) and (zombie.rect.left <= c.SCREEN_WIDTH + 10)):
|
||||
(self.rect.x + c.GRID_X_SIZE * 4 >= zombie.rect.x) and (zombie.rect.left <= c.SCREEN_WIDTH + 10)):
|
||||
return True
|
||||
return False
|
||||
|
||||
@ -1723,7 +1722,7 @@ class FumeShroom(Plant):
|
||||
if (zombie.name == c.SNORKELZOMBIE) and (zombie.frames == zombie.swim_frames):
|
||||
return False
|
||||
if (self.rect.x <= zombie.rect.right and
|
||||
(self.rect.x + c.GRID_X_SIZE * 5 >= zombie.rect.x) and (zombie.rect.left <= c.SCREEN_WIDTH + 10)):
|
||||
(self.rect.x + c.GRID_X_SIZE * 5 >= zombie.rect.x) and (zombie.rect.left <= c.SCREEN_WIDTH + 10)):
|
||||
return True
|
||||
return False
|
||||
|
||||
|
||||
@ -581,32 +581,32 @@ class Level(tool.State):
|
||||
# 检查小菜单有没有被点击
|
||||
def checkLittleMenuClick(self, mouse_pos):
|
||||
x, y = mouse_pos
|
||||
if(x >= self.little_menu_rect.x and x <= self.little_menu_rect.right and
|
||||
y >= self.little_menu_rect.y and y <= self.little_menu_rect.bottom):
|
||||
if (x >= self.little_menu_rect.x and x <= self.little_menu_rect.right and
|
||||
y >= self.little_menu_rect.y and y <= self.little_menu_rect.bottom):
|
||||
return True
|
||||
return False
|
||||
|
||||
# 检查小菜单的返回有没有被点击
|
||||
def checkReturnClick(self, mouse_pos):
|
||||
x, y = mouse_pos
|
||||
if(x >= self.return_button_rect.x and x <= self.return_button_rect.right and
|
||||
y >= self.return_button_rect.y and y <= self.return_button_rect.bottom):
|
||||
if (x >= self.return_button_rect.x and x <= self.return_button_rect.right and
|
||||
y >= self.return_button_rect.y and y <= self.return_button_rect.bottom):
|
||||
return True
|
||||
return False
|
||||
|
||||
# 检查小菜单的重新开始有没有被点击
|
||||
def checkRestartClick(self, mouse_pos):
|
||||
x, y = mouse_pos
|
||||
if(x >= self.restart_button_rect.x and x <= self.restart_button_rect.right and
|
||||
y >= self.restart_button_rect.y and y <= self.restart_button_rect.bottom):
|
||||
if (x >= self.restart_button_rect.x and x <= self.restart_button_rect.right and
|
||||
y >= self.restart_button_rect.y and y <= self.restart_button_rect.bottom):
|
||||
return True
|
||||
return False
|
||||
|
||||
# 检查小菜单的主菜单有没有被点击
|
||||
def checkMainMenuClick(self, mouse_pos):
|
||||
x, y = mouse_pos
|
||||
if(x >= self.mainMenu_button_rect.x and x <= self.mainMenu_button_rect.right and
|
||||
y >= self.mainMenu_button_rect.y and y <= self.mainMenu_button_rect.bottom):
|
||||
if (x >= self.mainMenu_button_rect.x and x <= self.mainMenu_button_rect.right and
|
||||
y >= self.mainMenu_button_rect.y and y <= self.mainMenu_button_rect.bottom):
|
||||
return True
|
||||
return False
|
||||
|
||||
@ -910,7 +910,7 @@ class Level(tool.State):
|
||||
new_plant = plant.TangleKlep(x, y)
|
||||
elif self.plant_name == c.DOOMSHROOM:
|
||||
if ((self.map_data[c.BACKGROUND_TYPE] in c.ON_ROOF_BACKGROUNDS) or
|
||||
(self.map_data[c.BACKGROUND_TYPE] in c.POOL_EQUIPPED_BACKGROUNDS)):
|
||||
(self.map_data[c.BACKGROUND_TYPE] in c.POOL_EQUIPPED_BACKGROUNDS)):
|
||||
new_plant = plant.DoomShroom(x, y, self.map.map[map_y][map_x][c.MAP_PLANT], explode_y_range=3)
|
||||
else:
|
||||
new_plant = plant.DoomShroom(x, y, self.map.map[map_y][map_x][c.MAP_PLANT], explode_y_range=2)
|
||||
@ -1188,7 +1188,7 @@ class Level(tool.State):
|
||||
continue
|
||||
for zombie in self.zombie_groups[i]:
|
||||
if ((abs(zombie.rect.centerx - x) <= x_range) or
|
||||
((zombie.rect.right - (x-x_range) > 20) or (zombie.rect.right - (x-x_range))/zombie.rect.width > 0.2, ((x+x_range) - zombie.rect.left > 20) or ((x+x_range) - zombie.rect.left)/zombie.rect.width > 0.2)[zombie.rect.x > x]): # 这代码不太好懂,后面是一个判断僵尸在左还是在右,前面是一个元组,[0]是在左边的情况,[1]是在右边的情况
|
||||
((zombie.rect.right - (x-x_range) > 20) or (zombie.rect.right - (x-x_range))/zombie.rect.width > 0.2, ((x+x_range) - zombie.rect.left > 20) or ((x+x_range) - zombie.rect.left)/zombie.rect.width > 0.2)[zombie.rect.x > x]): # 这代码不太好懂,后面是一个判断僵尸在左还是在右,前面是一个元组,[0]是在左边的情况,[1]是在右边的情况
|
||||
if effect == c.BULLET_EFFECT_UNICE:
|
||||
zombie.ice_slow_ratio = 1
|
||||
zombie.setDamage(1800, damageType=c.ZOMBIE_ASH_DAMAGE)
|
||||
@ -1280,7 +1280,7 @@ class Level(tool.State):
|
||||
for zombie in self.zombie_groups[i]:
|
||||
# 双判断:发生碰撞或在攻击范围内
|
||||
if ((pg.sprite.collide_mask(zombie, targetPlant)) or
|
||||
(abs(zombie.rect.centerx - targetPlant.rect.centerx) <= targetPlant.explode_x_range)):
|
||||
(abs(zombie.rect.centerx - targetPlant.rect.centerx) <= targetPlant.explode_x_range)):
|
||||
zombie.setDamage(1800, damageType=c.ZOMBIE_RANGE_DAMAGE)
|
||||
targetPlant.boomed = True
|
||||
elif targetPlant.name == c.SQUASH:
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user