<br><br><div class="gmail_quote">On Tue, Mar 20, 2012 at 1:54 PM, Manuel Kaufmann <span dir="ltr"><<a href="mailto:humitos@gmail.com">humitos@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
- removed a lot of trailing slashes<br>
- added spaces between operators<br>
- splited lines with more than 80 chars<br>
---<br>
game.py | 315 ++++++++++++++++++++++++++++++++++++---------------------------<br>
1 files changed, 182 insertions(+), 133 deletions(-)<br>
<br>
diff --git a/game.py b/game.py<br>
index f98a395..579c5c4 100644<br>
--- a/game.py<br>
+++ b/game.py<br>
@@ -6,27 +6,25 @@<br>
#<br>
# Copyright (C) 2007 Joshua Minor<br>
# This file is part of Maze.activity<br>
-#<br>
+#<br>
# Maze.activity is free software: you can redistribute it and/or modify<br>
# it under the terms of the GNU General Public License as published by<br>
# the Free Software Foundation, either version 3 of the License, or<br>
# (at your option) any later version.<br>
-#<br>
+#<br>
# Maze.activity is distributed in the hope that it will be useful,<br>
# but WITHOUT ANY WARRANTY; without even the implied warranty of<br>
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the<br>
# GNU General Public License for more details.<br>
-#<br>
+#<br>
# You should have received a copy of the GNU General Public License<br>
# along with Maze.activity. If not, see <<a href="http://www.gnu.org/licenses/" target="_blank">http://www.gnu.org/licenses/</a>>.<br>
<br>
<br>
import sys<br>
-import os<br>
import time<br>
<br>
import pygame<br>
-import olpcgames<br>
<br>
import olpcgames.pausescreen as pausescreen<br>
import olpcgames.mesh as mesh<br>
@@ -51,30 +49,30 @@ from player import Player<br>
class MazeGame:<br>
"""Maze game controller.<br>
This class handles all of the game logic, event loop, mulitplayer, etc."""<br>
-<br>
+<br>
# Munsell color values <a href="http://wiki.laptop.org/go/Munsell" target="_blank">http://wiki.laptop.org/go/Munsell</a><br>
- N10 = (255, 255, 255)<br>
+ N10 = (255, 255, 255)<br>
N9p5 = (243, 243, 243)<br>
- N9 = (232, 232, 232)<br>
- N8 = (203, 203, 203)<br>
- N7 = (179, 179, 179)<br>
- N6 = (150, 150, 150)<br>
- N5 = (124, 124, 124)<br>
- N4 = ( 97, 97, 97)<br>
- N3 = ( 70, 70, 70)<br>
- N2 = ( 48, 48, 48)<br>
- N1 = ( 28, 28, 28)<br>
- N0 = ( 0, 0, 0)<br>
+ N9 = (232, 232, 232)<br>
+ N8 = (203, 203, 203)<br>
+ N7 = (179, 179, 179)<br>
+ N6 = (150, 150, 150)<br>
+ N5 = (124, 124, 124)<br>
+ N4 = (97, 97, 97)<br>
+ N3 = (70, 70, 70)<br>
+ N2 = (48, 48, 48)<br>
+ N1 = (28, 28, 28)<br>
+ N0 = (0, 0, 0)<br>
EMPTY_COLOR = N8<br>
SOLID_COLOR = N1<br>
TRAIL_COLOR = N10<br>
- GOAL_COLOR = (0x00, 0xff, 0x00)<br>
- WIN_COLOR = (0xff, 0xff, 0x00)<br>
+ GOAL_COLOR = (0x00, 0xff, 0x00)<br>
+ WIN_COLOR = (0xff, 0xff, 0x00)<br>
<br>
def __init__(self, screen):<br>
# note what time it was when we first launched<br>
self.game_start_time = time.time()<br>
-<br>
+<br>
xoOwner = presenceService.get_owner()<br>
# keep a list of all local players<br>
self.localplayers = []<br>
@@ -87,36 +85,37 @@ class MazeGame:<br>
<br>
# keep a dictionary of all remote players, indexed by handle<br>
self.remoteplayers = {}<br>
- # keep a list of all players, local and remote,<br>
+ # keep a list of all players, local and remote,<br>
self.allplayers = [] + self.localplayers<br>
-<br>
+<br>
self.screen = screen<br>
canvas_size = screen.get_size()<br>
self.aspectRatio = canvas_size[0] / float(canvas_size[1])<br>
-<br>
- # start with a small maze using a seed that will be different each time you play<br>
- self.maze = Maze(int(time.time()), int(9*self.aspectRatio), 9)<br>
+<br>
+ # start with a small maze using a seed that will be different<br>
+ # each time you play<br>
+ self.maze = Maze(int(time.time()), int(9 * self.aspectRatio), 9)<br>
self.reset()<br>
self.frame = 0<br>
-<br>
+<br>
self.font = pygame.font.Font(None, 30)<br>
-<br>
+<br>
# support arrow keys, game pad arrows and game pad buttons<br>
# each set maps to a local player index and a direction<br>
self.arrowkeys = {<br>
- # real key: (localplayer index, ideal key)<br>
- pygame.K_UP: (0, pygame.K_UP),<br>
- pygame.K_DOWN: (0, pygame.K_DOWN),<br>
- pygame.K_LEFT: (0, pygame.K_LEFT),<br>
- pygame.K_RIGHT: (0, pygame.K_RIGHT),<br>
- pygame.K_KP8: (1, pygame.K_UP),<br>
- pygame.K_KP2: (1, pygame.K_DOWN),<br>
- pygame.K_KP4: (1, pygame.K_LEFT),<br>
- pygame.K_KP6: (1, pygame.K_RIGHT),<br>
- pygame.K_KP9: (2, pygame.K_UP),<br>
- pygame.K_KP3: (2, pygame.K_DOWN),<br>
- pygame.K_KP7: (2, pygame.K_LEFT),<br>
- pygame.K_KP1: (2, pygame.K_RIGHT)<br>
+ # real key: (localplayer index, ideal key)<br>
+ pygame.K_UP: (0, pygame.K_UP),<br>
+ pygame.K_DOWN: (0, pygame.K_DOWN),<br>
+ pygame.K_LEFT: (0, pygame.K_LEFT),<br>
+ pygame.K_RIGHT: (0, pygame.K_RIGHT),<br>
+ pygame.K_KP8: (1, pygame.K_UP),<br>
+ pygame.K_KP2: (1, pygame.K_DOWN),<br>
+ pygame.K_KP4: (1, pygame.K_LEFT),<br>
+ pygame.K_KP6: (1, pygame.K_RIGHT),<br>
+ pygame.K_KP9: (2, pygame.K_UP),<br>
+ pygame.K_KP3: (2, pygame.K_DOWN),<br>
+ pygame.K_KP7: (2, pygame.K_LEFT),<br>
+ pygame.K_KP1: (2, pygame.K_RIGHT)<br>
}<br>
<br>
def game_running_time(self, newelapsed=None):<br>
@@ -132,11 +131,12 @@ class MazeGame:<br>
player.reset()<br>
self.dirtyRect = None<br>
self.dirtyPoints = []<br>
- self.maze.map[self.maze.width-2][self.maze.height-2] = self.maze.GOAL<br>
-<br>
+ self.maze.map[self.maze.width - 2][self.maze.height - 2] = \<br>
+ self.maze.GOAL<br>
+<br>
# clear and mark the whole screen as dirty<br>
- self.screen.fill((0,0,0))<br>
- self.markRectDirty(pygame.Rect(0,0,99999,99999))<br>
+ self.screen.fill((0, 0, 0))<br>
+ self.markRectDirty(pygame.Rect(0, 0, 99999, 99999))<br>
self.mouse_in_use = 0<br>
<br>
def markRectDirty(self, rect):<br>
@@ -147,11 +147,11 @@ class MazeGame:<br>
self.dirtyRect = rect<br>
else:<br>
self.dirtyRect.union_ip(rect)<br>
-<br>
+<br>
def markPointDirty(self, pt):<br>
"""Mark a single point that needs to be redrawn."""<br>
self.dirtyPoints.append(pt)<br>
-<br>
+<br>
def processEvent(self, event):<br>
"""Process a single pygame event. This includes keystrokes<br>
as well as multiplayer events from the mesh."""<br>
@@ -164,22 +164,27 @@ class MazeGame:<br>
self.harder()<br>
elif event.key == pygame.K_MINUS:<br>
self.easier()<br>
- elif self.arrowkeys.has_key(event.key):<br>
+ elif event.key in self.arrowkeys:<br>
playernum, direction = self.arrowkeys[event.key]<br>
player = self.localplayers[playernum]<br>
player.hidden = False<br>
-<br>
+<br>
if direction == pygame.K_UP:<br>
- player.direction=(0,-1)<br>
+ player.direction = (0, -1)<br>
elif direction == pygame.K_DOWN:<br>
- player.direction=(0,1)<br>
+ player.direction = (0, 1)<br>
elif direction == pygame.K_LEFT:<br>
- player.direction=(-1,0)<br>
+ player.direction = (-1, 0)<br>
elif direction == pygame.K_RIGHT:<br>
- player.direction=(1,0)<br>
-<br>
- if len(self.remoteplayers)>0:<br>
- mesh.broadcast("move:%s,%d,%d,%d,%d" % (player.nick, player.position[0], player.position[1], player.direction[0], player.direction[1]))<br>
+ player.direction = (1, 0)<br>
+<br>
+ if len(self.remoteplayers) > 0:<br>
+ mesh.broadcast("move:%s,%d,%d,%d,%d" % \<br>
+ (player.nick,<br>
+ player.position[0],<br>
+ player.position[1],<br>
+ player.direction[0],<br>
+ player.direction[1]))<br>
elif event.type == pygame.KEYUP:<br>
pass<br>
elif event.type == pygame.MOUSEMOTION:<br>
@@ -191,26 +196,35 @@ class MazeGame:<br>
elif event.type == pygame.MOUSEBUTTONUP:<br>
if self.mouse_in_use:<br>
new_mouse_pos = pygame.mouse.get_pos()<br>
- mouse_movement = ( new_mouse_pos[0] - self.prev_mouse_pos[0],<br>
- new_mouse_pos[1] - self.prev_mouse_pos[1] )<br>
+ mouse_movement = (new_mouse_pos[0] - self.prev_mouse_pos[0],<br>
+ new_mouse_pos[1] - self.prev_mouse_pos[1])<br>
<br>
if ((abs(mouse_movement[0]) > 10) or<br>
- (abs(mouse_movement[1]) > 10)) :<br>
+ (abs(mouse_movement[1]) > 10)):<br>
player = self.localplayers[0]<br>
player.hidden = False<br>
- if abs(mouse_movement[0]) > abs(mouse_movement[1]): # x movement larger<br>
- if mouse_movement[0] > 0: # direction == pygame.K_RIGHT<br>
- player.direction=(1,0)<br>
- else: # direction == pygame.K_LEFT<br>
- player.direction=(-1,0)<br>
+ # x movement larger<br>
+ if abs(mouse_movement[0]) > abs(mouse_movement[1]):<br>
+ # direction == pygame.K_RIGHT<br>
+ if mouse_movement[0] > 0:<br>
+ player.direction = (1, 0)<br>
+ else:<br>
+ # direction == pygame.K_LEFT<br>
+ player.direction = (-1, 0)<br>
else:<br>
- if mouse_movement[1] < 0: # direction == pygame.K_UP<br>
- player.direction=(0,-1)<br>
+ if mouse_movement[1] < 0:<br>
+ # direction == pygame.K_UP<br>
+ player.direction = (0, -1)<br>
else: # direction == pygame.K_DOWN<br>
- player.direction=(0,1)<br>
+ player.direction = (0, 1)<br>
<br>
- if len(self.remoteplayers)>0:<br>
- mesh.broadcast("move:%s,%d,%d,%d,%d" % (player.nick, player.position[0], player.position[1], player.direction[0], player.direction[1]))<br>
+ if len(self.remoteplayers) > 0:<br>
+ mesh.broadcast("move:%s,%d,%d,%d,%d" % \<br>
+ (player.nick,<br>
+ player.position[0],<br>
+ player.position[1],<br>
+ player.direction[0],<br>
+ player.direction[1]))<br>
<br>
self.mouse_in_use = 0<br>
<br>
@@ -230,12 +244,20 @@ class MazeGame:<br>
# send a test message to the new player<br>
mesh.broadcast("Welcome %s" % player.nick)<br>
# tell them which maze we are playing, so they can sync up<br>
- mesh.send_to(event.handle, "maze:%d,%d,%d,%d" % (self.game_running_time(), self.maze.seed, self.maze.width, self.maze.height))<br>
+ mesh.send_to(event.handle, "maze:%d,%d,%d,%d" % \<br>
+ (self.game_running_time(),<br>
+ self.maze.seed,<br>
+ self.maze.width, self.maze.height))<br>
for player in self.localplayers:<br>
if not player.hidden:<br>
- mesh.send_to(event.handle, "move:%s,%d,%d,%d,%d" % (player.nick, player.position[0], player.position[1], player.direction[0], player.direction[1]))<br>
+ mesh.send_to(event.handle, "move:%s,%d,%d,%d,%d" % \<br>
+ (player.nick,<br>
+ player.position[0],<br>
+ player.position[1],<br>
+ player.direction[0],<br>
+ player.direction[1]))<br>
elif event.type == mesh.PARTICIPANT_REMOVE:<br>
- if self.remoteplayers.has_key(event.handle):<br>
+ if event.handle in self.remoteplayers:<br>
player = self.remoteplayers[event.handle]<br>
print "Leave:", player.nick<br>
self.markPointDirty(player.position)<br>
@@ -244,18 +266,21 @@ class MazeGame:<br>
self.markPointDirty(bonusplayer.position)<br>
self.allplayers.remove(bonusplayer)<br>
del self.remoteplayers[event.handle]<br>
- elif event.type == mesh.MESSAGE_UNI or event.type == mesh.MESSAGE_MULTI:<br>
+ elif event.type == mesh.MESSAGE_UNI or \<br>
+ event.type == mesh.MESSAGE_MULTI:<br>
buddy = mesh.get_buddy(event.handle)<br>
- #print "Message from %s / %s: %s" % (buddy.props.nick, event.handle, event.content)<br>
+ # print "Message from %s / %s: %s" % (buddy.props.nick,<br>
+ # event.handle, event.content)<br>
if event.handle == mesh.my_handle():<br>
# ignore messages from ourself<br>
pass<br>
- elif self.remoteplayers.has_key(event.handle):<br>
+ elif event.handle in self.remoteplayers:<br>
player = self.remoteplayers[event.handle]<br>
try:<br>
self.handleMessage(player, event.content)<br>
except:<br>
- print "Error handling message: %s\n%s" % (event, sys.exc_info())<br>
+ print "Error handling message: %s\n%s" % \<br>
+ (event, sys.exc_info())<br>
else:<br>
print "Message from unknown buddy?"<br>
else:<br>
@@ -263,18 +288,26 @@ class MazeGame:<br>
<br>
def handleMessage(self, player, message):<br>
"""Handle a message from a player on the mesh.<br>
- We try to be forward compatible with new versions of Maze by allowing messages to<br>
- have extra stuff at the end and ignoring unrecognized messages.<br>
- We allow some messages to contain a different nick than the message's source player<br>
- to support bonus players on that player's XO.<br>
+ We try to be forward compatible with new versions of Maze by<br>
+ allowing messages to have extra stuff at the end and ignoring<br>
+ unrecognized messages.<br>
+<br>
+ We allow some messages to contain a different nick than the<br>
+ message's source player to support bonus players on that<br>
+ player's XO.<br>
+<br>
The valid messages are:<br>
- maze:running_time,seed,width,height<br>
+<br>
+ maze: running_time, seed, width, height<br>
A player has a differen maze.<br>
- The one that has been running the longest will force all other players to use that maze.<br>
+ The one that has been running the longest will force all other<br>
+ players to use that maze.<br>
This way new players will join the existing game properly.<br>
- move:nick,x,y,dx,dy<br>
- A player's at x,y is now moving in direction dx,dy<br>
- finish:nick,elapsed<br>
+<br>
+ move: nick, x, y, dx, dy<br>
+ A player's at x, y is now moving in direction dx, dy<br>
+<br>
+ finish: nick, elapsed<br>
A player has finished the maze<br>
"""<br>
# ignore messages from myself<br>
@@ -282,21 +315,23 @@ class MazeGame:<br>
return<br>
if message.startswith("move:"):<br>
# a player has moved<br>
- nick,x,y,dx,dy = message[5:].split(",")[:5]<br>
+ nick, x, y, dx, dy = message[5:].split(",")[:5]<br>
player = player.bonusPlayer(nick)<br>
player.hidden = False<br>
self.markPointDirty(player.position)<br>
- player.position = (int(x),int(y))<br>
- player.direction = (int(dx),int(dy))<br>
+ player.position = (int(x), int(y))<br>
+ player.direction = (int(dx), int(dy))<br>
self.markPointDirty(player.position)<br>
elif message.startswith("maze:"):<br>
# someone has a different maze than us<br>
- running_time,seed,width,height = map(lambda x: int(x), message[5:].split(",")[:4])<br>
+ running_time, seed, width, height = map(lambda x: int(x),<br>
+ message[5:].split(",")[:4])<br>
# is that maze older than the one we're already playing?<br>
# note that we use elapsed time instead of absolute time because<br>
# people's clocks are often set to something totally wrong<br>
if self.game_running_time() < running_time:<br>
- # make note of the earlier time that the game really started (before we joined)<br>
+ # make note of the earlier time that the game really<br>
+ # started (before we joined)<br>
self.game_start_time = time.time() - running_time<br>
# use the new seed<br>
self.maze = Maze(seed, width, height)<br>
@@ -325,18 +360,19 @@ class MazeGame:<br>
self.draw()<br>
pygame.display.flip()<br>
clock = pygame.time.Clock()<br>
-<br>
+<br>
while self.running:<br>
- a,b,c,d=pygame.cursors.load_xbm('my_cursor.xbm','my_cursor_mask.xbm')<br>
- pygame.mouse.set_cursor(a,b,c,d)<br>
+ a, b, c, d = pygame.cursors.load_xbm('my_cursor.xbm',<br>
+ 'my_cursor_mask.xbm')<br>
+ pygame.mouse.set_cursor(a, b, c, d)<br>
self.frame += 1<br>
# process all queued events<br>
for event in pausescreen.get_events(sleep_timeout=30):<br>
self.processEvent(event)<br>
-<br>
+<br>
self.animate()<br>
self.draw()<br>
-<br>
+<br>
pygame.display.update()<br>
# don't animate faster than about 20 frames per second<br>
# this keeps the speed reasonable and limits cpu usage<br>
@@ -345,36 +381,40 @@ class MazeGame:<br>
def harder(self):<br>
"""Make a new maze that is harder than the current one."""<br>
# both width and height must be odd<br>
- newHeight = self.maze.height+2<br>
+ newHeight = self.maze.height + 2<br>
newWidth = int(newHeight * self.aspectRatio)<br>
if newWidth % 2 == 0:<br>
newWidth -= 1<br>
- self.maze = Maze(self.maze.seed+1, newWidth, newHeight)<br>
+ self.maze = Maze(self.maze.seed + 1, newWidth, newHeight)<br>
self.reset()<br>
# tell everyone which maze we are playing, so they can sync up<br>
- if len(self.remoteplayers)>0:<br>
+ if len(self.remoteplayers) > 0:<br>
# but fudge it a little so that we can be sure they'll use our maze<br>
self.game_start_time -= 10<br>
- mesh.broadcast("maze:%d,%d,%d,%d" % (self.game_running_time(), self.maze.seed, self.maze.width, self.maze.height))<br>
-<br>
+ mesh.broadcast("maze:%d,%d,%d,%d" % \<br>
+ (self.game_running_time(), self.maze.seed,<br>
+ self.maze.width, self.maze.height))<br>
+<br>
def easier(self):<br>
"""Make a new maze that is easier than the current one."""<br>
# both width and height must be odd<br>
- newHeight = max(self.maze.height-2, 5)<br>
+ newHeight = max(self.maze.height - 2, 5)<br>
newWidth = int(newHeight * self.aspectRatio)<br>
if newWidth % 2 == 0:<br>
newWidth -= 1<br>
- self.maze = Maze(self.maze.seed+1, newWidth, newHeight)<br>
+ self.maze = Maze(self.maze.seed + 1, newWidth, newHeight)<br>
self.reset()<br>
# tell everyone which maze we are playing, so they can sync up<br>
- if len(self.remoteplayers)>0:<br>
+ if len(self.remoteplayers) > 0:<br>
# but fudge it a little so that we can be sure they'll use our maze<br>
self.game_start_time -= 10<br>
- mesh.broadcast("maze:%d,%d,%d,%d" % (self.game_running_time(), self.maze.seed, self.maze.width, self.maze.height))<br>
+ mesh.broadcast("maze:%d,%d,%d,%d" % \<br>
+ (self.game_running_time(), self.maze.seed,<br>
+ self.maze.width, self.maze.height))<br>
<br>
def animate(self):<br>
"""Animate one frame of action."""<br>
-<br>
+<br>
for player in self.allplayers:<br>
oldposition = player.position<br>
newposition = player.animate(self.maze)<br>
@@ -382,37 +422,45 @@ class MazeGame:<br>
self.markPointDirty(oldposition)<br>
self.markPointDirty(newposition)<br>
if player in self.localplayers:<br>
- self.maze.map[player.previous[0]][player.previous[1]] = self.maze.SEEN<br>
- if self.maze.map[newposition[0]][newposition[1]] == self.maze.GOAL:<br>
+ self.maze.map[player.previous[0]][player.previous[1]] = \<br>
+ self.maze.SEEN<br>
+ if self.maze.map[newposition[0]][newposition[1]] == \<br>
+ self.maze.GOAL:<br>
self.finish(player)<br>
-<br>
+<br>
finish_delay = min(2 * len(self.allplayers), 6)<br>
- if self.finish_time is not None and time.time() > self.finish_time+finish_delay:<br>
+ if self.finish_time is not None and \<br>
+ time.time() > self.finish_time + finish_delay:<br>
self.harder()<br>
-<br>
+<br>
def finish(self, player):<br>
self.finish_time = time.time()<br>
player.elapsed = self.finish_time - self.level_start_time<br>
- if len(self.remoteplayers)>0:<br>
+ if len(self.remoteplayers) > 0:<br>
mesh.broadcast("finish:%s,%.2f" % (player.nick, player.elapsed))<br>
-<br>
+<br>
def draw(self):<br>
"""Draw the current state of the game.<br>
This makes use of the dirty rectangle to reduce CPU load."""<br>
- if self.dirtyRect is None and len(self.dirtyPoints)==0:<br>
+ if self.dirtyRect is None and len(self.dirtyPoints) == 0:<br>
return<br>
-<br>
+<br>
# compute the size of the tiles given the screen size, etc.<br>
size = self.screen.get_size()<br>
- self.tileSize = min(size[0] / self.maze.width, size[1] / self.maze.height)<br>
- self.bounds = pygame.Rect((size[0] - self.tileSize * self.maze.width)/2,<br>
- (size[1] - self.tileSize * self.maze.height)/2,<br>
+ self.tileSize = min(size[0] / self.maze.width,<br>
+ size[1] / self.maze.height)<br>
+ self.bounds = pygame.Rect((size[0] - self.tileSize *<br>
+ self.maze.width) / 2,<br>
+ (size[1] - self.tileSize *<br>
+ self.maze.height) / 2,<br>
self.tileSize * self.maze.width,<br>
self.tileSize * self.maze.height)<br>
- self.outline = int(self.tileSize/5)<br>
+ self.outline = int(self.tileSize / 5)<br>
<br>
- def drawPoint(x,y):<br>
- rect = pygame.Rect(self.bounds.x + x*self.tileSize, self.bounds.y + y*self.tileSize, self.tileSize, self.tileSize)<br>
+ def drawPoint(x, y):<br>
+ rect = pygame.Rect(self.bounds.x + x * self.tileSize,<br>
+ self.bounds.y + y * self.tileSize,<br>
+ self.tileSize, self.tileSize)<br>
tile = self.maze.map[x][y]<br>
if tile == self.maze.EMPTY:<br>
pygame.draw.rect(self.screen, self.EMPTY_COLOR, rect, 0)<br>
@@ -420,13 +468,13 @@ class MazeGame:<br>
pygame.draw.rect(self.screen, self.SOLID_COLOR, rect, 0)<br>
elif tile == self.maze.SEEN:<br>
pygame.draw.rect(self.screen, self.EMPTY_COLOR, rect, 0)<br>
- dot = rect.inflate(-self.outline*2, -self.outline*2)<br>
+ dot = rect.inflate(-self.outline * 2, -self.outline * 2)<br>
pygame.draw.ellipse(self.screen, self.TRAIL_COLOR, dot, 0)<br>
elif tile == self.maze.GOAL:<br>
pygame.draw.rect(self.screen, self.GOAL_COLOR, rect, 0)<br>
else:<br>
pygame.draw.rect(self.screen, (0xff, 0x00, 0xff), rect, 0)<br>
-<br>
+<br>
# re-draw the dirty rectangle<br>
if self.dirtyRect is not None:<br>
# compute the area that needs to be redrawn<br>
@@ -434,42 +482,44 @@ class MazeGame:<br>
right = min(self.maze.width, self.dirtyRect.right)<br>
top = max(0, self.dirtyRect.top)<br>
bottom = min(self.maze.height, self.dirtyRect.bottom)<br>
-<br>
+<br>
# loop over the dirty rect and draw<br>
for x in range(left, right):<br>
for y in range(top, bottom):<br>
- drawPoint(x,y)<br>
-<br>
+ drawPoint(x, y)<br>
+<br>
# re-draw the dirty points<br>
- for x,y in self.dirtyPoints:<br>
- drawPoint(x,y)<br>
-<br>
+ for x, y in self.dirtyPoints:<br>
+ drawPoint(x, y)<br>
+<br>
# draw all players<br>
for player in self.allplayers:<br>
if not player.hidden:<br>
player.draw(self.screen, self.bounds, self.tileSize)<br>
<br>
# draw the elapsed time for each player that has finished<br>
- finishedPlayers = filter(lambda p: p.elapsed is not None, self.allplayers)<br>
- finishedPlayers.sort(lambda a,b: cmp(a.elapsed,b.elapsed))<br>
+ finishedPlayers = filter(lambda p: p.elapsed is not None,<br>
+ self.allplayers)<br>
+ finishedPlayers.sort(lambda a, b: cmp(a.elapsed, b.elapsed))<br>
y = 0<br>
for player in finishedPlayers:<br>
fg, bg = player.colors<br>
text = "%3.2f - %s" % (player.elapsed, player.nick)<br>
textimg = self.font.render(text, 1, fg)<br>
textwidth, textheight = self.font.size(text)<br>
- rect = pygame.Rect(8, y+4, textwidth, textheight)<br>
- bigrect = rect.inflate(16,8)<br>
+ rect = pygame.Rect(8, y + 4, textwidth, textheight)<br>
+ bigrect = rect.inflate(16, 8)<br>
pygame.draw.rect(self.screen, bg, bigrect, 0)<br>
pygame.draw.rect(self.screen, fg, bigrect, 2)<br>
self.screen.blit(textimg, rect)<br>
-<br>
+<br>
y += bigrect.height + 4<br>
<br>
# clear the dirty rect so nothing will be drawn until there is a change<br>
self.dirtyRect = None<br>
self.dirtyPoints = []<br>
<br>
+<br>
def main():<br>
"""Run a game of Maze."""<br>
#canvas_size = 1024,768-75<br>
@@ -489,4 +539,3 @@ def main():<br>
<br>
if __name__ == '__main__':<br>
main()<br>
-<br>
<span class="HOEnZb"><font color="#888888">--<br>
1.7.9.1<br>
<br>
_______________________________________________<br>
Sugar-devel mailing list<br>
<a href="mailto:Sugar-devel@lists.sugarlabs.org">Sugar-devel@lists.sugarlabs.org</a><br>
<a href="http://lists.sugarlabs.org/listinfo/sugar-devel" target="_blank">http://lists.sugarlabs.org/listinfo/sugar-devel</a><br>
</font></span></blockquote></div><br><div><br></div><div>Thanks Manuel Applied as:</div><div><br></div><div><a href="http://git.sugarlabs.org/maze/mainline/commit/6deeb3f569e6c9a1c02a32a011b7a96a58fa8443">http://git.sugarlabs.org/maze/mainline/commit/6deeb3f569e6c9a1c02a32a011b7a96a58fa8443</a></div>
<div><br></div><div><br></div>