实现小游戏与冒险模式分开计数关卡

This commit is contained in:
星外之神 2022-04-12 23:20:07 +08:00
parent 0f699394a4
commit 5911f10f1b
9 changed files with 10 additions and 13 deletions

View File

@ -1,4 +1,3 @@
__author__ = 'wszqkzqk'
import random import random
import pygame as pg import pygame as pg
from .. import tool from .. import tool

View File

@ -1,4 +1,3 @@
__author__ = 'wszqkzqk'
import os import os
import random import random
import pygame as pg import pygame as pg

View File

@ -1,4 +1,3 @@
__author__ = 'wszqkzqk'
import random import random
import pygame as pg import pygame as pg
from .. import tool from .. import tool

View File

@ -1,4 +1,3 @@
__author__ = 'wszqkzqk'
import pygame as pg import pygame as pg
from .. import tool from .. import tool
from .. import constants as c from .. import constants as c

View File

@ -1,4 +1,3 @@
__author__ = 'wszqkzqk'
START_LEVEL_NUM = 1 START_LEVEL_NUM = 1
START_LITTLE_GAME_NUM = 1 START_LITTLE_GAME_NUM = 1
@ -47,6 +46,7 @@ SHOVEL_BOX = 'shovelBox'
#GAME INFO DICTIONARY KEYS #GAME INFO DICTIONARY KEYS
CURRENT_TIME = 'current time' CURRENT_TIME = 'current time'
LEVEL_NUM = 'level num' LEVEL_NUM = 'level num'
LITTLEGAME_NUM = 'littleGame num'
#STATES FOR ENTIRE GAME #STATES FOR ENTIRE GAME
MAIN_MENU = 'main menu' MAIN_MENU = 'main menu'

View File

@ -1,4 +1,3 @@
__author__ = 'wszqkzqk'
import os import os
import json import json
import sys import sys
@ -321,7 +320,8 @@ class Level(tool.State):
elif self.checkMainMenuClick(mouse_pos): elif self.checkMainMenuClick(mouse_pos):
self.done = True self.done = True
self.next = c.MAIN_MENU self.next = c.MAIN_MENU
self.persist = {c.CURRENT_TIME:0.0, c.LEVEL_NUM:c.START_LEVEL_NUM} #self.persist = {c.CURRENT_TIME:0.0, c.LEVEL_NUM:c.START_LEVEL_NUM} # 应该不能用c.LEVEL_NUM:c.START_LEVEL_NUM
self.persist = {c.CURRENT_TIME:0.0, c.LEVEL_NUM:self.persist[c.LEVEL_NUM], c.LITTLEGAME_NUM:self.persist[c.LITTLEGAME_NUM]}
pg.mixer.music.stop() pg.mixer.music.stop()
pg.mixer.music.load(os.path.join(os.path.dirname(os.path.dirname(os.path.dirname(__file__))) ,"resources", "music", "intro.opus")) pg.mixer.music.load(os.path.join(os.path.dirname(os.path.dirname(os.path.dirname(__file__))) ,"resources", "music", "intro.opus"))
pg.mixer.music.play(-1, 0) pg.mixer.music.play(-1, 0)
@ -675,7 +675,7 @@ class Level(tool.State):
_, map_y = self.map.getMapIndex(zombie.rect.centerx, zombie.rect.bottom) _, map_y = self.map.getMapIndex(zombie.rect.centerx, zombie.rect.bottom)
self.zombie_groups[map_y].remove(zombie) self.zombie_groups[map_y].remove(zombie)
self.hypno_zombie_groups[map_y].add(zombie) self.hypno_zombie_groups[map_y].add(zombie)
elif (plant.name == c.POTATOMINE and not plant.is_init): elif (plant.name == c.POTATOMINE and not plant.is_init): # 土豆雷不是灰烬植物不能用Boom
zombie.setDamage(1800) zombie.setDamage(1800)
# 避免僵尸在用铲子移除植物后还在原位啃食 # 避免僵尸在用铲子移除植物后还在原位啃食
plant.health = 0 plant.health = 0
@ -782,6 +782,9 @@ class Level(tool.State):
def checkGameState(self): def checkGameState(self):
if self.checkVictory(): if self.checkVictory():
if c.LITTLEGAME_BUTTON in self.game_info:
self.game_info[c.LITTLEGAME_NUM] += 1
else:
self.game_info[c.LEVEL_NUM] += 1 self.game_info[c.LEVEL_NUM] += 1
self.next = c.GAME_VICTORY self.next = c.GAME_VICTORY
self.done = True self.done = True

View File

@ -1,4 +1,3 @@
__author__ = 'wszqkzqk'
import pygame as pg import pygame as pg
from .. import tool from .. import tool
from .. import constants as c from .. import constants as c

View File

@ -1,4 +1,3 @@
__author__ = 'wszqkzqk'
import pygame as pg import pygame as pg
from .. import tool from .. import tool
from .. import constants as c from .. import constants as c

View File

@ -1,4 +1,3 @@
__author__ = 'wszqkzqk'
import os import os
import json import json
import sys import sys
@ -44,7 +43,8 @@ class Control():
self.state_name = None self.state_name = None
self.state = None self.state = None
self.game_info = {c.CURRENT_TIME:0.0, self.game_info = {c.CURRENT_TIME:0.0,
c.LEVEL_NUM:c.START_LEVEL_NUM} c.LEVEL_NUM:c.START_LEVEL_NUM,
c.LITTLEGAME_NUM:c.START_LITTLE_GAME_NUM}
def setup_states(self, state_dict, start_state): def setup_states(self, state_dict, start_state):
self.state_dict = state_dict self.state_dict = state_dict