diff options
-rw-r--r-- | brutalmaze/main.py | 28 | ||||
-rw-r--r-- | brutalmaze/maze.py | 10 | ||||
-rw-r--r-- | brutalmaze/settings.ini | 7 | ||||
-rwxr-xr-x | setup.py | 6 |
4 files changed, 40 insertions, 11 deletions
diff --git a/brutalmaze/main.py b/brutalmaze/main.py index 8aef9a0..c77cde6 100644 --- a/brutalmaze/main.py +++ b/brutalmaze/main.py @@ -18,7 +18,14 @@ # Copyright (C) 2017 Nguyễn Gia Phong from collections import deque +try: + from configparser import ConfigParser # Python 3 +except ImportError: + from ConfigParser import ConfigParser # Python 2 +from os.path import join +from appdirs import AppDirs +from pkg_resources import resource_filename import pygame from pygame.locals import * @@ -29,21 +36,36 @@ from .misc import some def main(): """Start game and main loop.""" + # Read configuration file + dirs = AppDirs(appname='brutalmaze') + config = ConfigParser() + if not config.read(join(dirs.user_config_dir, 'settings.ini')): + if not config.read(join(dirs.site_config_dir, 'settings.ini')): + config.read(resource_filename('brutalmaze', 'settings.ini')) + scrtype = RESIZABLE + if config.getboolean('Graphics', 'OpenGL'): + surftype |= OPENGL | DOUBLEBUF + fps = config.getfloat('Graphics', 'Maximum FPS') + + # Initialization pygame.mixer.pre_init(frequency=44100) pygame.init() pygame.mixer.music.load(MUSIC) pygame.mixer.music.play(-1) pygame.display.set_icon(ICON) pygame.fastevent.init() - maze, clock = Maze(SIZE, INIT_FPS), pygame.time.Clock() - fps, flash_time, going = INIT_FPS, deque(), True + maze = Maze((config.getint('Graphics', 'Screen width'), + config.getint('Graphics', 'Screen height')), scrtype, fps) + clock, flash_time, going = pygame.time.Clock(), deque(), True + + # Main loop while going: events = pygame.fastevent.get() for event in events: if event.type == QUIT: going = False elif event.type == VIDEORESIZE: - maze.resize(event.w, event.h) + maze.resize((event.w, event.h), scrtype) elif event.type == KEYDOWN: if event.key == K_F2: # new game maze.__init__((maze.w, maze.h), fps) diff --git a/brutalmaze/maze.py b/brutalmaze/maze.py index da3428f..f8c8169 100644 --- a/brutalmaze/maze.py +++ b/brutalmaze/maze.py @@ -81,10 +81,10 @@ class Maze: sfx_shot (Sound): sound effect indicating an enemy get shot sfx_lose (Sound): sound effect to be played when you lose """ - def __init__(self, size, fps): + def __init__(self, size, scrtype, fps): self.w, self.h = size self.fps = fps - self.surface = pygame.display.set_mode(size, RESIZABLE) + self.surface = pygame.display.set_mode(size, scrtype) self.distance = (self.w * self.h / 416) ** 0.5 self.x, self.y = self.w // 2, self.h // 2 self.centerx, self.centery = self.w / 2.0, self.h / 2.0 @@ -339,10 +339,10 @@ class Maze: self.vy += y * accel if abs(self.vy) > velocity: self.vy = y * velocity - def resize(self, w, h): + def resize(self, size, scrtype): """Resize the maze.""" - size = self.w, self.h = w, h - self.surface = pygame.display.set_mode(size, RESIZABLE) + self.w, self.h = size + self.surface = pygame.display.set_mode(size, scrtype) self.hero.resize() offsetx = (self.centerx-self.x) / self.distance diff --git a/brutalmaze/settings.ini b/brutalmaze/settings.ini new file mode 100644 index 0000000..ee5aefa --- /dev/null +++ b/brutalmaze/settings.ini @@ -0,0 +1,7 @@ +[Graphics] +Screen width: 640 +Screen height: 480 +# OpenGL should be supported on all machines with hardware acceleration +OpenGL: no +# FPS should not be greater than refresh rate +Maximum FPS: 60 diff --git a/setup.py b/setup.py index 1984de8..4f9ff98 100755 --- a/setup.py +++ b/setup.py @@ -7,7 +7,7 @@ with open('README.rst') as f: setup( name='brutalmaze', - version='0.4.2', + version='0.5.0', description='A hash and slash game with fast-paced action and a minimalist art style', long_description=long_description, url='https://github.com/McSinyx/brutalmaze', @@ -27,6 +27,6 @@ setup( 'Topic :: Games/Entertainment :: Arcade'], keywords='pygame action-game arcade-game maze', packages=['brutalmaze'], - install_requires=['pygame>=1.9'], - package_data={'brutalmaze': ['icon.png', 'soundfx/*.ogg']}, + install_requires=['appdirs', 'pygame>=1.9'], + package_data={'brutalmaze': ['icon.png', 'soundfx/*.ogg', 'settings.ini']}, entry_points={'gui_scripts': ['brutalmaze = brutalmaze:main']}) |