Closed ShivamKR12 closed 8 months ago
from ursina import * from ursina.prefabs.first_person_controller import FirstPersonController
t = -1 app = Ursina() a = Audio('assets/song_Forest.mp3', pitch=1, loop=True, autoplay=True) a.volume=5 window.title = 'Minecraft_clone' # The window title window.borderless = False # Show a border window.fullscreen = False # Do not go Fullscreen
window.fps_counter.enabled = True window.cursor_hidden = False
grass_texture = load_texture("assets/download.jpg") sky_texture = load_texture("assets/sky.jpg") soil_texture = load_texture("assets/soil.jpg") tree_texture = load_texture("assets/tree.jpg") plank_texture = load_texture("assets/planks.jpg") leaf_texture = load_texture("assets/leaf.jpg") wall_texture = load_texture("assets/wall.jpg") stone_texture = load_texture("assets/stone.png") iron_texture = load_texture("assets/images.png") gold_texture = load_texture("assets/gold.png") wall_2_texture = load_texture("assets/1.png") current_texture = soil_texture
def update(): global current_texture if held_keys['q']: exit() if held_keys['Q']: exit() if held_keys['1']: current_texture = grass_texture if held_keys['2']: current_texture = soil_texture if held_keys['3']: current_texture = tree_texture if held_keys['4']: current_texture = plank_texture if held_keys['5']: current_texture = leaf_texture if held_keys['6']: current_texture = wall_texture if held_keys['7']: current_texture = stone_texture if held_keys['8']: current_texture = gold_texture if held_keys['9']: current_texture = iron_texture if held_keys['0']: current_texture = wall_2_texture
class Sky(Entity): def init(self): super().init( parent=scene, model='sphere', scale=150, texture=sky_texture, double_sided=True )
class Voxel(Button): def init(self, position=(0, 0, 0), texture=grass_texture): super().init( parent=scene, model='cube', color=color.white, texture=texture, highlight_color=color.white, position=position, origin__y=0.5 )
def input(self, key):
if self.hovered:
if key == "left mouse down":
voxel = Voxel(position=self.position + mouse.normal, texture= current_texture)
if key == "right mouse down":
destroy(self)
for z in range(6): for x in range(6): voxel = Voxel((x, 0, z), texture= grass_texture) while t >= -10: for z in range(6): for x in range(6): voxel = Voxel((x, t, z) , texture= soil_texture) t-=1 player = FirstPersonController() sky = Sky() app.run()
this is the code to which i am trying to add the code of the inventory, so please help me.
Can i have more details pls ?
ya, sure. so, i was trying to add inventory to a small game of mine but everytime i tryed to run the code, i got the same error (or similar error). i tryed many different iterations but non of them seemed to work properly. if you like, i can provide you with those codes that i tryed so you can look into it.
It's because you did Ursina()
multiple times. Remember that importing a module will run the code inside it. I suspect you either had Ursina() multiple places in one file, or you did Ursina() in a module you imported and in the file you ran.
However, this error you got is not possible in newer versions of ursina for quite some time, since it will detect duplicates and reuse the same instance again, thus allowing this behavior.
screen resolution: (1366, 768) Known pipe types: wglGraphicsPipe (3 aux display modules not yet loaded.) :pnmimage:png(warning): iCCP: known incorrect sRGB profile :ffmpeg(warning): Estimating duration from bitrate, this may be inaccurate Known pipe types: wglGraphicsPipe (3 aux display modules not yet loaded.) Traceback (most recent call last): File "c:\Users\Shivam\Desktop\voxel 3d\minecraft\try3.py", line 171, in
app = Ursina()
^^^^^^^^
File "C:\Users\Shivam\AppData\Local\Programs\Python\Python312\Lib\site-packages\ursina\main.py", line 28, in init
super().init()
File "C:\Users\Shivam\AppData\Local\Programs\Python\Python312\Lib\site-packages\direct\showbase\ShowBase.py", line 429, in init
raise Exception("Attempt to spawn multiple ShowBase instances!")
Exception: Attempt to spawn multiple ShowBase instances!