VB.net 2010 视频教程 VB.net 2010 视频教程 python基础视频教程
SQL Server 2008 视频教程 c#入门经典教程 Visual Basic从门到精通视频教程
当前位置:
首页 > 编程开发 > python爬虫 >
  • 打砖游戏,详解每一行代码,历经三个小时解析,初学可看(6)

collision_sign_by = 1#标识为1 elif self.ball_y > self.brick_y + self.brick_wide: self.closestpoint_by = self.brick_y + self.brick_wide self.collision_sign_by = 2#标识为2 else: self.closestpoint_by = self.ball_y self.collision_sign_by = 3#标识为3 # 定义砖块到圆心最近点与圆心的距离(两点距离公式,根号下横纵坐标差的平方和) self.distanceb = math.sqrt( math.pow(self.closestpoint_bx - self.ball_x, 2) + math.pow(self.closestpoint_by - self.ball_y, 2)) # 球在砖块上左、上中、上右3种情况的碰撞检测 这个跟球在球拍的上左,上中,上右是一样的类似解析,这就不概述了 if self.distanceb < self.radius and self.collision_sign_by == 1 and ( self.collision_sign_bx == 1 or self.collision_sign_bx == 2): if self.collision_sign_bx == 1 and self.move_x > 0: self.move_x = - self.move_x self.move_y = - self.move_y if self.collision_sign_bx == 1 and self.move_x < 0: self.move_y = - self.move_y if self.collision_sign_bx == 2 and self.move_x < 0: self.move_x = - self.move_x self.move_y = - self.move_y if self.collision_sign_bx == 2 and self.move_x > 0: self.move_y = - self.move_y if self.distanceb < self.radius and self.collision_sign_by == 1 and self.collision_sign_bx == 3: self.move_y = - self.move_y # 球在砖块下左、下中、下右3种情况的碰撞检测 跟球在球拍的三个方向类似解析,不清楚可以看球在球拍的这三个方向解析 if self.distanceb < self.radius and self.collision_sign_by == 2 and ( self.collision_sign_bx == 1 or self.collision_sign_bx == 2): if self.collision_sign_bx == 1 and self.move_x > 0: self.move_x = - self.move_x self.move_y = - self.move_y if self.collision_sign_bx == 1 and self.move_x < 0: self.move_y = - self.move_y if self.collision_sign_bx == 2 and self.move_x < 0: self.move_x = - self.move_x self.move_y = - self.move_y if self.collision_sign_bx == 2 and self.move_x > 0: self.move_y = - self.move_y if self.distanceb < self.radius and self.collision_sign_by == 2 and self.collision_sign_bx == 3: self.move_y = - self.move_y # 球在砖块左、右两侧中间的碰撞检测 if self.distanceb < self.radius and self.collision_sign_by == 3: self.move_x = -

相关教程