0

so I am laying the foundations for a small project within my computer science class and I am still relatively new to programming with python, and this is my first real project with Ursina 3D game engine for python.

Anyway, I am remaking an aim trainer, like Kovaaks, and I would like to implement a challenge feature, where when I press tab, (eventually the play button), it starts a 60 second timer, clears the points to 0, then stops recording the points when the timer ends. However, every time I try to implement a sleep timer, it freezes the whole program and never actually starts anything. How could I do this?

# -*- 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()
  • Use a thread for the timer, and have it signal your main app when it has elapsed – 2e0byo Oct 05 '21 at 22:27
  • `sleep()` is not a timer, it just pauses your program. An easy way would be to record the time when the button was pressed and keep checking if it's expired on every frame. – Jan Wilamowski Oct 06 '21 at 04:53

1 Answers1

-1

Something like this:

timer = Text(text='60', t=60)
def update():
    time.t -= time.dt
    timer.text = str(round(timer.t, 2))
pokepetter
  • 1,383
  • 5
  • 8