我正在制作一个塔防游戏,而对于塔的范围,我做了一个圆圈,塔是它的中心点。虽然,当我使用pygame.draw.rect()绘制一个圆圈时,它似乎处于一个完全不同的位置。这是它的代码。
变量:
Radius = 50
Center_X = 100
Center_Y = 100
检查敌人是否在圆圈范围内:
for Enemy in Enemies:
if ((Enemy['Rect'].left + 10) - Center_X)^2 + ((Enemy['Rect'].top + (35/2)) Center_Y)^2 < Radius^2:
print(1)
绘制圆圈:
pygame.draw.circle(Window, Black, (Center_X, Center_Y), Radius, 0)
答案 0 :(得分:0)
使用pygame.Rect()
保持精灵位置。
Center_X = 100
Center_Y = 100
positon = pygame.Rect()
positon.centerx = Center_X
positon.centery = Center_Y
现在你可以画出来了
pygame.draw.circle(Window, Black, position.center, Radius, 0)
您可以将pygame.Rect()
与collision detection
在PyGame文档中查看更多内容:pygame.Rect()
答案 1 :(得分:0)
在Python中,取幂运算符为**
,而不是^
,即bitwise XOR operator。
2^2
0
32^1
33
相反:
2**2
4
32**1
32
所以:
if ((Enemy['Rect'].left + 10) - Center_X) ** 2 + ((Enemy['Rect'].top + (35/2)) - Center_Y)**2 < Radius**2: