Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorcoolestdude1 <arielzamparini@gmail.com>2010-02-18 10:25:46 (GMT)
committer coolestdude1 <arielzamparini@gmail.com>2010-02-18 10:25:46 (GMT)
commite6270fe585a7a6fdbefe5d9c58ff2d902b4013b0 (patch)
tree337ea07035bf566490a6b61c88100c3f49c5abb8
parentfddec5fb8eabe6fb44940bada6b590e472ff3c34 (diff)
added sound handlers and better text handlers
-rw-r--r--blocku.py38
1 files changed, 27 insertions, 11 deletions
diff --git a/blocku.py b/blocku.py
index 85b3507..1343bb1 100644
--- a/blocku.py
+++ b/blocku.py
@@ -38,6 +38,19 @@ def load_images(*files):
imgs.append(load_image(file))
return imgs
+class dummysound:
+ def play(self): pass
+
+def load_sound(file):
+ if not pygame.mixer: return dummysound()
+ file = os.path.join('data', file)
+ try:
+ sound = pygame.mixer.Sound(file)
+ return sound
+ except pygame.error:
+ print 'Warning, unable to load,', file
+ return dummysound()
+
class Block(pygame.sprite.Sprite):
images = []
def __init__(self, north=None, east=None, south=None, west=None):
@@ -54,7 +67,7 @@ class Block(pygame.sprite.Sprite):
self.west = west
def update(self):
- pass
+ self.rect = self.rect.clamp(SCREENRECT)
# game logic here for snapping to grid ...?
def move(self, direction):
# up = 0, right = 1, down = 2, left = 3
@@ -67,15 +80,13 @@ class Block(pygame.sprite.Sprite):
if direction == 3:
self.rect.move_ip(-KEYBOARDMOVESPEED,0)
#keep the block on the screen
- self.rect = self.rect.clamp(SCREENRECT)
def grab(self, pos):
x, y = pos;
- print x , y
- print self.rect.left, self.rect.top
+ #print x , y
+ #print self.rect.left, self.rect.top
#self.rect = self.rect.move(x, y)
self.rect.left = x-32
self.rect.top = y-32
- self.rect = self.rect.clamp(SCREENRECT)
class Puzzle:
def __init__(self):
@@ -115,6 +126,10 @@ class Game:
def run(self):
self.running = True
+ if pygame.mixer and not pygame.mixer.get_init():
+ print 'Warning, no sound'
+ pygame.mixer = None
+
#set the screen up
winstyle = 0 # |FULLSCREEN
bestdepth = pygame.display.mode_ok(SCREENRECT.size, winstyle, 32)
@@ -152,12 +167,12 @@ class Game:
#main blocku code structs
blocks = pygame.sprite.Group()
- Block.containers = spriteBatch
+ Block.containers = blocks,spriteBatch
aBlock = Block()
#see if there is a sprite font
if pygame.font:
- spriteBatch.add(Text(text = 'helloworld'))
+ spriteBatch.add(Text(''))
spriteBatch.add(mouseUpdate())
# it is important to note that like xna the origin is 0,0
@@ -218,17 +233,18 @@ class Game:
self.clock.tick(30)
class Text(pygame.sprite.Sprite):
- def __init__(self,text="blank"):
+ text = ''
+ def __init__(self,txt):
pygame.sprite.Sprite.__init__(self)
self.font = pygame.font.Font(None, 20)
self.font.set_italic(1)
self.color = Color('blue')
self.update()
- self.rect = self.image.get_rect().move(50, 200)
- self.text = text
+ self.rect = self.image.get_rect().move(55, 80)
+ self.text = txt
def update(self):
- msg = '' # 'Drawing call test'
+ msg = 'Drawing call test ' + self.text
self.image = self.font.render(msg, 0, self.color)
class mouseUpdate(pygame.sprite.Sprite):