Edit the level 2 game map

It has been a day since the last post, I am really busy recently working on the offline business so I really need to divide the time equally for both the online and the offline business. In this chapter, we will finish up the previous unfinished business which is to come out with a new game map for level 2. We need to edit those level 2 data for the player, the enemy, the background and the mana object as follows.

class BoyObject(object):

    def __init__(self):

        self.list_1 = [

            [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
            [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
            [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
            [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
            [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
            [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
            [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
            [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
            [1, 0, 0, 0, 0, 0, 0, 0, 0, 0],
            [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
        ]

        self.ladder_boundary_1 = [[9 * 64, 8 * 64],
                                  [9 * 64, 7 * 64],
                                  [5 * 64, 6 * 64],
                                  [5 * 64, 5 * 64],
                                  [2 * 64, 3 * 64],
                                  [2 * 64, 4 * 64],
                                  [0 * 64, 1 * 64],
                                  [0 * 64, 2 * 64],
                                  ] # the boundary of the ladder

        self.boundary_bottom_1 = [[9 * 64, 9 * 64],
                                  [5 * 64, 7 * 64],
                                  [2 * 64, 5 * 64],
                                  [0 * 64, 3 * 64]]  # the bottom boundary of the ladder

        self.boundary_side_1 = [[4 * 64, 6 * 64],
                                [1 * 64, 4 * 64],
                                [6 * 64, 2 * 64], ]  # the side boundary of the player

        self.boundary_door_1 = [[9 * 64, 0]]

        self.initial_1 = [0, 8 * 64]

        self.list_2 = [

            [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
            [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
            [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
            [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
            [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
            [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
            [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
            [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
            [1, 0, 0, 0, 0, 0, 0, 0, 0, 0],
            [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
        ]

        self.ladder_boundary_2 = [[9 * 64, 8 * 64],
                                  [9 * 64, 7 * 64],
                                  [2 * 64, 6 * 64],
                                  [2 * 64, 5 * 64],
                                  [2 * 64, 4 * 64],
                                  [2 * 64, 3 * 64],
                                  [8 * 64, 1 * 64],
                                  [8 * 64, 2 * 64],
                                  ]  # the boundary of the ladder

        self.boundary_bottom_2 = [[9 * 64, 9 * 64],
                                  [2 * 64, 7 * 64],
                                  [8 * 64, 3 * 64]]  # the bottom boundary of the ladder

        self.boundary_side_2 = [[1 * 64, 6 * 64],
                                [0 * 64, 2 * 64],]  # the side boundary of the player

        self.boundary_door_2 = [[0, 0]]

        self.initial_2 = [0, 8 * 64]

    def get_original_position(self, level):

        if (level == 1):
            return self.initial_1
        elif (level == 2):
            return self.initial_2

    def get_object_list(self, level):

        if(level == 1):
            return self.list_1
        elif (level == 2):
            return self.list_2

    def get_object_boundary(self, level):

        if (level == 1):
            return self.ladder_boundary_1
        elif (level == 2):
            return self.ladder_boundary_2

    def get_object_bottom_boundary(self, level):

        if (level == 1):
            return self.boundary_bottom_1
        elif (level == 2):
            return self.boundary_bottom_2

    def get_object_side_boundary(self, level):

        if (level == 1):
            return self.boundary_side_1
        elif (level == 2):
            return self.boundary_side_2

    def get_object_door_boundary(self, level):

        if(level == 1):
            return self.boundary_door_1
        elif (level == 2):
            return self.boundary_door_2
class EnemyObject(object):

    def __init__(self):

        self.list_1 = [

            [0, 1, 0, 0, 0, 1, 0, 0, 0, 0],
            [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
            [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
            [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
            [0, 0, 0, 0, 1, 0, 0, 0, 1, 0],
            [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
            [0, 0, 0, 0, 0, 0, 1, 0, 0, 0],
            [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
            [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
            [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
        ]

        self.boundary_1 = [
            [[0, 0], [8 * 64, 0]],
            [[0, 0], [8 * 64, 0]],
            [[2 * 64, 4 * 64], [8 * 64, 4 * 64]],
            [[2 * 64, 4 * 64], [8 * 64, 4 * 64]],
            [[5 * 64, 6 * 64], [8 * 64, 6 * 64]]
        ]

        self.initial_1 = [[64, 0], [5 * 64, 0],[4 * 64, 4 * 64], [8 * 64, 4 * 64],[6 * 64, 6 * 64]]

        self.list_2 = [

            [0, 0, 0, 0, 0, 1, 0, 1, 0, 0],
            [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
            [0, 0, 0, 1, 0, 1, 0, 0, 0, 0],
            [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
            [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
            [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
            [0, 0, 1, 0, 1, 0, 0, 0, 0, 0],
            [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
            [0, 0, 0, 0, 1, 0, 0, 0, 0, 0],
            [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
        ]

        self.boundary_2 = [
            [[0, 0], [9 * 64, 0]],
            [[0, 0], [9 * 64, 0]],
            [[0, 2 * 64], [9 * 64, 2 * 64]],
            [[0, 2 * 64], [9 * 64, 2 * 64]],
            [[2 * 64, 6 * 64], [9 * 64, 6 * 64]],
            [[2 * 64, 6 * 64], [9 * 64, 6 * 64]],
            [[0, 8 * 64], [9 * 64, 8 * 64]],
        ]

        self.initial_2 = [[64, 0], [5 * 64, 0], [3 * 64, 2 * 64], [5 * 64, 2 * 64], [3 * 64, 6 * 64], [5 * 64, 6 * 64],[4 * 64, 8 * 64] ]

    def get_original_position(self, level):

        if (level == 1):
            return self.initial_1
        elif (level == 2):
            return self.initial_2

    def get_object_list(self, level):

        if(level == 1):
            return self.list_1
        elif (level == 2):
            return self.list_2

    def get_object_boundary(self, level):

        if (level == 1):
            return self.boundary_1
        elif (level == 2):
            return self.boundary_2
class ManaObject(object):

    def __init__(self):

        self.list_1 = [

            [1, 1, 0, 0, 0, 0, 0, 0, 0, 0],
            [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
            [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
            [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
            [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
            [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
            [0, 0, 0, 0, 0, 0, 1, 0, 0, 0],
            [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
            [0, 0, 0, 1, 0, 0, 0, 0, 0, 0],
            [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
        ]

        self.initial_1 = [[3 * 64, 8 * 64], [6 * 64, 6 * 64],[0 * 64, 0 * 64], [1 * 64, 0 * 64]]

        self.list_2 = [

            [0, 0, 0, 0, 0, 1, 1, 0, 0, 0],
            [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
            [0, 0, 1, 1, 0, 0, 0, 0, 0, 0],
            [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
            [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
            [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
            [0, 0, 0, 0, 0, 0, 1, 1, 0, 0],
            [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
            [0, 1, 0, 0, 0, 0, 0, 0, 0, 0],
            [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
        ]

        self.initial_2 = [[1 * 64, 8 * 64], [6 * 64, 6 * 64], [7 * 64, 6 * 64], [3 * 64, 2 * 64],[4 * 64, 2 * 64],[5 * 64, 0 * 64], [6 * 64, 0 * 64]]

    def get_original_position(self, level):

        if (level == 1):
            return self.initial_1
        elif (level == 2):
            return self.initial_2

    def get_object_list(self, level):

        if(level == 1):
            return self.list_1
        elif (level == 2):
            return self.list_2
class BgObject(object):

    def __init__(self):

        self.list_1 = [
            [3, 3, 3, 3, 3, 3, 3, 3, 3, 2],
            [4, 0, 0, 0, 0, 0, 0, 0, 0, 0],
            [4, 3, 3, 3, 3, 3, 3, 3, 3, 3],
            [0, 0, 4, 0, 0, 0, 3, 3, 3, 3],
            [3, 3, 4, 3, 3, 3, 3, 3, 3, 3],
            [0, 0, 0, 0, 1, 4, 1, 0, 0, 1],
            [3, 3, 3, 3, 3, 4, 3, 3, 3, 3],
            [3, 3, 3, 3, 3, 1, 1, 0, 0, 4],
            [3, 3, 3, 3, 3, 3, 3, 3, 3, 4],
            [0, 1, 0, 0, 1, 1, 0, 1, 1, 0]
        ]

        self.list_2 = [
            [2, 3, 3, 3, 3, 3, 3, 3, 3, 3],
            [1, 0, 0, 0, 0, 0, 0, 0, 4, 0],
            [3, 3, 3, 3, 3, 3, 3, 3, 4, 3],
            [3, 0, 4, 0, 0, 0, 0, 0, 0, 0],
            [3, 3, 4, 3, 3, 3, 3, 3, 3, 3],
            [3, 3, 4, 3, 3, 3, 3, 3, 3, 3],
            [3, 3, 4, 3, 3, 3, 3, 3, 3, 3],
            [3, 3, 0, 0, 0, 1, 1, 0, 0, 4],
            [3, 3, 3, 3, 3, 3, 3, 3, 3, 4],
            [0, 1, 0, 0, 1, 1, 0, 1, 1, 0]
        ]

    def get_object_list(self, level):

        if(level == 1):
            return self.list_1
        elif(level == 2):
            return self.list_2

Besides the above, we also need to make sure to change the number under the create enemy method of the enemy sprite class for level 2.

    def create_enemy(self, level):

        self.enemy_boundary_list = self.enemy_object.get_object_boundary(level)
        self.enemy_original_position = self.enemy_object.get_original_position(level)

        i = 0
        if(level == 1):
            while(i < 5):
                self.total_enemy_list.append(Enemy(self.enemy_boundary_list[i], self.enemy_original_position[i]))
                i += 1
        elif (level == 2):
            while (i < 7):
                self.total_enemy_list.append(Enemy(self.enemy_boundary_list[i], self.enemy_original_position[i]))
                i += 1

The same goes to the create mana method of the mana sprite class.

    def create_mana(self, level):

        self.mana_original_position = self.mana_object.get_original_position(level)

        i = 0
        if(level == 1):
            while(i < 4):
                self.total_mana_list.append(Mana(self.mana_original_position[i]))
                i += 1
        elif (level == 2):
            while (i < 7):
                self.total_mana_list.append(Mana(self.mana_original_position[i]))
                i += 1

If you run the above program again you will see this result.

Basically this project is almost completed, just a few touch up need to be done so stay tune for the next chapter.

Leave a Reply

Your email address will not be published. Required fields are marked *