我有一个上下移动的火球,但问题是当它向下移动的时候,它有一个快速移动的动作,它看起来不像火球实际上是平稳地上下移动的。有什么办法能让情况好转吗?
视频我想让它像火球一样落下,而不是有那种弹跳的效果。
在我的主循环中,我有子弹移动的速度和方向。
for shot in shots:
if shot.direction == "down": # if the direction is down add to the y
shot.y += 2
if shot.direction == "up": # if the direction is up minus- to the y
shot.y -= 2
if shot.y <= 200: # if the object y is <= 200 then change the direction and add to the y
shot.direction = "down"
if shot.y >= 700: # if the object y is >= 700 then change the direction and minus the y
shot.direction = "up"
使用math.sin
:
class shot:
def __init__(self,x,y,height,width,color):
self.x = x
self.y = y
self.time = 0
# [...]
for shot in shots:
shot.y = 700 - math.sin(math.radians(self.time)) * 500
shot.time += 1
if shot.time >= 180:
shot.time = 0
或math.cos
:
for shot in shots:
shot.y = 200 + math.cos(math.radians(self.time)) * 500
shot.time += 1
if shot.time >= 360:
shot.time = 0