更改胜利、失败界面
This commit is contained in:
parent
20f6400e9a
commit
7263521ef7
@ -634,13 +634,6 @@ class Level(tool.State):
|
|||||||
self.level_progress_flag_rect = self.level_progress_flag.get_rect()
|
self.level_progress_flag_rect = self.level_progress_flag.get_rect()
|
||||||
self.level_progress_flag_rect.x = self.level_progress_bar_image_rect.x - 78
|
self.level_progress_flag_rect.x = self.level_progress_bar_image_rect.x - 78
|
||||||
self.level_progress_flag_rect.y = self.level_progress_bar_image_rect.y - 3
|
self.level_progress_flag_rect.y = self.level_progress_bar_image_rect.y - 3
|
||||||
|
|
||||||
def inArea(self, rect, x, y):
|
|
||||||
if (x >= rect.x and x <= rect.right and
|
|
||||||
y >= rect.y and y <= rect.bottom):
|
|
||||||
return True
|
|
||||||
else:
|
|
||||||
return False
|
|
||||||
|
|
||||||
# 用小铲子移除植物
|
# 用小铲子移除植物
|
||||||
def shovelRemovePlant(self, mouse_pos):
|
def shovelRemovePlant(self, mouse_pos):
|
||||||
|
|||||||
@ -99,13 +99,6 @@ class Menu(tool.State):
|
|||||||
self.adventure_clicked = False
|
self.adventure_clicked = False
|
||||||
self.option_button_clicked = False
|
self.option_button_clicked = False
|
||||||
|
|
||||||
def inArea(self, rect, x, y):
|
|
||||||
if (x >= rect.x and x <= rect.right and
|
|
||||||
y >= rect.y and y <= rect.bottom):
|
|
||||||
return True
|
|
||||||
else:
|
|
||||||
return False
|
|
||||||
|
|
||||||
def checkHilight(self, x, y):
|
def checkHilight(self, x, y):
|
||||||
# 高亮冒险模式按钮
|
# 高亮冒险模式按钮
|
||||||
if self.inArea(self.adventure_rect, x, y):
|
if self.inArea(self.adventure_rect, x, y):
|
||||||
|
|||||||
@ -6,48 +6,65 @@ from .. import constants as c
|
|||||||
class Screen(tool.State):
|
class Screen(tool.State):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
tool.State.__init__(self)
|
tool.State.__init__(self)
|
||||||
self.end_time = 3000
|
|
||||||
|
|
||||||
def startup(self, current_time, persist):
|
def startup(self, current_time, persist):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def getImageName(self):
|
|
||||||
pass
|
|
||||||
|
|
||||||
def set_next_state(self):
|
|
||||||
pass
|
|
||||||
|
|
||||||
def setupImage(self, name, frame_rect=(0, 0, 800, 600)):
|
def setupImage(self, name, frame_rect=(0, 0, 800, 600)):
|
||||||
|
# 背景图本身
|
||||||
self.image = tool.get_image(tool.GFX[name], *frame_rect)
|
self.image = tool.get_image(tool.GFX[name], *frame_rect)
|
||||||
self.rect = self.image.get_rect()
|
self.rect = self.image.get_rect()
|
||||||
self.rect.x = 0
|
self.rect.x = 0
|
||||||
self.rect.y = 0
|
self.rect.y = 0
|
||||||
|
|
||||||
|
# 按钮
|
||||||
|
frame_rect = (0, 0, 111, 26)
|
||||||
|
## 继续按钮
|
||||||
|
self.next_button_image = tool.get_image_menu(tool.GFX[c.UNIVERSAL_BUTTON], *frame_rect)
|
||||||
|
self.next_button_image_rect = self.next_button_image.get_rect()
|
||||||
|
self.next_button_image_rect.x = 70
|
||||||
|
### 继续按钮上的文字
|
||||||
|
font = pg.font.Font(c.FONT_PATH, 18)
|
||||||
|
next_text = font.render("继续", True, c.NAVYBLUE)
|
||||||
|
next_text_rect = next_text.get_rect()
|
||||||
|
next_text_rect.x = 37
|
||||||
|
## 主菜单按钮
|
||||||
|
self.main_menu_button_image = tool.get_image_menu(tool.GFX[c.UNIVERSAL_BUTTON], *frame_rect)
|
||||||
|
self.main_menu_button_image_rect = self.main_menu_button_image.get_rect()
|
||||||
|
self.main_menu_button_image_rect.x = 620
|
||||||
|
self.next_button_image_rect.y = self.main_menu_button_image_rect.y = 550
|
||||||
|
### 主菜单按钮上的文字
|
||||||
|
main_menu_text = font.render("主菜单", True, c.NAVYBLUE)
|
||||||
|
main_menu_text_rect = main_menu_text.get_rect()
|
||||||
|
main_menu_text_rect.x = 29
|
||||||
|
self.next_button_image.blit(next_text, next_text_rect)
|
||||||
|
self.main_menu_button_image.blit(main_menu_text, main_menu_text_rect)
|
||||||
|
self.image.blit(self.next_button_image, self.next_button_image_rect)
|
||||||
|
self.image.blit(self.main_menu_button_image, self.main_menu_button_image_rect)
|
||||||
|
|
||||||
def update(self, surface, current_time, mouse_pos, mouse_click):
|
def update(self, surface, current_time, mouse_pos, mouse_click):
|
||||||
if (current_time - self.start_time) < self.end_time:
|
surface.fill(c.WHITE)
|
||||||
surface.fill(c.WHITE)
|
surface.blit(self.image, self.rect)
|
||||||
surface.blit(self.image, self.rect)
|
if mouse_pos:
|
||||||
else:
|
# 点到继续
|
||||||
self.done = True
|
if self.inArea(self.next_button_image_rect, *mouse_pos):
|
||||||
|
self.next = c.LEVEL
|
||||||
|
self.done = True
|
||||||
|
# 点到主菜单
|
||||||
|
elif self.inArea(self.main_menu_button_image_rect, *mouse_pos):
|
||||||
|
self.next = c.MAIN_MENU
|
||||||
|
self.done = True
|
||||||
|
|
||||||
class GameVictoryScreen(Screen):
|
class GameVictoryScreen(Screen):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
Screen.__init__(self)
|
Screen.__init__(self)
|
||||||
|
self.image_name = c.GAME_VICTORY_IMAGE
|
||||||
def getImageName(self):
|
|
||||||
return c.GAME_VICTORY_IMAGE
|
|
||||||
|
|
||||||
def set_next_state(self):
|
|
||||||
return c.LEVEL
|
|
||||||
|
|
||||||
def startup(self, current_time, persist):
|
def startup(self, current_time, persist):
|
||||||
self.start_time = current_time
|
self.start_time = current_time
|
||||||
self.next = c.LEVEL
|
|
||||||
self.persist = persist
|
self.persist = persist
|
||||||
self.game_info = persist
|
self.game_info = persist
|
||||||
name = self.getImageName()
|
self.setupImage(self.image_name)
|
||||||
self.setupImage(name)
|
|
||||||
self.next = self.set_next_state()
|
|
||||||
pg.display.set_caption("pypvz: 战斗胜利!")
|
pg.display.set_caption("pypvz: 战斗胜利!")
|
||||||
# 停止播放原来关卡中的音乐
|
# 停止播放原来关卡中的音乐
|
||||||
pg.mixer.music.stop()
|
pg.mixer.music.stop()
|
||||||
@ -55,21 +72,13 @@ class GameVictoryScreen(Screen):
|
|||||||
class GameLoseScreen(Screen):
|
class GameLoseScreen(Screen):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
Screen.__init__(self)
|
Screen.__init__(self)
|
||||||
|
self.image_name = c.GAME_LOSE_IMAGE
|
||||||
def getImageName(self):
|
|
||||||
return c.GAME_LOSE_IMAGE
|
|
||||||
|
|
||||||
def set_next_state(self):
|
|
||||||
return c.LEVEL
|
|
||||||
|
|
||||||
def startup(self, current_time, persist):
|
def startup(self, current_time, persist):
|
||||||
self.start_time = current_time
|
self.start_time = current_time
|
||||||
self.next = c.LEVEL
|
|
||||||
self.persist = persist
|
self.persist = persist
|
||||||
self.game_info = persist
|
self.game_info = persist
|
||||||
name = self.getImageName()
|
self.setupImage(self.image_name, (-15, 0, 800, 600))
|
||||||
self.setupImage(name, (-15, 0, 800, 600))
|
|
||||||
self.next = self.set_next_state()
|
|
||||||
pg.display.set_caption("pypvz: 战斗失败!")
|
pg.display.set_caption("pypvz: 战斗失败!")
|
||||||
# 停止播放原来关卡中的音乐
|
# 停止播放原来关卡中的音乐
|
||||||
pg.mixer.music.stop()
|
pg.mixer.music.stop()
|
||||||
@ -187,7 +196,6 @@ class AwardScreen(tool.State):
|
|||||||
pg.mixer.music.set_volume(self.game_info[c.SOUND_VOLUME])
|
pg.mixer.music.set_volume(self.game_info[c.SOUND_VOLUME])
|
||||||
|
|
||||||
def update(self, surface, current_time, mouse_pos, mouse_click):
|
def update(self, surface, current_time, mouse_pos, mouse_click):
|
||||||
surface.fill(c.WHITE)
|
|
||||||
surface.blit(self.image, self.rect)
|
surface.blit(self.image, self.rect)
|
||||||
if mouse_pos:
|
if mouse_pos:
|
||||||
# 检查主菜单点击
|
# 检查主菜单点击
|
||||||
@ -198,10 +206,3 @@ class AwardScreen(tool.State):
|
|||||||
if self.inArea(self.next_button_image_rect, *mouse_pos):
|
if self.inArea(self.next_button_image_rect, *mouse_pos):
|
||||||
self.next = c.LEVEL
|
self.next = c.LEVEL
|
||||||
self.done = True
|
self.done = True
|
||||||
|
|
||||||
def inArea(self, rect, x, y):
|
|
||||||
if (x >= rect.x and x <= rect.right and
|
|
||||||
y >= rect.y and y <= rect.bottom):
|
|
||||||
return True
|
|
||||||
else:
|
|
||||||
return False
|
|
||||||
|
|||||||
@ -29,6 +29,14 @@ class State():
|
|||||||
# abstract method
|
# abstract method
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
# 工具:范围判断函数,用于判断点击
|
||||||
|
def inArea(self, rect, x, y):
|
||||||
|
if (x >= rect.x and x <= rect.right and
|
||||||
|
y >= rect.y and y <= rect.bottom):
|
||||||
|
return True
|
||||||
|
else:
|
||||||
|
return False
|
||||||
|
|
||||||
# control this game. do event loops
|
# control this game. do event loops
|
||||||
class Control():
|
class Control():
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user