一次按多个键可使我的角色沿对角线移动 [英] Press multiple keys at once to get my character to move diagonally

查看:87
本文介绍了一次按多个键可使我的角色沿对角线移动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到的问题是,当用户按下K_UP键和K_RIGHT键或K_UP键和K_DOWN键等时,我试图使我的角色在屏幕上对角移动.这是我的角色代码运动(事件处理):

The problem I'm having is that I'm trying to make my character move diagonally on screen when a user presses either the K_UP key and K_RIGHT key or the K_UP key and K_DOWN key, etc. Here is my code for character movement (event handling):

1. #Event Handling
2. for event in pygame.event.get():
3.     if event.type == pygame.QUIT: 
4.         sys.exit()
5.     elif (event.type == KEYDOWN):
6.         if ((event.key == K_ESCAPE)
7.             or (event.key == K_q)):
8.             sys.exit()
9.         if (event.key == K_UP):
10.            self.char_y = self.char_y - 10
11.        if (event.key == K_DOWN):
12.            self.char_y = self.char_y + 10
13.        if (event.key == K_RIGHT):
14.            self.char_x = self.char_x + 10
15.        if (event.key == K_LEFT):
16.            self.char_x = self.char_x - 10

推荐答案

您可以通过 查看全文

登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆