diff options
author | Alan Aguiar <alanjas@hotmail.com> | 2013-12-28 03:35:13 (GMT) |
---|---|---|
committer | Alan Aguiar <alanjas@hotmail.com> | 2013-12-28 03:35:13 (GMT) |
commit | e71b8cd3eb657384eddd1b0d891869fecb0d4d50 (patch) | |
tree | 2f2967f643f1dff5c0ab6d8fd84fe43a63163cf2 | |
parent | ef4a18ffb403dc2586a8433eb485c6335778b2e5 (diff) |
some cleans
-rwxr-xr-x[-rw-r--r--] | game.py | 21 | ||||
-rw-r--r-- | ghost.py | 6 | ||||
-rw-r--r-- | player.py | 13 | ||||
-rwxr-xr-x | setup.py | 2 | ||||
-rw-r--r-- | utils.py | 9 |
5 files changed, 25 insertions, 26 deletions
@@ -23,20 +23,14 @@ import sys -import os import time import pygame -import olpcgames -import olpcgames.pausescreen as pausescreen import olpcgames.mesh as mesh -import olpcgames.svgsprite as svgsprite -from pygame import sprite as sprite -from olpcgames.util import get_bundle_path from sugar.presence import presenceservice -bundlepath = get_bundle_path() + presenceService = presenceservice.get_instance() from maze import Maze @@ -68,6 +62,7 @@ class PacmanGame: def __init__(self, screen): print "init" + pygame.init() # note what time it was when we first launched self.game_start_time = time.time() self.pause = 0 @@ -149,7 +144,7 @@ class PacmanGame: # clear and mark the whole screen as dirty self.screen.fill((0,0,0)) - self.markRectDirty(pygame.Rect(0,0,99999,99999)) + self.markRectDirty(pygame.Rect(0,0,1200,900)) def markRectDirty(self, rect): """Mark an area that needs to be redrawn. This lets us @@ -242,8 +237,8 @@ class PacmanGame: print "Error handling message: %s\n%s" % (event, sys.exc_info()) else: print "Message from unknown buddy?" - else: - print "Unknown event:", event + """else: + print "Unknown event:", event""" def handleMessage(self, player, message): """Handle a message from a player on the mesh. @@ -306,7 +301,7 @@ class PacmanGame: def togglePause(self): if (self.pause == 1): self.pause = 0 - self.markRectDirty(pygame.Rect(0,0,99999,99999)) # repaint + self.markRectDirty(pygame.Rect(0,0,1200,900)) # repaint else: self.pause = 1 @@ -321,7 +316,7 @@ class PacmanGame: if (self.pause == 0): self.frame += 1 # process all queued events - for event in pausescreen.get_events(sleep_timeout=30): + for event in pygame.event.get(): self.processEvent(event) if (self.pause == 0): @@ -375,7 +370,7 @@ class PacmanGame: # stop game self.togglePause () # repaint - self.markRectDirty(pygame.Rect(0,0,99999,99999)) + self.markRectDirty(pygame.Rect(0,0,1200,900)) self.checkGhostPositions () # checks if player runs into ghost @@ -23,9 +23,8 @@ import pygame import random -import re, os -import olpcgames.svgsprite as svgsprite from pygame import sprite as sprite +from utils import get_dir class Ghost: def __init__(self, color, seed, x, y): @@ -34,7 +33,8 @@ class Ghost: self.color = color self.sprites = sprite.RenderUpdates() self.sprite = sprite.Sprite() - self.sprite.image = pygame.image.load ("/home/olpc/Activities/Pacman.activity/activity/ghost_" + color + ".png") + self.dirName = get_dir() + self.sprite.image = pygame.image.load(self.dirName + "ghost_" + color + ".png") self.sprites.add(self.sprite) self.position = (x, y) self.startposition = self.position @@ -21,14 +21,9 @@ # You should have received a copy of the GNU General Public License # along with Pacman.activity. If not, see <http://www.gnu.org/licenses/>. -from olpcgames.util import get_bundle_path -bundlepath = get_bundle_path() -from sugar.graphics.icon import Icon -from sugar.graphics.xocolor import XoColor import pygame -import re, os -import olpcgames.svgsprite as svgsprite from pygame import sprite as sprite +from utils import get_dir class Player: def __init__(self, buddy, startx, starty, color = 'green'): @@ -41,7 +36,7 @@ class Player: self.bonusplayers = None self.opensprites = sprite.RenderUpdates() self.closedsprites = sprite.RenderUpdates() - self.dirName = "/home/olpc/Activities/Pacman.activity/activity/" + self.dirName = get_dir() self.open = sprite.Sprite() self.closed = sprite.Sprite() self.open.image = pygame.image.load (self.dirName + "pacman-" + self.color + "-open-right.png") @@ -54,8 +49,8 @@ class Player: def draw(self, screen, bounds, size): rect = pygame.Rect(bounds.x+self.position[0]*size, bounds.y+self.position[1]*size, size, size) - border = size / 10. - center = rect.inflate(-border*2, -border*2) + #border = size / 10. + #center = rect.inflate(-border*2, -border*2) if (self.mouthClosed == 1): self.closed.rect = rect self.closedsprites.draw(screen) @@ -1,4 +1,4 @@ #!/usr/bin/env python from sugar.activity import bundlebuilder -bundlebuilder.start("Pacman") +bundlebuilder.start() diff --git a/utils.py b/utils.py new file mode 100644 index 0000000..74bcc9e --- /dev/null +++ b/utils.py @@ -0,0 +1,9 @@ + +import os + +def get_dir(): + path = os.path.dirname(__file__) + if path == '': + path = os.path.abspath('.') + return os.path.join(path, 'images/') + |