Re: [pygame] more circles

2010-10-10 Thread kevin hayes
Thank youyou've been so generous with your time and input, I can't thank
you enough.

On Sat, Oct 9, 2010 at 1:17 PM, B W  wrote:

> Yes, if you're not getting it then an example is probably better than more
> explanation. Here's your program with the changes I had in mind.
>
>
> """ MoveCircleSizeCircle.py
> Makes a circle that changes
> it's position and size by the
> keyboard, 10/3/10"""
>
> import pygame
> pygame.init()
>
> screen = pygame.display.set_mode((640, 480))
>
> class Circle(pygame.sprite.Sprite):
> def __init__(self, startPos, direction):
>
> pygame.sprite.Sprite.__init__(self)
> self.rect = pygame.Rect(0,0,50,50)
> self._base_image = self._make_image()
> self.image = self._base_image
>
> self.rect.center = startPos
> self.dx,self.dy = direction
> self.dw,self.dh = 0,0
>
> def update(self):
> """update size and position of sprite each frame"""
> if (self.dw,self.dh) != (0,0):
> self.resize(self.dw, self.dh)
>
>
> self.rect.centerx += self.dx   #move rect (x, y)
> self.rect.centery += self.dy
>
> if self.rect.right > screen.get_width():
> self.rect.left = screen.get_width() - 50
> if self.rect.left < 0:
> self.rect.right = 50
> if self.rect.bottom > screen.get_height():
> self.rect.top = screen.get_height() - 50
> if self.rect.top < 0:
> self.rect.bottom = 50
>
> def resize(self, x=0, y=0):
> """resize sprite once"""
> if (x,y) == (0,0):
> return
> r = self.rect
> save_center = r.center
> r.size = r.width+x, r.height+y
> if r.height > 200:
> r.height = 200
> if r.width > 200:
> r.width = 200
> if r.height < 2:
> r.height = 2
> if r.width < 2:
> r.width = 2
> r.center = save_center
> ## CHOICE: either remake or scale the image
> if False:
> self.image = self._make_image()
> else:
> ## but scaled images do not look as neat
> self._inflate_image()
>
> def _inflate_image(self):
> """use transform on base image"""
> self.image = pygame.transform.smoothscale(
> self._base_image, (self.rect.size))
>
> def _make_image(self):
> """make image from scratch"""
> image = pygame.Surface(self.rect.size)
>
> image.fill((255, 255, 255))
> rect = image.get_rect()
> w,h = self.rect.size
> radius = min(w, h) / 2
> pygame.draw.circle(image, (0, 0, 255), rect.center, radius)
> return image
>
>
> def main():
> pygame.display.set_caption("Move the Circle with Arrows, Resize it
> with(0)+(9)-")
>
> background = pygame.Surface(screen.get_size())
> background.fill((255, 255, 255))
> screen.blit(background, (0, 0))
>
> circle = Circle([320, 240], [0, 0])
>
> pygame.mouse.set_visible(False)
> allSprites = pygame.sprite.Group(circle)
> clock = pygame.time.Clock()
> keepGoing = True
>
> while keepGoing:
> clock.tick(30)
> for event in pygame.event.get():
> if event.type == pygame.QUIT:
> keepGoing = False
> elif event.type == pygame.KEYDOWN:
> if event.key == pygame.K_DOWN:
> circle.dy = 2
> if event.key == pygame.K_UP:
> circle.dy = -2
> if event.key == pygame.K_RIGHT:
> circle.dx = 2
> if event.key == pygame.K_LEFT:
> circle.dx = -2
> if event.key == pygame.K_ESCAPE:
> keepGoing = False
> if event.key == pygame.K_9:   #resize by -2
> circle.dw,circle.dh = (-2, -2)
>
> if event.key == pygame.K_0:
> circle.dw,circle.dh = (2, 2)  #resize by +2
>
>
> elif event.type == pygame.KEYUP:
> if event.key == pygame.K_DOWN:
> circle.dy = 0
> if event.key == pygame.K_UP:
> circle.dy = 0
> if event.key == pygame.K_LEFT:
> circle.dx = 0
> if event.key == pygame.K_RIG

Re: [pygame] more circles

2010-10-07 Thread kevin hayes
I put some thought into your suggestions, but I'm still not piecing it
together. I tried to use the inflate, transform.scale in my update function,
but that didn't work. Also, I don't understand your hint (hint: move some of
the constructor code to a resize method and call that from in constructor,
as well as the main) By constructor you mean the first __init__( variable,
variable...) ?  This stuff doesn't come naturally to me, but I find it
fascinating.  If you could just show me (more explicitly) how to do this,
that would help.
Thanks for the links, I will check them out.
On Wed, Oct 6, 2010 at 10:02 PM, B W  wrote:

> You have to resize the rect *and* the image. You can use pygame functions
> Rect.inflate* and transform.scale, respectively, or you can do-it-yerself
> (hint: move some of the constructor code to a resize method and call that
> from in constructor, as well as the main loop).
>
> Also, the += and -= in the event handler cases are probably not doing what
> you intend. If you get the resize working so you can see the circle change
> and it grows or moves at a strange rate, re-examine those calculations.
>
> Gumm
>
>
> On Wed, Oct 6, 2010 at 6:07 PM, kevin hayes  wrote:
>
>>
>> Hi,
>>
>> Well, I got it working.  The circle moves correctly according to keyboard
>> input. The trouble I am having is with resizing the circle/sprite.
>> Everything looks logical to me, but it won't function the way I want it to.
>> I tried using the rect.inflate(x,y) method, but I couldn't see how to
>> incorporate it. If someone could show me how to add the some resizing
>> functionality, that would be great. I am going to be getting a tutor soon,
>> so I won't be bringing my beginner questions to this board.  Thanks again to
>> everyone who has assisted me.
>>
>> Here she is:
>>
>> """ MoveCircleSizeCircle.py
>> Makes a circle that changes
>> it's position and size by the
>> keyboard, 10/3/10"""
>>
>> import pygame
>> pygame.init()
>>
>> screen = pygame.display.set_mode((640, 480))
>>
>> class Circle(pygame.sprite.Sprite):
>> def __init__(self, startPos, direction, reSize):
>> pygame.sprite.Sprite.__init__(self)
>> self.image = pygame.Surface((50, 50))
>> self.image.fill((255, 255, 255))
>> pygame.draw.circle(self.image, (0, 0, 255), (25, 25), 25)
>> self.rect = self.image.get_rect()
>> self.rect.center = startPos
>> self.dx,self.dy = direction
>> self.da,self.db = reSize
>>
>> def update(self):
>>
>> self.rect.width += self.da   #add to rects size by (x,y) values
>> self.rect.height += self.db
>>
>> if self.rect.height > 199:
>> self.rect.height = 200
>> if self.rect.width > 199:
>> self.rect.width = 200
>> if self.rect.height < 1:
>> self.rect.height = 1
>> if self.rect.width < 1:
>> self.rect.width = 1
>>
>> self.rect.centerx += self.dx   #move rect (x, y)
>> self.rect.centery += self.dy
>>
>> if self.rect.right > screen.get_width():
>> self.rect.left = screen.get_width() - 50
>> if self.rect.left < 0:
>> self.rect.right = 50
>> if self.rect.bottom > screen.get_height():
>> self.rect.top = screen.get_height() - 50
>> if self.rect.top < 0:
>> self.rect.bottom = 50
>> def main():
>> pygame.display.set_caption("Move the Circle with Arrows, Resize it
>> with(0)+(9)-")
>>
>> background = pygame.Surface(screen.get_size())
>> background.fill((255, 255, 255))
>> screen.blit(background, (0, 0))
>>
>>
>> circle = Circle([320, 240], [0, 0], [0, 0])
>> pygame.mouse.set_visible(False)
>> allSprites = pygame.sprite.Group(circle)
>> clock = pygame.time.Clock()
>> keepGoing = True
>>
>> while keepGoing:
>>  clock.tick(30)
>> for event in pygame.event.get():
>> if event.type == pygame.QUIT:
>> keepGoing = False
>> elif event.type == pygame.KEYDOWN:
>> if event.key == pygame.K_DOWN:
>> circle.dy += 2
>> if event.key == pygame.K_UP:
>> circle.dy -= 2
>> if event.key == pygame.K_RIGHT:
>> circle.dx += 2
&g

Re: [pygame] more circles

2010-10-06 Thread kevin hayes
Thank you so much for your reply! Yeah, I'm trying to get a tutor through
some friends of my Mom, but if I can't find one that wayI'll probably
ask people on this list.  I just need someone to answer a question every
couple of days.  I really appreciate your help.  Thanks again!

On Wed, Oct 6, 2010 at 10:02 PM, B W  wrote:

> You have to resize the rect *and* the image. You can use pygame functions
> Rect.inflate* and transform.scale, respectively, or you can do-it-yerself
> (hint: move some of the constructor code to a resize method and call that
> from in constructor, as well as the main loop).
>
> Also, the += and -= in the event handler cases are probably not doing what
> you intend. If you get the resize working so you can see the circle change
> and it grows or moves at a strange rate, re-examine those calculations.
>
> Gumm
>
>
> On Wed, Oct 6, 2010 at 6:07 PM, kevin hayes  wrote:
>
>>
>> Hi,
>>
>> Well, I got it working.  The circle moves correctly according to keyboard
>> input. The trouble I am having is with resizing the circle/sprite.
>> Everything looks logical to me, but it won't function the way I want it to.
>> I tried using the rect.inflate(x,y) method, but I couldn't see how to
>> incorporate it. If someone could show me how to add the some resizing
>> functionality, that would be great. I am going to be getting a tutor soon,
>> so I won't be bringing my beginner questions to this board.  Thanks again to
>> everyone who has assisted me.
>>
>> Here she is:
>>
>> """ MoveCircleSizeCircle.py
>> Makes a circle that changes
>> it's position and size by the
>> keyboard, 10/3/10"""
>>
>> import pygame
>> pygame.init()
>>
>> screen = pygame.display.set_mode((640, 480))
>>
>> class Circle(pygame.sprite.Sprite):
>> def __init__(self, startPos, direction, reSize):
>> pygame.sprite.Sprite.__init__(self)
>> self.image = pygame.Surface((50, 50))
>> self.image.fill((255, 255, 255))
>> pygame.draw.circle(self.image, (0, 0, 255), (25, 25), 25)
>> self.rect = self.image.get_rect()
>> self.rect.center = startPos
>> self.dx,self.dy = direction
>> self.da,self.db = reSize
>>
>> def update(self):
>>
>> self.rect.width += self.da   #add to rects size by (x,y) values
>> self.rect.height += self.db
>>
>> if self.rect.height > 199:
>> self.rect.height = 200
>> if self.rect.width > 199:
>> self.rect.width = 200
>> if self.rect.height < 1:
>> self.rect.height = 1
>> if self.rect.width < 1:
>> self.rect.width = 1
>>
>> self.rect.centerx += self.dx   #move rect (x, y)
>> self.rect.centery += self.dy
>>
>> if self.rect.right > screen.get_width():
>> self.rect.left = screen.get_width() - 50
>> if self.rect.left < 0:
>> self.rect.right = 50
>> if self.rect.bottom > screen.get_height():
>> self.rect.top = screen.get_height() - 50
>> if self.rect.top < 0:
>> self.rect.bottom = 50
>> def main():
>> pygame.display.set_caption("Move the Circle with Arrows, Resize it
>> with(0)+(9)-")
>>
>> background = pygame.Surface(screen.get_size())
>> background.fill((255, 255, 255))
>> screen.blit(background, (0, 0))
>>
>>
>> circle = Circle([320, 240], [0, 0], [0, 0])
>> pygame.mouse.set_visible(False)
>> allSprites = pygame.sprite.Group(circle)
>> clock = pygame.time.Clock()
>> keepGoing = True
>>
>> while keepGoing:
>>  clock.tick(30)
>> for event in pygame.event.get():
>> if event.type == pygame.QUIT:
>> keepGoing = False
>> elif event.type == pygame.KEYDOWN:
>> if event.key == pygame.K_DOWN:
>> circle.dy += 2
>> if event.key == pygame.K_UP:
>> circle.dy -= 2
>> if event.key == pygame.K_RIGHT:
>> circle.dx += 2
>> if event.key == pygame.K_LEFT:
>> circle.dx -= 2
>> if event.key == pygame.K_ESCAPE:
>> keepGoing = False
>> if event.key == pygame.K_9:  #resize by -2
>>

[pygame] more circles

2010-10-06 Thread kevin hayes
Hi,

Well, I got it working.  The circle moves correctly according to keyboard
input. The trouble I am having is with resizing the circle/sprite.
Everything looks logical to me, but it won't function the way I want it to.
I tried using the rect.inflate(x,y) method, but I couldn't see how to
incorporate it. If someone could show me how to add the some resizing
functionality, that would be great. I am going to be getting a tutor soon,
so I won't be bringing my beginner questions to this board.  Thanks again to
everyone who has assisted me.

Here she is:

""" MoveCircleSizeCircle.py
Makes a circle that changes
it's position and size by the
keyboard, 10/3/10"""

import pygame
pygame.init()

screen = pygame.display.set_mode((640, 480))

class Circle(pygame.sprite.Sprite):
def __init__(self, startPos, direction, reSize):
pygame.sprite.Sprite.__init__(self)
self.image = pygame.Surface((50, 50))
self.image.fill((255, 255, 255))
pygame.draw.circle(self.image, (0, 0, 255), (25, 25), 25)
self.rect = self.image.get_rect()
self.rect.center = startPos
self.dx,self.dy = direction
self.da,self.db = reSize

def update(self):

self.rect.width += self.da   #add to rects size by (x,y) values
self.rect.height += self.db

if self.rect.height > 199:
self.rect.height = 200
if self.rect.width > 199:
self.rect.width = 200
if self.rect.height < 1:
self.rect.height = 1
if self.rect.width < 1:
self.rect.width = 1

self.rect.centerx += self.dx   #move rect (x, y)
self.rect.centery += self.dy

if self.rect.right > screen.get_width():
self.rect.left = screen.get_width() - 50
if self.rect.left < 0:
self.rect.right = 50
if self.rect.bottom > screen.get_height():
self.rect.top = screen.get_height() - 50
if self.rect.top < 0:
self.rect.bottom = 50
def main():
pygame.display.set_caption("Move the Circle with Arrows, Resize it
with(0)+(9)-")

background = pygame.Surface(screen.get_size())
background.fill((255, 255, 255))
screen.blit(background, (0, 0))


circle = Circle([320, 240], [0, 0], [0, 0])
pygame.mouse.set_visible(False)
allSprites = pygame.sprite.Group(circle)
clock = pygame.time.Clock()
keepGoing = True

while keepGoing:
clock.tick(30)
for event in pygame.event.get():
if event.type == pygame.QUIT:
keepGoing = False
elif event.type == pygame.KEYDOWN:
if event.key == pygame.K_DOWN:
circle.dy += 2
if event.key == pygame.K_UP:
circle.dy -= 2
if event.key == pygame.K_RIGHT:
circle.dx += 2
if event.key == pygame.K_LEFT:
circle.dx -= 2
if event.key == pygame.K_ESCAPE:
keepGoing = False
if event.key == pygame.K_9:  #resize by -2
circle.da += -2
if event.key == pygame.K_0:
circle.db += 2   #resize by +2

elif event.type == pygame.KEYUP:
if event.key == pygame.K_DOWN:
circle.dy = 0
if event.key == pygame.K_UP:
circle.dy = 0
if event.key == pygame.K_LEFT:
circle.dx = 0
if event.key == pygame.K_RIGHT:
circle.dx = 0
if event.key == pygame.K_9:
circle.da = 0
if event.key == pygame.K_0:
circle.db = 0

allSprites.clear(screen, background)
allSprites.update()
allSprites.draw(screen)

pygame.display.flip()

pygame.mouse.set_visible(True)

if __name__ == "__main__":
main()

pygame.quit()


Re: [pygame] circles

2010-10-03 Thread kevin hayes
Thanks guys!  I think I've got a better handle on it now.

On Sat, Oct 2, 2010 at 10:05 PM, B W  wrote:

> I like Ian's earlier suggestion, Kevin, which he only hinted at. But I
> sense you're really struggling with how to extend your Circle class, and
> could use an example to go with the explanations.
>
> Note that every time you create a circle object with the Circle class,
> you're executing the constructor __init__. So if you add some parameters to
> __init__, then you can manipulate the creation and will get objects that
> behave in the same manner but with different details. Details such as
> position, direction, color, and anything else you need.
>
> In the constructor do something like this:
>
>
> class Circle(pygame.sprite.Sprite):
> def __init__(self, position, direction, color, *groups):
> pygame.sprite.Sprite.__init__(self, *groups)
> #[use your same image and rect code]
> self.rect.center = position
> self.dx,self.dy = direction
>
> Your update method is fine the way it is. As Ian points out, get rid of
> update_circle2; it doesn't serve your purposes.
>
> In main create some circles at different start positions, directions, and
> colors, and might as well supply their sprite group since the Sprite
> superclass's constructor can automatically add the sprite to the group for
> you:
>
> Circle([25,25], [+5,+5], Color("yellow"), allSprites)  # top-left, going
> down-right
> Circle([640-25,25], [-5,+5], Color("red"), allSprites)  # top-right, going
> down-left
>
> You may be wondering where the circles go, since you're obviously not
> assigning them to a variable. They're in your sprite group, by virtue of the
> pygame.sprite.Sprite.__init__(self, *groups) call.
>
> I'm sure you can figure out the other two circles.
>
> After making these changes, you can remove the few lines of main's sprite
> initialization that no longer serve a purpose.
>
> Hope that helps to get you over the hump.
>
> Gumm
>
>
>
> On Sat, Oct 2, 2010 at 7:38 PM, kevin hayes  wrote:
>
>> I just want to thank you for taking the time to help me out.  I'm going to
>> take a break for a while and when I come back I'm going to look over your
>> suggestions.  I hope to be able to answer some questions at some point
>> rather than asking them.
>>
>> On Sat, Oct 2, 2010 at 7:24 PM, Ian Mallett  wrote:
>>
>>> On Sat, Oct 2, 2010 at 8:09 PM, kevin hayes  wrote:
>>>
>>>> At this point I don't really care if the sprites write over eachother...
>>>
>>> You should.  Because otherwise, you can't see anything.  I don't mean
>>> proper handling of occlusion; I mean not being able to see what's going on.
>>> The problem can be found by first figuring out why they are being drawn on
>>> top of each other.  In graphics programming the problem is almost always
>>> self-evident once you see what's actually happening.
>>>
>>>> as long as that doesn't cause the program to crash.  I'm just trying to
>>>> get four circles going diagonally from each corner.  The problem I'm having
>>>> is with the update function...Do I write two update functions?  How do I 
>>>> get
>>>> the update function to apply separate code for the two (or more) circles?
>>>
>>> Only one update function can exist.  What you CAN (and should) do,
>>> though, is have the update function do a different thing for each sprite.
>>> Your second update function is never getting called, so delete it.
>>>
>>>> Here is my code as it stands:
>>>>
>>> Add this:
>>> circle2.dx = -5
>>> Then, you'll see that the sprites were being drawn over each other (and
>>> moreover, they were starting in the same position, so the yellow one darts
>>> off the screen to the left).  This latter is due to the fact that startPosx
>>> is never used.  Change your update function to change startPosx and
>>> startPosy instead of rect.center.
>>>
>>> Ian
>>>
>>
>>
>


Re: [pygame] circles

2010-10-02 Thread kevin hayes
I just want to thank you for taking the time to help me out.  I'm going to
take a break for a while and when I come back I'm going to look over your
suggestions.  I hope to be able to answer some questions at some point
rather than asking them.

On Sat, Oct 2, 2010 at 7:24 PM, Ian Mallett  wrote:

> On Sat, Oct 2, 2010 at 8:09 PM, kevin hayes  wrote:
>
>> At this point I don't really care if the sprites write over eachother...
>
> You should.  Because otherwise, you can't see anything.  I don't mean
> proper handling of occlusion; I mean not being able to see what's going on.
> The problem can be found by first figuring out why they are being drawn on
> top of each other.  In graphics programming the problem is almost always
> self-evident once you see what's actually happening.
>
>> as long as that doesn't cause the program to crash.  I'm just trying to
>> get four circles going diagonally from each corner.  The problem I'm having
>> is with the update function...Do I write two update functions?  How do I get
>> the update function to apply separate code for the two (or more) circles?
>
> Only one update function can exist.  What you CAN (and should) do, though,
> is have the update function do a different thing for each sprite.  Your
> second update function is never getting called, so delete it.
>
>> Here is my code as it stands:
>>
> Add this:
> circle2.dx = -5
> Then, you'll see that the sprites were being drawn over each other (and
> moreover, they were starting in the same position, so the yellow one darts
> off the screen to the left).  This latter is due to the fact that startPosx
> is never used.  Change your update function to change startPosx and
> startPosy instead of rect.center.
>
> Ian
>


Re: [pygame] circles

2010-10-02 Thread kevin hayes
At this point I don't really care if the sprites write over eachother...as
long as that doesn't cause the program to crash.  I'm just trying to get
four circles going diagonally from each corner.  The problem I'm having is
with the update function...Do I write two update functions?  How do I get
the update function to apply separate code for the two (or more) circles?
Here is my code as it stands:

import pygame
pygame.init()

screen = pygame.display.set_mode((640, 480))

class Circle(pygame.sprite.Sprite):
def __init__(self, color):
pygame.sprite.Sprite.__init__(self)
self.image = pygame.Surface((50, 50))
self.image.fill((255, 255, 255))
pygame.draw.circle(self.image, (color), (25, 25), 25)
self.rect = self.image.get_rect()
self.startPosx = self.rect.centerx
self.startPosy = self.rect.centery
self.dx = 5
self.dy = 5


def update(self):
self.rect.centerx += self.dx
self.rect.centery += self.dy
if self.rect.right > screen.get_width():
self.rect.left = 0
if self.rect.top > screen.get_height():
   self.rect.bottom = 0

def update_circle2(self):
self.rect.centerx -= self.dx
self.rect.centery += self.dy
if self.rect.left < 0:
self.rect.right = 0
if self.rect.top > screen.get_height():
self.rect.bottom = 0

def main():
pygame.display.set_caption("Diagonal Circle")

background = pygame.Surface(screen.get_size())
background.fill((255, 255, 255))
screen.blit(background, (0, 0))

circle1 = Circle(pygame.color.Color("yellow"))
circle2 = Circle(pygame.color.Color("red"))
circle1.startPosx = 0
circle1.startPosy = 0
circle2.startPosx = screen.get_width()
circle2.startPosy = 0


allSprites = pygame.sprite.Group(circle1, circle2)

clock = pygame.time.Clock()
keepGoing = True
while keepGoing:
clock.tick(30)
for event in pygame.event.get():
if event.type == pygame.QUIT:
keepGoing = False

allSprites.clear(screen, background)
allSprites.update()
allSprites.draw(screen)

pygame.display.flip()

if __name__ == "__main__":
main()

pygame.quit()







On Sat, Oct 2, 2010 at 6:43 PM, Ian Mallett  wrote:

> Hi,
>
> Your code only makes one circle.  How can you possibly expect four circles,
> when you only make one?  From the spec, you need to add other instances of
> your circle sprite in your pygame.sprite.Group() call.  Hint: try
> "[circle1,circle2,circle3,circle4]"
>
> If you tried this, then you'll see (or rather won't, but that's what's
> happening) that all the sprites draw over each other.  You'll need to write
> separate logic for each sprite's update function, or all the sprites will
> draw on top of each other.  I've done this by passing (varying) extra
> arguments to your sprites' constructors to alter their internal states.
>
> Ian
>


[pygame] circles

2010-10-02 Thread kevin hayes
Hi,
 This program creates a circle and moves it diagonally across
the screen. I'm having trouble understanding how to use the Circle class to
make Four circles (one on each corner), each going diagonally across the
screen in a different direction.  I've really hit a wall. Can someone show
me how to add to this to have more than one circle?


import pygame
pygame.init()

screen = pygame.display.set_mode((640, 480))

class Circle(pygame.sprite.Sprite):
def __init__(self, color):
pygame.sprite.Sprite.__init__(self)
self.image = pygame.Surface((50, 50))
self.image.fill((255, 255, 255))
pygame.draw.circle(self.image, (color), (25, 25), 25)
self.rect = self.image.get_rect()
self.rect.center = (0, 0)
self.dx = 5
self.dy = 5


def update(self):
self.rect.centerx += self.dx
self.rect.centery += self.dy
if self.rect.right > screen.get_width():
self.rect.left = 0
if self.rect.top > screen.get_height():
self.rect.bottom = 0

def main():
pygame.display.set_caption("Diagonal Circle")

background = pygame.Surface(screen.get_size())
background.fill((255, 255, 255))
screen.blit(background, (0, 0))

circle1 = Circle(pygame.color.Color("yellow"))



allSprites = pygame.sprite.Group(circle1)

clock = pygame.time.Clock()
keepGoing = True
while keepGoing:
clock.tick(30)
for event in pygame.event.get():
if event.type == pygame.QUIT:
keepGoing = False

allSprites.clear(screen, background)
allSprites.update()
allSprites.draw(screen)

pygame.display.flip()

if __name__ == "__main__":
main()

pygame.quit()


Re: [pygame] moving a filled circle from top to bottom

2010-09-29 Thread kevin hayes
Thanks for your reply!

On Wed, Sep 29, 2010 at 9:49 PM, B W  wrote:

> Hi, Kevin.
>
> You already created the example. :) Just replace the few lines in your
> __init__ method.
>
> Note that this is not a "better" way of doing it. It's just an approach
> that I find easier to work with when computing your graphics, i.e.
> "procedural" graphics.
>
> When you load your graphics from an image file, you get a surface sized to
> fit the image and can get your rect from it. In contrast, when computing
> your own graphics it might help to create your dimensions first (the rect)
> and use the rect in plotting your graphics primitives.
>
> Hope that explanation helps.
>
> Gumm
>
> On Wed, Sep 29, 2010 at 8:43 PM, kevin hayes  wrote:
>
>> Hey...my apologies for taking so long to get back to you, I was staying at
>> a friend's house for a couple of days. I honestly don't understand your
>> email. Maybe you could give me a small example...if you wish.
>>
>>
>> On Mon, Sep 27, 2010 at 9:00 PM, B W  wrote:
>>
>>> Changing the order might help with procedural images. Then you can make
>>> the rect's attributes work for you.
>>>
>>> self.rect = pygame.Rect(0,0,50,50)
>>> self.image = pygame.surface.Surface(self.rect.size)
>>> pygame.draw.circle(self.image, pygame.Color(0, 0, 255),
>>> self.rect.center, self.rect.width/2)
>>> self.image.set_colorkey(pygame.Color('black'))
>>> self.rect.center = 320,0
>>>
>>> Gumm
>>>
>>
>


Re: [pygame] moving a filled circle from top to bottom

2010-09-29 Thread kevin hayes
Hey...my apologies for taking so long to get back to you, I was staying at a
friend's house for a couple of days. I honestly don't understand your email.
Maybe you could give me a small example...if you wish.

On Mon, Sep 27, 2010 at 9:00 PM, B W  wrote:

> Changing the order might help with procedural images. Then you can make the
> rect's attributes work for you.
>
> self.rect = pygame.Rect(0,0,50,50)
> self.image = pygame.surface.Surface(self.rect.size)
> pygame.draw.circle(self.image, pygame.Color(0, 0, 255),
> self.rect.center, self.rect.width/2)
> self.image.set_colorkey(pygame.Color('black'))
> self.rect.center = 320,0
>
> Gumm
>
> On Mon, Sep 27, 2010 at 2:40 PM, kevin hayes  wrote:
>
>> Hey...thank you!  I'm now on someone else's computer, so I can't edit the
>> code, but I trust that you are correct. Thanks again. Kevin
>>
>>
>> On Mon, Sep 27, 2010 at 1:37 PM, Christopher Night <
>> cosmologi...@gmail.com> wrote:
>>
>>> It's extremely minor. Change the center of your circle from (320, 0) to
>>> (25, 25). The coordinates are with respect to self.image, not to screen.
>>>
>>> -Christopher
>>>
>>>
>>> On Mon, Sep 27, 2010 at 4:32 PM, kevin hayes wrote:
>>>
>>>> Hi,
>>>> This is my attempt at sending a circle(Sprite) vertically from
>>>> the top of the screen to the bottom.  Can someone
>>>> tell me how to change the code so it works?  Currently it is just
>>>> creating a white screen. Thanks in advance. Kevin
>>>>
>>>> """Attempt at moving a circle(Sprite) from top(of screen) to bottom"""
>>>>
>>>> import pygame
>>>> pygame.init()
>>>>
>>>> screen = pygame.display.set_mode((640, 480))
>>>>
>>>> class Circle(pygame.sprite.Sprite):
>>>> def __init__(self):
>>>> pygame.sprite.Sprite.__init__(self)
>>>> self.image = pygame.Surface((50, 50))
>>>> self.image.fill((255, 255, 255))
>>>>#fill with white to hide square???
>>>> pygame.draw.circle(self.image, (0, 0, 255), (320, 0), 25)
>>>> self.rect = self.image.get_rect()
>>>> self.rect.centerx = 320
>>>> self.rect.centery = 0
>>>>
>>>> def update(self):
>>>> self.rect.centery += 5
>>>> if self.rect.top > screen.get_height():
>>>> self.rect.bottom = 0
>>>>
>>>>
>>>> def main():
>>>> pygame.display.set_caption("Verticle Circle Sprite")
>>>>
>>>> background = pygame.Surface(screen.get_size())
>>>> background.fill((255, 255, 255))
>>>> screen.blit(background, (0, 0))
>>>>
>>>> circle = Circle()
>>>> allSprites = pygame.sprite.Group(circle)
>>>>
>>>> clock = pygame.time.Clock()
>>>> keepGoing = True
>>>> while keepGoing:
>>>> clock.tick(30)
>>>> for event in pygame.event.get():
>>>> if event.type == pygame.QUIT:
>>>> keepGoing == False
>>>>
>>>> allSprites.clear(screen, background)
>>>> allSprites.update()
>>>> allSprites.draw(screen)
>>>>
>>>> pygame.display.flip()
>>>>
>>>> if __name__ == "__main__":
>>>> main()
>>>>
>>>> pygame.quit()
>>>>
>>>>
>>>
>>
>


Re: [pygame] moving a filled circle from top to bottom

2010-09-27 Thread kevin hayes
Hey...thank you!  I'm now on someone else's computer, so I can't edit the
code, but I trust that you are correct. Thanks again. Kevin

On Mon, Sep 27, 2010 at 1:37 PM, Christopher Night
wrote:

> It's extremely minor. Change the center of your circle from (320, 0) to
> (25, 25). The coordinates are with respect to self.image, not to screen.
>
> -Christopher
>
>
> On Mon, Sep 27, 2010 at 4:32 PM, kevin hayes  wrote:
>
>> Hi,
>> This is my attempt at sending a circle(Sprite) vertically from the
>> top of the screen to the bottom.  Can someone
>> tell me how to change the code so it works?  Currently it is just creating
>> a white screen. Thanks in advance. Kevin
>>
>> """Attempt at moving a circle(Sprite) from top(of screen) to bottom"""
>>
>> import pygame
>> pygame.init()
>>
>> screen = pygame.display.set_mode((640, 480))
>>
>> class Circle(pygame.sprite.Sprite):
>> def __init__(self):
>> pygame.sprite.Sprite.__init__(self)
>> self.image = pygame.Surface((50, 50))
>> self.image.fill((255, 255, 255))
>>  #fill with white to hide square???
>> pygame.draw.circle(self.image, (0, 0, 255), (320, 0), 25)
>> self.rect = self.image.get_rect()
>> self.rect.centerx = 320
>> self.rect.centery = 0
>>
>> def update(self):
>> self.rect.centery += 5
>> if self.rect.top > screen.get_height():
>> self.rect.bottom = 0
>>
>>
>> def main():
>> pygame.display.set_caption("Verticle Circle Sprite")
>>
>> background = pygame.Surface(screen.get_size())
>> background.fill((255, 255, 255))
>> screen.blit(background, (0, 0))
>>
>> circle = Circle()
>> allSprites = pygame.sprite.Group(circle)
>>
>> clock = pygame.time.Clock()
>> keepGoing = True
>> while keepGoing:
>> clock.tick(30)
>> for event in pygame.event.get():
>> if event.type == pygame.QUIT:
>> keepGoing == False
>>
>> allSprites.clear(screen, background)
>> allSprites.update()
>> allSprites.draw(screen)
>>
>> pygame.display.flip()
>>
>> if __name__ == "__main__":
>> main()
>>
>> pygame.quit()
>>
>>
>


[pygame] moving a filled circle from top to bottom

2010-09-27 Thread kevin hayes
Hi,
This is my attempt at sending a circle(Sprite) vertically from the
top of the screen to the bottom.  Can someone
tell me how to change the code so it works?  Currently it is just creating a
white screen. Thanks in advance. Kevin

"""Attempt at moving a circle(Sprite) from top(of screen) to bottom"""

import pygame
pygame.init()

screen = pygame.display.set_mode((640, 480))

class Circle(pygame.sprite.Sprite):
def __init__(self):
pygame.sprite.Sprite.__init__(self)
self.image = pygame.Surface((50, 50))
self.image.fill((255, 255, 255))
   #fill with white to hide square???
pygame.draw.circle(self.image, (0, 0, 255), (320, 0), 25)
self.rect = self.image.get_rect()
self.rect.centerx = 320
self.rect.centery = 0

def update(self):
self.rect.centery += 5
if self.rect.top > screen.get_height():
self.rect.bottom = 0


def main():
pygame.display.set_caption("Verticle Circle Sprite")

background = pygame.Surface(screen.get_size())
background.fill((255, 255, 255))
screen.blit(background, (0, 0))

circle = Circle()
allSprites = pygame.sprite.Group(circle)

clock = pygame.time.Clock()
keepGoing = True
while keepGoing:
clock.tick(30)
for event in pygame.event.get():
if event.type == pygame.QUIT:
keepGoing == False

allSprites.clear(screen, background)
allSprites.update()
allSprites.draw(screen)

pygame.display.flip()

if __name__ == "__main__":
main()

pygame.quit()


Re: [pygame] program crashes

2010-09-24 Thread kevin hayes
Thanks you guys!  The workaround seems to do the trick.

On Thu, Sep 23, 2010 at 9:13 AM, Lenard Lindstrom  wrote:

> Hi,
>
> Yes, it looks like a bug. But there may be a simple workaround. Try replace
> line 68 with this:
>
>myFont = pygame.font.Font(None, 20)
>
> If that fails then possibly the default font that ships with Pygame is not
> being installed in the proper place.
>
> Lenard Lindstrom
>
> On 23/09/10 06:30 AM, kevin hayes wrote:
>
>> Well I put part of the traceback into google and apparently some other
>> people have had the same problem:
>> www.pyedpypers.org/forum/viewtopic.php?f=3&t=937his <
>> http://www.pyedpypers.org/forum/viewtopic.php?f=3&t=937his> solution
>> was to use a different version of python. The thing is that I'm using Python
>> 2.5 just like the book, and I'm using pygame 1.9.1release-py2.5 which is for
>> python 2.5!
>>
>> On Thu, Sep 23, 2010 at 5:38 AM, LukePaireepinart 
>> > rabidpoob...@gmail.com>> wrote:
>>
>>Looks to me like you either found a bug in the core pygame code
>>for loading the system font on Mac or you are calling that method
>>wrong. I checked the method and it seems like you should be able
>>to do what you're doing; it shouldn't find a sysfont called none
>>so it should load the default.
>>If no one else gets around to it, I'll give it a test on my Mac
>>after work and let you know.
>>
>>-
>>Sent from a mobile device with a bad e-mail client.
>>-
>>
>>On Sep 23, 2010, at 6:41 AM, kevin hayes ><mailto:kevino...@gmail.com>> wrote:
>>
>>> Can someone tell me what to do (or what I need to get) to get
>>this program to work properly?
>>> When I run the code(straight out of the book), I get this:
>>>
>>> Traceback (most recent call last):
>>>   File "/Users/kevinhayes/Desktop/code/ch05/paint.py", line 107,
>>in 
>>> main()
>>>   File "/Users/kevinhayes/Desktop/code/ch05/paint.py", line 102,
>>in main
>>> myLabel = showStats(drawColor, lineWidth)
>>>   File "/Users/kevinhayes/Desktop/code/ch05/paint.py", line 67,
>>in showStats
>>> myFont = pygame.font.SysFont("None", 20)
>>>   File
>>
>>  
>> "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/pygame/sysfont.py",
>>line 555, in SysFont
>>> initsysfonts()
>>>   File
>>
>>  
>> "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/pygame/sysfont.py",
>>line 522, in initsysfonts
>>> fonts = initsysfonts_darwin()
>>>   File
>>
>>  
>> "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/pygame/sysfont.py",
>>line 422, in initsysfonts_darwin
>>> _search_osx_font_paths(fonts)
>>> UnboundLocalError: local variable 'fonts' referenced before
>>assignment
>>>
>>>
>>>
>>> 
>>>
>>> here is the code:
>>>
>>> """ paint.py
>>> a simple paint program"""
>>>
>>> import pygame
>>>
>>> def checkKeys(myData):
>>> """test for various keyboard inputs"""
>>>
>>> #extract the data
>>> (event, background, drawColor, lineWidth, keepGoing) = myData
>>> #print myData
>>>
>>> if event.key == pygame.K_q:
>>> #quit
>>> keepGoing = False
>>> elif event.key == pygame.K_c:
>>> #clear screen
>>> background.fill((255, 255, 255))
>>> elif event.key == pygame.K_s:
>>> #save picture
>>> pygame.image.save(background, "painting.bmp")
>>> elif event.key == pygame.K_l:
>>> #load picture
>>> background = pygame.image.load("painting.bmp")
>>> elif event.key == pygame.K_r:
>>> #red
>>> drawColor = (255, 0, 0)
>>> elif event.key == pygame.K_g:
>>> #green
>>&g

Re: [pygame] program crashes

2010-09-23 Thread kevin hayes
Well I put part of the traceback into google and apparently some other
people have had the same problem:
www.pyedpypers.org/forum/viewtopic.php?f=3&t=937his solution was to use
a different version of python. The thing is that I'm using Python 2.5 just
like the book, and I'm using pygame 1.9.1release-py2.5 which is for python
2.5!
On Thu, Sep 23, 2010 at 5:38 AM, LukePaireepinart wrote:

> Looks to me like you either found a bug in the core pygame code for loading
> the system font on Mac or you are calling that method wrong. I checked the
> method and it seems like you should be able to do what you're doing; it
> shouldn't find a sysfont called none so it should load the default.
> If no one else gets around to it, I'll give it a test on my Mac after work
> and let you know.
>
> -
> Sent from a mobile device with a bad e-mail client.
> -----
>
> On Sep 23, 2010, at 6:41 AM, kevin hayes  wrote:
>
> > Can someone tell me what to do (or what I need to get) to get this
> program to work properly?
> > When I run the code(straight out of the book), I get this:
> >
> > Traceback (most recent call last):
> >   File "/Users/kevinhayes/Desktop/code/ch05/paint.py", line 107, in
> 
> > main()
> >   File "/Users/kevinhayes/Desktop/code/ch05/paint.py", line 102, in main
> > myLabel = showStats(drawColor, lineWidth)
> >   File "/Users/kevinhayes/Desktop/code/ch05/paint.py", line 67, in
> showStats
> > myFont = pygame.font.SysFont("None", 20)
> >   File
> "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/pygame/sysfont.py",
> line 555, in SysFont
> > initsysfonts()
> >   File
> "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/pygame/sysfont.py",
> line 522, in initsysfonts
> > fonts = initsysfonts_darwin()
> >   File
> "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/pygame/sysfont.py",
> line 422, in initsysfonts_darwin
> > _search_osx_font_paths(fonts)
> > UnboundLocalError: local variable 'fonts' referenced before assignment
> >
> >
> >
> > 
> >
> > here is the code:
> >
> > """ paint.py
> > a simple paint program"""
> >
> > import pygame
> >
> > def checkKeys(myData):
> > """test for various keyboard inputs"""
> >
> > #extract the data
> > (event, background, drawColor, lineWidth, keepGoing) = myData
> > #print myData
> >
> > if event.key == pygame.K_q:
> > #quit
> > keepGoing = False
> > elif event.key == pygame.K_c:
> > #clear screen
> > background.fill((255, 255, 255))
> > elif event.key == pygame.K_s:
> > #save picture
> > pygame.image.save(background, "painting.bmp")
> > elif event.key == pygame.K_l:
> > #load picture
> > background = pygame.image.load("painting.bmp")
> > elif event.key == pygame.K_r:
> > #red
> > drawColor = (255, 0, 0)
> > elif event.key == pygame.K_g:
> > #green
> > drawColor = (0, 255, 0)
> > elif event.key == pygame.K_w:
> > #white
> > drawColor = (255, 255, 255)
> > elif event.key == pygame.K_b:
> > #blue
> > drawColor = (0, 0, 255)
> > elif event.key == pygame.K_k:
> > #black
> > drawColor = (0, 0, 0)
> >
> > #line widths
> > elif event.key == pygame.K_1:
> > lineWidth = 1
> > elif event.key == pygame.K_2:
> > lineWidth = 2
> > elif event.key == pygame.K_3:
> > lineWidth = 3
> > elif event.key == pygame.K_4:
> > lineWidth = 4
> > elif event.key == pygame.K_5:
> > lineWidth = 5
> > elif event.key == pygame.K_6:
> > lineWidth = 6
> > elif event.key == pygame.K_7:
> > lineWidth = 7
> > elif event.key == pygame.K_8:
> > lineWidth = 8
> > elif event.key == pygame.K_9:
> > lineWidth = 9
> >
> > #return all values
> > myData = (event, background, drawColor, lineWidth, keepGoing)
> > return myData
> >
> > def showStats(drawColor, lineWidth):
> > """ shows the current statis

[pygame] program crashes

2010-09-23 Thread kevin hayes
Can someone tell me what to do (or what I need to get) to get this program
to work properly?
When I run the code(straight out of the book), I get this:

Traceback (most recent call last):
  File "/Users/kevinhayes/Desktop/code/ch05/paint.py", line 107, in 
main()
  File "/Users/kevinhayes/Desktop/code/ch05/paint.py", line 102, in main
myLabel = showStats(drawColor, lineWidth)
  File "/Users/kevinhayes/Desktop/code/ch05/paint.py", line 67, in showStats
myFont = pygame.font.SysFont("None", 20)
  File
"/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/pygame/sysfont.py",
line 555, in SysFont
initsysfonts()
  File
"/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/pygame/sysfont.py",
line 522, in initsysfonts
fonts = initsysfonts_darwin()
  File
"/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/pygame/sysfont.py",
line 422, in initsysfonts_darwin
_search_osx_font_paths(fonts)
UnboundLocalError: local variable 'fonts' referenced before assignment





here is the code:

""" paint.py
a simple paint program"""

import pygame

def checkKeys(myData):
"""test for various keyboard inputs"""

#extract the data
(event, background, drawColor, lineWidth, keepGoing) = myData
#print myData

if event.key == pygame.K_q:
#quit
keepGoing = False
elif event.key == pygame.K_c:
#clear screen
background.fill((255, 255, 255))
elif event.key == pygame.K_s:
#save picture
pygame.image.save(background, "painting.bmp")
elif event.key == pygame.K_l:
#load picture
background = pygame.image.load("painting.bmp")
elif event.key == pygame.K_r:
#red
drawColor = (255, 0, 0)
elif event.key == pygame.K_g:
#green
drawColor = (0, 255, 0)
elif event.key == pygame.K_w:
#white
drawColor = (255, 255, 255)
elif event.key == pygame.K_b:
#blue
drawColor = (0, 0, 255)
elif event.key == pygame.K_k:
#black
drawColor = (0, 0, 0)

#line widths
elif event.key == pygame.K_1:
lineWidth = 1
elif event.key == pygame.K_2:
lineWidth = 2
elif event.key == pygame.K_3:
lineWidth = 3
elif event.key == pygame.K_4:
lineWidth = 4
elif event.key == pygame.K_5:
lineWidth = 5
elif event.key == pygame.K_6:
lineWidth = 6
elif event.key == pygame.K_7:
lineWidth = 7
elif event.key == pygame.K_8:
lineWidth = 8
elif event.key == pygame.K_9:
lineWidth = 9

#return all values
myData = (event, background, drawColor, lineWidth, keepGoing)
return myData

def showStats(drawColor, lineWidth):
""" shows the current statistics """
myFont = pygame.font.SysFont("None", 20)
stats = "color: %s, width: %d" % (drawColor, lineWidth)
statSurf = myFont.render(stats, 1, (drawColor))
return statSurf

def main():
pygame.init()
screen = pygame.display.set_mode((640, 480))
pygame.display.set_caption("Paint:  (r)ed, (g)reen, (b)lue, (w)hite,
blac(k), (1-9) width, (c)lear, (s)ave, (l)oad, (q)uit")

background = pygame.Surface(screen.get_size())
background.fill((255, 255, 255))

clock = pygame.time.Clock()
keepGoing = True
lineStart = (0, 0)
drawColor = (0, 0, 0)
lineWidth = 3

while keepGoing:
clock.tick(30)

for event in pygame.event.get():
if event.type == pygame.QUIT:
keepGoing = False
elif event.type == pygame.MOUSEMOTION:
lineEnd = pygame.mouse.get_pos()
if pygame.mouse.get_pressed() == (1, 0, 0):
pygame.draw.line(background, drawColor, lineStart,
lineEnd, lineWidth)
lineStart = lineEnd
elif event.type == pygame.KEYDOWN:
myData = (event, background, drawColor, lineWidth,
keepGoing)
myData = checkKeys(myData)
(event, background, drawColor, lineWidth, keepGoing) =
myData
screen.blit(background, (0, 0))
myLabel = showStats(drawColor, lineWidth)
screen.blit(myLabel, (450, 450))
pygame.display.flip()

if __name__ == "__main__":
main()

***

I'm using python 2.5 and pygame-1.9.1release-py2.5 on Mac osx 10.4.11...any
help would be appreciated.  Thanks. Kevin


Re: [pygame] moving a box diagnally

2010-09-19 Thread kevin hayes
Thanks claudio, works great now!

On Sun, Sep 19, 2010 at 1:22 AM, claudio canepa  wrote:

>
>
> On Sun, Sep 19, 2010 at 5:08 AM, kevin hayes  wrote:
>
>> Hi, I'm just beginning to learn python and pygame. I've gone through the
>> first four chapters of "Game Programming, The L-line, the Express Line to
>> Learning.  Right now I'm working on an exercise that asks me to "make a box
>> that moves in a diagonal path. Can someone tell me why when I run the code
>> the program only executes while I move the mouse? Also, can you tell me how
>> i can change my code to avoid this? Thanks, Kevin
>>
>> here is my code:
>>
>> import pygame
>> pygame.init()
>>
>> screen = pygame.display.set_mode((640, 480))
>> pygame.display.set_caption("Diagonal Red Square")
>>
>> background = pygame.Surface(screen.get_size())
>> background = background.convert()
>> background.fill((0, 0, 0))
>>
>> box = pygame.Surface((20, 20))
>> box = box.convert()
>> box.fill((255, 0, 0))
>>
>> box_x = 0   #box variable for the x-axis
>> box_y = 0   #" " y-axis
>>
>> clock = pygame.time.Clock()
>> keepGoing = True
>>
>> while keepGoing:
>> clock.tick(30)
>> for event in pygame.event.get():
>> if event.type == pygame.QUIT:
>> keepGoing = False
>>
>> box_x += 5
>> box_y += 5
>>
>> if box_y > screen.get_height():  #checking for screen boundaries
>> box_y = 0
>> if box_x > screen.get_width():
>> box_x = 0
>>
>>
>> screen.blit(background, (0, 0))
>> screen.blit(box, (box_x, box_y))
>> pygame.display.flip()
>>
>> pygame.quit()
>>
>
> You change the box position only if an event is present, so you need to
> move the mouse or press keys to move.
>
> Move out of the event loop the lines that change the position, that is,
> dedent one level the lines:
> box_x += ...
> box_y += ...
>
> --
> claudio
>
>
>


[pygame] moving a box diagnally

2010-09-19 Thread kevin hayes
Hi, I'm just beginning to learn python and pygame. I've gone through the
first four chapters of "Game Programming, The L-line, the Express Line to
Learning.  Right now I'm working on an exercise that asks me to "make a box
that moves in a diagonal path. Can someone tell me why when I run the code
the program only executes while I move the mouse? Also, can you tell me how
i can change my code to avoid this? Thanks, Kevin

here is my code:

import pygame
pygame.init()

screen = pygame.display.set_mode((640, 480))
pygame.display.set_caption("Diagonal Red Square")

background = pygame.Surface(screen.get_size())
background = background.convert()
background.fill((0, 0, 0))

box = pygame.Surface((20, 20))
box = box.convert()
box.fill((255, 0, 0))

box_x = 0   #box variable for the x-axis
box_y = 0   #" " y-axis

clock = pygame.time.Clock()
keepGoing = True

while keepGoing:
clock.tick(30)
for event in pygame.event.get():
if event.type == pygame.QUIT:
keepGoing = False

box_x += 5
box_y += 5

if box_y > screen.get_height():  #checking for screen boundaries
box_y = 0
if box_x > screen.get_width():
box_x = 0


screen.blit(background, (0, 0))
screen.blit(box, (box_x, box_y))
pygame.display.flip()

pygame.quit()


Re: [pygame] Help with the 3rd Lecture, first tutorial

2007-11-03 Thread kevin hayes
Sorry it's taken me so long to respond.  I am just reading through your book
now.;) You wouldn't think it would take a genius (not me) to figure this
out.

On 11/2/07, RR4CLB <[EMAIL PROTECTED]> wrote:
>
>
> *From:* kevin hayes <[EMAIL PROTECTED]>
> *To:* pygame-users@seul.org
> *Sent:* Friday, November 02, 2007 2:08 AM
> *Subject:* Re: [pygame] Help with the 3rd Lecture, first tutorial
>
> I am thoroughly confused at this point. I guess I need to change the path.
>
>
> Kevin,
>
> When sending you information I can understand that you could have
> gotten confused since everything from setting the system path and such was
> thrown at you.
>
> You had said, and was reminded about the path you had loaded Python25
> from, and that was from the Python25 folder where it would normally be
> installed on the windows C drive. That is where it will fall apart. Yes, you
> had to change the path for running example programs for the path has to be
> where the example program is...
>
> You have to look at the program location and where all the data for
> the program is residing. If the data folder is a child, sub-directory of the
> example folder then you are OK as long as, I repeat, "AS LONG AS" you load
> the python25.exe at that directory point. Or you either go to the example
> directory by using the batch files I gave you or going to the command prompt
> and typing C: and hitting enter, then cd python25 and hitting enter then cd
> examples and hitting enter or
> The third way is to go to windows explorer and go to the examples
> folder and click on the Chimp.py game and if it runs it will run the chimp
> example or it may ask what you want to run it with. For if it asks you then
> go to the browse option and click on it. For by doing this it will allow you
> to select which program you wish to run. First it will ask you to enter the
> path to the program and that is what you enter. For the program to run any
> .py module is the very path you first went to and that is c:\Python25\ and
> you enter that path plus the Python25 program and once you have entered
> c:\Python25\Python25.exe and hit enter or go to OK and click on it your
> program will run from Windows Explorer each time you double click on a .py
> file.
>
> Now that you have set Windows Explorer to run any .py game or program
> you write all you have to do is go to the folder in which a .py module/file
> is located. Once you click on it it will load Python25.exe and the file
> and run.
>
> You will not have to go to a DOS prompt unless you want to when doing
> this. The Open Command Here is only if you want to run from the DOS shell
> for it will take you to the folder you are hovering over inside Explorer,
> thus bypassing going to the DOS prompt icon, clicking on it, and navigating
> the long way over to that folder.
>
> NOW:
> NOTE:
> You had asked if the path needed to be changed and that depends on
> where you are residing. For where you run Python25.exe, is where the
> OS.PATH connects to. If you are in the Python25 folder that is what is
> loaded into OS>PATH at the time of loading Python25.exe
>
> Now, you have many options, but you also have to look at the .py
> module you have and what it also demands. The Chimp.py file has
> join("data/file") and this is appended to the OS.PATH.
>
> So, you now have to locate where the data folder is. So, since the
> data folder is in the examples folder you either move to that folder, where
> Chimp.py is, and then click on Chimp.py from Explorer or at the DOS prompt
> move to that folder and type Python25 Chimp.Py and then hit enter.
>
> Your Chimp will run as long as the data folder is a child of the
> examples folder.
>
> If not, then you must change the Chimp.py program where it has the
> join(data/) reference. You must add the complete location of where you are
> at to get it running. So if Chimp.py is loaded and does not run you then
> modify the join( to reflect from where you were which was c:\Python25\ and
> add to the join statement everywhere it is located the addition of example/
> to it, or join("example/data/filename.ext) what ever was inside the parens
> and expand it...
>
>
> FINAL OPTIONS:
> 1) Go to the examples folder when at the DOS prompt then type Python25
> Chimp.py.
>
> 2) Or use Windows Explorer and click on Chimp.py inside the examples
> folder. Setup up Explorer so it runs Python25.exe upon the click.
>
>  3) Or from Windows download the Open Command Here, set it
> up, then hover over the examples folder, then click on the file/context menu
> option for Open Command
> Here and repeat step 1 if you want to b

Re: [pygame] Help with the 3rd Lecture, first tutorial

2007-11-01 Thread kevin hayes
I am thoroughly confused at this point. I guess I need to change the path.
You guys really are nerds, goddamit!

On 10/31/07, RR4CLB <[EMAIL PROTECTED]> wrote:
>
> Hi Both!
>
> I also downloaded it and it is an easy way to get to folders from the
> desk top. FOr if I have Python25 folder on my desk top then I click on it.
> Then go to the examples folder and hit the context menu key. It is a nice
> way to do it and quick.
> Also to have the least amount of work then he can make up a batch file
> for the loading of Python25 or run a program using it.
>
> Batch file:
> Either copy the text and paste it into Notepad or
> type: copy con:P.BAT 
> Type and hit enter at the end of each line:
> @echo off
> python25 %1.py %2 %3 %4 %5
> ctrl Z 
>
> Now this will keep you in that directory and I used just the letter P
> for the name so you only enter the least number of chars for a quick run.
> Bruce
>
> Close any currently running Windows Command Prompts (the environment is
> setup when the shell is started) and then download the 'Open Command
> Window Here' PowerToy from Microsoft on this page:
>
> http://www.microsoft.com/windowsxp/downloads/powertoys/xppowertoys.mspx
>
> and install it. It adds a context-menu (right-click) item 'Open Command
> Window Here' to the Windows Explorer (not IE).
>
> Now, using the Windows Explorer, navigate to the
> 'C:\Program Files\examples\' directory, right-click on it and select
> 'Open Command Window Here'. This should open a Windows Command Prompt with
> the current directory set to the examples directory.
>
> I find this invaluable, but that might just be me.
>
>
>


Re: [pygame] Help with the 3rd Lecture, first tutorial

2007-10-31 Thread kevin hayes
(1) I run python by c:\Python25>Python 

Once in the interpreter, I can import the pygame modules, initialize Python,
make a window, but when I try to set the caption it won't work. I did get it
to work in the GUI, however.

pygame.display.set_caption('Monkey Fever')

(2) C:\Program Files\examples\data\chimp.bmp   "Is the path to the image"

When trying to load the image with:

monkey_head_file_name = os.path.join("data","chimp.bmp")
>>> print monkey_head_file_name "Creating
a relative Path"
data\chimp.bmp

monkey_surface = pygame.image.load(monkey_head_file_name)"From the
tutorial...trying to load the image"






On 10/31/07, Ethan Glasser-Camp <[EMAIL PROTECTED]> wrote:
>
> -BEGIN PGP SIGNED MESSAGE-
> Hash: SHA1
>
> Michael George wrote:
> > Everything after the > is what you type at the dos prompt.  Everything
> > after the >>> is what you type at the python prompt.  Everything else is
> > what you should expect the system to respond
>
> It's a little more complicated than that, of course:
>
> >> >>> file = open("file.txt")
> >> >>> Traceback (etc...)
>
> You aren't supposed to type "Traceback (etc...)". Lukasz believes you
> may get a traceback here from an error (for example, a file-not-found
> error).
>
> >> >>> [ctrl+d]
>
> This presumably means "press Ctrl-D" rather than "type [ctrl+d]". I'm
> not sure if this is correct; I thought on Windows, EOF is Ctrl-Z? But
> I wouldn't swear to it.
>
> >> > cd files
> >> > dir
> >> file.txt
> >> > python
> >> >>> file = open("file.txt")(and it work!)
>
> And here "(and it work!)" is presumably a comment.
>
> However, if I were you, Kevin Hayes, I would refine what I meant by
> "won't load". I believe Lukasz believes that you are getting "Cannot
> find file" errors, and he is trying to show you how to find your way
> around DOS and how your current directory interacts with Python.
>
> If you are getting file-not-found errors, it may help to explain your
> situation further -- what directory are you running Python from? What
> directory is chimp.bmp in? And so on.
>
> Ethan
> -BEGIN PGP SIGNATURE-
> Version: GnuPG v1.4.6 (GNU/Linux)
> Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
>
> iD8DBQFHKNS6hRlgoLPrRPwRAoQAAJsENCwdxB2zBNEWH5QYL91lPMva5gCfYatO
> NWVybH/zprshjUxUMHAMtOk=
> =DS9h
> -END PGP SIGNATURE-
>


Re: [pygame] Help with the 3rd Lecture, first tutorial

2007-10-31 Thread kevin hayes
I don't understand the format of your email. Can you perhaps write it in a
different fashion.

I'm completely lost.

On 10/31/07, Lukasz <[EMAIL PROTECTED]> wrote:
>
>
> kevin hayes pisze:
> > I cannot load the chimp.bmp, and I cannot put a caption on the pygame
> window
> > while in the interpreter.
> >
> > I know the path to chimp.bmp, but when I follow the directions in the
> > tutorial, it won't load.
>
> just start interpreter "in" directory with files:
>
> > c:
> > cd chimp
> > python  (and then)
> >>> import pygame
>
>
> for example:
>
> > d:
> > dir
> files(this is directory)
> > python
> >>> file = open("file.txt")
> >>> Traceback (etc...)
> >>> [ctrl+d]
> > cd files
> > dir
> file.txt
> > python
> >>> file = open("file.txt")(and it work!)
> >>>
>


[pygame] Help with the 3rd Lecture, first tutorial

2007-10-31 Thread kevin hayes
I cannot load the chimp.bmp, and I cannot put a caption on the pygame window
while in the interpreter.

I know the path to chimp.bmp, but when I follow the directions in the
tutorial, it won't load.


Also, everything works fine in the python shell interpreter until I try to
add a caption to the window.

I can add the caption while in the IDLE GUI, but I can't do it inside the
interpreter. What is up with that?

I'm totally new to all of this...just re-learning dos, and python commands.