Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #50751

Re: Help with pygame

References <a18a24bf-7cbf-43ef-81a0-c13e7d812b35@googlegroups.com>
Date 2013-07-17 04:16 +1000
Subject Re: Help with pygame
From Chris Angelico <rosuav@gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.4778.1373998613.3114.python-list@python.org> (permalink)

Show all headers | View raw


On Wed, Jul 17, 2013 at 3:29 AM, Daniel Kersgaard
<danielkersgaard@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

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Help with pygame Daniel Kersgaard <danielkersgaard@gmail.com> - 2013-07-16 10:29 -0700
  Re: Help with pygame Chris Angelico <rosuav@gmail.com> - 2013-07-17 04:16 +1000
    Re: Help with pygame Daniel Kersgaard <danielkersgaard@gmail.com> - 2013-07-16 11:33 -0700
  Re: Help with pygame Dave Angel <davea@davea.name> - 2013-07-16 14:58 -0400
  Re: Help with pygame Terry Reedy <tjreedy@udel.edu> - 2013-07-16 20:10 -0400

csiph-web