diff --git a/Bear.py b/Bear.py index 2e25da2..74f0819 100644 --- a/Bear.py +++ b/Bear.py @@ -4,15 +4,15 @@ import MGO def mindist(a, b, size): - '''Distance between two values accounting for world wrapping''' + """Distance between two values accounting for world wrapping""" return min((b-a)%size,(a-b)%size) class Bear(MGO.GEMGO): - '''Harmless animal that follows the player''' + """Harmless animal that follows the player""" PER_TILE = 1/float(2000) def __init__(self, position, cellmap): - '''Create bear at position''' + """Create bear at position""" super(Bear, self).__init__(position, cellmap) self.direction = -1 # Left self.speed = 0.7 # Chance of moving per turn, max 1, min 0 @@ -21,14 +21,14 @@ def __init__(self, position, cellmap): self.hunting = False def directiontoplayer(self, playerpos): - '''Find the best direction to move towards the player''' + """Find the best direction to move towards the player""" if (mindist(playerpos[0], self.position[0], self.cellmap.size[0]) > self.pfmapsize or mindist(playerpos[1], self.position[1], self.cellmap.size[1]) > self.pfmapsize): # Player is outside pathfinder area return False def mapcoord(pfcoord): - '''Get map coordinate from pathfinder one''' + """Get map coordinate from pathfinder one""" return coords.modsum(self.position, pfcoord, (-self.pfmapsize,)*2, self.cellmap.size) foundtarget = False @@ -68,7 +68,7 @@ def mapcoord(pfcoord): def update(self, player): playerpos = player.position def chaseplayer(): - '''Decide whether to chase the player''' + """Decide whether to chase the player""" if (mindist(playerpos[0], self.position[0], self.cellmap.size[0])**2 + mindist(playerpos[1], self.position[1], self.cellmap.size[1])**2) > self.detectionrange**2: # Can't see/smell/hear (?) player @@ -79,7 +79,7 @@ def chaseplayer(): return True def randommove(): - '''Move in random direction''' + """Move in random direction""" move = [0, random.randint(-1,1)] random.shuffle(move) return move diff --git a/Dragon.py b/Dragon.py index 873c702..d5f2222 100644 --- a/Dragon.py +++ b/Dragon.py @@ -5,19 +5,19 @@ import MGO class Dragon(MGO.GEMGO): - '''Harmless flying thing that follows the player''' + """Harmless flying thing that follows the player""" PER_TILE = 1/float(6000) detectionrange = 18 speed = 0.8 def __init__(self, position, cellmap): - '''Create new dragon in position''' + """Create new dragon in position""" super(Dragon, self).__init__(position, cellmap) self.direction = UPLEFT self.hunting = False def update(self, player): - '''Fly toward the player if nearby, or continue in same direction''' + """Fly toward the player if nearby, or continue in same direction""" playerpos = player.position def tileoffset(a, b, size): offset = [0, 0] diff --git a/HUD.py b/HUD.py index 06c1843..7192531 100644 --- a/HUD.py +++ b/HUD.py @@ -5,7 +5,7 @@ from colors import * class ScoreWidget: - '''Widget to show a score and associated image''' + """Widget to show a score and associated image""" def __init__(self, image, window, total=None, stringfunc=None, bgtileimage=None): self.image = image self.bgtileimage = bgtileimage @@ -16,7 +16,7 @@ def __init__(self, image, window, total=None, stringfunc=None, bgtileimage=None) self.textbox = TextBox(22, (205, 205, 75), True) def draw(self, region, quantity): - '''Draw the score widget''' + """Draw the score widget""" region = pygame.Rect(region) old_clip = self.window.get_clip() self.window.set_clip(region) @@ -36,13 +36,13 @@ def draw(self, region, quantity): self.window.set_clip(old_clip) class MinimapWidget: - '''Widget to display a small map of the world''' + """Widget to display a small map of the world""" def __init__(self, world, window): self.world = world self.window = window def draw(self, region, scrollpos): - '''Draw the minimap''' + """Draw the minimap""" region = pygame.Rect(region) old_clip = self.window.get_clip() self.window.set_clip(region) @@ -65,7 +65,7 @@ def draw(self, region, scrollpos): self.window.set_clip(old_clip) class Frame: - '''Thingy to draw around widgets''' + """Thingy to draw around widgets""" HORIZONTAL = 0 VERTICAL = 1 def __init__(self, images, window): @@ -75,7 +75,7 @@ def __init__(self, images, window): self.window = window def draw(self, region, orientation): - '''Draw frame along top or left of region''' + """Draw frame along top or left of region""" region = pygame.Rect(region) old_clip = self.window.get_clip() self.window.set_clip(region) @@ -86,7 +86,7 @@ def draw(self, region, orientation): self.window.set_clip(old_clip) class HUD: - '''Vertical bar with player scores and minimap''' + """Vertical bar with player scores and minimap""" def __init__(self, world, window): self.window = window self.world = world @@ -99,7 +99,7 @@ def __init__(self, world, window): self.minimapwidget = MinimapWidget(world, window) def draw(self, region, scrollpos): - '''Draw the heads-up display''' + """Draw the heads-up display""" region = pygame.Rect(region) pygame.draw.rect(self.window, BLACK, region) framewidth = self.frame.thickness[Frame.VERTICAL] @@ -122,7 +122,7 @@ def draw(self, region, scrollpos): self.coinwidget.draw(widgetareas[2], self.world.player.score[collectables.COIN]) def splash(self, message, fontsize=40, icon=None): - '''Display a splash message across the entire window''' + """Display a splash message across the entire window""" windowrect = self.window.get_rect() pygame.draw.rect(self.window, BLACK, windowrect) textbox = TextBox(fontsize, WHITE, False) @@ -132,7 +132,7 @@ def splash(self, message, fontsize=40, icon=None): textbox.draw(message, windowrect, surface=self.window) def endsplash(self, reason): - '''Display an explanation for the game ending''' + """Display an explanation for the game ending""" if reason == collectables.CHOCOLATE: self.splash("You ran out of chocolate!") elif reason == collectables.COIN: @@ -141,5 +141,5 @@ def endsplash(self, reason): self.splash("What happened here?") def loadingsplash(self, description): - '''Display a splash screen while a new world loads''' + """Display a splash screen while a new world loads""" self.splash(description, 25, hudimages.HourGlass) diff --git a/MGO.py b/MGO.py index a792e4b..67a0f22 100644 --- a/MGO.py +++ b/MGO.py @@ -21,7 +21,7 @@ def __init__(self, position, cellmap): @classmethod def place(cls, cellmap): - '''Create set of objects with random positions''' + """Create set of objects with random positions""" created = [] for i in xrange(int(cellmap.size[0]*cellmap.size[1]*cls.PER_TILE)): attempt = (random.randint(0, cellmap.size[0]-1), diff --git a/Map.py b/Map.py index 479dd25..5613b3a 100644 --- a/Map.py +++ b/Map.py @@ -11,13 +11,13 @@ import sys class Map(): - '''Contains array of Cells and properties representing the map as a whole''' + """Contains array of Cells and properties representing the map as a whole""" CELLDAMAGEDCOST = 5 CELLBURNINGCOST = 200 DIRTYCACHE = False def __init__(self, mapdict): - '''Load the map from image files''' + """Load the map from image files""" self.startpos = tuple(mapdict['startpos']) self.signdefs = [] if 'signs' in mapdict: @@ -90,11 +90,11 @@ def createcell(ground, collectable): self.origcoins = (self.cellarray['collectableitem'] == collectables.COIN).sum() def __getitem__(self, coord): - '''Get map item with [], wrapping''' + """Get map item with [], wrapping""" return self.cellarray[coord[0]%self.size[0]][coord[1]%self.size[1]] def __setitem__(self, coord, value): - '''Set map item with [], wrapping''' + """Set map item with [], wrapping""" self.cellarray[coord[0]%self.size[0]][coord[1]%self.size[1]] = value def sprites(self, coord): @@ -151,7 +151,7 @@ def ignitefuse(self, coord): openlist.add(nbrpos) def destroy(self, coord): - '''Change cell attributes to reflect destruction''' + """Change cell attributes to reflect destruction""" cell = self[coord] if not cell['destructable']: return False @@ -169,7 +169,7 @@ def destroy(self, coord): return True def ignite(self, coord, multiplier=1, forceignite=False): - '''Start a fire at coord, with chance cell.firestartchance * multiplier''' + """Start a fire at coord, with chance cell.firestartchance * multiplier""" coord = coords.mod(coord, self.size) cell = self[coord] if coord in self.fusetiles: @@ -185,7 +185,7 @@ def ignite(self, coord, multiplier=1, forceignite=False): return False def detonate(self, coord): - '''Set off an explosion at coord''' + """Set off an explosion at coord""" def blam(epicentre): self[epicentre]['collectableitem'] = 0 for dx in (-1, 0, 1): @@ -199,7 +199,7 @@ def blam(epicentre): return True def update(self): - '''Spread fire, potentially other continuous map processes''' + """Spread fire, potentially other continuous map processes""" for tile in self.burningtiles.copy(): cell = self[tile] for nbrpos in coords.neighbours(tile): diff --git a/MessageBox.py b/MessageBox.py index b27d337..284c36a 100644 --- a/MessageBox.py +++ b/MessageBox.py @@ -4,7 +4,7 @@ from colors import * class MessageBox: - '''Horizontal bar with messages''' + """Horizontal bar with messages""" def __init__(self, window, mgolist): self.window = window self.textbox = TextBox(20, BLACK, False) @@ -12,7 +12,7 @@ def __init__(self, window, mgolist): self.mgolist = mgolist def draw(self, region): - '''Draw the message box''' + """Draw the message box""" if self.string != None: region = pygame.Rect(region) diff --git a/Pixie.py b/Pixie.py index 50bb2ba..982b977 100644 --- a/Pixie.py +++ b/Pixie.py @@ -4,9 +4,9 @@ import MGO class Pixie(MGO.GEMGO): - '''Pixie that says things when walked to''' + """Pixie that says things when walked to""" def __init__(self, phrasebook, position, cellmap): - '''Create new pixie in position''' + """Create new pixie in position""" super(Pixie, self).__init__(position, cellmap) self.direction = -1 # Left self.phrasebook = phrasebook @@ -20,7 +20,7 @@ def place(cls, cellmap): return created def update(self, player): - '''DOCSTRING NEEDED HERE''' + """DOCSTRING NEEDED HERE""" self.move() ppx, ppy = player.position for testx in (ppx-1, ppx, ppx+1): @@ -39,7 +39,7 @@ def update(self, player): def move(self): def randommove(): - '''Move in random direction''' + """Move in random direction""" move = [0, random.randint(-1,1)] random.shuffle(move) return move diff --git a/Player.py b/Player.py index cb3c902..acf2068 100644 --- a/Player.py +++ b/Player.py @@ -9,12 +9,12 @@ from directions import * class Player(MGO.GEMGO): - '''The player, exploring the grid-based world''' + """The player, exploring the grid-based world""" FREEPLAYER = False XRAYVISION = False def __init__(self, position, cellmap): - '''Initialise instance variables''' + """Initialise instance variables""" super(Player, self).__init__(position, cellmap) self.color = MAGENTA self.visibility = 15 @@ -55,7 +55,7 @@ def action(self, arg): self.move(*arg) def move(self, x, y): - '''Move if possible, update collectable levels accordingly''' + """Move if possible, update collectable levels accordingly""" if abs(x) + abs(y) != 1: return False self.direction = (x, y) @@ -89,7 +89,7 @@ def subtuple(a, b): return True def detonate(self): - '''Detonate carried explosives at player's location''' + """Detonate carried explosives at player's location""" if self.score[collectables.DYNAMITE] <= 0: return if not self.cellmap[self.position]['destructable']: @@ -115,7 +115,7 @@ def scattercoins(self, radius, number): scattered += 1 def updatevisible(self): - '''Calculate and return the set of tiles visible to player''' + """Calculate and return the set of tiles visible to player""" self.visibletiles = set() self.visibletiles.add(self.position) diff --git a/Sign.py b/Sign.py index ff22c3b..a0d80ab 100644 --- a/Sign.py +++ b/Sign.py @@ -2,9 +2,9 @@ import MGO class Sign(MGO.GEMGO): - '''Sign that displays message when walked over''' + """Sign that displays message when walked over""" def __init__(self, string, position, cellmap): - '''Create new sign in position''' + """Create new sign in position""" super(Sign, self).__init__(position, cellmap) self.string = string self.visible = False @@ -17,7 +17,7 @@ def place(cls, cellmap): return created def update(self, player): - '''Display message if becoming visible or trodden on''' + """Display message if becoming visible or trodden on""" if self.position == player.position: self._suggestmessage("The sign reads: " + self.string, 50) diff --git a/TextBox.py b/TextBox.py index f17f7a4..1bb59e5 100644 --- a/TextBox.py +++ b/TextBox.py @@ -2,9 +2,9 @@ from colors import * class TextBox: - '''Render text with given size/font/colors''' + """Render text with given size/font/colors""" def __init__(self, size, color, beveled=True, font="./fonts/MorrisRomanBlack.ttf"): - '''Set instance variables, calculate beveling colors''' + """Set instance variables, calculate beveling colors""" self.font = pygame.font.Font(font, size) self.beveled = beveled self.maincolor = pygame.Color(*color).correct_gamma(1) @@ -12,7 +12,7 @@ def __init__(self, size, color, beveled=True, font="./fonts/MorrisRomanBlack.ttf self.lightcolor = self.maincolor.correct_gamma(8) def draw(self, string, region, centered=(True, True), surface=None): - '''Draw text to surface, or return text on a new surface''' + """Draw text to surface, or return text on a new surface""" textsize = self.font.size(string) returnsurface = False if surface == None: diff --git a/World.py b/World.py index 15e2260..0098547 100644 --- a/World.py +++ b/World.py @@ -62,7 +62,7 @@ def rendervisibletiles(self, extrasprites=[]): self.surface.blit(*sprite[:2]) def moveplayer(self, arg): - '''Move the player by (x, y), move other fauna, update world surface around player''' + """Move the player by (x, y), move other fauna, update world surface around player""" self.cellmap.update() self.player.action(arg) diff --git a/WorldView.py b/WorldView.py index 55fac3c..065ad33 100644 --- a/WorldView.py +++ b/WorldView.py @@ -17,7 +17,7 @@ def updateregion(): drawregion.center = region.center def updatescrollpos(): - '''scroll towards the correct position''' + """scroll towards the correct position""" for axis in [0, 1]: pq = (world.player.position[axis]*TILESIZE+self.scrollpos[axis]) % world.surface.get_size()[axis] if drawregion.size[axis] > 2*world.player.visibility*TILESIZE: diff --git a/coords.py b/coords.py index 1c42697..a8bca21 100644 --- a/coords.py +++ b/coords.py @@ -2,21 +2,21 @@ import directions def sum(*args): - '''Element-wise sum of (equal-size) tuples''' + """Element-wise sum of (equal-size) tuples""" return tuple(map(__builtin__.sum, zip(*args))) def mod(a, b): - '''Element-wise modulo of a with b''' + """Element-wise modulo of a with b""" return tuple([ea%eb for ea, eb in zip(a, b)]) def modsum(*args): - '''Sum all but the last argument, modulo by that''' + """Sum all but the last argument, modulo by that""" modval = args[-1] args = args[:-1] return mod(sum(*args), modval) def mul(a, b): - '''Element-wise multiple of a by b (tuple or int)''' + """Element-wise multiple of a by b (tuple or int)""" try: return tuple([ea*b for ea in a]) except TypeError: diff --git a/hudimages.py b/hudimages.py index d0729d7..7a02d93 100644 --- a/hudimages.py +++ b/hudimages.py @@ -1,6 +1,6 @@ import pygame -'''Load and convert all HUD images''' +"""Load and convert all HUD images""" # HUD score widget images. Coin = pygame.image.load("hud/MoneyBag.png").convert_alpha() diff --git a/images.py b/images.py index 3ceb527..8b95f9f 100644 --- a/images.py +++ b/images.py @@ -3,7 +3,7 @@ from colors import MAGENTA from directions import * -'''Load and convert all in-game images''' +"""Load and convert all in-game images""" # Size of terrain sprites. TILESIZE = 12 diff --git a/main.py b/main.py index ba30db3..b7a7efb 100644 --- a/main.py +++ b/main.py @@ -1,6 +1,6 @@ #!/usr/bin/env python2.6 -'''Game of exploration in a grid-based world''' +"""Game of exploration in a grid-based world""" import pygame import sys @@ -107,7 +107,7 @@ def loadmap(newmap): return True def handleevents(): - '''respond to user input''' + """respond to user input""" global world global currentmap global window