Exemplo n.º 1
0
class MainMenu(object):

    def __init__(self):
        # common.Common.__init__(self)
        self.common = Common('title_screen.gif')
        self.level_to_load = 1
        self.screen = Screen()

        # self.levels = Levels()
        # self.level = Level1()
        # pg.display.update()

        self.level_sprites = pg.sprite.Group()
        self.prince = Prince()
        # initial_prince_pos =  (580, 85)
        # self.prince.rect.x = initial_prince_pos[0]
        # self.prince.rect.y = initial_prince_pos[1]
        self.level_sprites.add(self.prince)

        surface = pg.display.get_surface()

        # cursor.image, cursor.rect = self.common.get_image(x=0, y=0, width=640, height=480)
        # surface.blit(cursor.image, cursor.rect)
        image = self.common.get_image(x=0, y=0, width=800, height=600, scale_to=1.3)
        surface.blit(image, (0, 0))

        # self.levels = Levels()

        font = self.common.get_font();
        label = font.render("Press space to start!", 1, (255, 255, 255))
        surface.blit(label, (280, 530))

        # self.screen = pg.display.set_mode((800, 600))

        pg.display.update()

        self.events()

    def events(self):

        while True:
            e = pg.event.wait()
            if e.type == pg.QUIT:
                pg.quit()
            elif e.type == pg.KEYDOWN:

                # left = 276, right = 275, up=273, down=274

                # TODO: improve this

                if e.key == K_SPACE:
                    self.load_level(self.level_to_load)

                if e.key == K_LEFT:
                    self.move_left()



        self.levels.level_sprites.update()

        self.levels.level_sprites.draw(self.screen)


    def load_level(self, level):
        # if level == 1:
        self.level = Level1()
        pg.display.update()
        # pass
        # self.level_sprites.update()
        # pg.display.update()
        # self.level.load()

    def move_left(self):
        self.level.move_left()
Exemplo n.º 2
0
class Game():

    def __init__(self):

        pg.init()
        # pg.event.set_allowed([pg.KEYDOWN, pg.KEYUP, pg.QUIT])
        pg.display.set_caption('Prince of Persia!')

        self.screen = pg.display.set_mode((800, 600))

        self.level_to_load = 1

        self.level_sprites = pg.sprite.Group()
        self.prince = Prince()
        # self.prince.rect.x = 580
        # self.prince.rect.y = 85
        self.level_sprites.add(self.prince)

        self.common = Common('title_screen.gif')
        image = self.common.get_image(x=0, y=0, width=800, height=600, scale_to=1.3)
        self.screen.blit(image, (0, 0))

        font = self.common.get_font();
        label = font.render("Press space to start!", 1, (255, 255, 255))
        self.screen.blit(label, (280, 530))

        pg.display.flip()

        self.splash_screen()

    def splash_screen(self):
        while True:
            e = pg.event.wait()
            if e.type == pg.QUIT:
                pg.quit()
            elif e.type == pg.KEYDOWN and e.key == K_SPACE:
                self.load_level()
                self.main()

    def next_level(self):
        pass

    def quit_game(self):
        pass

    def main(self):
        clock = pg.time.Clock()
        while True:
            e = pg.event.wait()

            if e.type == pg.QUIT:
                pg.quit()
            elif e.type == pg.KEYDOWN:

                if e.key == K_LEFT:
                    self.move_left()

                self.update()

                # self.level_sprites.update()
                # self.level_sprites.draw(self.screen)
                # self.level.draw(self.screen)
                # self.level.update()

            # last_movement = self.prince.left_movements[-1]
            # self.prince.image = last_movement
            # self.prince.rect.x -= 65
            # self.level_sprites.update()

            clock.tick(60)

            pg.display.flip()


    def update(self):
        self.level.draw(self.screen)
        self.level_sprites.update()
        self.level_sprites.draw(self.screen)


    def load_level(self):
        self.level = Level1()
        position = self.level.get_prince_initial_position()
        self.prince.rect.x = position[0]
        self.prince.rect.y = position[1]
        # self.prince.rect = position
        self.update()

    def move_left(self):
        for mov in self.prince.left_movements[1:]:
            self.prince.image = mov
            self.prince.rect.x -= 55

            self.level_sprites.update()
            self.level_sprites.draw(self.screen)

            # pg.time.delay(50)
            pg.display.flip()