Python实现超级玛丽游戏系列教程05添加地面,管道和阶梯冲突检测

配套视频教程

配套视频教程

项目代码

项目代码

冲突检测

Python实现超级玛丽游戏系列教程05添加地面,管道和阶梯冲突检测_第1张图片

添加地面冲突

Python实现超级玛丽游戏系列教程05添加地面,管道和阶梯冲突检测_第2张图片

Python实现超级玛丽游戏系列教程05添加地面,管道和阶梯冲突检测_第3张图片

Python实现超级玛丽游戏系列教程05添加地面,管道和阶梯冲突检测_第4张图片

Python实现超级玛丽游戏系列教程05添加地面,管道和阶梯冲突检测_第5张图片

Python实现超级玛丽游戏系列教程05添加地面,管道和阶梯冲突检测_第6张图片

Python实现超级玛丽游戏系列教程05添加地面,管道和阶梯冲突检测_第7张图片

添加管道冲突

Python实现超级玛丽游戏系列教程05添加地面,管道和阶梯冲突检测_第8张图片

Python实现超级玛丽游戏系列教程05添加地面,管道和阶梯冲突检测_第9张图片

Python实现超级玛丽游戏系列教程05添加地面,管道和阶梯冲突检测_第10张图片

添加阶梯冲突

Python实现超级玛丽游戏系列教程05添加地面,管道和阶梯冲突检测_第11张图片

Python实现超级玛丽游戏系列教程05添加地面,管道和阶梯冲突检测_第12张图片

添加冲突完成

  def setup_ground(self):
        """Create collideable rects for each section of the ground"""

        self.ground_rect1 = collider.Collider(0, c.GROUND_HEIGHT, 2953, 60)
        self.ground_rect2 = collider.Collider(3048, c.GROUND_HEIGHT, 635, 60)
        self.ground_rect3 = collider.Collider(3819, c.GROUND_HEIGHT, 2735, 60)
        self.ground_rect4 = collider.Collider(6647, c.GROUND_HEIGHT, 2300, 60)

        self.ground_group = pg.sprite.Group(self.ground_rect1,
                                            self.ground_rect2,
                                            self.ground_rect3,
                                            self.ground_rect4)

    def setup_pipes(self):
        """Create collideable rects for all the pipes"""

        self.pipe1 = collider.Collider(1202, 452, 83, 82)
        self.pipe2 = collider.Collider(1631, 409, 83, 140)
        self.pipe3 = collider.Collider(1973, 366, 83, 170)
        self.pipe4 = collider.Collider(2445, 366, 83, 170)
        self.pipe5 = collider.Collider(6989, 452, 83, 82)
        self.pipe6 = collider.Collider(7675, 452, 83, 82)

        self.pipe_group = pg.sprite.Group(self.pipe1, self.pipe2,
                                          self.pipe3, self.pipe4,
                                          self.pipe5, self.pipe6)

    def setup_steps(self):
        """Create collideable rects for all the steps"""

        self.step1 = collider.Collider(5745, 495, 40, 44)
        self.step2 = collider.Collider(5788, 452, 40, 44)
        self.step3 = collider.Collider(5831, 409, 40, 44)
        self.step4 = collider.Collider(5874, 366, 40, 176)

        self.step5 = collider.Collider(6001, 366, 40, 176)
        self.step6 = collider.Collider(6044, 408, 40, 40)
        self.step7 = collider.Collider(6087, 452, 40, 40)
        self.step8 = collider.Collider(6130, 495, 40, 40)

        self.step9 = collider.Collider(6345, 495, 40, 40)
        self.step10 = collider.Collider(6388, 452, 40, 40)
        self.step11 = collider.Collider(6431, 409, 40, 40)
        self.step12 = collider.Collider(6474, 366, 40, 40)
        self.step13 = collider.Collider(6517, 366, 40, 176)

        self.step14 = collider.Collider(6644, 366, 40, 176)
        self.step15 = collider.Collider(6687, 408, 40, 40)
        self.step16 = collider.Collider(6728, 452, 40, 40)
        self.step17 = collider.Collider(6771, 495, 40, 40)

        self.step18 = collider.Collider(7760, 495, 40, 40)
        self.step19 = collider.Collider(7803, 452, 40, 40)
        self.step20 = collider.Collider(7845, 409, 40, 40)
        self.step21 = collider.Collider(7888, 366, 40, 40)
        self.step22 = collider.Collider(7931, 323, 40, 40)
        self.step23 = collider.Collider(7974, 280, 40, 40)
        self.step24 = collider.Collider(8017, 237, 40, 40)
        self.step25 = collider.Collider(8060, 194, 40, 40)
        self.step26 = collider.Collider(8103, 194, 40, 360)

        self.step27 = collider.Collider(8488, 495, 40, 40)

        self.step_group = pg.sprite.Group(self.step1, self.step2,
                                          self.step3, self.step4,
                                          self.step5, self.step6,
                                          self.step7, self.step8,
                                          self.step9, self.step10,
                                          self.step11, self.step12,
                                          self.step13, self.step14,
                                          self.step15, self.step16,
                                          self.step17, self.step18,
                                          self.step19, self.step20,
                                          self.step21, self.step22,
                                          self.step23, self.step24,
                                          self.step25, self.step26,
                                          self.step27)

Python实现超级玛丽游戏系列教程05添加地面,管道和阶梯冲突检测_第13张图片

你可能感兴趣的:(game)