Ejemplo n.º 1
0
Archivo: hpt.py Proyecto: cylvis/misc
def run_game():
    pygame.init()
    clock = pygame.time.Clock()
    game_settings = Settings()
    #message = input("Start Game:")
    screen = pygame.display.set_mode(game_settings.screen_size)
    pygame.display.set_caption("HPT - Test1")
    #hero = Hero(screen)
    #bullets = Group()
    #play_button = Play_button(screen, message)
    fullscreenCheckbox = checkbox(screen)




    while 1:
        clock.tick(game_settings.FRAMES_PER_SECOND)
        functions.check_events(screen, game_settings, fullscreenCheckbox)
        functions.update_screen(screen, game_settings, fullscreenCheckbox)
Ejemplo n.º 2
0
def main():
    pygame.init()
    screen = pygame.display.set_mode(SCREEN_RESOLUTION)
    clock = Clock()
    set_timer(USEREVENT_EACH_SECOND, 1000)

    font = Font('resources/Arial Rounded Bold.ttf', 14)
    background_color = (0, 0, 0)
    grid = BackgroundGrid(SCREEN_RESOLUTION, Color(20, 20, 20), 32)

    fps_text = FormattedText(font, COLOR_WHITE, "FPS: %i", 0)
    debug_texts = [
        fps_text,
        StaticText(font, COLOR_WHITE, "debug: 2"),
        StaticText(font, COLOR_WHITE, "debug: 3"),
    ]
    debug_window = ListContainer(width=200,
                                 height="fit_contents",
                                 children=debug_texts,
                                 margin=5,
                                 padding=5,
                                 orientation=Orientation.VERTICAL,
                                 style=Style(border_color=COLOR_WHITE))

    left_buttons = [
        button(font, (200, 48), callback=lambda: print("hello"),
               label="click"),
        button(font, (200, 48), callback=lambda: print("hello"),
               label="click"),
        button(font, (200, 48), callback=lambda: print("hello"),
               label="click"),
    ]
    counter = Counter((50, 50),
                      FormattedText(font, COLOR_WHITE, "%i", 0),
                      style=Style(background_color=Color(100, 100, 100)))
    right_buttons = [
        button(font, (200, 32),
               callback=lambda: counter.increment(),
               label="Increment (I)",
               hotkey=pygame.K_i),
        button(font, (200, 32),
               callback=lambda: counter.decrement(),
               label="Decrement (D)",
               hotkey=pygame.K_d),
        checkbox(font, (200, 32),
                 callback=lambda checked: debug_window.set_visible(checked),
                 label="Show debug",
                 checked=debug_window.is_visible()),
        checkbox(font, (200, 32),
                 callback=lambda checked: print("B: %s" % checked),
                 label="B"),
        checkbox(font, (200, 32),
                 callback=lambda checked: print("C: %s" % checked),
                 label="C"),
        checkbox(font, (200, 32),
                 callback=lambda checked: print("D: %s" % checked),
                 label="D"),
        checkbox(font, (200, 32),
                 callback=lambda checked: print("E: %s" % checked),
                 label="E"),
        checkbox(font, (200, 32),
                 callback=lambda checked: print("F: %s" % checked),
                 label="F"),
    ]
    left_menu_bar = ListContainer(width="fit_contents",
                                  height="fill_parent",
                                  children=left_buttons,
                                  margin=5,
                                  padding=5,
                                  orientation=Orientation.VERTICAL,
                                  style=Style(background_color=Color(
                                      150, 150, 255),
                                              border_color=COLOR_WHITE))
    right_menu_bar = ScrollContainer(height=166,
                                     children=right_buttons,
                                     margin=5,
                                     padding=5,
                                     orientation=Orientation.VERTICAL,
                                     style=Style(background_color=Color(
                                         150, 210, 255),
                                                 border_color=COLOR_WHITE))

    text_field = TextArea(font,
                          COLOR_WHITE, (100, 100),
                          padding=5,
                          style=Style(border_color=COLOR_WHITE))

    icon_background = load_and_scale_image('resources/stone_tile.png',
                                           (32, 32))

    grid_children = [
        number_button(font, text_field, "1", pygame.K_1),
        number_button(font, text_field, "2", pygame.K_2),
        number_button(font, text_field, "3", pygame.K_3),
        number_button(font, text_field, "4", pygame.K_4),
        number_button(font, text_field, "5", pygame.K_5),
        number_button(font, text_field, "6", pygame.K_6),
        icon(font, (32, 32), icon_background, "A", pygame.K_a),
        icon(font, (32, 32), icon_background, "B", pygame.K_b),
        icon(font, (32, 32), icon_background, "C", pygame.K_c),
        number_button(font, text_field, "0", pygame.K_0),
        backspace_button(font, text_field)
    ]
    grid_container = GridContainer(children=grid_children,
                                   dimensions=(3, 4),
                                   padding=5,
                                   margin=2,
                                   style=Style(background_color=Color(
                                       150, 130, 100),
                                               border_color=COLOR_WHITE))

    img = image_surface('resources/stone_tile.png', (100, 100))

    hud = ListContainer(
        width=800,
        height=200,
        children=[right_menu_bar, counter, grid_container, text_field, img],
        margin=5,
        padding=5,
        orientation=Orientation.HORIZONTAL,
        style=Style(border_color=COLOR_WHITE,
                    background_color=Color(0, 0, 150)))
    container = AbsolutePosContainer(SCREEN_RESOLUTION,
                                     [(Vector2(5, 5), debug_window),
                                      (Vector2(0, 400), hud)])
    container.set_pos(Vector2(0, 0))

    while True:
        for event in pygame.event.get():
            handle_exit(event)
            if event.type == pygame.MOUSEBUTTONDOWN:
                container.handle_mouse_was_clicked(pygame.mouse.get_pos())
            elif event.type == pygame.MOUSEBUTTONUP:
                container.handle_mouse_was_released()
            elif event.type == pygame.MOUSEMOTION:
                container.handle_mouse_motion(pygame.mouse.get_pos())
            elif event.type == USEREVENT_EACH_SECOND:
                fps_text.format_text(int(clock.get_fps()))
            elif event.type == pygame.KEYDOWN:
                container.handle_key_was_pressed(event.key)
            elif event.type == pygame.KEYUP:
                container.handle_key_was_released(event.key)
        elapsed_time = clock.tick()

        container.update(elapsed_time)

        screen.fill(background_color)
        grid.render(screen)
        container.render(screen)
        pygame.display.flip()
Ejemplo n.º 3
0
    def __init__(self, parent, startrun, runrecording, exit):
        Frame.__init__(self, parent)
        self.inter = checkbox.checkbox()
        self.rec = checkbox.checkbox()
        self.feat = checkbox.checkbox()

        # register the validation command
        vcmd = (self.register(self.onValidate),
                '%d', '%i', '%P', '%s', '%S', '%v', '%V', '%W')

        # define size of the grid labels/entry boxes
        self.sizelabel = Label(self, text = "Size:")
        self.rowlabel = Label(self, text = "Rows:")
        self.collabel = Label(self, text = "Columns:")
        self.rowent = Entry(self, width = 10, validate = 'focusout', validatecommand = vcmd)
        self.colent = Entry(self, width = 10)

        # define ratios labels/entry boxes
        self.ratlabel = Label(self, text = "Ratio:")
        self.emptlabel = Label(self, text = "Empty:")
        self.lionlabel = Label(self, text = "Lions:")
        self.antlabel = Label(self, text = "Antelope:")
        self.emptent = Entry(self, width = 10)
        self.lionent = Entry(self, width = 10)
        self.antent = Entry(self, width = 10)

        # define running time labels/entry boxes
        self.runlabel = Label(self, text = "Running Time:")
        self.genlabel = Label(self, text = "Generations:")
        self.genent = Entry(self, width = 10)

        # define buttons
        # the stop button sets the state of the interrupt object to false
        # so that the generation loop stops
        self.stopb = Button(self, text = "Stop", command=self.inter.pressed)
        self.runb = Button(self, text = "Run", command = startrun)
        self.exitb = Button(self, text = "Exit", command = exit)

        self.recrd = Checkbutton(self, text="Record simulation", command=self.rec.pressed)
        self.run = Button (self, text = "Run Recording", command = runrecording)
        self.featr = Checkbutton(self, text="Run with features", command=self.feat.pressed)

        #put the widgets in the frame
        self.sizelabel.grid(row = 0, column = 0, sticky=W)
        self.rowlabel.grid(row = 1, column = 0,sticky=E)
        self.rowent.grid(row = 1, column = 1)
        self.collabel.grid(row = 2, column = 0,sticky=E)
        self.colent.grid(row = 2, column = 1)

        self.ratlabel.grid(row = 3, column = 0, sticky=W)
        self.emptlabel.grid(row = 4, column = 0,sticky=E)
        self.emptent.grid(row = 4, column = 1)
        self.lionlabel.grid(row = 5, column = 0,sticky=E)
        self.lionent.grid(row = 5, column = 1)
        self.antlabel.grid(row = 6, column = 0,sticky=E)
        self.antent.grid(row = 6, column = 1)

        self.runlabel.grid(row = 7, column = 0, sticky=W)
        self.genlabel.grid(row = 8, column = 0, sticky=E)
        self.genent.grid(row = 8, column = 1)

        self.featr.grid(row = 9, column = 0, columnspan = 2)
        self.recrd.grid(row = 10, column = 0, columnspan = 2)

        self.runb.grid(row = 12, column = 0, columnspan=2, sticky = N+E+S+W)
        self.stopb.grid(row = 13, column = 0, columnspan=2, sticky = N+E+S+W)
        self.run.grid(row = 14, column = 0, columnspan = 2, sticky = N+E+S+W)
        self.exitb.grid(row = 15, column = 0, columnspan = 2, sticky = N+E+S+W)
Ejemplo n.º 4
0
def exitsim():
    """ close the window
    """
    root.destroy()

if __name__ == "__main__":
    # build the GUI window here
    # main frame
    root = Tk()
    root.title("CellularAutomata")

    # style it
    style = Style()
    style.theme_use('clam')

    features = checkbox.checkbox()

    # make an interface frame
    inframe = caframe(root,
                    startrun,
                    runrecording,
                    exitsim)

    # define canvas
    anigrid = Canvas(root,
                    height = 900,
                    width = 1200,
                    bg = "white",
                    confine = False,
                    bd = 3,
                    relief = "sunken")
Ejemplo n.º 5
0
    def __init__(self, parent, startrun, runrecording, exit):
        Frame.__init__(self, parent)
        self.inter = checkbox.checkbox()
        self.rec = checkbox.checkbox()
        self.feat = checkbox.checkbox()

        # register the validation command
        vcmd = (self.register(self.onValidate), '%d', '%i', '%P', '%s', '%S',
                '%v', '%V', '%W')

        # define size of the grid labels/entry boxes
        self.sizelabel = Label(self, text="Size:")
        self.rowlabel = Label(self, text="Rows:")
        self.collabel = Label(self, text="Columns:")
        self.rowent = Entry(self,
                            width=10,
                            validate='focusout',
                            validatecommand=vcmd)
        self.colent = Entry(self, width=10)

        # define ratios labels/entry boxes
        self.ratlabel = Label(self, text="Ratio:")
        self.emptlabel = Label(self, text="Empty:")
        self.lionlabel = Label(self, text="Lions:")
        self.antlabel = Label(self, text="Antelope:")
        self.emptent = Entry(self, width=10)
        self.lionent = Entry(self, width=10)
        self.antent = Entry(self, width=10)

        # define running time labels/entry boxes
        self.runlabel = Label(self, text="Running Time:")
        self.genlabel = Label(self, text="Generations:")
        self.genent = Entry(self, width=10)

        # define buttons
        # the stop button sets the state of the interrupt object to false
        # so that the generation loop stops
        self.stopb = Button(self, text="Stop", command=self.inter.pressed)
        self.runb = Button(self, text="Run", command=startrun)
        self.exitb = Button(self, text="Exit", command=exit)

        self.recrd = Checkbutton(self,
                                 text="Record simulation",
                                 command=self.rec.pressed)
        self.run = Button(self, text="Run Recording", command=runrecording)
        self.featr = Checkbutton(self,
                                 text="Run with features",
                                 command=self.feat.pressed)

        #put the widgets in the frame
        self.sizelabel.grid(row=0, column=0, sticky=W)
        self.rowlabel.grid(row=1, column=0, sticky=E)
        self.rowent.grid(row=1, column=1)
        self.collabel.grid(row=2, column=0, sticky=E)
        self.colent.grid(row=2, column=1)

        self.ratlabel.grid(row=3, column=0, sticky=W)
        self.emptlabel.grid(row=4, column=0, sticky=E)
        self.emptent.grid(row=4, column=1)
        self.lionlabel.grid(row=5, column=0, sticky=E)
        self.lionent.grid(row=5, column=1)
        self.antlabel.grid(row=6, column=0, sticky=E)
        self.antent.grid(row=6, column=1)

        self.runlabel.grid(row=7, column=0, sticky=W)
        self.genlabel.grid(row=8, column=0, sticky=E)
        self.genent.grid(row=8, column=1)

        self.featr.grid(row=9, column=0, columnspan=2)
        self.recrd.grid(row=10, column=0, columnspan=2)

        self.runb.grid(row=12, column=0, columnspan=2, sticky=N + E + S + W)
        self.stopb.grid(row=13, column=0, columnspan=2, sticky=N + E + S + W)
        self.run.grid(row=14, column=0, columnspan=2, sticky=N + E + S + W)
        self.exitb.grid(row=15, column=0, columnspan=2, sticky=N + E + S + W)