尝试引入新僵尸生成机制
This commit is contained in:
parent
f09eb5e5ec
commit
e4768049ac
@ -2,6 +2,7 @@
|
|||||||
"background_type":2,
|
"background_type":2,
|
||||||
"init_sun_value":5000,
|
"init_sun_value":5000,
|
||||||
"shovel":1,
|
"shovel":1,
|
||||||
|
"spawn_zombies":"zombie_list",
|
||||||
"zombie_list":[
|
"zombie_list":[
|
||||||
{"time":1000, "map_y":2, "name":"FootballZombie"},
|
{"time":1000, "map_y":2, "name":"FootballZombie"},
|
||||||
{"time":60000, "map_y":2, "name":"Zombie"}
|
{"time":60000, "map_y":2, "name":"Zombie"}
|
||||||
|
|||||||
@ -2,6 +2,9 @@
|
|||||||
"background_type": 0,
|
"background_type": 0,
|
||||||
"init_sun_value": 50,
|
"init_sun_value": 50,
|
||||||
"shovel": 1,
|
"shovel": 1,
|
||||||
|
"spawn_zombies":"auto",
|
||||||
|
"included_zombies":["Zombie"],
|
||||||
|
"num_flags":2,
|
||||||
"zombie_list": [
|
"zombie_list": [
|
||||||
{ "time": 20000, "name": "Zombie" },
|
{ "time": 20000, "name": "Zombie" },
|
||||||
{ "time": 40000, "name": "FlagZombie" },
|
{ "time": 40000, "name": "FlagZombie" },
|
||||||
|
|||||||
@ -2,6 +2,8 @@
|
|||||||
"background_type":0,
|
"background_type":0,
|
||||||
"init_sun_value":50,
|
"init_sun_value":50,
|
||||||
"shovel":1,
|
"shovel":1,
|
||||||
|
"spawn_zombies":"auto",
|
||||||
|
"num_flags":3,
|
||||||
"zombie_list":[
|
"zombie_list":[
|
||||||
{"time":20000, "name":"Zombie"},
|
{"time":20000, "name":"Zombie"},
|
||||||
{"time":40000, "name":"FlagZombie"},
|
{"time":40000, "name":"FlagZombie"},
|
||||||
|
|||||||
@ -2,6 +2,8 @@
|
|||||||
"background_type":1,
|
"background_type":1,
|
||||||
"init_sun_value":50,
|
"init_sun_value":50,
|
||||||
"shovel":1,
|
"shovel":1,
|
||||||
|
"spawn_zombies":"auto",
|
||||||
|
"num_flags":3,
|
||||||
"zombie_list":[
|
"zombie_list":[
|
||||||
{"time":20000, "name":"Zombie"},
|
{"time":20000, "name":"Zombie"},
|
||||||
{"time":40000, "name":"ConeheadZombie"},
|
{"time":40000, "name":"ConeheadZombie"},
|
||||||
|
|||||||
@ -2,6 +2,8 @@
|
|||||||
"background_type":2,
|
"background_type":2,
|
||||||
"init_sun_value":50,
|
"init_sun_value":50,
|
||||||
"shovel":1,
|
"shovel":1,
|
||||||
|
"spawn_zombies":"auto",
|
||||||
|
"num_flags":4,
|
||||||
"zombie_list":[
|
"zombie_list":[
|
||||||
{"time":20000, "name":"Zombie"},
|
{"time":20000, "name":"Zombie"},
|
||||||
{"time":40000, "name":"ConeheadZombie"},
|
{"time":40000, "name":"ConeheadZombie"},
|
||||||
|
|||||||
@ -2,6 +2,8 @@
|
|||||||
"background_type":0,
|
"background_type":0,
|
||||||
"choosebar_type":1,
|
"choosebar_type":1,
|
||||||
"shovel":1,
|
"shovel":1,
|
||||||
|
"spawn_zombies":"auto",
|
||||||
|
"num_flags":4,
|
||||||
"card_pool":[
|
"card_pool":[
|
||||||
{"name":"Peashooter"},
|
{"name":"Peashooter"},
|
||||||
{"name":"SnowPea"},
|
{"name":"SnowPea"},
|
||||||
|
|||||||
@ -2,6 +2,8 @@
|
|||||||
"background_type":6,
|
"background_type":6,
|
||||||
"choosebar_type":2,
|
"choosebar_type":2,
|
||||||
"shovel":0,
|
"shovel":0,
|
||||||
|
"spawn_zombies":"auto",
|
||||||
|
"num_flags":4,
|
||||||
"card_pool":[
|
"card_pool":[
|
||||||
{"name":"WallNutBowling"},
|
{"name":"WallNutBowling"},
|
||||||
{"name":"RedWallNutBowling"}
|
{"name":"RedWallNutBowling"}
|
||||||
|
|||||||
@ -97,6 +97,15 @@ BACKGROUND_WALLNUTBOWLING = 6
|
|||||||
BACKGROUND_SINGLE = 7
|
BACKGROUND_SINGLE = 7
|
||||||
BACKGROUND_TRIPLE = 8
|
BACKGROUND_TRIPLE = 8
|
||||||
|
|
||||||
|
# 僵尸生成方式
|
||||||
|
SPAWN_ZOMBIES = 'spawn_zombies'
|
||||||
|
SPAWN_ZOMBIES_AUTO = 'auto'
|
||||||
|
SPAWN_ZOMBIES_LIST = 'list'
|
||||||
|
NUM_FLAGS = 'num_flags'
|
||||||
|
INEVITABLE_ZOMBIE_DICT = 'inevitable_zombie_list'
|
||||||
|
SURVIVAL_ROUNDS = 'survival_rounds'
|
||||||
|
|
||||||
|
|
||||||
# 地图单元格属性
|
# 地图单元格属性
|
||||||
MAP_PLANT = 'plantnames'
|
MAP_PLANT = 'plantnames'
|
||||||
MAP_SLEEP = 'sleep' # 有没有休眠的蘑菇,作是否能种植咖啡豆的判断
|
MAP_SLEEP = 'sleep' # 有没有休眠的蘑菇,作是否能种植咖啡豆的判断
|
||||||
|
|||||||
@ -104,12 +104,57 @@ class Level(tool.State):
|
|||||||
self.hypno_zombie_groups.append(pg.sprite.Group())
|
self.hypno_zombie_groups.append(pg.sprite.Group())
|
||||||
self.bullet_groups.append(pg.sprite.Group())
|
self.bullet_groups.append(pg.sprite.Group())
|
||||||
|
|
||||||
|
# 新的僵尸生成机制:级别——权重生成
|
||||||
|
self.createZombieInfo = {# 生成僵尸:(级别, 权重)
|
||||||
|
c.NORMAL_ZOMBIE:(1, 4000),
|
||||||
|
c.FLAG_ZOMBIE:(1, 0),
|
||||||
|
c.CONEHEAD_ZOMBIE:(2, 4000),
|
||||||
|
c.BUCKETHEAD_ZOMBIE:(4, 3000),
|
||||||
|
c.NEWSPAPER_ZOMBIE:(2, 1000),
|
||||||
|
c.FOOTBALL_ZOMBIE:(2, 2000)
|
||||||
|
}
|
||||||
|
|
||||||
|
# 按照规则生成每一波僵尸
|
||||||
|
# 可以考虑将波刷新和一波中的僵尸生成分开
|
||||||
|
# useableZombie是指可用的僵尸种类的元组
|
||||||
|
# inevitableZombie指在本轮必然出现的僵尸,输入形式为字典: {波数1:(僵尸1, 僵尸2……), 波数2:(僵尸1, 僵尸2……)……}
|
||||||
|
def createWaves(self, useableZombies, numFlags, survivalRounds=0, inevitableZombieDict=None):
|
||||||
|
waves = []
|
||||||
|
|
||||||
|
# 权重值
|
||||||
|
weights = []
|
||||||
|
for zombie in useableZombies:
|
||||||
|
weights.append(self.createZombieInfo[zombie][1])
|
||||||
|
|
||||||
|
# 按照原版pvz设计的僵尸容量函数,是从无尽解析的,但是普通关卡也可以遵循
|
||||||
|
for wave in range(1, 10 * numFlags + 1):
|
||||||
|
volume = int(int((wave + survivalRounds*20)*0.8)/2) + 1
|
||||||
|
if wave % 10 == 0:
|
||||||
|
volume = int(volume*2.5)
|
||||||
|
zombieList = []
|
||||||
|
|
||||||
|
if inevitableZombieDict and (wave in inevitableZombieDict.keys()):
|
||||||
|
for newZombie in inevitableZombieDict[wave]:
|
||||||
|
zombieList += newZombie
|
||||||
|
volume -= self.createZombieInfo[newZombie][0]
|
||||||
|
if volume < 0:
|
||||||
|
print('警告:第{}波中手动设置的僵尸级别总数超过上限!'.format(wave))
|
||||||
|
|
||||||
|
while (volume > 0) and (len(zombieList) < 50):
|
||||||
|
newZombie = choices(useableZombies, weights) # 注意这个的输出是列表
|
||||||
|
if self.createZombieInfo[newZombie][0] <= volume:
|
||||||
|
zombieList += newZombie
|
||||||
|
volume -= self.createZombieInfo[newZombie][0]
|
||||||
|
waves.append(zombieList)
|
||||||
|
|
||||||
|
self.waves = waves
|
||||||
|
|
||||||
def setupZombies(self):
|
def setupZombies(self):
|
||||||
def takeTime(element):
|
def takeTime(element):
|
||||||
return element[0]
|
return element[0]
|
||||||
|
|
||||||
self.zombie_list = []
|
self.zombie_list = []
|
||||||
# 目前设置为从JSON文件中读取僵尸出现的时间、种类、位置信息,以后可以将时间设置为模仿原版的机制,位置设置为随机数
|
# 目前设置为从JSON文件中读取僵尸出现的时间、种类、位置信息,以后可以将时间设置为模仿原版的机制
|
||||||
for data in self.map_data[c.ZOMBIE_LIST]:
|
for data in self.map_data[c.ZOMBIE_LIST]:
|
||||||
if 'map_y' in data.keys():
|
if 'map_y' in data.keys():
|
||||||
self.zombie_list.append((data['time'], data['name'], data['map_y']))
|
self.zombie_list.append((data['time'], data['name'], data['map_y']))
|
||||||
@ -199,7 +244,19 @@ class Level(tool.State):
|
|||||||
|
|
||||||
self.removeMouseImage()
|
self.removeMouseImage()
|
||||||
self.setupGroups()
|
self.setupGroups()
|
||||||
|
if (c.ZOMBIE_LIST in self.map_data.keys()) and self.map_data[c.SPAWN_ZOMBIES] == c.SPAWN_ZOMBIES_LIST:
|
||||||
self.setupZombies()
|
self.setupZombies()
|
||||||
|
else:
|
||||||
|
# 暂时没有生存模式,所以 survivalRounds = 0
|
||||||
|
if c.INEVITABLE_ZOMBIE_DICT in self.map_data.keys():
|
||||||
|
self.createWaves( useableZombies=self.map_data[c.USEABLE_ZOMBIES],
|
||||||
|
numFlags=self.map_data[c.NUM_FLAGS],
|
||||||
|
survivalRounds=0,
|
||||||
|
inevitableZombieDict=self.map_data[c.INEVITABLE_ZOMBIE_DICT])
|
||||||
|
else:
|
||||||
|
self.createWaves( useableZombies=self.map_data[c.USEABLE_ZOMBIES],
|
||||||
|
numFlags=self.map_data[c.NUM_FLAGS],
|
||||||
|
survivalRounds=0)
|
||||||
self.setupCars()
|
self.setupCars()
|
||||||
|
|
||||||
# 地图有铲子才添加铲子
|
# 地图有铲子才添加铲子
|
||||||
@ -217,16 +274,6 @@ class Level(tool.State):
|
|||||||
|
|
||||||
self.setupLittleMenu()
|
self.setupLittleMenu()
|
||||||
|
|
||||||
# 新的僵尸生成机制:级别——权重生成
|
|
||||||
self.createZombieInfo = {# 生成僵尸:(级别, 权重)
|
|
||||||
c.NORMAL_ZOMBIE:(1, 4000),
|
|
||||||
c.FLAG_ZOMBIE:(1, 0),
|
|
||||||
c.CONEHEAD_ZOMBIE:(2, 4000),
|
|
||||||
c.BUCKETHEAD_ZOMBIE:(4, 3000),
|
|
||||||
c.NEWSPAPER_ZOMBIE:(2, 1000),
|
|
||||||
c.FOOTBALL_ZOMBIE:(2, 2000)
|
|
||||||
}
|
|
||||||
|
|
||||||
# 小菜单
|
# 小菜单
|
||||||
def setupLittleMenu(self):
|
def setupLittleMenu(self):
|
||||||
# 具体运行游戏必定有个小菜单, 导入菜单和选项
|
# 具体运行游戏必定有个小菜单, 导入菜单和选项
|
||||||
@ -451,42 +498,6 @@ class Level(tool.State):
|
|||||||
self.checkGameState()
|
self.checkGameState()
|
||||||
|
|
||||||
|
|
||||||
# 按照规则生成每一波僵尸
|
|
||||||
# 可以考虑将波刷新和一波中的僵尸生成分开
|
|
||||||
# useableZombie是指可用的僵尸种类的元组
|
|
||||||
# inevitableZombie指在本轮必然出现的僵尸,输入形式为字典: {波数1:(僵尸1, 僵尸2……), 波数2:(僵尸1, 僵尸2……)……}
|
|
||||||
def createWaves(self, useableZombies, numFlags, survivalRounds=0, inevitableZombieDict=None):
|
|
||||||
waves = []
|
|
||||||
|
|
||||||
# 权重值
|
|
||||||
weights = []
|
|
||||||
for zombie in useableZombies:
|
|
||||||
weights.append(self.createZombieInfo[zombie][1])
|
|
||||||
|
|
||||||
# 按照原版pvz设计的僵尸容量函数,是从无尽解析的,但是普通关卡也可以遵循
|
|
||||||
for wave in range(1, 10 * numFlags + 1):
|
|
||||||
volume = int(int((wave + survivalRounds*20)*0.8)/2) + 1
|
|
||||||
if wave % 10 == 0:
|
|
||||||
volume = int(volume*2.5)
|
|
||||||
zombieList = []
|
|
||||||
|
|
||||||
if inevitableZombieDict and (wave in inevitableZombieDict.keys()):
|
|
||||||
for newZombie in inevitableZombieDict[wave]:
|
|
||||||
zombieList += newZombie
|
|
||||||
volume -= self.createZombieInfo[newZombie][0]
|
|
||||||
if volume < 0:
|
|
||||||
print('警告:第{}波中手动设置的僵尸级别总数超过上限!'.format(wave))
|
|
||||||
|
|
||||||
while (volume > 0) and (len(zombieList) < 50):
|
|
||||||
newZombie = choices(useableZombies, weights) # 注意这个的输出是列表
|
|
||||||
if self.createZombieInfo[newZombie][0] <= volume:
|
|
||||||
zombieList += newZombie
|
|
||||||
volume -= self.createZombieInfo[newZombie][0]
|
|
||||||
waves.append(zombieList)
|
|
||||||
|
|
||||||
self.waves = waves
|
|
||||||
|
|
||||||
|
|
||||||
def createZombie(self, name, map_y=None):
|
def createZombie(self, name, map_y=None):
|
||||||
# 有指定时按照指定生成,无指定时随机位置生成
|
# 有指定时按照指定生成,无指定时随机位置生成
|
||||||
# 0:白天 1:夜晚 2:泳池 3:浓雾 4:屋顶 5:月夜 6:坚果保龄球
|
# 0:白天 1:夜晚 2:泳池 3:浓雾 4:屋顶 5:月夜 6:坚果保龄球
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user