我有一个Minecraft的克隆,我想看看玩家是否从岛上掉下来,它会退出游戏.我想如果我写的话.

if player.position == Vec3(x, -80, z):
     quit()

它会退出游戏

这是Minecraft的克隆代码.

from ursina import *
from ursina.prefabs.first_person_controller import FirstPersonController
app = Ursina()

grass_color = color.rgb(1, 235, 113)
stone_color = color.rgb(138,141,143)
dirt_color = color.rgb(200, 157, 124)

block_pick = 1

def update():
    if held_keys['escape']:
        quit()

    global block_pick

    if held_keys['1']: block_pick = 1
    if held_keys['2']: block_pick = 2
    if held_keys['3']: block_pick = 3

class Voxel(Button):
    def __init__(self, position = (0,0,0), color = color.white):
        super().__init__(
            parent = scene,
            position = position,
            model = 'cube',
            origin_y = 0.5,
            texture = 'white_cube',
            color = color,
            highlight_color = color,
                    )

    def input(self,key):
        if self.hovered:
            if key == 'right mouse down':
                if block_pick == 1:voxel = Voxel(position = self.position + mouse.normal, color = grass_color)
                if block_pick == 2:voxel = Voxel(position = self.position + mouse.normal, color = stone_color)
                if block_pick == 3:voxel = Voxel(position = self.position + mouse.normal, color = dirt_color)
            if key == 'left mouse down':
                destroy(self)
            
for z in range(20):
    for x in range(20):
        voxel = Voxel(position=(x,0,z), color = grass_color)

for y in range(3):
    for x in range(20):
        for z in range(20):
            voxel = Voxel(position=(x,y + -3,z), color = dirt_color)

player = FirstPersonController()
app.run()

推荐答案

你只判断了球员y位置的一个值,这是行不通的——毕竟,你很快就会摔倒.你可以判断球员的身高是否低于某个临界值:

def update():
    if player.y < -80:
        print('You fell to death!')
        app.quit()

Python相关问答推荐

查找3D数组中沿一个轴的相同值序列的长度(与行程长度编码相关)

如何从不同长度的HTML表格中抓取准确的字段?

键盘.任务组

pyramid 内部数组中的连续序列-两极

在Arrow上迭代的快速方法.Julia中包含3000万行和25列的表

使用matplotlib pcolormesh,如何停止从一行绘制的磁贴连接到上下行?

Python无法在已导入的目录中看到新模块

理解Python的二分库:澄清bisect_left的使用

如何使用Python将工作表从一个Excel工作簿复制粘贴到另一个工作簿?

'discord.ext. commanders.cog没有属性监听器'

如何使用表达式将字符串解压缩到Polars DataFrame中的多个列中?

SQLAlchemy Like ALL ORM analog

为一个组的每个子组绘制,

计算分布的标准差

Python Pandas获取层次路径直到顶层管理

解决调用嵌入式函数的XSLT中表达式的语法移位/归约冲突

可以bcrypts AES—256 GCM加密损坏ZIP文件吗?

lityter不让我输入左边的方括号,'

Geopandas未返回正确的缓冲区(单位:米)

ruamel.yaml dump:如何阻止map标量值被移动到一个新的缩进行?