pygame.Rect question

Dave Angel d at davea.name
Sun Apr 8 20:29:00 EDT 2012


On 04/08/2012 07:58 PM, Scott Siegler wrote:
> Hello,
>
> I am new to Python and began using pygame to start some game programming.  I was hoping someone could help me out with something that seems simple but is really confusing me.
>
> I am creating a rect and then using the attributes of the rect to set the size and location.
>
> I set rect.left to 30, rect.top to 30 and rect.width = 20
>
> This works fine.  However, when looking at rect.right() it shows that it is equal to 50. I suppose this is equal to 30+20.  However, since the first pixel is on location 30, wouldn't the 20th pixel be on 49 (not 50)? 
>
> Am I missing something here?  It is really confusing me when I am doing some collision algorithms.
>
> Any help?
>
> Thanks,
> Scott

I don't know about pygame, but almost everywhere in the standard
library, ranges are closed at the begin and open at the end.  For
example, if you have range(30, 50), there are 20 items, numbered 30
through 49.  I expect the same will be true for rect.right() and
rect.bottom().



-- 

DaveA




More information about the Python-list mailing list