I'm not entirely sure how function work, and ive been trying different combos for a while..

Main:

import pygame, motherWhale, scoreBoard
pygame.init()


def main():

    global motherWhale
    global seaWorld
    global scoreBoard

    screen = pygame.display.set_mode((640, 480))
    pygame.display.set_caption("Bubble Battle")

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

    motherwhale = motherWhale.MotherWhale()
    seaworld = seaWorld.SeaWorld()
    scoreboard = scoreBoard.Scoreboard()

    goodSprites = pygame.sprite.Group(motherwhale) 
    scoreSprite = pygame.sprite.Group(scoreboard)

    clock = pygame.time.Clock()
    keepGoing = True
    while keepGoing:
        clock.tick(30)


        pygame.mouse.set_visible(False)
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                keepGoing = False


            elif event.type == pygame.KEYDOWN:
                if event.key == pygame.K_ESCAPE or event.key == pygame.K_q:
                    keepGoing = False

                if event.key == pygame.K_UP:
                    motherwhale.y -= 10   

                if event.key == pygame.K_DOWN:
                    motherwhale.y += 10

                #if event.key == pygame.K_RIGHT:
                    #motherWhale.x += 20

                #if event.key == pygame.K_LEFT:
                    #motherWhale.x -= 20


            elif event.type == pygame.KEYUP:
                if event.key == pygame.K_UP:                    #WHEN KEYPRESS LIFTED, STOP SPRITE
                    motherwhale.speed = 0

                elif event.key == pygame.K_DOWN:
                    motherwhale.speed = 0


                if motherwhale.y >= screen.get_width():
                    motherWhale.speed = 0

                if motherwhale.y >= screen.get_height():
                    motherWhale.speed = 0


        #check collisions
        #TODO: change to sprite.collideany

        #check collisions

        #if plane.rect.colliderect(island.rect):
            #plane.sndYay.play()
            #island.reset()
            #scoreboard.score += 100

        #hitClouds = pygame.sprite.spritecollide(plane, cloudSprites, False)
        #if hitClouds:
            #plane.sndThunder.play()
            #scoreboard.lives -= 1
            #if scoreboard.lives <= 0:
                #print "Game over!"
                #scoreboard.lives = 5
                #scoreboard.score = 0
            #for theCloud in hitClouds:
                #theCloud.reset()

        goodSprites.clear(screen, background)
        #cloudSprites.clear(screen, background)
        scoreSprite.clear(screen, background)

        goodSprites.update()
        scoreSprite.update()

        goodSprites.draw(screen)
        scoreSprite.draw(screen)

        pygame.display.flip()
    motherWhale.sndEngine.stop() 


if __name__ == "__main__":
    main()

The problem is here:

seaWorld class module:

import pygame
pygame.init()

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

class SeaWorld(pygame.sprite.Sprite):
    def __init__(self):

        pygame.sprite.Sprite.__init__(self)

        self.image = pygame.image.load("ocean.gif")
        self.rect = self.image.get_rect()
        self.dx = 5
        self.reset()

    def update(self):
        self.rect.bottom += self.dx
        if self.rect.bottom >= 1440:
            self.reset() 

    def reset(self):
        self.rect.top = -960

Error Console:

seaworld = seaWorld.SeaWorld()
NameError: global name 'seaWorld is not defined.

You should have import seaWorld, not global seaWorld. I think it is not quite so clever to have 3 identifiers only differing by cases, use my_seaworld or something like it.

Ah thank you. Didn't even see that (stupido), I've removed the globals :)

This article has been dead for over six months. Start a new discussion instead.