猫史档案馆


【Python作品分享】rss

用户:RtsstsRtssts查看:0 回复:0 评论:0 创建时间:2023-07-02T17:31:13


【作品展示】

center_image

 

【作品介绍】

ursina minecraft

 

【作品源代码】

from ursina import*
from ursina.prefabs.first_person_controller import FirstPersonController
from perlin_noise import PerlinNoise
app=Ursina()
window.fps_counter.enabled=False
window.exit_button.visible=False
punch=Audio('assets/punch.wav',autoplay=False)
blocks=[load_texture('assets/grass.png'),load_texture('assets/stone.png'),load_texture('assets/gold.png'),load_texture('assets/lava.png'),load_texture('assets/sky.jpg')]
block_RTSSTS=0
def input(key):
    if key=='escape':quit()
    if key=='E':show.texture='assets/inventory.jpg'
def update():
    global block_RTSSTS,hand
    if held_keys['0']:block_RTSSTS=0
    if held_keys['1']:block_RTSSTS=1
    if held_keys['2']:block_RTSSTS=2
    if held_keys['3']:block_RTSSTS=3
    hand.texture=blocks[block_RTSSTS]
    if held_keys['right mouse']or held_keys['left mouse']:hand.active()
    else:hand.passive()
class Block(Button):
    def __init__(self,position=(0,0,0),texture='assets/grass.png'):
        super().__init__(
            parent=scene,
            position=position,
            model='assets/block',
            origin_y=0.5,
            texture=texture,
            color=color.white,
            scale=0.5,
            double_sided=True)
    def input(self, key):
        if self.hovered:
            if key=='right mouse down':
                punch.play()
                block=Block((self.position+mouse.normal),texture=blocks[block_RTSSTS])
            if key=='left mouse down':
                punch.play()
                destroy(self)
class Hand(Entity):
    def __init__(self):
        super().__init__(
            parent=camera.ui,
            model='assets/block',
            texture=blocks[block_RTSSTS],
            color=color.white,
            scale=0.2,
            rotation=Vec3(0,2,0),
            position=Vec2(0.5,-0.5),
            double_sided=True)
    def active(key):
        hand.position=Vec2(0.4,-0.4)
    def passive(key):
        hand.position=Vec2(0.5,-0.5)
class Sky(Entity):
    def __init__(self):
        super().__init__(
            parent=scene,
            model='cube',
            texture='assets/sky.jpg',
            scale=299,
            double_sided=True)
noise=PerlinNoise(octaves=2,seed=random.randint(1, 999999999))
for r in range(59):
    for s in range(59):
        block=Block((r,0,s))
        block.y=floor(noise([r/29,s/29])*5)
sky=Sky()
block=Block()
player=FirstPersonController()
hand=Hand()
if __name__=='__main__':
    print('Welcome Rtssts Minecraft')
    print('SEED:',random.randint(1,999999999))
    print('Minecraft is loading...')
    time.sleep(9)
    app.run()

 

【提示】

部分含有Python第三方库相关内容的作品,在海龟编辑器网页端无法运行哦!如遇到这种情况,可以打开下面的链接,下载海龟编辑器客户端:

https://python.codemao.cn


回复

上一页1 页 / 共 0下一页