Exemplo n.º 1
0
class Hint:

    scrol_frames = ['img/scrol_frame_1.png', 'img/scrol_frame_2.png']

    def __init__(self, pos, hint, screen):

        self.pos = pos
        self.hint = hint
        self.screen = screen

        self.overlay = Overlay(self.screen, (0, 0),
                               self.screen.get_size()[0],
                               self.screen.get_size()[1])
        self.textsurface = Text(self.screen, self.pos, self.hint, True,
                                (232, 197, 150))

        self.scrol = Animation(self.scrol_frames, self.pos, self.screen)
        self.scrol.reduce_scale(4)
        self.scrol.centralize()

        self.elements = [self.overlay, self.scrol, self.textsurface]

    def draw(self):

        for element in self.elements:
            element.draw()
Exemplo n.º 2
0
    def __init__(self):

        super().__init__()

        self.w, self.h = self.screen.get_size()
        self.sound_queue.append(sounds['menu'])

        bg = Animation(frames_path['play-background'], (0, 0), self.screen)

        tree1 = Animation(frames_path['tree'], (150, self.h/2), self.screen)
        tree1.reduce_scale(4)
        tree1.centralize()
        tree1.flip()

        tree2 = Animation(frames_path['tree'], (self.w-150, self.h/2), self.screen)
        tree2.reduce_scale(4)
        tree2.centralize()

        title = Animation(frames_path['title'], (self.w/2,200), self.screen)
        title.reduce_scale(3)
        title.centralize()

        self.ship = Animation(frames_path['ship'], ((self.w/16)*2, 200), self.screen)
        self.ship.reduce_scale(4)
        self.ship.centralize()
        self.ship_speed = -1
        
        self.next_state 
        self.menu = Menu(self.screen)

        ''' 
            O botao criado no menu inicial recebe como parametro o nome do proximo estado que sera executado
            assim que este aqui acabar
        '''
        
        self.menu.add_button('start', frames_path['start-button'], (self.w/2, self.h/2), 'SELECTCHAR')
        self.menu.buttons['start'].reduce_scale(1.5)
        self.menu.buttons['start'].centralize()

        self.menu.add_button('htp', frames_path['htp-button'], (self.w/2, self.h/2 + 100), 'HOWTOPLAY')
        self.menu.buttons['htp'].reduce_scale(1.5)
        self.menu.buttons['htp'].centralize()


        self.menu.add_button('sound', frames_path['sound'],(int((self.w/16)*15), int((self.h/10)*1)),self.switch_sound)
        self.menu.buttons['sound'].reduce_scale(5)
        self.menu.buttons['sound'].centralize()

        self.elements = [bg, self.ship, self.menu, tree1, tree2, title]
Exemplo n.º 3
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.º 4
0
class Gameplay(State):

    char_sex = 1

    def __init__(self):

        super().__init__()
        self.w, self.h = self.screen.get_size()
        
        self.sound_queue.append(sounds['stage'])

        self.menu = Menu(self.screen)
        self.menu.add_button('sound', frames_path['sound'],(int((self.w/16)*15), int((self.h/10)*1)),self.switch_sound)
        self.menu.buttons['sound'].reduce_scale(5)
        self.menu.buttons['sound'].centralize()

        self.msgs = {
            'lose': Text(self.screen, (int(self.w/2), 200), 'Oh não, os piratas chegaram na ilha, melhor zarparmos e tentarmos denovo outro dia!', True, (255,255,255))
        }

        ''' Sessões de Jogo '''
        self.played_sections = 0
        self.wins = 0
        self.stage_done = False
        self.stage_begin = True

        ''' Mapa '''
        self.block_index = 0
        self.stage_map = Map(3, self.screen, self.w, self.h)
        
        ''' Escavações '''
        self.last_dig = None
        self.curr_dig = None
        self.show_item = False

        ''' Personagem '''
        self.char = Character(self.screen, Gameplay.char_sex, self.stage_map.blocks[self.block_index])
        self.char.reduce_scale(4)
        self.char.centralize()

        ''' Cena '''
        self.ship = Animation(frames_path['ship'], ((self.w/16)*14, 200), self.screen)
        self.ship.reduce_scale(4)
        self.ship.centralize()
        self.bg = Animation(frames_path['play-background'], (0, 0), self.screen)
        self.elements = [self.bg, self.stage_map, self.ship, self.char]

    def update(self):

        if(self.curr_dig != None):
            if(isinstance(self.curr_dig, Treasure)):
                self.sound_queue.append(sounds['win'])
                self.stage_done = True
                self.wins += 1
            
            if(isinstance(self.curr_dig, Hint)):
                self.sound_queue.append(sounds['hint'])

            self.last_dig = self.curr_dig
            self.curr_dig = None
            self.show_item = True
        
        elif(self.char.chances <= 0):
            self.stage_done = True
            self.last_dig = self.msgs['lose']         

        if(self.played_sections == 3):
            self.done = True
            '''fim de jogo, ir para tela de resultados(?)'''

    def check_event(self, event):

        if event.type == pygame.QUIT:
            self.quit = True

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

                self.sound_queue.append(sounds['button-switch'])

                if(callable(self.menu.last_clicked_state)):
                    self.menu.last_clicked_state()
                    self.menu.last_clicked_state = None

        if event.type == pygame.KEYDOWN:

            if(self.stage_begin):
                self.stage_begin = False
                return

            if(self.stage_done):
                self.next_stage()
                return

            if self.show_item:
                self.show_item = False
                return

            if event.key == pygame.K_RIGHT:
                self.sound_queue.append(sounds['stepping-sand'])
                if (not self.block_index + 1 >= len(self.stage_map.blocks)):
                    if(self.char.dir == 0):
                        self.char.flip()
                    self.block_index += 1
                    self.char.update_block(self.stage_map.blocks[self.block_index])
                    self.char.centralize()

            elif event.key == pygame.K_LEFT:
                self.sound_queue.append(sounds['stepping-sand'])
                if (not self.block_index - 1 < 0):
                    if(self.char.dir == 1):
                        self.char.flip()
                    self.block_index -= 1
                    self.char.update_block(self.stage_map.blocks[self.block_index])
                    self.char.centralize()

            elif event.key == pygame.K_DOWN:
                self.sound_queue.append(sounds['stepping-sand'])
                if (not self.block_index + self.stage_map.col >= len(self.stage_map.blocks)):
                    self.block_index += self.stage_map.col
                    self.char.update_block(self.stage_map.blocks[self.block_index])
                    self.char.centralize()

            elif event.key == pygame.K_UP:
                self.sound_queue.append(sounds['stepping-sand'])
                if (not self.block_index - self.stage_map.col < 0):
                    self.block_index -= self.stage_map.col
                    self.char.update_block(self.stage_map.blocks[self.block_index])
                    self.char.centralize()

            elif event.key == pygame.K_SPACE:
                self.sound_queue.append(sounds['digging'])
                self.move_ship()
                self.char.chances -= 1
                self.curr_dig = self.char.dig()

    def draw(self):

        for element in self.elements:
            element.draw()

        if(self.stage_begin):
            self.stage_map.first_hint.draw()

        elif(self.show_item): 
            self.last_dig.draw()
        
        self.menu.draw()

    def move_ship(self):

        self.ship.update_pos((self.ship.rect.x - 200, 200))
        self.ship.reduce_scale(0.9)
        self.ship.centralize()
        
    def next_stage(self):

        self.ship = Animation(frames_path['ship'], ((self.w/16)*14, 200), self.screen)
        self.ship.reduce_scale(4)
        self.ship.centralize()

        self.sound_queue.append(sounds['stage'])

        self.played_sections += 1

        self.last_dig = None
        self.curr_dig = None
        self.show_item = False

        self.stage_done = False
        self.treasure_found = False
        
        self.stage_begin = True

        self.block_index = 0

        self.stage_map = Map(3 + self.played_sections, self.screen, self.w, self.h)

        self.char = Character(self.screen, Gameplay.char_sex, self.stage_map.blocks[self.block_index])
        self.char.reduce_scale(4)
        self.char.centralize()

        self.elements = [self.bg, self.stage_map, self.ship, self.char]

    def switch_sound(self):
        super().switch_sound()
        if (State.volume == 0):
            self.menu.buttons['sound'].switch_state('off')
        elif(State.volume == 1):
            self.menu.buttons['sound'].switch_state('on')  
Exemplo n.º 5
0
class StartScreen(State):
    
    def __init__(self):

        super().__init__()

        self.w, self.h = self.screen.get_size()
        self.sound_queue.append(sounds['menu'])

        bg = Animation(frames_path['play-background'], (0, 0), self.screen)

        tree1 = Animation(frames_path['tree'], (150, self.h/2), self.screen)
        tree1.reduce_scale(4)
        tree1.centralize()
        tree1.flip()

        tree2 = Animation(frames_path['tree'], (self.w-150, self.h/2), self.screen)
        tree2.reduce_scale(4)
        tree2.centralize()

        title = Animation(frames_path['title'], (self.w/2,200), self.screen)
        title.reduce_scale(3)
        title.centralize()

        self.ship = Animation(frames_path['ship'], ((self.w/16)*2, 200), self.screen)
        self.ship.reduce_scale(4)
        self.ship.centralize()
        self.ship_speed = -1
        
        self.next_state 
        self.menu = Menu(self.screen)

        ''' 
            O botao criado no menu inicial recebe como parametro o nome do proximo estado que sera executado
            assim que este aqui acabar
        '''
        
        self.menu.add_button('start', frames_path['start-button'], (self.w/2, self.h/2), 'SELECTCHAR')
        self.menu.buttons['start'].reduce_scale(1.5)
        self.menu.buttons['start'].centralize()

        self.menu.add_button('htp', frames_path['htp-button'], (self.w/2, self.h/2 + 100), 'HOWTOPLAY')
        self.menu.buttons['htp'].reduce_scale(1.5)
        self.menu.buttons['htp'].centralize()


        self.menu.add_button('sound', frames_path['sound'],(int((self.w/16)*15), int((self.h/10)*1)),self.switch_sound)
        self.menu.buttons['sound'].reduce_scale(5)
        self.menu.buttons['sound'].centralize()

        self.elements = [bg, self.ship, self.menu, tree1, tree2, title]

    def check_event(self, event):

        if event.type == pygame.QUIT:
            self.quit = True
            ''' 
                Assim que o mouse for clicado o handler de evento deste estado chama a funcao do menu que verifica
                se este click ocorreu em algum dos botoes presentes no menu
            '''
        elif event.type == pygame.MOUSEBUTTONUP:
            if(self.menu.check_click(pygame.mouse.get_pos())):

                ''' Colocar o som de selecao de botão aqui '''
                self.sound_queue.append(sounds['button-switch'])

                if(callable(self.menu.last_clicked_state)):
                    self.menu.last_clicked_state()
                    self.menu.last_clicked_state = None
                    return

                ''' 
                    Se algum botao foi clicado e conter um estado como callback, o status desse evento e marcado como 'done' (self.done = True) e o
                    ponteiro para o proximo estado vira o valor que havia sido armazenado como next_state, do botão
                    em questão
                '''

                self.next_state = self.menu.last_clicked_state
                self.done = True

    def switch_sound(self):
        super().switch_sound()
        if (State.volume == 0):
            self.menu.buttons['sound'].switch_state('off')
        elif(State.volume == 1):
            self.menu.buttons['sound'].switch_state('on')

    def draw(self):
        for element in self.elements:
            element.draw()

    def update(self):
        
        self.ship.update_pos((self.ship.rect.x + self.ship_speed, self.ship.rect.y))
        if(self.ship.rect.x == 0 or self.ship.rect.x == self.w):
            self.ship_speed *= -1
            print('ship speed is now ' + str(self.ship_speed))
            self.ship.rect.x + self.ship_speed * 1000
            self.ship.flip()