This commit is contained in:
wcb_dell 2020-11-25 23:48:58 +08:00
parent 83d72e6f46
commit 9ed9404c26
11 changed files with 92 additions and 18 deletions

View File

@ -1,6 +1,7 @@
{
"background_type":0,
"init_sun_value":500,
"shovel":1,
"zombie_list":[
{"time":1000, "map_y":2, "name":"Zombie"}
]

View File

@ -1,6 +1,7 @@
{
"background_type":0,
"init_sun_value":5000,
"shovel":1,
"zombie_list":[
{"time":20000, "map_y":0, "name":"Zombie"},
{"time":40000, "map_y":2, "name":"FlagZombie"},

View File

@ -1,6 +1,7 @@
{
"background_type":0,
"init_sun_value":50,
"shovel":1,
"zombie_list":[
{"time":20000, "map_y":0, "name":"Zombie"},
{"time":40000, "map_y":2, "name":"FlagZombie"},

View File

@ -1,6 +1,7 @@
{
"background_type":1,
"init_sun_value":50,
"shovel":1,
"zombie_list":[
{"time":20000, "map_y":0, "name":"Zombie"},
{"time":40000, "map_y":2, "name":"ConeheadZombie"},

View File

@ -1,6 +1,7 @@
{
"background_type":0,
"choosebar_type":1,
"shovel":1,
"card_pool":[
{"name":"Peashooter"},
{"name":"SnowPea"},

View File

@ -1,6 +1,7 @@
{
"background_type":4,
"choosebar_type":2,
"shovel":0,
"card_pool":[
{"name":"WallNutBowling"},
{"name":"RedWallNutBowling"}

Binary file not shown.

After

Width:  |  Height:  |  Size: 41 KiB

View File

@ -380,7 +380,7 @@ class MoveBar():
def __init__(self, card_pool):
self.loadFrame(c.MOVEBAR_BACKGROUND)
self.rect = self.image.get_rect()
self.rect.x = 90
self.rect.x = 20
self.rect.y = 0
self.card_start_x = self.rect.x + 8

View File

@ -34,6 +34,7 @@ BIG_MENU = 'bigMenu'
RETURN_BUTTON = 'returnButton'
RESTART_BUTTON = 'restartButton'
MAINMENU_BUTTON = 'mainMenuButton'
LITTLEGAME_BUTTON = 'littleGameButton'
# 小铲子
SHOVEL = 'shovel'
SHOVEL_BOX = 'shovelBox'

View File

@ -24,7 +24,10 @@ class Level(tool.State):
self.initState()
def loadMap(self):
map_file = 'level_' + str(self.game_info[c.LEVEL_NUM]) + '.json'
if c.LITTLEGAME_BUTTON in self.game_info:
map_file = 'littleGame_' + str(self.game_info[c.LEVEL_NUM]) + '.json'
else:
map_file = 'level_' + str(self.game_info[c.LEVEL_NUM]) + '.json'
file_path = os.path.join('resources', 'data', 'map', map_file)
# 最后一关之后应该结束了
try:
@ -36,6 +39,11 @@ class Level(tool.State):
self.done = True
self.next = c.MAIN_MENU
return
if self.map_data[c.SHOVEL] == 0:
self.hasShovel = False
else:
self.hasShovel = True
def setupBackground(self):
img_index = self.map_data[c.BACKGROUND_TYPE]
@ -128,7 +136,7 @@ class Level(tool.State):
# 是否拖住植物或者铲子
self.drag_plant = False
self.drag_plant = False
self.drag_shovel = False
self.hint_image = None
self.hint_plant = False
@ -143,17 +151,18 @@ class Level(tool.State):
self.setupZombies()
self.setupCars()
# 小游戏才有CHOOSEBAR_TYPE小游戏没有铲子
if c.CHOOSEBAR_TYPE not in self.map_data:
# 地图有铲子才添加铲子
if self.hasShovel:
# 导入小铲子
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_positon = (550, 2)
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.shovel_rect.x = self.shovel_box_rect.x = self.shovel_positon[0]
self.shovel_rect.y = self.shovel_box_rect.y = self.shovel_positon[1]
self.setupLittleMenu()
@ -222,11 +231,22 @@ class Level(tool.State):
return True
return False
# 检查小铲子有没有被点击
# 用小铲子移除植物
def shovelRemovePlant(self, mouse_pos):
x, y = mouse_pos
map_x, map_y = self.map.getMapIndex(x, y)
for i in self.plant_groups[map_y]:
if(x >= i.rect.x and x <= i.rect.right and
y >= i.rect.y and y <= i.rect.bottom):
i.kill()
return
# 检查小铲子的位置有没有被点击
# 方便放回去
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):
if(x >= self.shovel_box_rect.x and x <= self.shovel_box_rect.right and
y >= self.shovel_box_rect.y and y <= self.shovel_box_rect.bottom):
return True
return False
@ -272,8 +292,17 @@ class Level(tool.State):
# 暂停 显示菜单
self.showLittleMenu = True
elif self.checkShovelClick(mouse_pos):
self.drag_shovel = True
self.drag_shovel = not self.drag_shovel
if self.drag_shovel:
# 小铲子要隐藏鼠标
pg.mouse.set_visible(False)
else:
self.removeMouseImagePlus()
elif self.drag_shovel:
# 移出这地方的植物
self.shovelRemovePlant(mouse_pos)
# 拖动植物或者铲子
if not self.drag_plant and mouse_pos and mouse_click[0]:
result = self.menubar.checkCardClick(mouse_pos)
if result:
@ -288,6 +317,9 @@ class Level(tool.State):
self.addPlant()
elif mouse_pos is None:
self.setupHintImage()
elif self.drag_shovel:
if mouse_click[1]:
self.removeMouseImagePlus()
if self.produce_sun:
@ -296,7 +328,9 @@ class Level(tool.State):
map_x, map_y = self.map.getRandomMapIndex()
x, y = self.map.getMapGridPos(map_x, map_y)
self.sun_group.add(plant.Sun(x, 0, x, y))
if not self.drag_plant and mouse_pos and mouse_click[0]:
# 检查有没有捡到阳光
if not self.drag_plant and not self.drag_shovel and mouse_pos and mouse_click[0]:
for sun in self.sun_group:
if sun.checkCollision(mouse_pos[0], mouse_pos[1]):
self.menubar.increaseSunValue(sun.sun_value)
@ -331,6 +365,7 @@ class Level(tool.State):
x, y = pg.mouse.get_pos()
return self.map.showPlant(x, y)
# 种植物
def addPlant(self):
pos = self.canSeedPlant()
if pos is None:
@ -444,6 +479,13 @@ class Level(tool.State):
self.hint_image = None
self.hint_plant = False
# 移除小铲子
def removeMouseImagePlus(self):
pg.mouse.set_visible(True)
self.drag_shovel = False
self.shovel_rect.x = self.shovel_positon[0]
self.shovel_rect.y = self.shovel_positon[1]
def checkBulletCollisions(self):
collided_func = pg.sprite.collide_circle_ratio(0.7)
for i in range(self.map_y_len):
@ -650,6 +692,12 @@ class Level(tool.State):
self.mouse_rect.centerx = x
self.mouse_rect.centery = y
surface.blit(self.mouse_image, self.mouse_rect)
def drawMouseShowPlus(self, surface):
x, y = pg.mouse.get_pos()
self.shovel_rect.centerx = x
self.shovel_rect.centery = y
surface.blit(self.shovel, self.shovel_rect)
def drawZombieFreezeTrap(self, i, surface):
for zombie in self.zombie_groups[i]:
@ -661,9 +709,10 @@ 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)
if self.hasShovel:
# 画铲子
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)
@ -682,7 +731,7 @@ class Level(tool.State):
if self.drag_plant:
self.drawMouseShow(surface)
if self.drag_shovel:
if self.hasShovel and self.drag_shovel:
self.drawMouseShowPlus(surface)
if self.showLittleMenu:

View File

@ -46,6 +46,13 @@ class Menu(tool.State):
self.exit_rect.x = 690
self.exit_rect.y = 400
# 小游戏
frame_rect = [0, 0, 317, 139]
self.option_littleGame = tool.get_image_menu(tool.GFX[c.LITTLEGAME_BUTTON], *frame_rect, c.BLACK, 0.9)
self.option_littleGame_rect = self.option_littleGame.get_rect()
self.option_littleGame_rect.x = 425
self.option_littleGame_rect.y = 200
self.option_start = 0
self.option_timer = 0
self.option_clicked = False
@ -66,6 +73,15 @@ class Menu(tool.State):
self.done = True
self.next = c.EXIT
# 检查有没有按到小游戏
def checkLittleGameClick(self, mouse_pos):
x, y = mouse_pos
if(x >= self.option_littleGame_rect.x and x <= self.option_littleGame_rect.right and
y >= self.option_littleGame_rect.y and y <= self.option_littleGame_rect.bottom):
self.done = True
# 确实小游戏还是用的level
self.persist[c.LITTLEGAME_BUTTON] = True
def update(self, surface, current_time, mouse_pos, mouse_click):
self.current_time = self.game_info[c.CURRENT_TIME] = current_time
@ -74,6 +90,7 @@ class Menu(tool.State):
if mouse_pos:
self.checkOptionClick(mouse_pos)
self.checkExitClick(mouse_pos)
self.checkLittleGameClick(mouse_pos)
else:
# 点到后播放动画
if(self.current_time - self.option_timer) > 200:
@ -88,4 +105,5 @@ class Menu(tool.State):
surface.blit(self.bg_image, self.bg_rect)
surface.blit(self.option_image, self.option_rect)
surface.blit(self.option_exit, self.exit_rect)
surface.blit(self.option_exit, self.exit_rect)
surface.blit(self.option_littleGame, self.option_littleGame_rect)