import os import pygame import tools import constants as c os.environ['SDL_Video_CENTERED'] = '1' pygame.init() pygame.display.set_caption(c.ORIGINAL_CAPTION) SCREEN = pygame.display.set_mode(c.SCREEN_SIZE) FONTS = tools.load_all_fonts(os.path.join("resources", "fonts")) MUSIC = tools.load_all_music(os.path.join("resources", "music")) GFX = tools.load_all_gfx(os.path.join("resources", "graphics")) SFX = tools.load_all_sfx(os.path.join("resources", "sound"))
SCREEN_SIZE = (640, 480) ORIGINAL_CAPTION = "Sprite Builder" pg.mixer.pre_init(44100, -16, 1, 512) pg.init() os.environ['SDL_VIDEO_CENTERED'] = "TRUE" pg.display.set_caption(ORIGINAL_CAPTION) SCREEN = pg.display.set_mode(SCREEN_SIZE) SCREEN_RECT = SCREEN.get_rect() FONTS = load_all_fonts(os.path.join("resources", "font")) MY_FONT=FONTS['Mouse'] MUSIC = load_all_music(os.path.join("resources", "music")) BG_M = MUSIC['bg'] SHOW_M = MUSIC['show'] SOUND = load_all_sfx(os.path.join("resources", "sound")) BUTTON_M = SOUND['button'] GFX = load_all_gfx(os.path.join("resources", "graphics")) BG_IMAGE = GFX['bg'] HELP_IMAGE = GFX['help'] CURSOR1_IMAGE = GFX['mouse0']
SCREEN_SIZE = (1280, 720) WORLD_SIZE = (3200, 3200) ORIGINAL_CAPTION = "Turkey Shoot" pg.mixer.pre_init(44100, -16, 1, 512) pg.init() os.environ['SDL_VIDEO_CENTERED'] = "TRUE" pg.display.set_caption(ORIGINAL_CAPTION) SCREEN = pg.display.set_mode(SCREEN_SIZE) SCREEN_RECT = SCREEN.get_rect() GFX = tools.load_all_gfx(os.path.join("resources", "graphics")) SFX = tools.load_all_sfx(os.path.join("resources", "sounds")) FONTS = tools.load_all_fonts(os.path.join("resources", "fonts")) MUSIC = tools.load_all_music(os.path.join("resources", "music")) for num in range(1, 7): img = GFX["tree{}".format(num)] curvy = pg.Rect(0, 0, 128, 128) straight = pg.Rect(128, 0, 96, 128) GFX["curvy-tree{}".format(num)] = img.subsurface(curvy) GFX["straight-tree{}".format(num)] = img.subsurface(straight) for x in range(1, 7): SFX["gobble{}".format(x)].set_volume(.2) for x in range(1, 3): SFX["step{}".format(x)].set_volume(.5) SFX["knifesharpener"].set_volume(.4)
import pygame as pg import tools import options import map_tools opts = options.Options() the_map = map_tools.Map(opts) screen_width = opts.cell_width * ( the_map.num_cells_x + opts.wraparound_repeat * 2 + opts.coord_display) screen_height = opts.cell_height * ( the_map.num_cells_y + opts.wraparound_repeat * 2 + opts.coord_display) pg.init() screen = pg.display.set_mode((screen_width, screen_height), pg.RESIZABLE, 32) pg.display.set_caption("MapMaker BT by CanuckMonkey Games") GFX = tools.load_all_gfx(os.path.join("asset", "image")) SFX = tools.load_all_sfx(os.path.join("asset", "sound")) FONTS = tools.load_all_fonts(os.path.join("asset", "font")) MUSIC = tools.load_all_music(os.path.join("asset", "music")) background = pg.Surface(screen.get_size()) background = background.convert() overlay = pg.Surface(screen.get_size()) overlay = screen.convert_alpha() the_map.draw(background) screen.blit(background, (0, 0)) pg.display.flip()
import constants as c import tools # Center game window. os.environ['SDL_VIDEO_CENTERED'] = 'TRUE' pg.init() pg.display.set_caption(c.CAPTION) display = pg.display.set_mode(c.DISPLAY_SIZE) surf_to_display = pg.Surface(c.DISPLAY_SIZE) window = pg.Surface(c.WINDOW_SIZE) GFX = tools.load_all_gfx(os.path.join('assets', 'graphics')) TMX = tools.load_all_tmx(os.path.join('assets', 'tmx')) FONTS = tools.load_all_fonts(os.path.join('assets', 'fonts')) MUSIC = tools.load_all_music(os.path.join('assets', 'music')) SFX = tools.load_all_sfx(os.path.join('assets', 'sfx')) pg.display.set_icon(GFX['icon']) def play_sfx(sound_name, volume=c.SFX_DEFAULT_VOLUME): sound = SFX[sound_name] sound.set_volume(volume) sound.play() def update_display(window): pg.transform.scale(window, c.DISPLAY_SIZE, surf_to_display) display.blit(surf_to_display, (0, 0))
# 设置运行环境 work_dir = os.path.split(os.path.abspath(__file__))[0] os.chdir(work_dir) # 切换工作目录到当前文件目录,方便加载资源 os.environ['SDL_VIDEO_CENTERED'] = '1' # 使Pygame窗体居中 # Pygame窗口初始化 pg.init() SCREEN = pg.display.set_mode(SCREEN_SIZE) land_list = [ '宝库', '草地', '高山', '池塘', '火山', '黑森林', '森林', '废墟', '神殿', '沙漠', '沼泽', '矿洞', '大海' ] # 创立一个地点列表备用 FONTS = tools.load_all_fonts(os.path.join('resources', 'fonts')) MUSIC = tools.load_all_music(os.path.join('resources', 'music')) IMAGES = tools.load_all_images(os.path.join('resources', 'images')) TILES = tools.load_all_images(os.path.join('resources', 'tiles')) SFX = tools.load_all_sfx(os.path.join('resources', 'sound')) # TMX = tools.load_all_tmx(os.path.join('resources', 'tmx')) pg.display.set_caption('Dragon Island: First Start') pg.display.set_icon(IMAGES['icon']) FONT_SMALL = pg.font.Font(FONTS['FZXIANGSU16'], 16) FONT_SMALL.set_bold(True) FONT_NORMAL = pg.font.Font(FONTS['FZXIANGSU'], 20) FONT_NORMAL2 = pg.font.Font(FONTS['FZXIANGSU'], 22) FONT_NORMAL3 = pg.font.Font(FONTS['FZXIANGSU12'], 24)
import pygame as pg import tools import options import map_tools opts = options.Options() the_map = map_tools.Map(opts) screen_width = opts.cell_width * (the_map.num_cells_x + opts.wraparound_repeat * 2 + opts.coord_display) screen_height = opts.cell_height * (the_map.num_cells_y + opts.wraparound_repeat * 2 + opts.coord_display) pg.init() screen = pg.display.set_mode((screen_width, screen_height), pg.RESIZABLE, 32) pg.display.set_caption("MapMaker BT by CanuckMonkey Games") GFX = tools.load_all_gfx(os.path.join("asset", "image")) SFX = tools.load_all_sfx(os.path.join("asset", "sound")) FONTS = tools.load_all_fonts(os.path.join("asset", "font")) MUSIC = tools.load_all_music(os.path.join("asset", "music")) background = pg.Surface(screen.get_size()) background = background.convert() overlay = pg.Surface(screen.get_size()) overlay = screen.convert_alpha() the_map.draw(background) screen.blit(background, (0, 0)) pg.display.flip()