python-3.x - 当我尝试在 Pygame 中使用鼠标事件和按键事件时,它不起作用
问题描述
您好,我想在 Pygame 中寻求帮助。我正在尝试制作类似于 osu 的非常非常 aliexpress 版本的东西,而我的问题是让我们说有两个不同的圆圈,一个是红色的,一个是蓝色的
x = random.randint(100, 650)
y = random.randint(100, 650)
circle_list = [circlered, circleblue]
circle = random.choice(circle_list)
window.blit(circle,(x,y))
这就是我画圆的方式
现在我想知道是否在右圆圈中按下了右键对于红色圆圈,键是 K_x 对于蓝色圆圈,键是 K_y
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_x and incircle == True and circle == circlered:
window.blit(background, (0,0))
x = random.randint(100, 650)
y = random.randint(100, 650)
circle_list = [circlered, circleblue]
circle = random.choice(circle_list)
window.blit(circle,(x,y))
incircle = False
if event.key == pygame.K_c and incircle == True and circle == circleblue:
window.blit(background, (0,0))
x = random.randint(100, 650)
y = random.randint(100, 650)
circle_list = [circlered, circleblue]
circle = random.choice(circle_list)
window.blit(circle,(x,y))
incircle = False
顺便说一句,“incircle”是让程序知道光标是否在圆圈中:D
好的,这里的问题是我可以按 x 或 c 并且它仍然可以完成任务可能不会有时我可以在红色圆圈上按 c 有时我可以在蓝色圆圈上按 x
如果您需要查看整个代码: https ://paste.pythondiscord.com/oyipamataf.apache
每一个帮助都非常感谢!
解决方案
推荐阅读
- opencl - 强制工作组中的所有线程执行相同的 if/else 分支
- clang - 在运行时更改 LLVM Xray 指令
- python - 在字典中查找产生一定总和的键组合
- taxonomy - Umbraco 8 中是否有分层分类支持?
- angular - Ionic 从页面中的另一个组件打开一个 Popover
- python - 二维嵌套字典是否比 python 中带有 if 语句的几个扁平字典更快?
- c# - C#关闭另一个应用程序打开的Excel实例
- c# - System.ExecutionEngineException 使用特定的 .dll (CodeArtEng.Gauge.dll)
- reactjs - 反应管理员未满足的对等依赖项警告
- r - R中的缺失值Jarque Bera测试