python我的世界

我的世界不知道大家有没有玩过,今天博主用python的Ursina库复刻了我的世界给大家分享


  1. 安装Ursina
    pip install ursina
  2. 导入Ursina
    from ursina import *
    from ursina.prefabs.first_person_controller import FirstPersonController
  3. 创建app
    app = Ursina()
  4. 创建Voxel类
    class Voxel(Button):
  5. 创建自定义函数__init__
    def __init__(self, position=(0,0,0)):
            super().__init__(
                parent = scene,
                position = position,
                model = 'cube',
                origin_y = .5,
                texture = 'white_cube',
                color = color.color(0, 0, random.uniform(.9, 1.0)),
                highlight_color = color.lime,
            )
  6. 创建自定义函数input
    def input(self, key):
            if self.hovered:
                if key == 'left mouse down':
                    voxel = Voxel(position=self.position + mouse.normal)
    
                if key == 'right mouse down':
                    destroy(self)
  7. 用两个for循环创建一个25×1×25的地面
    for z in range(25):
        for x in range(25):
            voxel = Voxel(position=(x,0,z))
  8. 创建摄像机
    player = FirstPersonController()
  9.  运行app
    app.run()

效果:

python我的世界_第1张图片

到这里,一个基础的我的世界模型就做好了。接着博主参考了一些代码完善了这个模型:

python我的世界_第2张图片

下载:

python我的世界下载

你可能感兴趣的:(python3.11)