[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [pygame] simple examples



On Feb 9, 2008 4:21 PM, Mikhail Ramendik <mr@xxxxxxxxxxx> wrote:
So I should just call it each time from the main loop?
Yep.
Actually I do plan to have a different picture for each sprite. So I was
planning to use the Sprite class to store the pictures and coordinates, and
only do the blit in the main loop.
Try something like
Sprites = []
class Sprite:
    def __init__(self,x,y):
        self.x = x
        self.y = y
        self.speedx = 0.1
        self.speedy = 0.1
        self.picture = pygame.image.load(#Your picture here)
def Move():
    for s in Sprites:
        s.x += s.speedx
        s.y += s.speedy
def main(): #this is your main
    while True:
        GetInput()
        Move()
        Draw()
#And in you GetInput() function, if you add a sprite:
#Sprites.append(Sprite(400,300))
As for moving position by speed - I would somehow need to coordinate it with
real time as "speed per loop" seems somewhat meaningless.
Just move once each frame.
I am a total beginner in pygame and that's why I hoped to see an example.
Right now I am not even sure how the main loop should be constructed.
Ian