我和一些朋友一直在編碼一個有趣的新射擊機制。爲了它的工作,我們需要朝着玩家面對的方向射擊。 Sprite被Pygame.Transform.Rotate旋轉。我們怎樣才能找到一個角度,並朝這個方向發射我們的子彈?Pygame旋轉射擊
這裏是我們的的雪碧
char_image_number = pygame.mouse.get_pressed()
if char_image_number == (0, 0, 0):
char_image = pygame.image.load(player_none).convert_alpha()
char_image = pygame.transform.rotate(char_image, angle)
screen.blit(background, (0,0))
screen.blit(char_image,(540, 260))
pygame.display.update()
elif char_image_number == (1, 0, 0):
print (angle)
char_image = pygame.image.load(player_left).convert_alpha()
angle+=1
char_image = pygame.transform.rotate(char_image, angle)
screen.blit(background, (0,0))
screen.blit(char_image,(540, 260))
pygame.display.update()
elif char_image_number == (0, 0, 1):
print (angle)
angle-=1
char_image = pygame.image.load(player_right).convert_alpha()
char_image=pygame.transform.rotate(char_image, angle)
screen.blit(background, (0,0))
screen.blit(char_image,(540, 260))
pygame.display.update()
elif char_image_number == (1, 0, 1):
char_image = pygame.image.load(player_both).convert_alpha()
char_image = pygame.transform.rotate(char_image, angle)
screen.blit(background, (0,0))
screen.blit(char_image,(540, 260))
pygame.display.update()
我們怎樣才能拍出的球員面臨的角度旋轉代碼?
使用帶'angle'和一些'speed'值三角函數得到'move_x'和'move_y' – furas
你能聯繫我的教程或文檔?我熟悉矢量,但不知如何在代碼中做到這一點。 – user2975896