Esempio n. 1
0
def main():
    """
    The main function. Welcome to the beginning of the end.
    """
    # start pygame init
    pygame.init()
    game_clock = pygame.time.Clock()

    settings = settings_parse.parse_settings("../config/config.cfg")

    print settings

    font = pygame.font.SysFont(None, 48)

    ui_tree = ET.parse("../config/ui_data.xml")
    ui_root = ui_tree.getroot()
    ui_ingame = ui_root.find("ingame")
    ui_inmenu = ui_root.find("inmenu")

    # Bootstrap the GUI

    window_details = ui_root.find("window")
    name = window_details.get("label")
    window_x = int(window_details.find("width").text)
    window_y = int(window_details.find("height").text)

    # Full screen size
    # window_x, window_y = 1920, 1080

    window_surface = pygame.display.set_mode((window_x, window_y), 0, 32)

    pygame.display.set_caption(name)

    BLACK = (0, 0, 0)

    game_object = game.Game(ui_root)

    while True:

        # This whole while loops in while loops may be better as a set of ifs
        # you can then control the frame rate with one function

        game_object.handle_events(pygame.event.get())

        # game_object.update()

        for inter in game_object.state.interface_list:
            window_surface.blit(inter.surface, (0, 0))

        draw.draw_fps(window_surface, game_clock.get_fps())
        pygame.display.update()
        game_clock.tick()

        window_surface.fill(BLACK)

        # End of main game loop

    # End of main function
    return True
def main():
    """
    The main function. Welcome to the beginning of the end.
    """
    # start pygame init
    pygame.init()

    # Read the config file
    config = ConfigParser.RawConfigParser()
    config.read('../config/config.cfg')

    UIConfig = ConfigParser.RawConfigParser()
    UIConfig.read('../config/UIConfig.cfg')

    # example of printing from config
    # print config.get('Strings', 'welcome')

    # Bootstrap the universe

    # Bootstrap the GUI
    name = config.get('Strings', 'name')
    window_x = int(500)
    window_y = int(500)

    object_size = (2 * window_y) / 5

    window_surface = pygame.display.set_mode((window_x, window_y), 0, 32)
    pygame.display.set_caption(name)

    BLACK = (0, 0, 0)
    WHITE = (255, 255, 255)
    LEFT = 1
    RIGHT = 3
    ROLLUP = 4
    ROLLDOWN = 5

    time.clock()

    game_clock = pygame.time.Clock()

    circle_x = window_surface.get_rect().centerx
    circle_y = window_surface.get_rect().centery

    surface_origin = (circle_x, circle_y)

    number_bands = 6

    palette = [
        (207,240,158),
        (168,219,168),
        (121,189,154),
        (59,134,134),
        (11,72,107)
    ]

    planet_points = draw.create_gas_giant(number_bands, object_size, palette)

    planet_colour = palette[0]
    palette.remove(planet_colour)

    movement = [0, 0]
    movement_flag = False

    scale_size = object_size * 2
    planet_info = [[(circle_x, circle_y), scale_size, "terrian"]]
    planet_surface = draw.draw_gas_giant(window_surface, surface_origin, object_size, planet_colour, planet_points)
    overlay = draw.clean_planets(window_surface, planet_info)
    planet_surface.blit(overlay, (0,0))


    while True:
        # This whole while loops in while loops may be better as a set of ifs
        # you can then control the frame rate with one function

        for event in pygame.event.get():
            # check for the close button being pressed and exit
            if event.type == QUIT:
                pygame.quit()
                sys.exit()

            if event.type == MOUSEMOTION and movement_flag:
                # Detect a mouse click

                mouse_move = pygame.mouse.get_rel()

                movement[0] += mouse_move[0]
                movement[1] += mouse_move[1]

            if (event.type == MOUSEBUTTONDOWN) and (event.button == LEFT):

                planet_points = draw.create_gas_giant(number_bands, object_size, palette)

            if (event.type == MOUSEBUTTONDOWN) and (event.button == ROLLUP):

                scale_size = int(scale_size / 0.9)

            if (event.type == MOUSEBUTTONDOWN) and (event.button == ROLLDOWN):

                scale_size = int(scale_size / 1.1)

            if (event.type == MOUSEBUTTONDOWN) and (event.button == RIGHT):
                pygame.mouse.get_rel()
                movement_flag = True

            if (event.type == MOUSEBUTTONUP) and (event.button == RIGHT):
                pygame.mouse.get_rel()
                movement_flag = False

        planet_surface = draw.draw_gas_giant(window_surface, surface_origin, scale_size, planet_colour, planet_points)

        overlay = draw.clean_planets(window_surface, planet_info)

        planet_surface.blit(overlay, (0,0))

        window_surface.blit(planet_surface, movement)

        # Draw FPS
        draw.draw_fps(window_surface, game_clock.get_fps())

        pygame.display.update()
        game_clock.tick()

        window_surface.fill(BLACK)

        # End of main game loop

    # End of main function
    return True