I'm developing a little game with Ursina and for some reason it doesn't show all the elements and ignores an update. The game is about clicking the randomly generated points. This is my code:
- menu.py (Main file)
from ursina import *
from point import *
from game import play, play_2
class Menu(Entity):
def __init__(self, **kwargs):
super().__init__(parent = camera.ui, ignore_paused = True)
self.main_menu = Entity(parent = self, enabled = True)
# More menus
Text(text = 'Main Menu', parent = self.main_menu, y=0.4, x=0, origin=(0,0))
def starting(): # Game starts
self.main_menu.disable()
play()
def update(): # The program ignores this update, so the following line isn't executed
play_2()
ButtonList(button_dict = {
'Start':Func(starting),
'Settings':Func(print, 'Settings was clicked')
}, y = 0, parent = self.main_menu)
app = Ursina(fullscreen = True)
menu = Menu()
app.run()
- point.py
from ursina import *
class Point(Entity):
def __init__(self, position = (0,0,0), parent = camera, **kwargs):
super().__init__(
parent = parent,
model = 'sphere',
scale = .04,
position = position,
collider = 'sphere'
)
def input(self, key):
global generate
global score
global missed
if key == 'left mouse down' and self.hovered:
score += 1
self.disable()
generate = True
if key == 'left mouse down' and self.hovered == False:
missed += 1
generate = False
score = 0
missed = 0
- game.py
from ursina import *
from point import Point, generate, score, missed
from random import uniform
score_text = Text(text = 'h')
missed_text = Text(text = 'h')
points = []
def play(): # Generates all the needed things and an init point
global score_text
global missed_text
camera.position = (0,0,-4)
camera.rotation_x = 10
board = Entity(parent = camera, model = 'quad', scale = 2, color = color.rgb(0,0,0), position = (0,0,3))
score_text.scale = 1
score_text.position = (.66,.43)
missed_text.scale = 1
missed_text.position = (.66,.4)
point = Point(parent = board)
def play_2(): # The actual game starts
global generate
global score
global missed
global score_text
global missed_text
global points
if generate == True:
point = Point(position = (uniform(-.44,.44), uniform(-.265,.265),-.1))
points.append(point)
generate = False
score_text.text = f'Score: {score}'
missed_text.text = f'Missed: {missed}'
In the second image you can see one of the points you need to click, however, it is supposed to appear another one in a random location, but it doesn't. Also, the score and missed clicks texts should appear, but they doesn't.
All help is appreciated.