python我的世界
我的世界不知道大家有没有玩过,今天博主用python的Ursina库复刻了我的世界给大家分享
- 安装Ursina
pip install ursina
- 导入Ursina
from ursina import * from ursina.prefabs.first_person_controller import FirstPersonController
- 创建app
app = Ursina()
- 创建Voxel类
class Voxel(Button):
- 创建自定义函数__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,)
- 创建自定义函数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)
- 用两个for循环创建一个25×1×25的地面
for z in range(25):for x in range(25):voxel = Voxel(position=(x,0,z))
- 创建摄像机
player = FirstPersonController()
- 运行app
app.run()
效果:
到这里,一个基础的我的世界模型就做好了。接着博主参考了一些代码完善了这个模型:
下载:
python我的世界下载