猫史档案馆


【Python作品分享】Mc.py【教程贴】

用户:ღ小宇ོꦿ࿐ღ小宇ོꦿ࿐查看:0 回复:0 评论:0 创建时间:2023-03-26T09:39:29


【作品展示】

center_image

 

【作品介绍】

rtrtndygvbfghd

 

【作品源代码】

from ursina import *
from ursina.prefabs.first_person_controller import FirstPersonController

app = Ursina()

grass_texture = load_texture('assets/grass_block.png')
stone_texture = load_texture('assets/stone_block.png')
brick_texture = load_texture('assets/brick_block.png')
dirt_texture = load_texture('assets/dirt_block.png')
block_pick = 0

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 Block(Button):
    def __init__(self,position=(0,0,0),texture = grass_texture):
        super().__init__(
            parent = scene,
            position = position,
            model = 'assets/block',
            orgin_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':
                if block_pick == 1:block = Block(position=self.position+mouse.normal, texture=grass_texture)
                if block_pick == 2:block = Block(position=self.position+mouse.normal, texture=stone_texture)
                if block_pick == 3:block = Block(position=self.position+mouse.normal, texture=brick_texture)
                if block_pick == 4:block = Block(position=self.position+mouse.normal, texture=dirt_texture)
            if key == 'right mouse down':
                destroy(self)

for z in range(8):
    for x in range(8):
        block = Block(position = (x,0,z))

player = FirstPersonController()

app.run()

 

【提示】

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

https://python.codemao.cn


回复

上一页1 页 / 共 0下一页