From d1060817004a0039676fbbfbdc493e40603db014 Mon Sep 17 00:00:00 2001 From: coolestdude1 Date: Thu, 18 Feb 2010 11:28:03 +0000 Subject: added in broken rotation to the block press space to break --- diff --git a/blocku.py b/blocku.py index 1343bb1..5ccf4ac 100644 --- a/blocku.py +++ b/blocku.py @@ -67,8 +67,10 @@ class Block(pygame.sprite.Sprite): self.west = west def update(self): + #keep the block on the screen self.rect = self.rect.clamp(SCREENRECT) # game logic here for snapping to grid ...? + # when the block is snapped to the grid clamp the rect there def move(self, direction): # up = 0, right = 1, down = 2, left = 3 if direction == 0: @@ -79,14 +81,19 @@ class Block(pygame.sprite.Sprite): self.rect.move_ip(0,KEYBOARDMOVESPEED) if direction == 3: self.rect.move_ip(-KEYBOARDMOVESPEED,0) - #keep the block on the screen + def grab(self, pos): x, y = pos; #print x , y #print self.rect.left, self.rect.top #self.rect = self.rect.move(x, y) + #remember the offset here is 32 as this will center the mouse in our 64pixel image self.rect.left = x-32 self.rect.top = y-32 + def rotate(self, angle): + global debugText + debugText = 'trying to rotate' + self.image = pygame.transform.rotate(self.image,angle) class Puzzle: def __init__(self): @@ -170,9 +177,11 @@ class Game: Block.containers = blocks,spriteBatch aBlock = Block() + global debugText + debugText = '' #see if there is a sprite font if pygame.font: - spriteBatch.add(Text('')) + spriteBatch.add(Text('Drawing call test ')) spriteBatch.add(mouseUpdate()) # it is important to note that like xna the origin is 0,0 @@ -215,13 +224,19 @@ class Game: aBlock.move(2) if keystate[K_LEFT]: aBlock.move(3) - + if keystate[K_SPACE]: + aBlock.rotate(3) + #for block in blocks: x, y = mouse.get_pos() - #blockx, blocky = block.rect + if event.get_grab(): + debugText = 'holding mouse button 1' if aBlock.rect.collidepoint(x,y): aBlock.grab(mouse.get_pos()) + debugText += 'grabed the block' + else: + debugText = '' # note random here is random.random() # note foreach here is for object in @@ -234,7 +249,7 @@ class Game: class Text(pygame.sprite.Sprite): text = '' - def __init__(self,txt): + def __init__(self,txt=''): pygame.sprite.Sprite.__init__(self) self.font = pygame.font.Font(None, 20) self.font.set_italic(1) @@ -244,7 +259,8 @@ class Text(pygame.sprite.Sprite): self.text = txt def update(self): - msg = 'Drawing call test ' + self.text + global debugText + msg = self.text + debugText self.image = self.font.render(msg, 0, self.color) class mouseUpdate(pygame.sprite.Sprite): -- cgit v0.9.1