Lv.1
我是屑
签名:小号__eq__, 大号__name__kP81.
在 【岛3-API教程3!】用方块检测,做一片刀山火海🌋 中回复

看~
代码:
function cylinder(cx,cy,cz,vox,radius,height){
var xend = cx+radius
var yend = cy+height
var zend = cz+radius
for(var x=cx-radius;x<=xend;x++){
for(var z=cz-radius;z<=zend;z++){
var dx = x-cx;
var dz = z-cz;
if(Math.round(Math.sqrt(dx*dx+dz*dz))<=radius){
for(var y=cy;y<yend;y++){
voxels.setVoxel(x,y,z,vox)
}
}
}
}
}
for (var i = 0; i < 300; i++) { // 300个随机圆柱体构成场景
let x = Math.random() * 125 // x坐标
let y = 9 + Math.random() * 20 //y坐标
let z = Math.random() * 125 // z坐标
let h = Math.random() * 4 // 高 0~4
let r = 2 + Math.random() * 5 //半径 2~7
cylinder(x, y, z, 'stone', r, h)
}
for(var y=9;y<125;y++){//扫描9~12层的格子
for(var x=0;x<127;x++){
for(var z=0;z<127;z++){
// 如果当前格子不为空而它上面那格是空的, 则表示它是复杂地形的表面
if(voxels.getVoxel(x,y,z)!=0 && voxels.getVoxel(x,y+1,z)==0){
voxels.setVoxel(x,y,z,'grass')
var rnd = Math.random()
var cx = x+0.5 // 修正到方块中心的x坐标
var cz = z+0.5 // 修正到方块中心的z坐标
if(rnd<0.01){
const ng= spawn(cx,y+1,cz,'mesh/小南瓜2.vb',1)
ng.meshEmissive=0.1
ng.meshColor=new Box3RGBAColor(1,1,0,1)
ng.a喵Tag('南瓜')
}
else if (rnd<0.02) {
spawn(cx,y+1,cz,'mesh/枯树1.vb',0.8)
} else if (rnd<0.03) {
spawn(cx,y+1,cz,'mesh/尖刺栏杆1.vb',0.8)
} else if (rnd<0.04) {
voxels.setVoxel(cx,y+1,cz,voxels.id('yellow_light'))
} else if (rnd<0.05) {
}
}
}
}
}
async function correctY(entity){
await sleep(1)//entity.bounds需要等到下一个tick才会变成真正的值
entity.position.y += entity.bounds.y//bounds.y是中心点到模型顶部或底部的距离
}
function spawn(x,y,z,meshName,scale){
const meshScale = scale/16 //默认模型方块大小倍数为地图方块的1/16
const entity = world.createEntity({
mesh:meshName,//模型名
collides:false,//不能碰撞
fixed:true,//固定
gravity:false,// 不受重力影响
meshScale:[meshScale,meshScale,meshScale],//xyz放大倍数
position:[x,y,z],//位置坐标
})
if (meshName==='mesh/小南瓜2.vb') {
voxels.setVoxel(x,y-1,z,voxels.id('yellow_light'))
}
correctY(entity)
return entity
}
链接:https://box3create.codemao.cn/games/18ca953836983d8f1fed
2020-11-07T09:05:36 点赞:0
在 教你怎么做彩虹字 中回复
本
彩
虹
字
生
成
器
可
生
成
一
段
带
有
颜
色
属
性
H
T
M
L
代
码
的
文
字
,
起
始
颜
色
和
结
束
颜
色
搭
配
得
当
将
产
生
多
色
平
滑
过
渡
2020-11-20T17:29:44 点赞:0
在 教你怎么做彩虹字 中回复
本
彩
虹
字
生
成
器
可
生
成
一
段
带
有
颜
色
属
性
H
T
M
L
代
码
的
文
字
,
起
始
颜
色
和
结
束
颜
色
搭
配
得
当
将
产
生
多
色
平
滑
过
渡
2020-11-22T13:51:52 点赞:0
在 【岛3圣诞更新🎄】创作节赢新皮肤,传送门API连通多个地图! 中回复
https://box3.codemao.cn/e/dfb6f14772bb7b929748
有人来帮忙吗?
2020-12-05T10:17:12 点赞:0
在 【岛3圣诞更新🎄】创作节赢新皮肤,传送门API连通多个地图! 中回复
https://shequ.codemao.cn/community/352475
2020-12-08T18:08:10 点赞:0
在 【🎄岛3大新闻】圣诞世界树即将诞生!哈农上空出现神秘身影…… 中回复
·地图名字:圣诞公园【】
·游玩链接:https://box3.codemao.cn/p/79861c4b5f7ef0da8f7b
·作品截图:
2020-12-10T18:20:10 点赞:1