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
评论列表
文章目录