I'm trying to create a 2D game in ursina and I have a class FirstLevel
in which I create the player 2D entity, enemies, cubes etc and I also use this class' update
method for player action etc. In my main.py, first I create a menu like interface with Start & Exit buttons etc. and then if the start button is clicked I will run the first level.
My question is: can I create second class, say, SecondLevel
(inheriting from the first some info like the player speed, enemies etc.) and destroy the FirstLevel
class (after the first level boss is destroyed)? If not, does someone know how I can switch between different class Entities (which are levels in my case)?
The source code is here: https://github.com/VulpeanuAdrian/LordMuffinGame
def start_level():
global m
destroy(play)
destroy(help)
destroy(help_text)
destroy(exit_button)
destroy(cat_screen)
m = True
m = FirstLevel()
def help_text_func():
play.visible = True
exit_button.visible = True
destroy(help_text_bt)
def help_menu():
global help_text_bt
help_text_bt = Button(
text=help_text_string,
on_click=help_text_func,
scale=(1, 0.6),
x=-0.4,
y=0.35,
color=color.orange,
text_color=color.violet
)
if __name__ == '__main__':
app = Ursina()
window.fullscreen = True
cat_screen = Animation('cat_gif', fps=30, loop=True, autoplay=True, scale=(13, 13))
cat_screen.start()
play = Button(' Play ', on_click=start_level, scale=(0.095, 0.095), x=0, y=0, color=color.blue)
help = Button('Help', on_click=help_menu, scale=(0.095, 0.095), x=0, y=-0.1)
help_text = Text(text=help_text_string, x=-0.3, y=0.3, visible=False, color=color.random_color())
exit_button = Button(' Quit ', on_click=application.quit, x=0, y=-0.2, scale=(0.095, 0.095), color=color.red)