Hey guys, I'm working on my game project for college, I have the code started, just enough to put the sprite on the screen and have a scrolling background. It is telling me there are no errors but when i go to run the game it terminates immediately, it's got me confuzzeled, here's the code:

import pygame
pygame.init()

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

class Player(pygame.sprite.Sprite):
    def __init__(self):
        pygame.sprite.Sprite.__init__(self)
        self.image = pygame.image.load("gameProject/friendlyShip.gif")
        self.image = self.image.convert()
        self.rect = self.image.get_rect()
        
        def update(self):
            mousex, mousey = pygame.mouse.get_pos()
            self.rect.center = (200,mousey)
            
class Space(pygame.sprite.Sprite):
    def __init__(self):
        pygame.sprite.Sprite.__init__(self)
        self.image = pygame.image.load("gameProject/background.gif")
        self.rect = self.image.get_rect()
        self.dy = 5
        self.reset()
            
    def update(self):
        self.rect.bottom +=self.dy
        if self.rect.bottom >= 1440:
            self.reset
            
    def reset(self):
        self.rect.top = -960
        
        
def main():
    pygame.display.set_caption("Space wars")
    
    background = pygame.Surface(screen.get_size())
    background.fill((0,0,0))
    screen.blit(background, (0,0))
    player = Player()
    space= Space()
    
    friendSprites = pygame.sprite.Group(space, player)
    
    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
                
        friendSprites.update()
        
        friendSprites.draw(screen)
        
        pygame.display.flip()

Any ideas??

You have to call main somehow. Usually, it is

if __name__ == '__main__':
    main()

I tried that but it's still doing the same thing :/

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.