Example #1
0
class Credits(GameState):
    def __init__(self):
        super(Credits, self).__init__()
        self.font = pygame.font.Font(SUB_TITLE_FONT[0], 34)
        self.title = self.font.render("CREDITS", True, (255, 255, 255))
        self.title_rect = self.title.get_rect(x=(SCREEN_SIZE[0] / 2) - 80, y=50)
        self.next_state = "SPLASH"
        self.menu = Menu([
            Button("Back", ((SCREEN_SIZE[0] / 2) - 125, 390, 250, 40), active = True)
        ])

    def get_event(self, event):
        if event.type == pygame.QUIT:
            self.quit = True
        elif event.type == pygame.KEYDOWN:
            self.done = True

    def draw(self, surface):
        surface.fill(Color("black"))
        surface.blit(self.title, self.title_rect)
        self.menu.draw(surface)

        center = SCREEN_SIZE[0] / 2

        Text((100, 20), (center - 50, 200), "Author",
            pygame.font.Font(SUB_TITLE_FONT[0], 18),
            Color("white")
        ).draw(surface)

        Text((100, 20), (center - 50, 230), "Jose Saldana",
            pygame.font.Font(None, 25),
            Color("white")
        ).draw(surface)

        Text((100, 20), (center - 50, 280), "Group",
            pygame.font.Font(SUB_TITLE_FONT[0], 18),
            Color("white")
        ).draw(surface)

        Text((100, 20), (center - 50, 310), "1LS-231",
            pygame.font.Font(None, 25),
            Color("white")
        ).draw(surface)
Example #2
0
class SplashScreen(GameState):
    def __init__(self):
        super(SplashScreen, self).__init__()
        self.font = pygame.font.Font(MAIN_TITLE_FONT[0], 54)
        self.title = self.font.render(GAME_TITLE, True, (229, 22, 22))
        self.title_rect = self.title.get_rect(x=(SCREEN_SIZE[0] / 2) - 220, y=80)
        self.persist["screen_color"] = "black"
        self.next_state = "GAMEPLAY"
        self.menu = Menu([
            Button("Start", ((SCREEN_SIZE[0] / 2) - 125, 300, 250, 40)),
            Button("Credits", ((SCREEN_SIZE[0] / 2) - 125, 350, 250, 40))
        ])
        self.sound = Sound("assets/sound/MainTheme.wav")
        self.sound.play()

    def startup(self, persistent):
        self.sound.play()
        self.menu.select_option(0)

    def get_event(self, event):
        if event.type == pygame.QUIT:
            self.quit = True
        elif event.type == pygame.KEYDOWN:
            if event.key == pygame.K_UP:
                self.menu.select_option(-1)
            elif event.key == pygame.K_DOWN:
                self.menu.select_option(1)
            elif event.key == pygame.K_RETURN:
                self.next_state = "GAMEPLAY" if self.menu.selected_option == 0 else "CREDITS"
                self.persist["selected_option"] = self.menu.selected_option
                self.done = True
                self.sound.stop()

    def draw(self, surface):
        surface.fill(Color("black"))
        background = pygame.image.load("assets/images/nave.png").convert()
        background.set_colorkey((255, 255, 255))
        surface.blit(background, [(SCREEN_SIZE[0] / 2) - 250, (SCREEN_SIZE[1] / 2) - 140])
        surface.blit(self.title, self.title_rect)
        self.menu.draw(surface)

    def update(self, surface):
        self.menu.update()