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 23:00:32 (GMT)
committer coolestdude1 <arielzamparini@gmail.com>2010-02-18 23:00:32 (GMT)
commiteb22c65f8f0c66b3e335cb2571c6a1863fb3c218 (patch)
tree079b5967f24546166db467f5d8753bc29ab0520e
parentd1060817004a0039676fbbfbdc493e40603db014 (diff)
added in text to the block and better handlers for numbers
-rw-r--r--blocku.py49
1 files changed, 33 insertions, 16 deletions
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()