Skip to content
This repository has been archived by the owner on Nov 30, 2020. It is now read-only.

Commit

Permalink
Clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
McSinyx committed Feb 12, 2018
1 parent 50a8398 commit 06468ff
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 31 deletions.
3 changes: 1 addition & 2 deletions brutalmaze/characters.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@

__doc__ = 'brutalmaze module for hero and enemy classes'

from collections import deque
from math import atan, atan2, sin, pi
from random import choice, randrange, shuffle
from sys import modules
Expand Down Expand Up @@ -138,7 +137,7 @@ def __init__(self, maze, x, y, color):
def get_pos(self):
"""Return coordinate of the center of the enemy."""
x, y = self.maze.get_pos(self.x, self.y)
step = self.maze.distance * HERO_SPEED / self.maze.fps
step = self.maze.distance * ENEMY_SPEED / self.maze.fps
return x + self.offsetx*step, y + self.offsety*step

def get_distance(self):
Expand Down
23 changes: 13 additions & 10 deletions brutalmaze/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,20 @@

__doc__ = 'brutalmaze module for shared constants'

from pygame import image, K_UP, K_w, K_LEFT, K_a, K_DOWN, K_s, K_RIGHT, K_d
from pygame.mixer import Sound
from os.path import join

from appdirs import user_config_dir, site_config_dir
from pkg_resources import resource_filename
from pygame import image
from pygame.mixer import Sound

USER_CONFIG = join(user_config_dir('brutalmaze'), 'settings.ini')
SITE_CONFIG = join(site_config_dir('brutalmaze'), 'settings.ini')
DEFAULT_BINDINGS = {'New game': 'F2', 'Pause': 'p',
'Move left': 'Left', 'Move right': 'Right',
'Move up': 'Up', 'Move down': 'Down',
'Long-range attack': 'Mouse1',
'Close-range attack': 'Mouse3'}

ICON = image.load(resource_filename('brutalmaze', 'icon.png'))
MUSIC = resource_filename('brutalmaze', 'soundfx/music.ogg')
Expand All @@ -34,16 +45,8 @@
SFX_HEART = resource_filename('brutalmaze', 'soundfx/heart.ogg')
SFX_LOSE = resource_filename('brutalmaze', 'soundfx/lose.ogg')

UP = (K_UP, K_w)
LEFT = (K_LEFT, K_a)
DOWN = (K_DOWN, K_s)
RIGHT = (K_RIGHT, K_d)

SQRT2 = 2 ** 0.5
INIT_SCORE = 5**0.5/2 + 0.5 # golden mean
INIT_FPS = 30.0
MAX_FPS = 60.0
SIZE = 640, 480
MAZE_SIZE = 10
ROAD_WIDTH = 5 # grids
CELL_WIDTH = ROAD_WIDTH * 2 # grids
Expand Down
18 changes: 3 additions & 15 deletions brutalmaze/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,26 +23,14 @@
from configparser import ConfigParser, NoOptionError, NoSectionError
except ImportError: # Python 2
from ConfigParser import ConfigParser, NoOptionError, NoSectionError
from os.path import join

from appdirs import user_config_dir, site_config_dir
from pkg_resources import resource_filename
import pygame
from pygame import DOUBLEBUF, KEYDOWN, OPENGL, QUIT, RESIZABLE, VIDEORESIZE

from .constants import *
from .constants import USER_CONFIG, SITE_CONFIG, DEFAULT_BINDINGS, ICON, MUSIC
from .maze import Maze


USER_CONFIG = join(user_config_dir('brutalmaze'), 'settings.ini')
SITE_CONFIG = join(site_config_dir('brutalmaze'), 'settings.ini')
DEFAULT_BINDINGS = {'New game': 'F2', 'Pause': 'p',
'Move left': 'Left', 'Move right': 'Right',
'Move up': 'Up', 'Move down': 'Down',
'Long-range attack': 'Mouse1',
'Close-range attack': 'Mouse3'}


def getconf(config, section, option, valtype=str, fallback=None):
"""Return an option value for a given section from a ConfigParser
object.
Expand Down Expand Up @@ -77,7 +65,7 @@ def main():
scrtype = RESIZABLE
if getconf(config, 'Graphics', 'OpenGL', bool):
scrtype |= OPENGL | DOUBLEBUF
fps = getconf(config, 'Graphics', 'Maximum FPS', float, 60.0)
fps = max_fps = getconf(config, 'Graphics', 'Maximum FPS', float, 60.0)

# Read control configurations
key, mouse = {}, {}
Expand Down Expand Up @@ -144,7 +132,7 @@ def main():
flash_time.popleft()
if new_fps < fps:
fps -= 1
elif fps < MAX_FPS and not maze.paused:
elif fps < max_fps and not maze.paused:
fps += 5
maze.update(fps)
flash_time.append(pygame.time.get_ticks())
Expand Down
2 changes: 0 additions & 2 deletions brutalmaze/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@
import pygame
from pygame.gfxdraw import filled_polygon, aapolygon

from .constants import MIDDLE


def round2(number):
"""Round a number to an int."""
Expand Down
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
author_email='vn.mcsinyx@gmail.com',
license='GPLv3+',
classifiers=[
'Development Status :: 3 - Alpha',
'Development Status :: 4 - Beta',
'Environment :: MacOS X',
'Environment :: Win32 (MS Windows)',
'Environment :: X11 Applications',
Expand All @@ -28,5 +28,5 @@
keywords='pygame action-game arcade-game maze',
packages=['brutalmaze'],
install_requires=['appdirs', 'pygame>=1.9'],
package_data={'brutalmaze': ['icon.png', 'soundfx/*.ogg', 'settings.ini']},
package_data={'brutalmaze': ['icon.png', 'soundfx/*.ogg']},
entry_points={'gui_scripts': ['brutalmaze = brutalmaze:main']})

0 comments on commit 06468ff

Please sign in to comment.