here's a moving bird/ball that is bouncing off the walls, first of all you need only one type of class for sprites, simply create different instances with different images. Hope it helps
import sys, pygame, random
SIZE = width, height = 640, 480
SPEED = [2, 2]
black = 0, 0, 0
class mySprite(pygame.sprite.Sprite):
def __init__(self, image="ball.bmp", speed=[2,2]):
pygame.sprite.Sprite.__init__(self)
self.speed = speed
self.image = pygame.image.load(image)
self.rect = self.image.get_rect()
def update(self):
global SIZE
#i used 110 px because it's the size of the image, but it's better to use the rect property of the pygame
if (self.rect.x <0) or (self.rect.x > 640-110):
self.speed[0] *= -1
if (self.rect.y<0) or (self.rect.y > 480-110):
self.speed[1] *= -1
self.rect.x =self.rect.x + self.speed[0]
self.rect.y =self.rect.y + self.speed[1]
#OR: self.rect = self.rect.move(self.speed)
def draw(self, screen):
screen.blit(self.image, self.rect)
#
pygame.init()
screen = pygame.display.set_mode(SIZE)
iaka = mySprite()
while 1:
for event in pygame.event.get():
if event.type == pygame.QUIT: sys.exit()
screen.fill(black)
iaka.draw(screen)
iaka.update()
pygame.display.flip()