所以我正在为我的计算机科学类中的一个小项目奠定基础,我仍然是相对较新的python编程,这是我的第一个真正的项目与Ursina 3D游戏引擎的python。
无论如何,我正在重新制作一个目标训练器,如Kovaaks,我想执行一个挑战功能,当我按下tab时,(最终是播放按钮),它开始一个60秒的计时器,清除点到0,然后在计时器结束时停止记录点。然而,每次我试图实现一个睡眠计时器,它冻结了整个程序,从来没有真正启动任何东西。我怎么能这么做?
# -*- 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()
像这样:
timer = Text(text='60', t=60)
def update():
time.t -= time.dt
timer.text = str(round(timer.t, 2))