示例#1
0
文件: maps.py 项目: phinias12/305Proj
    def __init__(self, player):
        Map.__init__(self, player)

        # The length of the map make it negative to act as a positive
        self.map_limit = -3000

        # Create an array holding (width,height,x,y) I will randomly generate these later

        map = [[210, 20, 500, 450],
               [510, 70, 680, 490],
               [210, 70, 990, 360],
               [210, 70, 1230, 320],
               [210, 70, 1460, 190],
               [210, 70, 1790, 420]]

        for platform in map:
            # Pass the width and height to the Platform Class
            plat = Platform(platform[0], platform[1])
            plat.rect.x = platform[2]
            plat.rect.y = platform[3]
            # Put it in the player class so it can be applied to collisions
            plat.player = self.player
            # add it to the platforms list of collisions
            self.platforms.add(plat)
    def define_levels(self, level_num, init):
        # Define Level 0
        if init or level_num == 0:
            if init:
                level0 = Level()
                level0.start_pos = (100,
                                    constants.GROUND_HEIGHT - Player.HEIGHT)
                x = constants.SCREEN_WIDTH - self.player.rect.width
                y = constants.GROUND_HEIGHT - Player.HEIGHT
                level0.end_pos = (x, y)
            else:
                level0 = Level.level_list[0]
                level0.platform_list.empty()
                level0.enemy_list.empty()
                level0.tripped_projectiles.empty()

            platform0 = Platform(constants.SCREEN_WIDTH, 60)
            platform0.rect.x = 0
            platform0.rect.y = constants.SCREEN_HEIGHT - platform0.rect.height
            level0.platform_list.add(platform0)

            for i in range(4, 8):
                tp0 = TrippedProjectile()
                tp0.player = self.player
                tp0.rect.x = i * 100
                tp0.rect.y = constants.GROUND_HEIGHT - 250
                level0.tripped_projectiles.add(tp0)

            hidden_wall = Platform(20, constants.SCREEN_HEIGHT)
            hidden_wall.rect.x = -20
            hidden_wall.rect.y = 0
            level0.platform_list.add(hidden_wall)

        # Define Level 1
        if init or level_num == 1:
            if init:
                level1 = Level()
                level1.start_pos = (0, constants.GROUND_HEIGHT - Player.HEIGHT)
                x = constants.SCREEN_WIDTH - self.player.rect.width
                y = constants.GROUND_HEIGHT - Player.HEIGHT
                level1.end_pos = (x, y)
            else:
                level1 = Level.level_list[1]
                level1.platform_list.empty()
                level1.enemy_list.empty()
                level1.tripped_projectiles.empty()

            platform0 = Platform(200, 60)
            platform0.rect.x = 0
            platform0.rect.y = constants.SCREEN_HEIGHT - platform0.rect.height
            level1.platform_list.add(platform0)

            platform1 = MovingPlatform(100, 20)
            platform1.player = self.player
            right = constants.SCREEN_WIDTH - platform1.rect.width - 140
            platform1.rect.x = right
            platform1.rect.y = constants.SCREEN_HEIGHT - 140
            platform1.x_change = -4
            platform1.boundary_left = 140
            platform1.boundary_right = right
            level1.platform_list.add(platform1)

            platform2 = Platform(200, 60)
            platform2.rect.x = constants.SCREEN_WIDTH - platform2.rect.width
            platform2.rect.y = constants.SCREEN_HEIGHT - platform2.rect.height
            level1.platform_list.add(platform2)

        # Define Level 2
        if init or level_num == 2:
            if init:
                level2 = Level()
                level2.start_pos = (0, constants.GROUND_HEIGHT - Player.HEIGHT)
                x = constants.SCREEN_WIDTH - self.player.rect.width
                y = constants.GROUND_HEIGHT - Player.HEIGHT
                level2.end_pos = (x, y)
            else:
                level2 = Level.level_list[2]
                level2.platform_list.empty()
                level2.enemy_list.empty()
                level2.tripped_projectiles.empty()

            platform0 = Platform(constants.SCREEN_WIDTH, 60)
            platform0.rect.x = 0
            platform0.rect.y = constants.SCREEN_HEIGHT - platform0.rect.height
            level2.platform_list.add(platform0)

            platform1 = Platform(20, constants.SCREEN_HEIGHT - 100)
            platform1.rect.x = constants.SCREEN_WIDTH / 2
            platform1.rect.y = 100
            level2.platform_list.add(platform1)

            platform2 = MovingPlatform(100, 20)
            platform2.player = self.player
            right = constants.SCREEN_WIDTH - platform2.rect.width - 140
            platform2.rect.x = right
            platform2.rect.y = constants.SCREEN_HEIGHT - 140
            platform2.x_change = -4
            platform2.boundary_left = 40
            platform2.boundary_right = right + 100
            level2.platform_list.add(platform2)

            platform3 = MovingPlatform(100, 20)
            platform3.player = self.player
            platform3.rect.x = 200
            platform3.rect.y = 300
            platform3.y_change = -2
            platform3.boundary_bottom = constants.GROUND_HEIGHT - 140
            platform3.boundary_top = 100
            level2.platform_list.add(platform3)

            cannon0 = Cannon("left")
            cannon0.game = self
            cannon0.rect.x = constants.SCREEN_WIDTH - Cannon.WIDTH
            cannon0.rect.y = constants.GROUND_HEIGHT - 80
            level2.platform_list.add(cannon0)

            cannon1 = Cannon("left")
            cannon1.game = self
            cannon1.rect.x = constants.SCREEN_WIDTH - Cannon.WIDTH
            cannon1.rect.y = cannon0.rect.y - 60
            cannon1.fire_counter = 45
            level2.platform_list.add(cannon1)

            tp0 = TrippedProjectile()
            tp0.player = self.player
            tp0.rect.x = 700
            tp0.rect.y = 50
            level2.tripped_projectiles.add(tp0)

        # define final level
        if init or level_num == len(Level.level_list) - 1:
            if init:
                final_level = Level()
                x = 100
                y = constants.GROUND_HEIGHT - Player.HEIGHT
                final_level.start_pos = (x, y)
                x = constants.SCREEN_WIDTH - self.player.rect.width
                final_level.end_pos = (x, y)
            else:
                final_level = Level.level_list[level_num]
                final_level.platform_list.empty()
                final_level.enemy_list.empty()
                final_level.tripped_projectiles.empty()

            platform0 = Platform(constants.SCREEN_WIDTH, 60)
            platform0.rect.x = 0
            platform0.rect.y = constants.SCREEN_HEIGHT - platform0.rect.height
            final_level.platform_list.add(platform0)

            hidden_wall = Platform(20, constants.SCREEN_HEIGHT)
            hidden_wall.rect.x = -20
            hidden_wall.rect.y = 0
            final_level.platform_list.add(hidden_wall)

            cannon0 = Cannon("left")
            cannon0.game = self
            cannon0.rect.x = constants.SCREEN_WIDTH - Cannon.WIDTH - 112
            cannon0.rect.y = constants.GROUND_HEIGHT - Cannon.HEIGHT
            final_level.platform_list.add(cannon0)

            boss = Boss()
            boss.game = self
            final_level.enemy_list.add(boss)
            final_level.platform_list.add(boss.health_bar)