Example #1
0
    def initialize_level(self):
        for tile_object in self.map.tmxdata.objects:
            if tile_object.type == 'Player':
                self.player.position.x = tile_object.x
                self.player.position.y = tile_object.y
                self.player.hit_rect.x = tile_object.x
                self.player.hit_rect.y = tile_object.y
            if tile_object.type == 'Block':
                if tile_object.name == 'bounce':
                    direction = tile_object.Direction
                else:
                    direction = None
                sprites.Block(self, tile_object.x, tile_object.y,
                              tile_object.width, tile_object.height,
                              tile_object.name, direction)
            if tile_object.type == 'Interactable':
                if tile_object.name == 'button':
                    ability = tile_object.Ability
                else:
                    ability = None

                sprites.Interactable(self, tile_object.x, tile_object.y,
                                     tile_object.width, tile_object.height,
                                     tile_object.name, self.button_down_img,
                                     self.button_up_img, ability)

        self.camera = tilemap.Camera(self.map.width, self.map.height)
Example #2
0
 def player_add(self, pos, type_):
     grid_x = int(pos.x // st.TILESIZE)
     grid_y = int(pos.y // st.TILESIZE)
     if self.map[grid_y][grid_x] == None:
         inv = self.game.player.inventory
         if type_ in inv:
             if inv[type_] > 0:
                 inv[type_] -= 1
                 b = spr.Block(self.game, type_, pos.x, pos.y)
                 self.map[grid_y][grid_x] = b
                 self.map_blueprint[grid_y][grid_x] = type_
Example #3
0
    def manage_blocks_initial(self):
        player = self.game.player
        self.sector_w = int((player.pos.x / st.MAP_WIDTH) * st.NO_SECTORS_W)
        self.sector_h = int((player.pos.y / st.MAP_HEIGHT) * st.NO_SECTORS_H)
        for i in range(self.width):
            # load sector the player is in and the adjacent ones
            # load horizontal sectors
            if (i >= (self.sector_w - 1) * st.SECTOR_WIDTH and i <
                (self.sector_w + 2) * st.SECTOR_WIDTH):
                for j in range(self.height):
                    # load vertical sectors
                    if (j >= (self.sector_h - 1) * st.SECTOR_HEIGHT and j <
                        (self.sector_h + 2) * st.SECTOR_HEIGHT):

                        if self.map_blueprint[j][i]:
                            b_x = int(i * st.TILESIZE)
                            b_y = int(j * st.TILESIZE)
                            # place block sprite
                            self.map[j][i] = spr.Block(
                                self.game, self.map_blueprint[j][i], b_x, b_y)
Example #4
0
def generate_level(show_title):
    for sprite in public.all_sprites:
        if sprite.type != 'Cloud':
            sprite.kill()

    level_data = dictionaries.LEVELS[public.level]
    public.bg_type = level_data[1]
    public.wrapping = level_data[2]

    platform = sprites.Platform()

    if show_title:
        title = sprites.Title(level_data[0])

    for i, row in enumerate(level_data[3]):
        for _i, col in enumerate(row):
            if col in 'ABC':
                color = color_return('ABC', col)
                block = sprites.Block((_i * 20, i * 20), color)

            elif col in 'DEF':
                color = color_return('DEF', col)
                exit = sprites.Exit((_i * 20, i * 20), color)

            elif col in 'GHI':
                color = color_return('GHI', col)
                pit = sprites.Pit((_i * 20, i * 20), color, 'U')

            elif col in 'JKL':
                color = color_return('JKL', col)
                pit = sprites.Pit((_i * 20, i * 20), color, 'D')

            elif col in 'MNO':
                color = color_return('MNO', col)
                jumpad = sprites.Jumpad((_i * 20, i * 20), color, 'U')

            elif col in 'PQR':
                color = color_return('PQR', col)
                jumpad = sprites.Jumpad((_i * 20, i * 20), color, 'D')

            elif col in 'STU':
                color = color_return('STU', col)
                breakable = sprites.Breakable((_i * 20, i * 20), color, 'U')

            elif col in 'VWX':
                color = color_return('VWX', col)
                breakable = sprites.Breakable((_i * 20, i * 20), color, 'D')

            elif col in '123':
                color = color_return('123', col)
                flipad = sprites.Flipad((_i * 20, i * 20), color, 'U')

            elif col in '456':
                color = color_return('456', col)
                flipad = sprites.Flipad((_i * 20, i * 20), color, 'D')

            elif col in '><':
                public.spawn = (_i * 20, i * 20)

                if col == '>':
                    public.player = sprites.Ox(public.spawn, 'R')

                elif col == '<':
                    public.player = sprites.Ox(public.spawn, 'L')

            elif col == '.':
                sphere = sprites.RGBSphere((_i * 20, i * 20), 192)

    for sprite in public.blocks:
        if sprite.type == 'Block':
            sprite.image = block_return(sprite, sprite.color)

        elif sprite.type == 'Pit':
            pit_return(sprite, sprite.color)

        elif sprite.type == 'Breakable':
            sprite.image = breakable_return(sprite, sprite.color)

            if sprite.direction == 'D':
                sprite.image = pygame.transform.flip(sprite.image, 0, 1)
Example #5
0
    def __init__(self, player):
        level.Level.__init__(self, player)

        self.background = pygame.image.load(constants.PATH + "background_l1.png").convert()
        self.background.set_colorkey(constants.WHITE)
        self.max_frames = 2
        self.number = 0

        platforms = sprites.Platform(pygame.image.load(constants.PATH + "level_1.png"), 0, 0)
        platforms.player = self.player
        self.platform_list.add(platforms)

        # Array with type of platform, and x, y location of the platform.
        level_platforms = [sprites.HorizontalMovingPlatform(images.get_platform(images.GROUND, 145, 32), 3655, 324,
                                                            4011, 3650),
                           sprites.VerticalMovingPlatform(images.get_platform(images.GROUND, 145, 32), 4207, 400, 100,
                                                          500),
                           sprites.VerticalMovingPlatform(images.get_platform(images.PIPE_G, 90, 440, images.PIPE_G_C),
                                                          4985, 300, 150, 427),
                           sprites.VerticalMovingPlatform(images.get_platform(images.PIPE_R, 90, 440, images.PIPE_R_C),
                                                          5075, 350, 200, 400),
                           sprites.VerticalMovingPlatform(images.get_platform(images.PIPE_Y, 90, 440, images.PIPE_Y_C),
                                                          5165, 250, 170, 380),
                           sprites.VerticalMovingPlatform(images.get_platform(images.PIPE_Y, 90, 440, images.PIPE_Y_C),
                                                          5255, 400, 220, 427),
                           sprites.VerticalMovingPlatform(images.get_platform(images.PIPE_G, 90, 440, images.PIPE_G_C),
                                                          5345, 300, 180, 380),
                           sprites.VerticalMovingPlatform(images.get_platform(images.PIPE_G, 90, 440, images.PIPE_G_C),
                                                          5700, 270, 160, 420),
                           sprites.VerticalMovingPlatform(images.get_platform(images.PIPE_R, 90, 440, images.PIPE_R_C),
                                                          5790, 350, 220, 400),
                           sprites.VerticalMovingPlatform(images.get_platform(images.PIPE_Y, 90, 440, images.PIPE_Y_C),
                                                          5975, 300, 200, 390)]
        level_pipes = [sprites.Pipe(Level1_1(self.player, self), -350, 1776),
                       sprites.Pipe(None, 0, 2845, 0),
                       sprites.Pipe(Level1_2(self.player, self), 0, 5880, 339,
                                    images.get_platform(images.PIPE_B, 95, 215, images.PIPE_B_C))]
        level_blocks = [sprites.BreakableBlock(710, 135), sprites.BreakableBlock(802, 135),
                        sprites.BreakableBlock(1877, 48), sprites.Block(None, 2846, 396),
                        sprites.Block(None, 2892, 396), sprites.QBlock(756, 135, sprites.Reward(None)),
                        sprites.QBlock(1923, 48, sprites.Coin(1923, 48)), sprites.BreakableBlock(6313, 170),
                        sprites.QBlock(6267, 170, sprites.Reward(None))]
        level_enemies = [sprites.Goomba(831, 270), sprites.Koopa(3002, 358), sprites.Koopa(3400, 358)]

        star0 = sprites.StarCoin(1615, 418, 0)
        star2 = sprites.StarCoin(5220, 0, 2)
        self.star_coins.add(star0)
        self.star_coins.add(star2)
        level_coins = [sprites.Coin(720, 42), sprites.Coin(759, 3), sprites.Coin(796, 42), sprites.Coin(1070, 205),
                       sprites.Coin(1210, 160), sprites.Coin(1412, 205), sprites.Coin(1950, 455),
                       sprites.Coin(1997, 455), sprites.Coin(2042, 455), sprites.Coin(2090, 455),
                       sprites.Coin(3104, 270), sprites.Coin(3146, 225), sprites.Coin(3200, 225),
                       sprites.Coin(3240, 270), sprites.Coin(3545, 268), sprites.Coin(4210, 0, True, 0),
                       sprites.Coin(4255, 0, True, 0), sprites.Coin(4300, 0, True, 0), star0, star2]

        # Go through the arrays above and add platforms
        utils.add_all(level_platforms, self.platform_list, None, self.player)
        utils.add_all(level_pipes, self.platform_list, self, self.player)
        utils.add_all(level_enemies, self.enemy_list, None, self.player)
        utils.add_all(level_coins, self.reward_list)
        for aBlock in level_blocks:
            self.block_list.add(aBlock)
            if isinstance(aBlock, sprites.BreakableBlock):
                aBlock.level = self
Example #6
0
 def set_at(self, pos, type_):
     grid_x = int(pos.x // st.TILESIZE)
     grid_y = int(pos.y // st.TILESIZE)
     b = spr.Block(self.game, type_, pos.x, pos.y)
     self.map[grid_y][grid_x] = b
Example #7
0
 def add(self, pos, type_):
     grid_x = int(pos.x // st.TILESIZE)
     grid_y = int(pos.y // st.TILESIZE)
     if not self.map[grid_y][grid_x]:
         b = spr.Block(self.game, type_, pos.x, pos.y)
         self.map[grid_y][grid_x] = b
Example #8
0
    def manage_blocks(self):
        '''
        creates and deletes blocks around the players FOV
        '''
        player = self.game.player
        # calculating the sector the player is in
        change_w = 0
        change_h = 0
        sector_w = int((player.pos.x / st.MAP_WIDTH) * st.NO_SECTORS_W)
        sector_h = int((player.pos.y / st.MAP_HEIGHT) * st.NO_SECTORS_H)

        if sector_w != self.sector_w:
            change_w = sector_w - self.sector_w
            self.sector_w = sector_w

        if sector_h != self.sector_h:
            change_h = sector_h - self.sector_h
            self.sector_h = sector_h

        # define boundaries for looping through the grid
        start_w = max(0, (self.sector_w - 2) * st.SECTOR_WIDTH)
        stop_w = min((self.sector_w + 3) * st.SECTOR_WIDTH, self.width)
        start_h = max(0, (self.sector_h - 2) * st.SECTOR_HEIGHT)
        stop_h = min((self.sector_h + 3) * st.SECTOR_HEIGHT, self.height)

        if change_w != 0:
            # if the player went to a different sector horizontally
            # load blocks in sector based on direction
            # MEMO: THIS IS TOO MUCH CODE!?!?
            for i in range(start_w, stop_w):
                if change_w == 1:
                    # player went right
                    # load sector the player is going to
                    if (i >= (self.sector_w + 1) * st.SECTOR_WIDTH and i <
                        (self.sector_w + 2) * st.SECTOR_WIDTH):

                        for j in range(start_h, stop_h):
                            if (j >= (self.sector_h - 1) * st.SECTOR_HEIGHT
                                    and j <
                                (self.sector_h + 2) * st.SECTOR_HEIGHT):
                                if self.map_blueprint[j][i]:
                                    b_x = int(i * st.TILESIZE)
                                    b_y = int(j * st.TILESIZE)
                                    # place block sprite
                                    self.map[j][i] = spr.Block(
                                        self.game, self.map_blueprint[j][i],
                                        b_x, b_y)

                    # unload the sector the player is leaving
                    if (i < (self.sector_w - 1) * st.SECTOR_WIDTH):
                        for j in range(start_h, stop_h):
                            if (j >= (self.sector_h - 1) * st.SECTOR_HEIGHT
                                    and j <
                                (self.sector_h + 2) * st.SECTOR_HEIGHT):
                                if self.map[j][i]:
                                    # remove block sprite
                                    self.map[j][i].kill()
                                    self.map[j][i] = None

                elif change_w == -1:
                    # player went left
                    # load sector the player is going to
                    if (i < self.sector_w * st.SECTOR_WIDTH and i >=
                        (self.sector_w - 1) * st.SECTOR_WIDTH):

                        for j in range(start_h, stop_h):
                            if (j >= (self.sector_h - 1) * st.SECTOR_HEIGHT
                                    and j <
                                (self.sector_h + 2) * st.SECTOR_HEIGHT):
                                if self.map_blueprint[j][i]:
                                    b_x = int(i * st.TILESIZE)
                                    b_y = int(j * st.TILESIZE)
                                    # place block sprite
                                    self.map[j][i] = spr.Block(
                                        self.game, self.map_blueprint[j][i],
                                        b_x, b_y)

                    # unload the sector the player is leaving
                    if (i >= (self.sector_w + 2) * st.SECTOR_WIDTH):
                        for j in range(start_h, stop_h):
                            if (j >= (self.sector_h - 1) * st.SECTOR_HEIGHT
                                    and j <
                                (self.sector_h + 2) * st.SECTOR_HEIGHT):
                                if self.map[j][i]:
                                    # remove block sprite
                                    self.map[j][i].kill()
                                    self.map[j][i] = None

        if change_h != 0:
            for i in range(start_w, stop_w):
                if change_h == 1:
                    # player went down
                    # load sector the player is going to
                    if (i >= (self.sector_w - 1) * st.SECTOR_WIDTH and i <
                        (self.sector_w + 2) * st.SECTOR_WIDTH):
                        for j in range(start_h, stop_h):
                            if (j >= (self.sector_h + 1) * st.SECTOR_HEIGHT
                                    and j <
                                (self.sector_h + 2) * st.SECTOR_HEIGHT):
                                if self.map_blueprint[j][i]:
                                    b_x = int(i * st.TILESIZE)
                                    b_y = int(j * st.TILESIZE)
                                    # place block sprite
                                    self.map[j][i] = spr.Block(
                                        self.game, self.map_blueprint[j][i],
                                        b_x, b_y)

                            # unload the sector the player is leaving
                            if (j < (self.sector_h - 1) * st.SECTOR_HEIGHT):
                                for k in range(start_w, stop_w):
                                    if (k >=
                                        (self.sector_w - 1) * st.SECTOR_WIDTH
                                            and k <
                                        (self.sector_w + 2) * st.SECTOR_WIDTH):
                                        if self.map[j][k]:
                                            # remove block sprite
                                            self.map[j][k].kill()
                                            self.map[j][k] = None

                elif change_h == -1:
                    # player went up
                    # load sector the player is going to
                    if (i >= (self.sector_w - 1) * st.SECTOR_WIDTH and i <
                        (self.sector_w + 2) * st.SECTOR_WIDTH):
                        for j in range(start_h, stop_h):
                            if (j >= (self.sector_h - 1) * st.SECTOR_HEIGHT
                                    and j < self.sector_h * st.SECTOR_HEIGHT):
                                if self.map_blueprint[j][i]:
                                    b_x = int(i * st.TILESIZE)
                                    b_y = int(j * st.TILESIZE)
                                    # place block sprite
                                    self.map[j][i] = spr.Block(
                                        self.game, self.map_blueprint[j][i],
                                        b_x, b_y)

                            # unload the sector the player is leaving
                            if (j >= (self.sector_h + 2) * st.SECTOR_HEIGHT):
                                for k in range(start_w, stop_w):
                                    if (k >=
                                        (self.sector_w - 1) * st.SECTOR_WIDTH
                                            and k <
                                        (self.sector_w + 2) * st.SECTOR_WIDTH):
                                        if self.map[j][k]:
                                            # remove block sprite
                                            self.map[j][k].kill()
                                            self.map[j][k] = None