python-Pygame让雪碧的脸变成老鼠

我是Pygame的新手,但Python上的Kinda可以,我用俯视图创建一个僵尸射击游戏.
按下箭头键时,我设法使角色移动.但是现在我需要让播放器面对鼠标/光标而不需要一直单击屏幕.
有帮助吗?

解决方法:

for event in pygame.event.get():
    if event.type == MOUSEMOTION:
        mousex, mousey = event.pos
        # build a vector between player position and mouse position
        moveVector = (mousex-playerx, mousey-playery)

        """
        compute the angle of moveVector from current vector that player is facing (faceVector).
        you should be keeping and updating this unit vector, with each mouse motion
        assume you have initial facing vector as (1,0) - facing East
        """

        # compute angle as in [1]

        # rotate the image to that angle and update faceVector

[1]-如何找到两个向量之间的夹角:
http://www.euclideanspace.com/maths/algebra/vectors/angleBetween/index.htm

以小角度旋转时,图像可能会失去质量.在Pygame文档页面中进行了讨论:http://pygame.org/docs/ref/transform.html#pygame.transform.rotate

上一篇:python-敌人死后如何让他们丢钱?


下一篇:在 pygame 中好好玩玩精灵,滚雪球学 Python 游戏番