From eb22c65f8f0c66b3e335cb2571c6a1863fb3c218 Mon Sep 17 00:00:00 2001 From: coolestdude1 Date: Thu, 18 Feb 2010 23:00:32 +0000 Subject: added in text to the block and better handlers for numbers --- diff --git a/blocku.py b/blocku.py index 5ccf4ac..ad7007f 100644 --- a/blocku.py +++ b/blocku.py @@ -53,22 +53,31 @@ def load_sound(file): class Block(pygame.sprite.Sprite): images = [] - def __init__(self, north=None, east=None, south=None, west=None): + north='' + east='' + south='' + west='' + def __init__(self, n='', e='', s='', w=''): pygame.sprite.Sprite.__init__(self, self.containers) - self.image = self.images[0] - self.rect = self.image.get_rect().move(200, 200) + self.image = self.images[0].copy() + self.rect = pygame.Rect(200,200,64,64) self.font = pygame.font.Font(None, 20) self.font.set_italic(1) - self.color = Color('red') + self.color = Color('blue') self.update() - self.north = north - self.east = east - self.south = south - self.west = west + self.north = n + self.east = e + self.south = s + self.west = w def update(self): #keep the block on the screen self.rect = self.rect.clamp(SCREENRECT) + self.image = self.images[0].copy() + self.image.blit(self.font.render('1', 0, self.color),(30,0)) + self.image.blit(self.font.render('2', 0, self.color),(50,25)) + self.image.blit(self.font.render('3', 0, self.color),(25,50)) + self.image.blit(self.font.render('4', 0, self.color),(5,25)) # game logic here for snapping to grid ...? # when the block is snapped to the grid clamp the rect there def move(self, direction): @@ -90,10 +99,13 @@ class Block(pygame.sprite.Sprite): #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) + def rotate(self): + temp = self.north + self.north = self.east + self.east = self.south + self.south = self.west + self.west = temp + print self.north, self.east, self.south, self.west class Puzzle: def __init__(self): @@ -175,7 +187,7 @@ class Game: #main blocku code structs blocks = pygame.sprite.Group() Block.containers = blocks,spriteBatch - aBlock = Block() + aBlock = Block(1,2,3,4) global debugText debugText = '' @@ -184,6 +196,9 @@ class Game: spriteBatch.add(Text('Drawing call test ')) spriteBatch.add(mouseUpdate()) + #if a key is down + global keyDown + keyDown = False # it is important to note that like xna the origin is 0,0 # the top left of the current window # and increases as you go down and to the right @@ -209,8 +224,9 @@ class Game: # get the state of the keyboard for input keystate = pygame.key.get_pressed() + if not keystate[K_SPACE]: + keyDown = False # for key test use keystate[key] and a return of true will occur when key down - # clear/erase the last drawn sprites spriteBatch.clear(screen, background) # update all the sprites @@ -224,8 +240,9 @@ class Game: aBlock.move(2) if keystate[K_LEFT]: aBlock.move(3) - if keystate[K_SPACE]: - aBlock.rotate(3) + if keystate[K_SPACE] and not keyDown: + aBlock.rotate() + keyDown = True #for block in blocks: x, y = mouse.get_pos() -- cgit v0.9.1