Pygame - 在中心周围创建一个旋转弹丸

问题描述

我的问题更像是一个数学问题,由于我不太擅长数学,我想寻求帮助或任何想法。我想创建可以围绕敌人中心创建螺旋或围绕敌人中心旋转的射弹,如下图所示。现在,我只创建了敌人向各个方向随机发射弹丸,如您在视频中看到的那样。对某些数学公式有什么想法或如何做?

图片

enter image description here

视频: https://vimeo.com/534844958

每当敌人射击时,我都会在每个方向创建 4 个敌人射弹的对象,这是射弹移动的代码。这对我的问题并不重要,但至少你可以看到它是如何完成的。

class Enemy_projectile:
    projectiles = []

    def __init__(self,color,x,y,size,veLocity,direction,position):
        self.color = color
        self.x = x
        self.y = y
        self.size = size
        self.veLocity = veLocity
        self.hitBox = (self.x - self.size,self.y - 2,self.size * 2,self.size * 2)
        self.direction = direction # -1 or 1
        self.position= position # x or y

    def shoot(self,window):
        py.draw.circle(window,self.color,(self.x,self.y),self.size)
        if self.position == 1:
            self.y += self.veLocity * self.direction
        else:
            self.x += self.veLocity * self.direction
        self.hitBox = (self.x - self.size,self.size * 2)
        projectile_border = py.Rect(self.hitBox)
        if hitBoxes:
            py.draw.rect(window,(255,0),self.hitBox,2)
        if self.x >= width_window or self.x <= 0 or self.y >= height_window or self.y <= 0:
            Enemy_projectile.projectiles.remove(self)

        for element in Element.elements:
            element_border = py.Rect(element.hitBox)
            collision = element_border.colliderect(projectile_border)
            if collision:
                Enemy_projectile.projectiles.remove(self)


# This for loop runs in while loop
for projectile in Enemy_projectile.projectiles:
    projectile.shoot(window)


解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)