猫史档案馆


【Python作品分享】我的世界1-副本【作品秀】

用户:zzc20121202zzc20121202查看:0 回复:1 评论:0 创建时间:2023-07-30T19:59:02


【作品展示】

center_image

 

【作品介绍】

我的世界,(材质不行)wasd移动,空格跳跃,左键创建,右键删除,1234换方块esc或q键退出

 

【作品源代码】

from ursina import *
from  ursina.prefabs.first_person_controller import FirstPersonController
from perlin_noise import PerlinNoise
app=Ursina()
a=int(input('世界种子'))
grass_testure=load_texture('assets/grass_block.png')
stone_testure=load_texture('assets/stone_block.png')
brick_testure=load_texture('assets/brick_block.png')
dirt_testure=load_texture('assets/dirt_block.png')
sky_testure=load_texture('assets/skybox.png')
arm_testure=load_texture('assets/arm_texture.png')
punsh_sound=Audio('assets/punch_sound.wav',loop=False,autoplay=False)
block_pick=1
scene.fog_color=color.white
scene.fog_density=0.04
def input(key):
    if key=='escape' or key=='q':
        quit()
def update():
    global block_pick
    if held_keys['1']: block_pick = 1
    if held_keys['2']: block_pick = 2
    if held_keys['3']: block_pick = 3
    if held_keys['4']: block_pick = 4



class sky(Entity):
    def __init__(self):
        super().__init__(
            parent=scene,
            model='sphere',
            texture=sky_testure,
            scale=150,
            double_sided=True

        )
class Hand(Entity):
    def __init__(self):
        super().__init__(
            parent=camera.ui,
            model='assets/arm',
            texture=arm_testure,
            scale=0.2,
            rotation=Vec3(150,-10,0),
            position=Vec2(0.4,-0.6)
        )

class Block(Button):
    def __init__(self,position=(0,0,0,),texture=grass_testure):
        super().__init__(
            parent=scene,
            position=position,
            model='assets/block',
            origin_y=0.5,
            texture=texture,
            color=color.color(0,0,random.uniform(0.9,1)),
            highlight_color=color.green,
            scale=0.5
        )

    def input(self, key):
        if self.hovered:
            if key == 'left mouse down':
                punsh_sound.play()
                if block_pick == 1:
                    block = Block(position=self.position + mouse.normal,texture=grass_testure)
                if block_pick == 2:
                    block = Block(position=self.position + mouse.normal,texture=stone_testure)
                if block_pick == 3:
                    block = Block(position=self.position + mouse.normal,texture=brick_testure)
                if block_pick == 4:
                    block = Block(position=self.position + mouse.normal,texture=dirt_testure)
            if key == 'right mouse down':
                punsh_sound.play()
                destroy(self)

noise=PerlinNoise(octaves=3,seed=a)
scale=24

for z in range(100):
    for x in range(100):
        block=Block(position=(x,0,z))
        block.y=floor(noise([x/scale,z/scale])*8)


player=FirstPersonController()
sky=Sky()
hand=Hand()
app.run()

 

【提示】

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

https://python.codemao.cn


回复

上一页1 页 / 共 1下一页
|宸宸||宸宸|

把材质包发过来呀

没图片

啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊

点赞1


评论