Exemplo n.º 1
0
def start_screen():

    menu = Menu(SCREEN)
    menu.add_button('iniciar 1',
                    ['img/button_frame_1.png', 'img/button_frame_2.png'], play)
    #menu.add_button('iniciar 2', ['img/button_frame_1.png', 'img/button_frame_2.png'], print_click)

    bg = Animation([
        "img/start_background_frame_1.jpg", "img/start_background_frame_2.jpg"
    ], (0, 0), SCREEN)
    bg.set_fps(15)

    tree1 = Animation(["img/tree_frame_1.png", "img/tree_frame_2.png"],
                      (150, h / 2), SCREEN)
    tree1.reduce_scale(4)
    tree1.centralize()
    tree1.flip()

    tree2 = Animation(["img/tree_frame_1.png", "img/tree_frame_2.png"],
                      (w - 150, h / 2), SCREEN)
    tree2.reduce_scale(4)
    tree2.centralize()

    title = Animation(["img/title_frame_1.png"], (w / 2, 200), SCREEN)
    title.reduce_scale(3)
    title.centralize()

    while True:

        for event in pygame.event.get():
            if event.type == QUIT:
                pygame.quit()
                exit()

            if event.type == MOUSEBUTTONUP:
                menu.check_click(pygame.mouse.get_pos())

        bg.draw()
        tree1.draw()
        tree2.draw()
        title.draw()
        menu.draw()
        pygame.display.update()

        clock.tick(27)
Exemplo n.º 2
0
        3,
        3,
    ))
    textbox = widgets.TextBox(plt.axes([0.4, 0.8, 0.4, 0.1]), "Clip:", '0')
    lentextbox = widgets.TextBox(plt.axes([0.4, 0.7, 0.4, 0.1]),
                                 "Clip Length:", '240')

    prevbutton = widgets.Button(plt.axes([0.25, 0.4, 0.1, 0.1]), "$\u29CF$")
    pausebutton = widgets.Button(plt.axes([0.25 + 0.2, 0.4, 0.1, 0.1]),
                                 "$\u25A0$")
    nextbutton = widgets.Button(plt.axes([0.25 + 0.4, 0.4, 0.1, 0.1]),
                                "$\u29D0$")
    widgets.TextBox(plt.axes([0.1, 0.2, 0.8, 0.1]), "",
                    "Total number of clips: %d " % (len(data) / 240))
    frameslider = widgets.Slider(plt.axes([0.2, 0.55, 0.6, 0.06]), "", 0, 1, 0)
    printbutton = widgets.Button(plt.axes([0.25, 0.08, 0.2, 0.1]), "Print")

    # Drawing
    anim = Animation(data, frameslider)
    anim.select_clip(0)

    prevbutton.on_clicked(prev)
    pausebutton.on_clicked(pause)
    nextbutton.on_clicked(next)
    textbox.on_submit(set_start)
    lentextbox.on_submit(set_len)
    frameslider.on_changed(on_slider)
    printbutton.on_clicked(print_clip)
    anim.draw(130)
    anim.play()
    plt.show()

#    InSight()

hero = Hero()
good_units = []
bad_units = [Enemy(*random_coords()) for x in range(enemies)]
good_shots = []
bad_shots = []
camera = Camera()
animation = Animation(camera)
controls = Controls(camera, hero, animation.screen)


def where(event):
    print(camera.x, camera.y, '\n', camera.x + camera.w, camera.y + camera.h)


for i in bad_units:
    print(i.x, i.y)

animation.draw(hero)
ticks()
animation.screen.bind('<space>', where)
animation.screen.bind('<Key>', controls.key_pressed)  # <KeyPress>
animation.screen.bind('<KeyRelease>', controls.key_release)  # <KeyRelease>
#screen.bind('<Motion>', ticks)
#screen.screen.focus_set()

mainloop()
Exemplo n.º 4
0
class Button():

    def __init__(self, text, on_click_deferred, on_click_return_value, window_values, surface, hover_animation_surface = None, mouse_down_animation = None, spritesheet_dimensions=(2, 2), font_size='big'): #spritesheet for potential fancy animations later
        self.x, self.y, self.w, self.h = window_values

        self.font_size = font_size

        self.text = text

        self.surface = surface

        self.text_label = render_text(text, (0,0,0), font_size)
        self.get_text_draw_coords()

        self.on_click_deferred = on_click_deferred
        self.on_click_return_value = on_click_return_value

        hover_animation_surface = None

        if hover_animation_surface:
            self.on_hover_animation = Animation(TileSheet(hover_animation_surface, 292, 120, spritesheet_dimensions[0], spritesheet_dimensions[1]), 10, 4)
        else:
            self.on_hover_animation = None

        if mouse_down_animation:
            self.mouse_down_animation = Animation(TileSheet(mouse_down_animation, 292, 120, 1, 1), 10, 1)
        else:
            self.mouse_down_animation = None

        self.on_hover_animation_active = False
        self.mouse_down_animation_active = False

    def on_click(self):
        if self.mouse_down_animation:
            self.mouse_down_animation.done = True
        self.on_click_deferred.value = self.on_click_return_value

    def on_mouse_down(self):
        if not self.mouse_down_animation_active and self.mouse_down_animation:
            self.mouse_down_animation_active = True

    def on_hover(self):
        if not self.on_hover_animation_active and self.on_hover_animation:
            self.on_hover_animation_active = True

    def on_hover_off(self):
        self.mouse_down_animation_active = False

    def update(self, time=1):
        if self.mouse_down_animation_active:
            if self.mouse_down_animation.done:
                self.mouse_down_animation.done = False
                self.mouse_down_animation.reset()
                #self.mouse_down_animation_active = False

            self.mouse_down_animation.update(time)

        elif self.on_hover_animation_active:
            if self.on_hover_animation.done:
                self.on_hover_animation.done = False
                self.on_hover_animation.reset()
                self.on_hover_animation_active = False

            self.on_hover_animation.update(time)


    def draw(self):
        if self.mouse_down_animation_active:
            self.mouse_down_animation.draw(screen, self.x, self.y)
        elif self.on_hover_animation_active:
            self.on_hover_animation.draw(screen, self.x, self.y)
        else:
            screen.blit(self.surface, (self.x, self.y))

        screen.blit(self.text_label, (self.text_x, self.text_y))


    def mouse_over_button(self, mouse_pos):
        return Utils.point_in_rect(mouse_pos, (self.x, self.y, self.w, self.h))

    def get_text_draw_coords(self):
        if self.font_size == "big":
            text_w = font.size(self.text)[0]
            text_h = font.size(self.text)[1]
        elif self.font_size == "small":
            text_w = font_small.size(self.text)[0]
            text_h = font_small.size(self.text)[1]

        self.text_x = self.x + 0.5 * self.w - 0.5 * text_w
        self.text_y = self.y + 0.5 * self.h - 0.5 * text_h
Exemplo n.º 5
0
def play(label):

    # print('button {}'.format(label))

    bg = Animation([
        "img/start_background_frame_1.jpg", "img/start_background_frame_2.jpg"
    ], (0, 0), SCREEN)
    bg.set_fps(15)

    # title = Animation(["img/title_frame_1.png"], (w/2,200), SCREEN)
    # title.reduce_scale(3)
    # title.centralize()

    mapa = Map(4, SCREEN, w, h)
    block_index = 0
    last_dig = False
    char = Character(SCREEN, 1, mapa.blocks[block_index])
    char.reduce_scale(4)
    char.centralize()
    print(char.image)

    while True:

        for event in pygame.event.get():
            if event.type == QUIT:
                pygame.quit()
                exit()

            if event.type == KEYDOWN:
                if last_dig != False:
                    print('changing dig to false')
                    last_dig = False
                if event.key == K_RIGHT:
                    if (not block_index + 1 >= len(mapa.blocks)):
                        if (char.dir == 0):
                            char.dir = 1
                            char.flip()
                        block_index += 1
                        char.update_block(mapa.blocks[block_index])
                        char.centralize()
                if event.key == K_LEFT:
                    if (not block_index - 1 < 0):
                        if (char.dir == 1):
                            char.dir = 0
                            char.flip()
                        block_index -= 1
                        char.update_block(mapa.blocks[block_index])
                        char.centralize()
                if event.key == K_DOWN:
                    if (not block_index + mapa.col >= len(mapa.blocks)):
                        block_index += mapa.col
                        char.update_block(mapa.blocks[block_index])
                        char.centralize()
                if event.key == K_UP:
                    if (not block_index - mapa.col < 0):
                        block_index -= mapa.col
                        char.update_block(mapa.blocks[block_index])
                        char.centralize()
                if event.key == K_SPACE:
                    print('digging')
                    last_dig = char.dig()

        bg.draw()
        mapa.draw()
        char.draw()

        if (last_dig != False):

            if (isinstance(last_dig, Treasure)):

                print('treasure found')
                last_dig.draw()

            if (isinstance(last_dig, Hint)):

                print('hint found')
                last_dig.draw()

            if (last_dig == None):

                print('Empty block')

        # title.draw()
        # hint.draw()
        pygame.display.update()

    clock.tick(27)