add some buttons
BIN
resources/graphics/Screen/bigMenu.png
Normal file
|
After Width: | Height: | Size: 233 KiB |
BIN
resources/graphics/Screen/littleMenu.png
Normal file
|
After Width: | Height: | Size: 3.7 KiB |
BIN
resources/graphics/Screen/mainMenuButton.png
Normal file
|
After Width: | Height: | Size: 10 KiB |
BIN
resources/graphics/Screen/restartButton.png
Normal file
|
After Width: | Height: | Size: 11 KiB |
BIN
resources/graphics/Screen/returnButton.png
Normal file
|
After Width: | Height: | Size: 45 KiB |
BIN
resources/graphics/Screen/shovel.png
Normal file
|
After Width: | Height: | Size: 9.2 KiB |
BIN
resources/graphics/Screen/shovelBox.png
Normal file
|
After Width: | Height: | Size: 7.9 KiB |
@ -28,6 +28,15 @@ SIZE_MULTIPLIER = 1.3
|
||||
EXIT = 'exit'
|
||||
# 当想要一个特殊值时用
|
||||
NULL = 'null'
|
||||
# 游戏界面可选的菜单
|
||||
LITTLE_MENU = 'littleMenu'
|
||||
BIG_MENU = 'bigMenu'
|
||||
RETURN_BUTTON = 'returnButton'
|
||||
RESTART_BUTTON = 'restartButton'
|
||||
MAINMENU_BUTTON = 'mainMenuButton'
|
||||
# 小铲子
|
||||
SHOVEL = 'shovel'
|
||||
SHOVEL_BOX = 'shovelBox'
|
||||
|
||||
|
||||
#GAME INFO DICTIONARY KEYS
|
||||
|
||||
@ -16,6 +16,9 @@ class Level(tool.State):
|
||||
self.map_y_len = c.GRID_Y_LEN
|
||||
self.map = map.Map(c.GRID_X_LEN, self.map_y_len)
|
||||
|
||||
# 默认显然不用显示菜单
|
||||
self.showLittleMenu = False
|
||||
|
||||
self.loadMap()
|
||||
self.setupBackground()
|
||||
self.initState()
|
||||
@ -23,9 +26,16 @@ class Level(tool.State):
|
||||
def loadMap(self):
|
||||
map_file = 'level_' + str(self.game_info[c.LEVEL_NUM]) + '.json'
|
||||
file_path = os.path.join('resources', 'data', 'map', map_file)
|
||||
# 最后一关之后应该结束了
|
||||
try:
|
||||
f = open(file_path)
|
||||
self.map_data = json.load(f)
|
||||
f.close()
|
||||
except Exception as e:
|
||||
print("游戏结束")
|
||||
self.done = True
|
||||
self.next = c.MAIN_MENU
|
||||
return
|
||||
|
||||
def setupBackground(self):
|
||||
img_index = self.map_data[c.BACKGROUND_TYPE]
|
||||
@ -37,6 +47,7 @@ class Level(tool.State):
|
||||
self.viewport = tool.SCREEN.get_rect(bottom=self.bg_rect.bottom)
|
||||
self.viewport.x += c.BACKGROUND_OFFSET_X
|
||||
|
||||
|
||||
def setupGroups(self):
|
||||
self.sun_group = pg.sprite.Group()
|
||||
self.head_group = pg.sprite.Group()
|
||||
@ -114,7 +125,11 @@ class Level(tool.State):
|
||||
self.menubar = menubar.MenuBar(card_list, self.map_data[c.INIT_SUN_NAME])
|
||||
else:
|
||||
self.menubar = menubar.MoveBar(card_list)
|
||||
|
||||
# 是否拖住植物或者铲子
|
||||
self.drag_plant = False
|
||||
self.drag_plant = False
|
||||
|
||||
self.hint_image = None
|
||||
self.hint_plant = False
|
||||
if self.background_type == c.BACKGROUND_DAY and self.bar_type == c.CHOOSEBAR_STATIC:
|
||||
@ -128,7 +143,108 @@ class Level(tool.State):
|
||||
self.setupZombies()
|
||||
self.setupCars()
|
||||
|
||||
# 小游戏才有CHOOSEBAR_TYPE,小游戏没有铲子
|
||||
if c.CHOOSEBAR_TYPE not in self.map_data:
|
||||
# 导入小铲子
|
||||
frame_rect = [0, 0, 71, 67]
|
||||
self.shovel = tool.get_image_menu(tool.GFX[c.SHOVEL], *frame_rect, c.BLACK, 1.1)
|
||||
self.shovel_rect = self.shovel.get_rect()
|
||||
frame_rect = [0, 0, 77, 75]
|
||||
self.shovel_box = tool.get_image_menu(tool.GFX[c.SHOVEL_BOX], *frame_rect, c.BLACK, 1.1)
|
||||
self.shovel_box_rect = self.shovel_box.get_rect()
|
||||
self.shovel_rect.x = self.shovel_box_rect.x = 550
|
||||
self.shovel_rect.y = self.shovel_box_rect.y = 2
|
||||
|
||||
self.setupLittleMenu()
|
||||
|
||||
# 小菜单
|
||||
def setupLittleMenu(self):
|
||||
# 具体运行游戏必定有个小菜单, 导入菜单和选项
|
||||
frame_rect = [0, 0, 108, 31]
|
||||
self.little_menu = tool.get_image_menu(tool.GFX[c.LITTLE_MENU], *frame_rect, c.BLACK, 1.1)
|
||||
self.little_menu_rect = self.little_menu.get_rect()
|
||||
self.little_menu_rect.x = 650
|
||||
self.little_menu_rect.y = 0
|
||||
|
||||
frame_rect = [0, 0, 500, 500]
|
||||
self.big_menu = tool.get_image_menu(tool.GFX[c.BIG_MENU], *frame_rect, c.BLACK, 1.1)
|
||||
self.big_menu_rect = self.big_menu.get_rect()
|
||||
self.big_menu_rect.x = 150
|
||||
self.big_menu_rect.y = 0
|
||||
|
||||
frame_rect = [0, 0, 342, 87]
|
||||
self.return_button = tool.get_image_menu(tool.GFX[c.RETURN_BUTTON], *frame_rect, c.BLACK, 1.1)
|
||||
self.return_button_rect = self.return_button.get_rect()
|
||||
self.return_button_rect.x = 220
|
||||
self.return_button_rect.y = 440
|
||||
|
||||
frame_rect = [0, 0, 207, 45]
|
||||
self.restart_button = tool.get_image_menu(tool.GFX[c.RESTART_BUTTON], *frame_rect, c.BLACK, 1.1)
|
||||
self.restart_button_rect = self.restart_button.get_rect()
|
||||
self.restart_button_rect.x = 295
|
||||
self.restart_button_rect.y = 325
|
||||
|
||||
frame_rect = [0, 0, 206, 43]
|
||||
self.mainMenu_button = tool.get_image_menu(tool.GFX[c.MAINMENU_BUTTON], *frame_rect, c.BLACK, 1.1)
|
||||
self.mainMenu_button_rect = self.mainMenu_button.get_rect()
|
||||
self.mainMenu_button_rect.x = 299
|
||||
self.mainMenu_button_rect.y = 372
|
||||
|
||||
# 检查小菜单有没有被点击
|
||||
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):
|
||||
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):
|
||||
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):
|
||||
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):
|
||||
return True
|
||||
return False
|
||||
|
||||
# 检查小铲子有没有被点击
|
||||
def checkShovelClick(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):
|
||||
return True
|
||||
return False
|
||||
|
||||
def play(self, mouse_pos, mouse_click):
|
||||
# 如果暂停
|
||||
if self.showLittleMenu:
|
||||
if mouse_click[0]:
|
||||
if self.checkReturnClick(mouse_pos):
|
||||
# 暂停 显示菜单
|
||||
self.showLittleMenu = False
|
||||
elif self.checkRestartClick(mouse_pos):
|
||||
self.done = True
|
||||
self.next = c.LEVEL
|
||||
elif self.checkMainMenuClick(mouse_pos):
|
||||
self.done = True
|
||||
self.next = c.MAIN_MENU
|
||||
return
|
||||
|
||||
if self.zombie_start_time == 0:
|
||||
self.zombie_start_time = self.current_time
|
||||
elif len(self.zombie_list) > 0:
|
||||
@ -149,6 +265,15 @@ class Level(tool.State):
|
||||
self.head_group.update(self.game_info)
|
||||
self.sun_group.update(self.game_info)
|
||||
|
||||
# wcb 添加
|
||||
# 检查是否点击菜单
|
||||
if mouse_click[0]:
|
||||
if self.checkLittleMenuClick(mouse_pos):
|
||||
# 暂停 显示菜单
|
||||
self.showLittleMenu = True
|
||||
elif self.checkShovelClick(mouse_pos):
|
||||
self.drag_shovel = True
|
||||
|
||||
if not self.drag_plant and mouse_pos and mouse_click[0]:
|
||||
result = self.menubar.checkCardClick(mouse_pos)
|
||||
if result:
|
||||
@ -164,6 +289,7 @@ class Level(tool.State):
|
||||
elif mouse_pos is None:
|
||||
self.setupHintImage()
|
||||
|
||||
|
||||
if self.produce_sun:
|
||||
if(self.current_time - self.sun_timer) > c.PRODUCE_SUN_INTERVAL:
|
||||
self.sun_timer = self.current_time
|
||||
@ -180,6 +306,8 @@ class Level(tool.State):
|
||||
|
||||
self.menubar.update(self.current_time)
|
||||
|
||||
|
||||
# 检查碰撞啥的
|
||||
self.checkBulletCollisions()
|
||||
self.checkZombieCollisions()
|
||||
self.checkPlants()
|
||||
@ -533,6 +661,12 @@ class Level(tool.State):
|
||||
if self.state == c.CHOOSE:
|
||||
self.panel.draw(surface)
|
||||
elif self.state == c.PLAY:
|
||||
# 画铲子
|
||||
surface.blit(self.shovel_box, self.shovel_box_rect)
|
||||
surface.blit(self.shovel, self.shovel_rect)
|
||||
# 画小菜单
|
||||
surface.blit(self.little_menu, self.little_menu_rect)
|
||||
|
||||
self.menubar.draw(surface)
|
||||
for i in range(self.map_y_len):
|
||||
self.plant_groups[i].draw(surface)
|
||||
@ -547,3 +681,12 @@ class Level(tool.State):
|
||||
|
||||
if self.drag_plant:
|
||||
self.drawMouseShow(surface)
|
||||
|
||||
if self.drag_shovel:
|
||||
self.drawMouseShowPlus(surface)
|
||||
|
||||
if self.showLittleMenu:
|
||||
surface.blit(self.big_menu, self.big_menu_rect)
|
||||
surface.blit(self.return_button, self.return_button_rect)
|
||||
surface.blit(self.restart_button, self.restart_button_rect)
|
||||
surface.blit(self.mainMenu_button, self.mainMenu_button_rect)
|
||||