0
我目前正在尝试创建一个数字速度计。由于尝试控制拨号时遇到问题,该项目已陷入戛然而止。我的可变radial_pos旨在计算出准确的x,y坐标的速度计的每个刻度的,并且如果用户按下K_UP,radial_pos将增加1,以显示速度表的下一个勾号。不过,恐怕自从我学习了找到圆的坐标这个概念以来,这已经太多年了,更别说足够理解它,从而能够相应地增加它。这是我到目前为止的代码:如何查找Pygame中圆的x,y坐标
import pygame, sys
from pygame.locals import *
pygame.init()
#Screen Resolution
width = 1080
height = 720
#Instrument Characteristics
color = (255,255,255)
background = (0,0,0)
radius_speedometer = 100
weight_speedometer = radius_speedometer-5
#Window Measurements
screen= pygame.display.set_mode((width,height),0,32)
pos_center_x = width/2
pos_center_y = height/2
#Speedometer Dial Position
pos_speedometer_dial_x = pos_center_x - 60
pos_speedometer_dial_y = pos_center_y +60
#Radial Position (hint: ticks on the clock)
'''
radial_pos = ...
'''
while True:
for event in pygame.event.get():
if event.type==QUIT:
pygame.quit()
sys.exit()
if event.type==KEYDOWN:
if event.key==K_DOWN:
radial_pos=-1
if event.key==K_UP:
radial_pos=+1
if event.type==KEYUP:
if event.key==K_DOWN:
radial_pos=0
if event.key==K_UP:
radial_pos=0
screen.lock()
#Speedometer Ring
pygame.draw.circle(screen, color, (pos_center_x,pos_center_y), radius_speedometer)
pygame.draw.circle(screen, background, (pos_center_x,pos_center_y), weight_speedometer)
#Speedometer Dial
pygame.draw.line(screen, color, (pos_center_x,pos_center_y), (pos_speedometer_dial_x, pos_speedometer_dial_y),5)
screen.unlock()
pygame.display.update()
如果任何人有这个问题上的任何意见,这将不胜感激。感谢您的时间。
你已经给我们太多的代码来通过。下一次尝试将其降至[mcve]。 – Teepeemm