Kris Schnee | 1 Oct 01:23 2010
Picon

Re: Quit pygame

On 2010.9.30 12:01 PM, Massimo Di Stefano wrote:
> I tried the following code in a standard python shell :
>
>>>> from pygame.locals import *
>>>> import pygame
>>>> pygame.init()
> Leopard libedit detected.
> (6, 0)
>>>> for event in pygame.event.get():
> ...     if event.type == QUIT:
> ...         running = False
> ...
>>>> pygame.event.pump()
>>>> pygame.quit()

Different note: isn't pygame.event.pump redundant here, since you're 
already clearing the latest events by calling pygame.event.get()?

Lenard Lindstrom | 1 Oct 09:11 2010
Picon

Re: Quit pygame

On 30/09/10 04:23 PM, Kris Schnee wrote:
> On 2010.9.30 12:01 PM, Massimo Di Stefano wrote:
>> I tried the following code in a standard python shell :
>>
>>>>> from pygame.locals import *
>>>>> import pygame
>>>>> pygame.init()
>> Leopard libedit detected.
>> (6, 0)
>>>>> for event in pygame.event.get():
>> ...     if event.type == QUIT:
>> ...         running = False
>> ...
>>>>> pygame.event.pump()
>>>>> pygame.quit()
>
> Different note: isn't pygame.event.pump redundant here, since you're 
> already clearing the latest events by calling pygame.event.get()?

Probably. I just suggested pygame.event.pump as an alternative to an 
event loop. But pygame.init() does not open a window, so no event loop 
should be needed.

Lenard Lindstrom

B W | 2 Oct 07:30 2010
Picon

Orbiting bodies in pymunk

Howdy, folks.

I made a small pymunk demo in which a Pygame sprite orbits the mouse pointer. I'm trying to figure out a way to get an elliptical orbiting body. Body.impulse is the only thing that appears to behave how I want, but after many hours of experimentation there remain gross eccentricities in the orbit that I can't resolve. The ball circles around the mouse a few times, its orbit decaying, then flips around the other way; and cycles back and forth between the two orbit-like patterns. It seems there are other influences at work: pymunk physics I don't know about yet, or maybe precision errors, or perhaps I'm just doing it all wrong.

I did the poring over docs thing, digging in modules, searching for demos and articles, and came up rather empty. Certainly nothing on topic. I did find a lot of complaints, though, about the dearth of pymunk demos. :)

If you are inclined to take a look, you'll need:
05_impulse.py
game_clock.py
pymunk

Use the down arrow to slow the ball if it gets going too fast, and move the mouse a little to guide the ball into an elliptical path.

I sure would appreciate some new insight. Thanks in advance for any assistance.

Gumm

#avg_ls_inline_popup { position:absolute; z-index:9999; padding: 0px 0px; margin-left: 0px; margin-top: 0px; width: 240px; overflow: hidden; word-wrap: break-word; color: black; font-size: 10px; text-align: left; line-height: 13px;}
kevin hayes | 3 Oct 03:03 2010
Picon

circles

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()
        

Ian Mallett | 3 Oct 03:43 2010
Picon

Re: circles

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

#avg_ls_inline_popup { position:absolute; z-index:9999; padding: 0px 0px; margin-left: 0px; margin-top: 0px; width: 240px; overflow: hidden; word-wrap: break-word; color: black; font-size: 10px; text-align: left; line-height: 13px;}
kevin hayes | 3 Oct 04:09 2010
Picon

Re: circles

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 <geometrian <at> gmail.com> 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

Ian Mallett | 3 Oct 04:24 2010
Picon

Re: circles

On Sat, Oct 2, 2010 at 8:09 PM, kevin hayes <kevinosky-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> 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
#avg_ls_inline_popup { position:absolute; z-index:9999; padding: 0px 0px; margin-left: 0px; margin-top: 0px; width: 240px; overflow: hidden; word-wrap: break-word; color: black; font-size: 10px; text-align: left; line-height: 13px;}
kevin hayes | 3 Oct 04:38 2010
Picon

Re: circles

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 <geometrian <at> gmail.com> wrote:
On Sat, Oct 2, 2010 at 8:09 PM, kevin hayes <kevinosky <at> gmail.com> 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

Greg Ewing | 3 Oct 06:47 2010
Picon
Picon

ANN: Fifth Pyggy Awards Open

The Fifth Pyggy Awards are open for registrations.

http://pyggy.pyweek.org/

You may begin working on your entries immediately. Judging will be from 5-19 
December 2010.

About the Pyggy Awards
----------------------

The Pyggy Awards is a follow-up event to the PyWeek competition, for authors who 
would like to develop their games further or explore one of the alternative 
themes that didn't get chosen. It provides an extended period for development at 
a more leisurely pace, an environment in which to try out each others' works in 
progress and share feedback, an an occasion at which to show off the results to 
an audience of like-minded people.

B W | 3 Oct 07:05 2010
Picon

Re: circles

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 <kevinosky <at> gmail.com> 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 <geometrian-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:
On Sat, Oct 2, 2010 at 8:09 PM, kevin hayes <kevinosky-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> 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


#avg_ls_inline_popup { position:absolute; z-index:9999; padding: 0px 0px; margin-left: 0px; margin-top: 0px; width: 240px; overflow: hidden; word-wrap: break-word; color: black; font-size: 10px; text-align: left; line-height: 13px;}

Gmane