Help with pygame

Chris Angelico rosuav at gmail.com
Tue Jul 16 14:16:45 EDT 2013


On Wed, Jul 17, 2013 at 3:29 AM, Daniel Kersgaard
<danielkersgaard at gmail.com> wrote:
> def drawWalls(surface):
>
>     #left and right walls
>     for y in range(HEIGHT):
>         surface.blit(wallblock, (0, y * BLOCK_SIZE))
>         surface.blit(wallblock, (WIDTH * BLOCK_SIZE, y * BLOCK_SIZE))
>
>         for x in range(WIDTH):
>             surface.blit(wallblock, (x * BLOCK_SIZE, 0))
>             surface.blit(wallblock, (x * BLOCK_SIZE, HEIGHT * BLOCK_SIZE))

Hm. I'm not entirely sure as I don't have pygame to test your code on,
but this strikes me as odd: you're blitting the x loop once for every
iteration of the y loop. Shouldn't the two loops be at the same
indentation?

I think you perhaps want to offset one of the lines. Currently, you're
running x from 0 up, and y from 0 up, so you're drawing the (0,0) cell
twice. If you add 1 to one of them, you should be able to draw all
four walls correctly. Alternatively, leave this as it is, and just add
one more draw at (WIDTH, HEIGHT) to fill in the last square.

ChrisA



More information about the Python-list mailing list