(小白)尝试用Visual Studio梳理python《植物大战僵尸》源码003 20200911
相关配置
Visual Studio:1.46.1
python:3.8
源码地址:WX:amdy-liuhao 备注:植物大战僵尸
- 今天要看的是主界面是怎么生成的?
我在资源包里看到,背景图是:MainMenu.png
所以在代码里搜索一下,结果……没有
搜索png,倒是能搜到,可以发现,这个名称不是直接引用的;
这个代码在tool里,同时发现tool的最后有执行的一串代码
pg.init()
pg.display.set_caption(c.ORIGINAL_CAPTION)
SCREEN = pg.display.set_mode(c.SCREEN_SIZE)
GFX = load_all_gfx(os.path.join("resources","graphics"))
ZOMBIE_RECT = loadZombieImageRect()
PLANT_RECT = loadPlantImageRect()
第一句:
pg.display.set_caption(c.ORIGINAL_CAPTION)
这是设置标题
ORIGINAL_CAPTION = ‘Plant VS Zombies Game’
第二句:
SCREEN = pg.display.set_mode(c.SCREEN_SIZE)
这是设置窗口大小
SCREEN_WIDTH = 800
SCREEN_HEIGHT = 600
SCREEN_SIZE = (SCREEN_WIDTH, SCREEN_HEIGHT)
第三句:
GFX = load_all_gfx(os.path.join(“resources”,“graphics”))
def load_all_gfx(directory, colorkey=c.WHITE, accept=('.png', '.jpg', '.bmp', '.gif')):
graphics = {}
for name1 in os.listdir(directory):
# subfolders under the folder resources\graphics
dir1 = os.path.join(directory, name1)
if os.path.isdir(dir1):
for name2 in os.listdir(dir1):
dir2 = os.path.join(dir1, name2)
if os.path.isdir(dir2):
# e.g. subfolders under the folder resources\graphics\Zombies
for name3 in os.listdir(dir2):
dir3 = os.path.join(dir2, name3)
# e.g. subfolders or pics under the folder resources\graphics\Zombies\ConeheadZombie
if os.path.isdir(dir3):
# e.g. it's the folder resources\graphics\Zombies\ConeheadZombie\ConeheadZombieAttack
image_name, _ = os.path.splitext(name3)
graphics[image_name] = load_image_frames(dir3, image_name, colorkey, accept)
else:
# e.g. pics under the folder resources\graphics\Plants\Peashooter
image_name, _ = os.path.splitext(name2)
graphics[image_name] = load_image_frames(dir2, image_name, colorkey, accept)
break
else:
# e.g. pics under the folder resources\graphics\Screen
name, ext = os.path.splitext(name2)
if ext.lower() in accept:
img = pg.image.load(dir2)
if img.get_alpha():
img = img.convert_alpha()
else:
img = img.convert()
img.set_colorkey(colorkey)
graphics[name] = img
return graphics
这里有一串:os.path.join(“resources”,“graphics”)
- 先了解下OS
度娘告诉我:
https://blog.csdn.net/weixin_37895339/article/details/79185119
这是一个路径的拼接
os.path.join()函数用于路径拼接文件路径。
os.path.join()函数中可以传入多个路径:
会从第一个以”/”开头的参数开始拼接,之前的参数全部丢弃。
以上一种情况为先。在上一种情况确保情况下,若出现”./”开头的参数,会从”./”开头的参数的上一个参数开始拼接。
import os
print("1:",os.path.join('aaaa','/bbbb','ccccc.txt'))
print("2:",os.path.join('/aaaa','/bbbb','/ccccc.txt'))
print("3:",os.path.join('aaaa','./bbb','ccccc.txt'))
输出为:
1: /bbbb\ccccc.txt
2: /ccccc.txt
3: aaaa\./bbb\ccccc.txt
疑问出现在第二句
print("2:",os.path.join('/aaaa','/bbbb','/ccccc.txt'))
测试下来,实际上是从右往左去看‘/’的,
所以只要右边有,那左边就算有/也不会加进去,如果没有/,就都加进去:
也就是如下:
import os
print("1:",os.path.join('aaaa','bbbb','/ccccc.txt'))
print("2:",os.path.join('aaaa','/bbbb','ccccc.txt'))
print("3:",os.path.join('/aaaa','bbbb','ccccc.txt'))
print("4:",os.path.join('aaaa','/bbbb','/ccccc.txt'))
print("5:",os.path.join('/aaaa','/bbbb','/ccccc.txt'))
print("6:",os.path.join('/aaaa','/bbbb','ccccc.txt'))
print("7:",os.path.join('/aaaa','bbbb','ccccc.txt'))
print("8:",os.path.join('aaaa','bbbb','ccccc.txt'))
结果:
1: /ccccc.txt
2: /bbbb\ccccc.txt
3: /aaaa\bbbb\ccccc.txt
4: /ccccc.txt
5: /ccccc.txt
6: /bbbb\ccccc.txt
7: /aaaa\bbbb\ccccc.txt
8: aaaa\bbbb\ccccc.txt
回过来,也就是我们的:
GFX = load_all_gfx(os.path.join(“resources”,“graphics”))
把resources\graphics作为参数传进了load_all_gfx();
在这个文件夹里有这些含有图片的文件夹:
for name1 in os.listdir(directory):
这里os.listdir,应该是把文件夹里的文件名称生成了一个list:
if os.path.isdir(dir1):
这个是判断dir1是否是dir
也就是这一段:
for name1 in os.listdir(directory):
# subfolders under the folder resources\graphics
dir1 = os.path.join(directory, name1)
if os.path.isdir(dir1):
for name2 in os.listdir(dir1):
dir2 = os.path.join(dir1, name2)
if os.path.isdir(dir2):
# e.g. subfolders under the folder resources\graphics\Zombies
for name3 in os.listdir(dir2):
dir3 = os.path.join(dir2, name3)
# e.g. subfolders or pics under the folder resources\graphics\Zombies\ConeheadZombie
if os.path.isdir(dir3):
实际上是把所在文件夹里的所有的图片都生成了地址:
image_name, _ = os.path.splitext(name3)
这一段应该是把地址给我们的image_name,了解一下os.path.splitext
度娘给的答案:
https://www.cnblogs.com/liangmingshen/p/10215065.html
import os
path_01='E:\STH\Foobar2000\install.log'
path_02='E:\STH\Foobar2000'
res_01=os.path.splitext(path_01)
res_02=os.path.splitext(path_02)
print(root_01)
print(root_02)
结果:
('E:\\STH\\Foobar2000\\install', '.log')
('E:\\STH\\Foobar2000', '')
也就是把地址和图片后缀分开了
graphics[image_name] = load_image_frames(dir3, image_name, colorkey, accept)
这里应该是把所有的图片地址存进了:graphics
dir3:有后缀的图片地址
image_name:对应没有后缀的图片名称
colorkey=c.WHITE
accept=(’.png’, ‘.jpg’, ‘.bmp’, ‘.gif’)
- 了解load_image_frames:
def load_image_frames(directory, image_name, colorkey, accept):
frame_list = []
tmp = {}
# image_name is "Peashooter", pic name is 'Peashooter_1', get the index 1
index_start = len(image_name) + 1
frame_num = 0
for pic in os.listdir(directory):
name, ext = os.path.splitext(pic)
if ext.lower() in accept:
index = int(name[index_start:])
img = pg.image.load(os.path.join(directory, pic))
if img.get_alpha():
img = img.convert_alpha()
else:
img = img.convert()
img.set_colorkey(colorkey)
tmp[index]= img
frame_num += 1
for i in range(frame_num):
frame_list.append(tmp[i])
return frame_list
结果是把我们的图片地址都加进了graphics:
我们打印:graphics看看
graphics: {'BulletMushRoom': [<Surface(66x32x32 SW)>, <Surface(66x32x32 SW)>, <Surface(66x32x32 SW)>, <Surface(66x32x32 SW)>, <Surface(66x32x32 SW)>], 'BulletMushRoomExplode': [<Surface(51x45x32 SW)>], 'PeaIce': [<Surface(56x34x32 SW)>], 'PeaNormal': [<Surface(56x34x32 SW)>], 'PeaNormalExplode': [<Surface(52x46x32 SW)>], 'card_cherrybomb': <Surface(64x90x32 SW)>, 'card_cherrybomb_move': <Surface(64x90x32 SW)>, 'card_chomper': <Surface(64x89x32 SW)>, 'card_chomper_move': <Surface(64x89x32 SW)>, 'card_hypnoshroom': <Surface(64x89x32 SW)>, 'card_iceshroom': <Surface(64x89x32 SW)>, 'card_jalapeno': <Surface(64x89x32 SW)>, 'card_peashooter': <Surface(65x90x32 SW)>, 'card_peashooter_move': <Surface(65x90x32 SW)>, 'card_potatomine': <Surface(64x89x32 SW)>, 'card_potatomine_move': <Surface(64x89x32 SW)>, 'card_puffshroom': <Surface(64x89x32 SW)>, 'card_redwallnut_move': <Surface(64x89x32 SW)>, 'card_repeaterpea': <Surface(64x89x32 SW)>, 'card_repeaterpea_move': <Surface(64x89x32 SW)>, 'card_scaredyshroom': <Surface(64x89x32 SW)>, 'card_snowpea': <Surface(64x90x32 SW)>, 'card_snowpea_move': <Surface(64x90x32 SW)>, 'card_spikeweed': <Surface(64x89x32 SW)>, 'card_squash': <Surface(64x89x32 SW)>, 'card_sunflower': <Surface(64x89x32 SW)>, 'card_sunshroom': <Surface(64x89x32 SW)>, 'card_threepeashooter': <Surface(64x89x32 SW)>, 'card_wallnut': <Surface(64x90x32 SW)>, 'card_wallnut_move': <Surface(64x89x32 SW)>, 'Background': [<Surface(1400x600x32 SW)>, <Surface(1400x600x32 SW)>, <Surface(1400x600x32 SW)>, <Surface(1400x600x32 SW)>, <Surface(1400x600x32 SW)>], 'CherryBomb': [<Surface(112x81x32
SW)>, <Surface(112x81x32 SW)>, <Surface(112x81x32 SW)>, <Surface(112x81x32 SW)>, <Surface(112x81x32 SW)>, <Surface(112x81x32 SW)>, <Surface(112x81x32 SW)>], 'Chomper': [<Surface(130x114x32 SW)>, <Surface(130x114x32 SW)>, <Surface(130x114x32 SW)>, <Surface(130x114x32 SW)>, <Surface(130x114x32 SW)>, <Surface(130x114x32 SW)>, <Surface(130x114x32 SW)>, <Surface(130x114x32 SW)>, <Surface(130x114x32 SW)>, <Surface(130x114x32 SW)>, <Surface(130x114x32 SW)>, <Surface(130x114x32 SW)>, <Surface(130x114x32 SW)>], 'ChomperAttack': [<Surface(130x114x32 SW)>, <Surface(130x114x32 SW)>, <Surface(130x114x32 SW)>, <Surface(130x114x32 SW)>, <Surface(130x114x32 SW)>, <Surface(130x114x32 SW)>, <Surface(130x114x32 SW)>, <Surface(130x114x32 SW)>, <Surface(130x114x32 SW)>], 'ChomperDigest': [<Surface(130x114x32 SW)>, <Surface(130x114x32 SW)>, <Surface(130x114x32 SW)>, <Surface(130x114x32 SW)>, <Surface(130x114x32 SW)>, <Surface(130x114x32 SW)>], 'HypnoShroom': [<Surface(68x76x32 SW)>, <Surface(68x76x32 SW)>, <Surface(68x76x32 SW)>, <Surface(68x76x32 SW)>, <Surface(68x76x32 SW)>, <Surface(68x76x32 SW)>, <Surface(68x76x32 SW)>, <Surface(68x76x32 SW)>, <Surface(68x76x32 SW)>,
<Surface(68x76x32 SW)>, <Surface(68x76x32 SW)>, <Surface(68x76x32 SW)>, <Surface(68x76x32 SW)>, <Surface(68x76x32 SW)>, <Surface(68x76x32 SW)>], 'HypnoShroomSleep': [<Surface(71x80x32 SW)>, <Surface(71x80x32 SW)>, <Surface(71x80x32 SW)>, <Surface(71x80x32 SW)>, <Surface(71x80x32 SW)>, <Surface(71x80x32 SW)>, <Surface(71x80x32 SW)>, <Surface(71x80x32 SW)>, <Surface(71x80x32 SW)>, <Surface(71x80x32 SW)>, <Surface(71x80x32 SW)>, <Surface(71x80x32 SW)>, <Surface(71x80x32 SW)>], 'IceShroom': [<Surface(83x75x32 SW)>, <Surface(83x75x32 SW)>, <Surface(83x75x32 SW)>, <Surface(83x75x32 SW)>, <Surface(83x75x32 SW)>, <Surface(83x75x32 SW)>, <Surface(83x75x32 SW)>, <Surface(83x75x32 SW)>, <Surface(83x75x32 SW)>, <Surface(83x75x32 SW)>, <Surface(83x75x32 SW)>], 'IceShroomSleep': [<Surface(83x75x32 SW)>, <Surface(83x75x32 SW)>, <Surface(83x75x32 SW)>, <Surface(83x75x32 SW)>, <Surface(83x75x32 SW)>, <Surface(83x75x32 SW)>, <Surface(83x75x32 SW)>, <Surface(83x75x32 SW)>, <Surface(83x75x32 SW)>, <Surface(83x75x32 SW)>, <Surface(83x75x32 SW)>, <Surface(83x75x32 SW)>], 'IceShroomSnow': [<Surface(475x405x32 SW)>], 'IceShroomTrap': [<Surface(54x30x32 SW)>], 'Jalapeno': [<Surface(68x89x32 SW)>, <Surface(68x89x32 SW)>, <Surface(68x89x32 SW)>, <Surface(68x89x32 SW)>, <Surface(68x89x32 SW)>, <Surface(68x89x32 SW)>, <Surface(68x89x32 SW)>, <Surface(68x89x32 SW)>], 'JalapenoExplode': [<Surface(755x131x32 SW)>, <Surface(755x131x32 SW)>, <Surface(755x131x32 SW)>, <Surface(755x131x32 SW)>, <Surface(755x131x32 SW)>, <Surface(755x131x32 SW)>, <Surface(755x131x32 SW)>, <Surface(755x131x32 SW)>], 'Peashooter': [<Surface(71x71x32 SW)>, <Surface(71x71x32 SW)>, <Surface(71x71x32 SW)>, <Surface(71x71x32 SW)>, <Surface(71x71x32 SW)>, <Surface(71x71x32 SW)>, <Surface(71x71x32 SW)>, <Surface(71x71x32 SW)>, <Surface(71x71x32 SW)>, <Surface(71x71x32 SW)>, <Surface(71x71x32 SW)>, <Surface(71x71x32 SW)>, <Surface(71x71x32 SW)>], 'PotatoMine': [<Surface(75x55x32 SW)>, <Surface(75x55x32 SW)>, <Surface(75x55x32 SW)>, <Surface(75x55x32 SW)>, <Surface(75x55x32 SW)>, <Surface(75x55x32 SW)>, <Surface(75x55x32 SW)>, <Surface(75x55x32 SW)>], 'PotatoMineExplode': [<Surface(132x93x32 SW)>], 'PotatoMineInit': [<Surface(75x55x32 SW)>], 'PuffShroom': [<Surface(40x66x32 SW)>, <Surface(40x66x32 SW)>, <Surface(40x66x32 SW)>, <Surface(40x66x32 SW)>, <Surface(40x66x32 SW)>, <Surface(40x66x32 SW)>, <Surface(40x66x32 SW)>, <Surface(40x66x32 SW)>, <Surface(40x66x32 SW)>, <Surface(40x66x32 SW)>, <Surface(40x66x32 SW)>, <Surface(40x66x32 SW)>, <Surface(40x66x32 SW)>, <Surface(40x66x32 SW)>], 'PuffShroomSleep': [<Surface(40x66x32 SW)>, <Surface(40x66x32 SW)>, <Surface(40x66x32 SW)>, <Surface(40x66x32 SW)>, <Surface(40x66x32 SW)>, <Surface(40x66x32 SW)>, <Surface(40x66x32 SW)>, <Surface(40x66x32 SW)>, <Surface(40x66x32 SW)>, <Surface(40x66x32 SW)>, <Surface(40x66x32 SW)>, <Surface(40x66x32 SW)>, <Surface(40x66x32 SW)>, <Surface(40x66x32 SW)>, <Surface(40x66x32 SW)>, <Surface(40x66x32 SW)>, <Surface(40x66x32 SW)>], 'RepeaterPea': [<Surface(73x71x32 SW)>, <Surface(73x71x32 SW)>, <Surface(73x71x32 SW)>, <Surface(73x71x32 SW)>, <Surface(73x71x32 SW)>, <Surface(73x71x32 SW)>, <Surface(73x71x32 SW)>, <Surface(73x71x32 SW)>, <Surface(73x71x32 SW)>, <Surface(73x71x32 SW)>, <Surface(73x71x32 SW)>, <Surface(73x71x32 SW)>, <Surface(73x71x32 SW)>, <Surface(73x71x32 SW)>, <Surface(73x71x32 SW)>], 'ScaredyShroom': [<Surface(57x81x32 SW)>, <Surface(57x81x32 SW)>, <Surface(57x81x32 SW)>, <Surface(57x81x32 SW)>, <Surface(57x81x32 SW)>, <Surface(57x81x32 SW)>, <Surface(57x81x32 SW)>, <Surface(57x81x32 SW)>, <Surface(57x81x32 SW)>, <Surface(57x81x32 SW)>, <Surface(57x81x32 SW)>, <Surface(57x81x32 SW)>, <Surface(57x81x32 SW)>, <Surface(57x81x32 SW)>, <Surface(57x81x32 SW)>, <Surface(57x81x32 SW)>, <Surface(57x81x32 SW)>], 'ScaredyShroomCry': [<Surface(57x81x32 SW)>, <Surface(57x81x32 SW)>, <Surface(57x81x32 SW)>, <Surface(57x81x32 SW)>, <Surface(57x81x32 SW)>, <Surface(57x81x32 SW)>, <Surface(57x81x32 SW)>, <Surface(57x81x32 SW)>, <Surface(57x81x32 SW)>, <Surface(57x81x32 SW)>, <Surface(57x81x32 SW)>],
'ScaredyShroomSleep': [<Surface(57x81x32 SW)>, <Surface(57x81x32 SW)>, <Surface(57x81x32 SW)>, <Surface(57x81x32 SW)>, <Surface(57x81x32 SW)>, <Surface(57x81x32 SW)>, <Surface(57x81x32 SW)>, <Surface(57x81x32 SW)>, <Surface(57x81x32 SW)>, <Surface(57x81x32 SW)>, <Surface(57x81x32 SW)>, <Surface(57x81x32 SW)>, <Surface(57x81x32 SW)>, <Surface(57x81x32 SW)>, <Surface(57x81x32 SW)>, <Surface(57x81x32 SW)>], 'SnowPea': [<Surface(71x71x32
SW)>, <Surface(71x71x32 SW)>, <Surface(71x71x32 SW)>, <Surface(71x71x32 SW)>, <Surface(71x71x32 SW)>, <Surface(71x71x32 SW)>, <Surface(71x71x32 SW)>, <Surface(71x71x32 SW)>, <Surface(71x71x32 SW)>, <Surface(71x71x32 SW)>, <Surface(71x71x32 SW)>, <Surface(71x71x32 SW)>, <Surface(71x71x32 SW)>, <Surface(71x71x32 SW)>, <Surface(71x71x32 SW)>], 'Spikeweed': [<Surface(85x35x32 SW)>, <Surface(85x35x32 SW)>, <Surface(85x35x32 SW)>, <Surface(85x35x32 SW)>, <Surface(85x35x32 SW)>, <Surface(85x35x32 SW)>, <Surface(85x35x32 SW)>, <Surface(85x35x32 SW)>, <Surface(85x35x32 SW)>, <Surface(85x35x32 SW)>, <Surface(85x35x32 SW)>, <Surface(85x35x32 SW)>, <Surface(85x35x32 SW)>, <Surface(85x35x32 SW)>, <Surface(85x35x32 SW)>, <Surface(85x35x32 SW)>, <Surface(85x35x32 SW)>, <Surface(85x35x32 SW)>, <Surface(85x35x32 SW)>], 'Squash': [<Surface(100x226x32 SW)>, <Surface(100x226x32 SW)>, <Surface(100x226x32 SW)>, <Surface(100x226x32 SW)>, <Surface(100x226x32 SW)>, <Surface(100x226x32 SW)>, <Surface(100x226x32 SW)>, <Surface(100x226x32 SW)>, <Surface(100x226x32 SW)>, <Surface(100x226x32 SW)>, <Surface(100x226x32 SW)>, <Surface(100x226x32 SW)>, <Surface(100x226x32 SW)>, <Surface(100x226x32 SW)>, <Surface(100x226x32 SW)>, <Surface(100x226x32 SW)>, <Surface(100x226x32 SW)>], 'SquashAim': [<Surface(100x226x32 SW)>], 'SquashAttack': [<Surface(100x226x32 SW)>, <Surface(100x226x32 SW)>, <Surface(100x226x32 SW)>, <Surface(100x226x32 SW)>], 'Sun': [<Surface(78x78x32 SW)>, <Surface(78x78x32 SW)>, <Surface(78x78x32 SW)>, <Surface(78x78x32 SW)>, <Surface(78x78x32 SW)>, <Surface(78x78x32 SW)>, <Surface(78x78x32 SW)>, <Surface(78x78x32 SW)>, <Surface(78x78x32 SW)>, <Surface(78x78x32 SW)>, <Surface(78x78x32 SW)>, <Surface(78x78x32 SW)>, <Surface(78x78x32 SW)>, <Surface(78x78x32 SW)>, <Surface(78x78x32 SW)>, <Surface(78x78x32 SW)>, <Surface(78x78x32 SW)>, <Surface(78x78x32 SW)>, <Surface(78x78x32 SW)>, <Surface(78x78x32 SW)>, <Surface(78x78x32 SW)>, <Surface(78x78x32 SW)>], 'SunFlower': [<Surface(73x74x32 SW)>, <Surface(73x74x32 SW)>, <Surface(73x74x32 SW)>, <Surface(73x74x32 SW)>, <Surface(73x74x32 SW)>, <Surface(73x74x32 SW)>, <Surface(73x74x32 SW)>, <Surface(73x74x32 SW)>, <Surface(73x74x32 SW)>, <Surface(73x74x32 SW)>, <Surface(73x74x32 SW)>, <Surface(73x74x32 SW)>, <Surface(73x74x32 SW)>, <Surface(73x74x32 SW)>, <Surface(73x74x32
SW)>, <Surface(73x74x32 SW)>, <Surface(73x74x32 SW)>, <Surface(73x74x32 SW)>], 'SunShroom': [<Surface(59x61x32 SW)>, <Surface(59x61x32 SW)>, <Surface(59x61x32 SW)>, <Surface(59x61x32 SW)>, <Surface(59x61x32 SW)>, <Surface(59x61x32 SW)>, <Surface(59x61x32 SW)>, <Surface(59x61x32 SW)>, <Surface(59x61x32 SW)>, <Surface(59x61x32 SW)>], 'SunShroomBig': [<Surface(59x61x32 SW)>, <Surface(59x61x32 SW)>, <Surface(59x61x32 SW)>, <Surface(59x61x32 SW)>, <Surface(59x61x32 SW)>, <Surface(59x61x32 SW)>, <Surface(59x61x32 SW)>, <Surface(59x61x32 SW)>, <Surface(59x61x32 SW)>, <Surface(59x61x32 SW)>], 'SunShroomSleep': [<Surface(59x61x32 SW)>, <Surface(59x61x32 SW)>, <Surface(59x61x32 SW)>, <Surface(59x61x32 SW)>, <Surface(59x61x32 SW)>, <Surface(59x61x32 SW)>, <Surface(59x61x32 SW)>, <Surface(59x61x32 SW)>, <Surface(59x61x32 SW)>, <Surface(59
这里生成的是对应文件夹里的文件名和surface 的list,里面有几张图片,就会有几个Surface
- ZOMBIE_RECT = loadZombieImageRect()
def loadZombieImageRect():
file_path = os.path.join('source', 'data', 'entity', 'zombie.json')
f = open(file_path)
data = json.load(f)
f.close()
return data[c.ZOMBIE_IMAGE_RECT]
这个方法是把json文件加载进了data
ZOMBIE_IMAGE_RECT = ‘zombie_image_rect’
对应的json是:
{
"zombie_image_rect":{
"Zombie":{"x":62, "width":90},
"ZombieAttack":{"x":62, "width":90},
"ZombieLostHead":{"x":62, "width":90},
"ZombieLostHeadAttack":{"x":62, "width":90},
"ZombieDie":{"x":0, "width":164},
"BoomDie":{"x":68, "width":80},
"ConeheadZombie":{"x":80, "width":80},
"ConeheadZombieAttack":{"x":79, "width":87},
"BucketheadZombie":{"x":54, "width":90},
"BucketheadZombieAttack":{"x":46, "width":90},
"FlagZombie":{"x":56, "width":110},
"FlagZombieAttack":{"x":60, "width":100},
"FlagZombieLostHead":{"x":55, "width":110},
"FlagZombieLostHeadAttack":{"x":55, "width":110},
"NewspaperZombie":{"x":48, "width":92},
"NewspaperZombieAttack":{"x":48, "width":92},
"NewspaperZombieNoPaper":{"x":40, "width":98},
"NewspaperZombieNoPaperAttack":{"x":48, "width":92},
"NewspaperZombieLostHead":{"x":44, "width":96},
"NewspaperZombieLostHeadAttack":{"x":48, "width":92},
"NewspaperZombieDie":{"x":0, "width":100}
}
}
发现这里写的是僵尸不同状态下的x值和width值
- PLANT_RECT = loadPlantImageRect()
def loadPlantImageRect():
file_path = os.path.join('source', 'data', 'entity', 'plant.json')
f = open(file_path)
data = json.load(f)
f.close()
return data[c.PLANT_IMAGE_RECT]
这里的json
{
"plant_image_rect":{
"PeaNormal":{"x":28, "y":0, "width":28, "height":34},
"PeaIce":{"x":26, "y":0, "width":30, "height":34},
"Chomper":{"x":0, "y":0, "width":100, "height":114},
"PuffShroom":{"x":0, "y":28, "width":35, "height":38},
"PuffShroomSleep":{"x":1, "y":0, "width":39, "height":65},
"BulletMushRoom":{"x":0, "y":1, "width":55, "height":21},
"PotatoMine":{"x":0, "y":0, "width":75, "height":55},
"Squash":{"x":10, "y":140, "width":80, "height":86},
"SquashAim":{"x":10, "y":140, "width":80, "height":86},
"Spikeweed":{"x":3, "y":0, "width":80, "height":35}
}
}
这里是植物的大小和位置设置
发现看完了,还是没找到主界面是怎么设置进去的。继续分析!
感觉所需要的应该不在tool里,自己大概都看完了这里的代码。
再回头梳理!