所以我正在为我的计算机科学课上的一个小项目奠定基础,我对使用 python 编程仍然相对较新,这是我第一个使用 Ursina 3D 游戏引擎的真正项目。
无论如何,我正在重新制作一个瞄准训练器,比如 Kovaaks,我想实现一个挑战功能,当我按下 Tab 时(最终是播放按钮),它会启动 60 秒计时器,将点数清零,然后停止记录计时器结束时的点数。但是,每次我尝试实现睡眠定时器时,它都会冻结整个程序,并且实际上从未启动任何东西。我怎么能这样做?
# -*- coding: utf-8 -*-
"""
Created on Tue Oct 5 16:46:24 2021
@author: gf112234
"""
import random
from ursina import *
from ursina.prefabs.first_person_controller import FirstPersonController
##########
# update #
##########
def update():
pass
#########
# start #
#########
def targetspawn():
xpos = random.randrange(-10,10)
ypos = random.randrange(-6,6)
zpos = random.randrange(17,20)
return xpos, ypos, zpos
points = -3
def spawn():
global points
points += 1
xpos, ypos, zpos = targetspawn()
target1.position=(xpos, ypos, zpos)
def spawn2():
global points
points += 1
xpos, ypos, zpos = targetspawn()
target2.position=(xpos, ypos, zpos)
def spawn3():
global points
points += 1
xpos, ypos, zpos = targetspawn()
target3.position=(xpos, ypos, zpos)
def input(key):
if key == 'tab':
global points
points = 0
# print(points)
######################
# Application Window #
######################
app = Ursina()
window.title = 'Static-Click 3 Targets'
window.borderless = False
window.fullscreen = True
mouse.locked = True
ground = Entity(model='plane', scale=(2,1,1), color=color.blue, collider='box')
crosshair = Entity(parent=camera.ui, model='quad', color=color.pink, scale=0.007, rotation_z=45)
player = FirstPersonController(y=0, origin_y=0, mouse_sensitivity=(10,10))
target1 = Button(parent=scene, model='sphere', color=color.blue, position=(0 ,0, 0), collider='sphere')
spawn()
target2 = Button(parent=scene, model='sphere', color=color.red, position=(0 ,0, 0), collider='sphere')
spawn2()
target3 = Button(parent=scene, model='sphere', color=color.yellow, position=(0 ,0, 0), collider='sphere')
spawn3()
target1.on_click = spawn
target2.on_click = spawn2
target3.on_click = spawn3
input('tab')
update()
app.run()