Re: [pygame] Background ghosts

2009-01-02 Thread Michael Phipps
Weeble - 

You nailed it! Thanks for your help - it is very much appreciated.

Michael


Re: [pygame] Background ghosts

2009-01-01 Thread Michael Phipps
Hi Jake!

Thanks for responding.

The background that I blit in is the same size as the display surface, so I 
really am clearing the screen. :-/ I can see this - when I complete a row, I 
redraw the screen and everything looks fine. Then a new sprite starts making 
its  way down the board (imagine tetris) and, as soon as it is over top of the 
highest point where a block had been (even though it isn't there because rows 
disappeared), that old block  shows through.

As for the splitting the sprites, I considered that. The problem is that when a 
row is complete (just like in Tetris), a whole piece that fell wouldn't 
necessarily disappear, but only part of one. I guess I could separate each 
piece into multiple sprites, but that would involve dozens of sprites and I 
don't think that the tracking of it would be any better than what I have right 
now.

Michael




-Original Message-
From: Jake b [ninmonk...@gmail.com]
Date: 12/31/2008 23:12
To: pygame-users@seul.org
Subject: Re: [pygame] Background ghosts

It looks like you never clear the screen. try something like:
def drawBoard():
   self.screen.fill( (128,128,128) )
   blit background to display
   for piece in fallenPieces:
blit piece to display
  display.flip()

Why do you split sprites into two groups? ( stopped, and moving )

(Not sure if that will exactly integrate into how your code, is, but
this is what I mean):

class TetrisMain():
def __init__(self):
init pygame, surfaces, sprite groups
self.screen = #pygame screen
self.pieces_list = #sprite group filled with pieces

def draw(self):
clear, blit background, blit pieces, flip.
self.screen.fill((128,128,128))
self.screen.blit( self.background, (0,0))
self.pieces_list.draw(self.screen)
pygame.display.flip()

def loop(self):
main loop
self.pieces_list.update() # update using sprite group
self.draw()

On Wed, Dec 31, 2008 at 8:47 PM, Michael Phipps
michael.phi...@bluetie.com wrote:
 I am finishing up my first pygame; everything has been fun and easy except 
 this:

 The game is a tetris-like game (with a twist). I have the falling piece as a 
 sprite. The background is just a bitmap. The pieces that have already fallen, 
 I blit into place. So I have something like (in pseudo code):

 def drawBoard():
blit background to display
for piece in fallenPieces:
 blit piece to display
   display.flip()

 while 1: # game loop
moveSprite()
if sprite.nextLocation == taken
fallenPieces.Append(sprite.asPiece())
sprite = None
removeSolidRows() # This removes fallen pieces that have formed 
 complete rows
drawboard()

 The problem that I have is that as the sprite is falling, I can see rows that 
 have been removed. I have confirmed that drawBoard() is doing the right thing 
 - when the sprite hits the bottom and the screen redraws, the ghosts 
 disappear. They are only there when the sprite floats over them. It looks 
 like the sprite is getting the data from the old version of the screen (i.e. 
 before the last piece fell and rows were removed) to redraw the screen's 
 dirty regions.

 Help!

 Michael




-- 
Jake




Re: [pygame] Background ghosts

2009-01-01 Thread Michael Phipps
I don't usually respond to myself. :-) I thought some more about it and thought 
that maybe the source code would be helpful. The game needs a lot of spit and 
polish - the graphics are pretty ugly, the title screen is very basic, and ... 
oh - the game doesn't end when the tiles pile up over the top. Not to mention 
that the block sequence is always the same (this is for debugging).

Anyway, if someone wants to take a look, the code is attached...




-Original Message-
From: Michael Phipps [michael.phi...@bluetie.com]
Date: 01/01/2009 13:14
To: pygame-users@seul.org
Subject: Re: [pygame] Background ghosts

Hi Jake!

Thanks for responding.

The background that I blit in is the same size as the display surface, so I 
really am clearing the screen. :-/ I can see this - when I complete a row, I 
redraw the screen and everything looks fine. Then a new sprite starts making 
its  way down the board (imagine tetris) and, as soon as it is over top of the 
highest point where a block had been (even though it isn't there because rows 
disappeared), that old block  shows through.

As for the splitting the sprites, I considered that. The problem is that when a 
row is complete (just like in Tetris), a whole piece that fell wouldn't 
necessarily disappear, but only part of one. I guess I could separate each 
piece into multiple sprites, but that would involve dozens of sprites and I 
don't think that the tracking of it would be any better than what I have right 
now.

Michael




-Original Message-
From: Jake b [ninmonk...@gmail.com]
Date: 12/31/2008 23:12
To: pygame-users@seul.org
Subject: Re: [pygame] Background ghosts

It looks like you never clear the screen. try something like:
def drawBoard():
   self.screen.fill( (128,128,128) )
   blit background to display
   for piece in fallenPieces:
blit piece to display
  display.flip()

Why do you split sprites into two groups? ( stopped, and moving )

(Not sure if that will exactly integrate into how your code, is, but
this is what I mean):

class TetrisMain():
def __init__(self):
init pygame, surfaces, sprite groups
self.screen = #pygame screen
self.pieces_list = #sprite group filled with pieces

def draw(self):
clear, blit background, blit pieces, flip.
self.screen.fill((128,128,128))
self.screen.blit( self.background, (0,0))
self.pieces_list.draw(self.screen)
pygame.display.flip()

def loop(self):
main loop
self.pieces_list.update() # update using sprite group
self.draw()

On Wed, Dec 31, 2008 at 8:47 PM, Michael Phipps
michael.phi...@bluetie.com wrote:
 I am finishing up my first pygame; everything has been fun and easy except 
 this:

 The game is a tetris-like game (with a twist). I have the falling piece as a 
 sprite. The background is just a bitmap. The pieces that have already fallen, 
 I blit into place. So I have something like (in pseudo code):

 def drawBoard():
blit background to display
for piece in fallenPieces:
 blit piece to display
   display.flip()

 while 1: # game loop
moveSprite()
if sprite.nextLocation == taken
fallenPieces.Append(sprite.asPiece())
sprite = None
removeSolidRows() # This removes fallen pieces that have formed 
 complete rows
drawboard()

 The problem that I have is that as the sprite is falling, I can see rows that 
 have been removed. I have confirmed that drawBoard() is doing the right thing 
 - when the sprite hits the bottom and the screen redraws, the ghosts 
 disappear. They are only there when the sprite floats over them. It looks 
 like the sprite is getting the data from the old version of the screen (i.e. 
 before the last piece fell and rows were removed) to redraw the screen's 
 dirty regions.

 Help!

 Michael




-- 
Jake



import sys, pygame, random

class scoreClass:
value = 100
def get(self):
return self.value
def increment(self,blocks,multiplier):
self.value+=(100*blocks)*multiplier

class rastras:
size = width, height = 640, 768
playfieldSize = 5,12
blockWidth,blockHeight = 48,48
playfieldOffset = 60,50
normalSpeed = 2
acceleratedSpeed = 8
score = scoreClass()
colors = ( (255,0,0), (0,255,0), (0,0,255), (0,255,255), (255,0,255), 
(255,255,0))
waysToScore = ((1,0),(0,-1),(-1,-1),(1,-1))

playfield = blockWidth*playfieldSize[0],blockHeight*playfieldSize[1]
playfieldBottom = playfield[1]+playfieldOffset[1]
scoreLocation = width/2 + (playfield[0]+playfieldOffset[0])/2, height/3 

pygame.init()
screen = pygame.display.set_mode(size)
clock = pygame.time.Clock()
font = pygame.font.Font(None, 24)

light

Re: [pygame] @

2008-12-31 Thread Michael Phipps
Yanom - 

A decorator is a method that takes another method as a parameter so that it can 
do something. It is usually used for aspect oriented programming.

For example:

def logThisMethodCall(methodCall)
# Do some logging here

@logThisMethodCall
def myMethod(a,b,c)
# do Somthing in here

Now, whenever you call myMethod, logThisMethodCall gets called first, with 
the invocation of myMethod passed into it. You can use it for logging, security 
(i.e. does this person have permission to be calling this), etc.

Michael




-Original Message-
From: Yanom Mobis [ya...@rocketmail.com]
Date: 12/31/2008 11:19
To: pygame-users@seul.org
Subject: Re: [pygame] @

so when you do this:

@foo
def bar(): pass

you assume that a function foo() already exists.

and it creates something like this:

def foo():
def bar(): pass
pass

?
I'm sorry, I just got confused.
   



- On Wed, 12/31/08, Noah Kantrowitz n...@coderanger.net wrote:
From: Noah Kantrowitz n...@coderanger.net
Subject: Re: [pygame] @
To: pygame-users@seul.org
Date: Wednesday, December 31, 2008, 3:01 AM

decorator. The short version is that this

@foo
def bar(): pass

is the same as this

def bar(): pass
bar = foo(bar)

The long version is look it up because it gets very complicated and
voodoo-ish

--Noah

On Dec 30, 2008, at 9:55 PM, Yanom Mobis wrote:

 I was reading some Python code examples, and i found the @ symbol. What
exactly does this operator do?