Exemplo n.º 1
0
 def initialize_main_menu(self):
     self.menu = GameMenu(self)
Exemplo n.º 2
0
class Sim:
    SCREENWIDTH = 800
    SCREENHEIGHT = 600
    SPRITE_SIZE = 16
    FLORA_COUNT = 0
    MAX_FLORA = 256
    FAUNA_COUNT = 0
    MAX_FAUNA = 32
    NUM_ITERATIONS = 100
    NUM_GENERATIONS = 2
    MAPWIDTH = 80
    MAPHEIGHT = 48
    FRAMERATE = 30

# INITIALIZATION FUNCTIONS
# Sim - __init__() and helper functions
# ------------------------------------------------------------------

    def __init__(self):

        #self-explanatory
        self.initialize_pygame()

        #create menu
        self.initialize_main_menu()

        #create screen
        self.initialize_screen()

        #create map and camera
        self.initialize_map()

        # draw  onto screen
        self.draw_start_screen()
        # begin main loop
        self.loop()

    def initialize_pygame(self):
        pygame.init()

        #create clock to track FPS
        self.clock = pygame.time.Clock()

    def initialize_main_menu(self):
        self.menu = GameMenu(self)

    def initialize_screen(self):
        #initialize screen with size
        self.width = self.SCREENWIDTH
        self.height = self.SCREENHEIGHT
        self.screen = pygame.display.set_mode((self.width, self.height))

        #create pygame surface for screen
        self.background = pygame.Surface(self.screen.get_size())


    def initialize_map(self):
        # initialize game map and game camera
        self.map = Map(self.MAPWIDTH, self.MAPHEIGHT, self)

        # create empty sprite groups for foreground objects
        self.plants = pygame.sprite.Group()
        self.animals = pygame.sprite.Group()


# ------------------------------------------------------------------------------


# DRAWING FUNCTIONS
# render program and rendering helper functions
# --------------------------------------------------------------------------------------

    def draw_start_screen(self):
        # clear screen
        self.background.fill((0,0,0))

        #load start image
        self.background = pygame.image.load(os.path.join('images', "start.png"))
        self.background = pygame.transform.scale(self.background, (self.SCREENWIDTH, self.SCREENHEIGHT))

        self.screen.blit(self.background, (0, 0))
        #display screen
        pygame.display.flip()



# -------------------------------------------------------------------------------------------



    def loop(self):
        while True:
            for event in pygame.event.get():
                if event.type == pygame.QUIT:
                    sys.exit()
                if event.type == pygame.MOUSEBUTTONDOWN:
                    self.menu.main_loop()
Exemplo n.º 3
0
i = 0
#class Main():
while mainLoop:

    #print "Doing main game loop"
    gameclock.tick(60)

    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            mainLoop = False

        #else:
    # I took this out of the event loop
    funcs = {
        "Start":startGame,
        "Quit":sys.exit
    }

    if current_state == "MENU":
        gameMenu = GameMenu(screen, funcs.keys(), funcs)
        gameMenu.run()
        current_state = startGame()
    elif current_state == "LEVELSELECT":
        levelSelect = LevelSelect(screen)
        levelSelect.run()
    elif current_state == "PLAY":
        theme.play()
        playScreen = Play.Play(screen)
        playScreen.run()
pygame.quit()