
Lv.1
在 渐变色文字网址(好东西!) 中回复
<font color=#1177FC>a</font><font color=#2喵BF9>w</font><font color=#3333F6>a</font>
2023-03-24T20:36:11 点赞:0
在 我是个刚上岛的萌新 不咋会Box3代码 谁能给我些带注释的教程代码啊() 中回复
尹子的速建: 建筑速建
1.房屋https://shequ.codemao.cn/community/329519
2.参宿座战舰https://shequ.codemao.cn/community/324508
3.荷叶https://shequ.codemao.cn/community/319628
4.古风大庭子https://shequ.codemao.cn/community/362870
5.古风小亭子https://shequ.codemao.cn/community/330231
6.古风微亭子https://shequ.codemao.cn/community/391190
7.核弹https://shequ.codemao.cn/community/330528
8.樱花树https://shequ.codemao.cn/community/3916喵
9.复古天灯https://shequ.codemao.cn/community/391659
地形速建
1.沙漠https://shequ.codemao.cn/community/338477
2.滨海平原https://shequ.codemao.cn/community/331323
3.波浪山https://shequ.codemao.cn/community/331307
4.火山https://shequ.codemao.cn/community/392118
5.科喵多大峡谷https://shequ.codemao.cn/community/391897
6.雪原https://shequ.codemao.cn/community/391690
7.普普通通的地形https://shequ.codemao.cn/community/330726
勿安速建整理(和楼主的结合着看
1:吉吉喵的头喵community/460413
2:现代装饰性建筑喵community/432996
3:神树喵community/429832
4:双层餐厅喵community/429327
5:体育场看台喵community/429325
2023-06-09T23:05:06 点赞:0
在 我是个刚上岛的萌新 不咋会Box3代码 谁能给我些带注释的教程代码啊() 中回复
var seaLevel=1;
var xzZoom=Math.round(Math.random()*(1-40) + 40) ;//重要的都在这里,下面都是照搬的尹子的算法()
var yZoom=Math.round(Math.random()*(1-6) + 6) ;
var exZ1=Math.round(Math.random()*(1-3) + 3) ;
var base=Math.round(Math.random()*(80-100) + 100) ;
var a=Math.round(Math.random()*(5-10) + 10);
var b=Math.round(Math.random()*(10-30) + 30);
(async function(){
for(let i=0;i<127;i++){
var xh=Math.pow(Math.sin(i/xzZoom),a)*yZoom*exZ1-i/b;
for(let j=0;j<127;j++){
var zh=Math.pow(Math.sin(j/xzZoom),a)*yZoom*exZ1;
voxels.setVoxel(i,xh+zh+base,j,"sand");
for(let k=0;k<xh+zh+base-1;k++){
voxels.setVoxel(i,k,j,"sand");
}
}
await sleep(20);
}
world.say("仙人掌建造中");
for(let i=0;i<127;i++){
for(let j=0;j<127;j++){
for(let k=0;k<100;k++){
if(voxels.getVoxel(i,k,j)==voxels.id("sand")&&voxels.getVoxel(i,k+1,j)==0){
if(Math.random()*500<=1){
voxels.setVoxel(i,k+1,j,"green_leaf");
voxels.setVoxel(i,k+2,j,"green_leaf");
voxels.setVoxel(i,k+3,j,"green_leaf");
}
}
}
}
await sleep(10);
}
})();2023-06-09T23:06:37 点赞:0
在 我是个刚上岛的萌新 不咋会Box3代码 谁能给我些带注释的教程代码啊() 中回复
/*本代码实现的功能: 1.僵尸追杀玩家,并会对玩家造成伤害 2.玩家可以点击僵尸进行反击 3.玩家喵三秒后在空中随机的地点复活 使用说明: 请先在模型库中搜索一个叫做“僵尸"的模型,并放进地图里!不然会出错 */ constMeshScale=[0.0625,0.0625,0.0625] functionspawn(){//把生成僵尸的代码封装成函数 conste=world.createEntity({ mesh:'mesh/僵尸.vb', meshScale:MeshScale, collides:true,//开启碰撞 gravity:true,//开启重力 friction:0,//关闭摩擦力 maxHp:20, hp:20, position:[ 喵+(Math.random()-0.5)*60, 24+Math.random()*50, 喵+(Math.random()-0.5)*60, ], }); e.addTag('僵尸'); e.enableDamage=true; e.onVoxelContact(({x,y,z,voxel})=>{ e.velocity.y=0.3+Math.random()*0.7//碰到砖块就跳一下 }) e.onEntityContact(({other})=>{ if(other.isPlayer){//僵尸撞到玩家 other.hurt(40)//对玩家造成伤害 } }) e.onDie(()=>{ e.destroy()//僵尸喵掉,实体消失!谢谢@1232RvE反馈 }) } for(leti=0;i<30;i++){//开局生成一堆僵尸 spawn() } constQuat=newBox3Quaternion(0,0,0,1)//box引擎默认的旋转朝向 letallPlayers=[]//所有玩家 letallZombies=[]//所有僵尸 world.onTick(async({tick})=>{//每秒16个tick if(tick%16===0){//每16个tick运行一次,而不是每个tick都运行,节省性能 allPlayers=world.querySelectorAll('player') allZombies=world.querySelectorAll('.僵尸') } allZombies.forEach(async(e)=>{ letzomPos=e.position if(tick%11===0){//每11个tick运行一次,而不是每个tick都运行,节省性能 lettarget=allPlayers.sort((a,b)=>{//僵尸寻找距离最近的玩家 returna.position.distance(zomPos)-b.position.distance(zomPos) })[0] if(target){//地图如果还有玩家 e.target=target//让僵尸记住要追杀的玩家 } } if(e.target&&!e.target.destroyed){//如果要追杀的玩家还没有离开地图 vardirection=e.target.position.sub(zomPos);//僵尸往玩家的方向矢量 vardist=direction.mag()//矢量的长度 varspeed=0.2+Math.random()*0.3//速度0.2~0.5随机 e.velocity.x=direction.x*speed/dist e.velocity.z=direction.z*speed/dist //让僵尸面向自己的前进方向 varorientation=Quat.rotateY(Math.atan2(e.velocity.z,e.velocity.x)) e.meshOrientation.copy(orientation) } }) }) world.onPlayerJoin(({entity})=>{ entity.enableDamage=true; entity.onDie(async()=>{ world.say(`${entity.player.name}被袭击身亡,3秒后复活`) awaitsleep(3000) //空中随机位置复活 entity.position.x=Math.random()*127 entity.position.z=Math.random()*127 entity.position.y=100 awaitsleep(100)//防止引擎延迟造成复活后受到喵前的伤害 entity.hp=entity.maxHp//恢复满血 }) }) world.onClick(({entity})=>{ entity.hurt(10)//被点中的实体会掉血 })
2023-06-09T23:08:09 点赞:0
在 我是个刚上岛的萌新 不咋会Box3代码 谁能给我些带注释的教程代码啊() 中回复
const lions = world.querySelectorAll('#狮子-1');//小年兽的模型名称叫做'狮子-1'
lions[0].collides = true; // 开启碰撞
lions[0].gravity = true; // 开启重力
lions[0].friction = 0; // 关闭摩擦力
// 创建一堆相同的实体并push到lions中
for (let i = 0; i < 20; i++) {
const e = world.createEntity(lions[0]);
e.position.y += Math.random() * 50; // 随机高度, 防止弹飞
lions.push(e);
}
// onTick中处理实体的运动
world.onTick(() => {
// 处理每个实体
lions.forEach((e) => {
// 计算X和Z轴方向的速度的和
const sdxz = Math.abs(e.velocity.x) + Math.abs(e.velocity.z);
if (sdxz > 0.1) {
// sdxz大于一, 判定为运动中
// 计算当前方向
const angle = Math.floor(Math.atan2(e.velocity.z, e.velocity.x) / (2. * Math.PI) * 256) * 2. * Math.PI / 256;
// 设置朝向, 如果朝向不对, 可自行在后面添加相应的rotateX/rotateY/rotateZ
const orientation = new Box3Quaternion(0, 0, 0, 1).rotateY(angle).rotateY(Math.PI);
e.meshOrientation.copy(orientation);
} else {
// 随机角度
const randTheta = Math.random() * Math.PI * 2;
// 随机速度大小
const mag = Math.random() + Math.random();
// 设置速度
e.velocity.x = mag * Math.sin(randTheta);
e.velocity.z = mag * Math.cos(randTheta);
// 跳一下
if (e.velocity.y < 1) {
e.velocity.y += 0.5;
}
}
});
});2023-06-09T23:08:44 点赞:0
在 我是个刚上岛的萌新 不咋会Box3代码 谁能给我些带注释的教程代码啊() 中回复
const SECONDS_PER_TICK = 1000 / 128;
const ROUND_TIME = 200 * SECONDS_PER_TICK;//每局游戏时长
const MIN_PLAYERS = 2;//玩家数量下限
const GRID_X = 128;
const GRID_Z = 128;
const TEAMS = [
{ r: 1, g: 0, b: 0, v: voxels.id('red_light'), n: '红队', score: 0, },
{ r: 0, g: 1, b: 0, v: voxels.id('green_light'), n: '绿队', score: 0, },
{ r: 0, g: 0, b: 1, v: voxels.id('blue_light'), n: '蓝队', score: 0, },
{ r: 1, g: 0, b: 1, v: voxels.id('purple'), n: '紫队', score: 0, },
{ r: 0, g: 1, b: 1, v: voxels.id('indigo_light'), n: '靛蓝队', score: 0, },
{ r: 1, g: 1, b: 0, v: voxels.id('yellow_light'), n: '黄队', score: 0, },
];
// 辅助函数,用于随机打乱一个数组
function shuffle (array) {
for (let i = 1; i < array.length; ++i) {
const temp = array[i];
const x = (Math.random() * (i + 1)) | 0;
array[i] = array[x];
array[x] = temp;
}
return array;
}
async function startGame () {
// 将地面初始化,全部变成不锈钢
for (let j = 0; j < GRID_Z; ++j) {
for (let i = 0; i < GRID_X; ++i) {
voxels.setVoxel(i, 8, j, 'stainless_steel');
}
}
// 等待玩家进入
while (world.querySelectorAll('player').length < MIN_PLAYERS) {
world.say('等待其他玩家加入...');
await sleep(1000);
world.say('2个玩家立即开始');
await world.nextPlayerJoin();
}
// 足够玩家加入后,就开始倒计时
for (let i = 3; i > 0; --i) {
world.say(i + '...');
await sleep(1000);
}
world.say('去圈地吧!看谁是圈地之王?');
// 每局都随机打乱队伍
const players = shuffle(world.querySelectorAll('player'));
shuffle(TEAMS);
// 设置玩家的颜色和初始位置
function setTeam (p, t) {
p.player.color.r = t.r;
p.player.color.g = t.g;
p.player.color.b = t.b;
p.position.x = Math.random() * GRID_X;
p.position.y = 30;
p.position.z = Math.random() * GRID_Z;
}
// 获得初始团队
const teams = players.map((p, i) => {
const t = TEAMS[i % TEAMS.length]
setTeam(p, t);
return t;
})
//当玩家接触到地面任意方块时,更新该方块的颜色
const contactHandler = world.onVoxelContact(({ entity, x, y, z }) => {
const idx = players.indexOf(entity);
if (idx < 0) {
return;
}
const t = teams[idx];
voxels.setVoxelId(x, y, z, t.v);
});
// 新玩家加入,会被随机分配到一个队伍
const joinHandler = world.onPlayerJoin(({entity}) => {
const t = TEAMS[(Math.random() * teams.length) | 0];
setTeam(entity, t);
teams.push(t);
players.push(entity)
});
// 每局游戏会在计时到达时结束。
const endTick = world.currentTick + ROUND_TIME;
// 检测游戏是否进行中
function gameInProgress () {
let numActivePlayers = 0;
for (let i = 0; i < players.length; ++i) {
if (!players[i].destroyed) {
numActivePlayers += 1;
}
}
return world.currentTick < endTick && numActivePlayers >= MIN_PLAYERS;
}
// 通过深度优先搜索,将圈起来的地自动填色
const visited = new Uint8Array(GRID_X * GRID_Z)
const toVisit = []
function mark (i, j, team) {
const idx = i + j * GRID_X;
if (i < 0 || i >= GRID_X ||
j < 0 || j >= GRID_Z ||
visited[idx] ||
voxels.getVoxel(i, 8, j) === team) {
return;
}
visited[idx] = true;
toVisit.push(i, j);
}
function fillHoles (team) {
visited.fill(0);
for (let i = 0; i < Math.max(GRID_X, GRID_Z); ++i) {
mark(i, 0, team);//更正了,将8改成了0
mark(0, i, team);
mark(GRID_X - 1, i, team);
mark(i, GRID_Z - 1, team);
}
while (toVisit.length > 0) {
const z = toVisit.pop() | 0;
const x = toVisit.pop() | 0;
mark(x - 1, z, team);
mark(x + 1, z, team);
mark(x, z - 1, team);
mark(x, z + 1, team);
}
let score = 0;
for (let j = 0; j < GRID_Z; ++j) {
for (let i = 0; i < GRID_X; ++i) {
const idx = i + j * GRID_X;
if (!visited[idx]) {
voxels.setVoxelId(i, 8, j, team);
score += 1;
}
}
}
return score;
}
// 当游戏运行时
while (gameInProgress()) {
// 等待 1 Tick
await world.nextTick();
// 计算各队伍的分数
for (let i = 0; i < TEAMS.length; ++i) {
const c = TEAMS[i].score = fillHoles(TEAMS[i].v);
// 如果有团队圈完全场,那么直接胜出
if (c >= GRID_X * GRID_Z) {
break;
}
}
}
// 清除事件处理器
contactHandler.cancel();
joinHandler.cancel();
// 重置玩家颜色
for (let i = 0; i < players.length; ++i) {
const c = players[i].player.color;
c.r = c.g = c.b = 1;
}
world.say('本局游戏结束!');
await sleep(5000);
// 宣布获胜队伍
TEAMS.sort((a, b) => b.score - a.score);
world.say(`恭喜 ${TEAMS[0].n} 成为圈地之王!!`);
await sleep(10000);
}
// 无限循环游戏
async function gameLoop () {
while (true) {
await startGame();
}
}
gameLoop();2023-06-09T23:09:23 点赞:0