在游戏中上下移动火球

2024-05-16 20:27:46 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个上下移动的火球,但问题是当它向下移动的时候,它有一个向下移动的快照,看起来火球实际上根本没有平稳地上下移动。有没有办法让这更好

VIDEO

我想让它像火球一样落下,而不是像弹跳一样

在我的主循环中,我有子弹移动的速度和方向

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"

Tags: andthetoaddifobjectischange
1条回答
网友
1楼 · 发布于 2024-05-16 20:27:46

使用^{}怎么样:

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

^{}

for shot in shots:
    shot.y = 200 + math.cos(math.radians(self.time)) * 500
    shot.time += 1
    if shot.time >= 360:
        shot.time = 0

相关问题 更多 >