forked from CharlesPikachu/Games
-
Notifications
You must be signed in to change notification settings - Fork 0
/
magictower.py
66 lines (62 loc) · 2.27 KB
/
magictower.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
'''
Function:
魔塔小游戏
Author:
Charles
微信公众号:
Charles的皮卡丘
'''
import os
import pygame
from ..base import PygameBaseGame
from .modules import StartGameInterface, GameLevels
'''配置类'''
class Config():
# 根目录
rootdir = os.path.split(os.path.abspath(__file__))[0]
# 屏幕大小
BLOCKSIZE = 54
SCREENBLOCKSIZE = (18, 13)
SCREENSIZE = (BLOCKSIZE * SCREENBLOCKSIZE[0], BLOCKSIZE * SCREENBLOCKSIZE[1])
# 标题
TITLE = '魔塔 —— Charles的皮卡丘'
# FPS
FPS = 30
# 字体路径
FONT_PATHS_NOPRELOAD_DICT = {
'font_cn': os.path.join(rootdir, 'resources/fonts/font_cn.ttf'),
'font_en': os.path.join(rootdir, 'resources/fonts/font_en.ttf')
}
# 游戏地图路径
MAPPATHS = [
os.path.join(os.path.split(os.path.abspath(__file__))[0], f'resources/levels/{idx}.lvl') for idx in range(len(os.listdir(os.path.join(rootdir, f'resources/levels/'))))
]
# 游戏图片路径
IMAGE_PATHS_DICT = {
'battlebg': os.path.join(rootdir, f'resources/images/battlebg.png'),
'blankbg': os.path.join(rootdir, f'resources/images/blankbg.png'),
'gamebg': os.path.join(rootdir, f'resources/images/gamebg.png'),
'hero': {},
'mapelements': {},
}
for filename in os.listdir(os.path.join(rootdir, 'resources/images/map0/')):
IMAGE_PATHS_DICT['mapelements'][filename.split('.')[0]] = [
os.path.join(rootdir, f'resources/images/map0/{filename}'),
os.path.join(rootdir, f'resources/images/map1/{filename}'),
]
for filename in os.listdir(os.path.join(rootdir, 'resources/images/player/')):
IMAGE_PATHS_DICT['hero'][filename.split('.')[0]] = os.path.join(rootdir, f'resources/images/player/{filename}')
'''魔塔小游戏'''
class MagicTowerGame(PygameBaseGame):
game_type = 'magictower'
def __init__(self, **kwargs):
self.cfg = Config
super(MagicTowerGame, self).__init__(config=self.cfg, **kwargs)
'''运行游戏'''
def run(self):
# 开始界面
sg_interface = StartGameInterface(self.cfg)
sg_interface.run(self.screen)
# 游戏进行中界面
game_client = GameLevels(self.cfg, self.resource_loader)
game_client.run(self.screen)