test.py 文件源码

python
阅读 27 收藏 0 点赞 0 评论 0

项目:fright-before-christmas-clone 作者: bobhob314 项目源码 文件源码
def update_velocity(self):
        HALF_WIDTH = const.WINDOW_WIDTH//2 - self.width//2
        if (const.BOMB_X+self.width/2) - self.dest_x == 0:
            self.vel_x = 0
            self.vel_y = self.SPEED
        elif (const.BOMB_Y+self.height/2) - self.dest_y == 0:
            if self.dest_x <= const.BOMB_X:
                ''' note the equals '''
                self.vel_x = -self.SPEED
                self.vel_y = 0
            elif self.dest_x > const.BOMB_X:
                self.vel_x = self.SPEED
                self.vel_y = 0
        else:
            '''(x+width/2, y+height/2) is the centre of the projectile image'''
            dy = self.dest_y - (const.BOMB_Y+self.height/2)
            dx = self.dest_x - (const.BOMB_X+self.width/2)
            radians = math.atan2(dy, dx)
            self.vel_y = math.sin(radians)*self.SPEED
            self.vel_x = math.cos(radians)*self.SPEED
            degrees = radians * 180.0 / math.pi
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号