有没有办法将Perlin噪声合并到我的“我的世界”克隆中?我尝试了许多不同的方法,但都不起作用。
下面是我的代码片段:
from ursina import *
from ursina.prefabs.first_person_controller import FirstPersonController
from ursina.shaders import camera_grayscale_shader
app = Ursina()
grass = 'textures/grass.jpg'
class Voxel(Button):
def __init__(self, position = (0,0,0), texture = grass):
super().__init__(
model='cube',
texture=texture,
color=color.color(0,0,random.uniform(.823,.984)),
parent=scene,
position=position,
)
def input(self, key):
if self.hovered:
if key == 'right mouse down':
voxel = Voxel(position = self.position + mouse.normal, texture = plank)
if key == 'left mouse down':
destroy(self)
for z in range(16):
for x in range(16):
voxel = Voxel(position = (x,0,z))我正在尝试使用立方体和Perlin的噪波来创建随机生成的地形。没有关于如何使用它的教程。
发布于 2021-02-07 23:33:01
我是一个12岁的游戏开发人员,我猜这可能是你的问题的解决方案这不是完美的我使用随机模块使x,y和z值随机化,你可以根据你的喜好对这些值进行调整我很抱歉,如果代码中有缩进错误,顺便说一下,这是代码:
from ursina import *
from ursina.prefabs.first_person_controller import FirstPersonController
from ursina.shaders import camera_grayscale_shader
import random
app = Ursina()
class Voxel(Button):
def __init__(self, position=(0, 0, 0)):
super().__init__(
model='cube',
texture=texture,
color=color.color(0, 0, random.uniform(.823, .984)),
parent=scene,
position=position,
)
def input(self, key):
if self.hovered:
if key == 'right mouse down':
voxel = Voxel(position=self.position + mouse.normal)
if key == 'left mouse down':
destroy(self)
for z in range(random.randint(5,10)):
print(z)
for x in range(random.randint(5,7)):
print(x)
voxel = Voxel(position=(x, random.randint(0,2), z))
player = FirstPersonController()
app.run()这是该产品的屏幕截图:
发布于 2021-09-28 14:23:57
是的,有一种方法可以将perlin噪声合并到一个“我的世界”克隆中。
from perlin_noise import PerlinNoise
import random
noise = PerlinNoise (octaves=3,seed=random.randint(1,1000000))
for z in range(-10,10):
for x in range(-10,10):
y = noise([x * .02,z * .02])
y = math.floor(y * 7.5)
voxel = Voxel(position=(x,y,z))这是一个简单的示例,演示了如何在“我的世界”克隆中创建随机地形,最终结果如下:https://imgur.com/a/VZd1Uip
请记住,您需要安装perlin noise,为此,只需在终端中写入以下内容: pip install perlin-noise
https://stackoverflow.com/questions/65888586
复制相似问题