用户:
橙子nUcg查看:10 回复:14 评论:10 创建时间:2021-10-09T16:21:53
最近,本人新作《月球越狱大冒险》发布了!!!
欧耶!!!!
在此,本人想把作品的代码进行公布,
供大家学习。
341行代码,
你能看懂多少?
//这是本人的第一个作品的代码,不喜勿喷!
const mms = world.querySelector('#密码锁-1'); //让密码锁-1交互
mms.enableInteract = true;
mms.interactHint = '密码锁';
mms.interactRadius = 4;
mms.onInteract(async({entity})=>{ //当发起交互
const result = await entity.player.dialog({
type: Box3DialogType.SELECT,
title: '门锁',
content: '本作品的作者是?',
options: ['吉吉喵','搬砖喵','名字鬼知道','ExtBLO','橙子nUcg','MC玩家103','木叶龙1342'],
});
if(result.index === 4){ //如果选择正确
world.say(`${entity.player.name}顺利通过第一关!`)
entity.player.directMessage('正确!')
entity.position.set(240,8,248) //逃走
}
else{ //否则
entity.hurt(15) //伤害
entity.player.directMessage('错误!')
}
})
const rw = world.querySelector('#人物-1')
rw.enableInteract = true;
rw.interactRadius = 4;
rw.interactHint = `战友`;
rw.interactColor = new Box3RGBColor(1,1,1);//互动字体颜色
rw.onInteract(async({entity}) => {//当发起交互
if(entity.zy === 1){
entity.player.dialog({
type: Box3DialogType.TEXT, // 对话框的类型
title: `战友`, // 对话框标题
content: `快去越狱吧!`,
});
}
else{
entity.player.dialog({
type:Box3DialogType.TEXT,
title:`战友`,
content:`${entity.player.name},我送你20元钱,帮你越狱!`
});
entity.zy = 1
entity.money += 20
entity.player.directMessage(`钱 增加20元`)
}
})
const mms1 = world.querySelector('#密码锁-2')
mms1.enableInteract = true;
mms1.interactRadius = 4;
mms1.interactHint = `门锁`;
mms1.onInteract(async({entity})=>{
const r1 = await entity.player.dialog({
type:Box3DialogType.SELECT,
title:`门锁`,
content:`月球距离地球?`,
options:['8000千米','38万千米','42万千米','1089亿千米','13500万千米'],
})
if(r1.index === 1){
world.say(`${entity.player.name}顺利通过第二关!`)
entity.player.directMessage(`正确!`)
entity.position.set(219,8,235)
}
else{
entity.hurt(15)
entity.player.directMessage(`错误!`)
}
})
mms2 = world.querySelector('#密码锁-3');
mms2.enableInteract = true;
mms2.interactRadius = 4;
mms2.interactHint = '门锁';
mms2.onInteract(async({entity})=>{
const r2 = await entity.player.dialog({
type:Box3DialogType.SELECT,
title:`门锁`,
content:`圆周率四舍五入保留8位小数是?`,
options:['3.14159269','3.14259269','3.14195238','3.14145235','3.14159265'],
})
if(r2.index === 4){
world.say(`${entity.player.name}顺利通过隔离门!`)
entity.player.directMessage(`正确!`)
entity.position.set(203,8,223)
}
else{
entity.hurt(15)
entity.player.directMessage(`错误!`)
}
})
world.onPlayerJoin(({entity})=>{ //当玩家进入地图
entity.position.set(250,8,246)//出生地
entity.enableDamage = true //允许伤害
entity.things = ['取消'] //物品列表
entity.money = 10
entity.atk = 0
entity.zy = 0
entity.box = 0
entity.qg = 0
entity.lw = 0
entity.zidan = 0
entity.cg = 0
entity.qsj = '装备' //各种变量
if(entity.player.name === '橙子nUcg'){ //欢迎作者
world.say('欢迎作者橙子nUcg的到来!')
entity.player.canFly = true //能飞
}
else if(entity.player.name === '小小瓢虫'||entity.player.name === '一只小虎喵'||entity.player.name === 'studentNo.1(学员一号)'){ //欢迎合作者
world.say('欢迎合作者'+entity.player.name+'的到来!')
entity.player.canFly = true //也能飞
}
entity.player.dialog({
type:Box3DialogType.TEXT,
content:`你,${entity.player.name},在超时空对决中,被外星人抓到了这个位于月球的监狱。`,
});
entity.player.dialog({
type:Box3DialogType.TEXT,
content:`你暂时只有10元钱。请你凭借智慧,破解门锁,拾取道具,击败外星人,逃回地球!`
});
entity.player.addWearable({
bodyPart:Box3BodyPart.TORSO,
mesh:'mesh/黄喵包.vb',
orientation:new Box3Quaternion(0,1,0,0).rotateY(Math.PI/2),
scale:new Box3Vector3(0.5,0.5,0.5),
offset:new Box3Vector3(0,0,-0.45),
});
});
world.onChat(({entity,message})=>{
if(message==='关闭飞行'){
if(entity.player.name==='橙子nUcg'||entity.player.name==='小小瓢虫'||entity.player.name === '一只小虎喵'||entity.player.name === 'studentNo.1(学员1号)'){
entity.player.canFly = false
world.say('成功!')
}
else{
entity.hurt(5)
entity.player.directMessage('喂,别吵!你又不是作者!')
}
}
else if(message==='开启飞行')
if(entity.player.name==='橙子nUcg'||entity.player.name==='小小瓢虫'||entity.player.name === '一只小虎喵'||entity.player.name === 'studentNo.1(学员1号)'){
entity.player.canFly = true
world.say('成功!')
}
else{
entity.hurt(5)
entity.player.directMessage('呃......')
}
})
world.onPress(async({ button, entity }) => {
if(!entity.isPlayer || entity.player.dead) return;
if(button == 'action1'){
const pl_1=await entity.player.dialog({
type:Box3DialogType.SELECT,
title:entity.player.name+"的状态",
content:entity.player.name+"的状态:\n血量:"+entity.hp+"\n金钱:"+entity.money+"\n攻击力:"+entity.atk,
options:['保存','道具','取消']
});
if(pl_1.index===2){
return;
}
else if(pl_1.index===1){
const pl_2 = await entity.player.dialog({
type:Box3DialogType.SELECT,
title:entity.player.name+'的道具',
options:entity.things,
})
if(pl_2.value === '潜水镜'){
const pl_3 = await entity.player.dialog({
type:Box3DialogType.SELECT,
title:`潜水镜`,
content:`潜水镜:装备后可以进入水中而不扣血`,
options:[qsj,'取消']
});
if(pl_3.index === 0){
if(qsj === '装备'){
//装备
}
else{
entity.qsl = '卸下'
//清除
}
}
}
}
else if(pl_1.index===2){
if(entity.player.userKey){
entity.player.dialog({
type:Box3DialogType.TEXT,
title:entity.player.name+'的状态',
content:'你是游客,无法保存!',
})
}
else{
}
}
}
})
const bz = world.querySelector('#箱子-1')
bz.enableInteract = true;
bz.interactRadius = 4;
bz.interactHint = '箱子'
bz.onInteract(async({entity})=>{
if(entity.box === 0){
entity.player.dialog({
type:Box3DialogType.TEXT,
title:`箱子`,
content:`恭喜你在箱子里找到了:50元钱,和:潜水镜一双!`,
});
entity.money += 50
entity.player.directMessage(`钱 增加50元`)
entity.things.push('潜水镜')
entity.player.directMessage(`获得:潜水镜一双`)
entity.box += 1
}
else{
entity.player.directMessage(`这个箱子已经开过了!`)
}
})
const gift = world.querySelector('#圣诞礼物')
gift.enableInteract = true;
gift.interactRadius = 2;
gift.interactHint = '奖品';
gift.onInteract(async({entity})=>{
if(entity.lw === 0){
world.say(`恭喜${entity.player.name}捡到了礼物彩蛋!`)
entity.player.dialog({
type:Box3DialogType.TEXT,
title:'礼物',
content:`恭喜你捡到了礼物,获得:30元钱,2发子弹!`,
});
entity.lw += 1
entity.money += 30
entity.zidan += 2
}
else{
entity.player.directMessage(`礼物捡过了哦~`)
}
})
const pp = world.querySelector('#PP')
pp.enableInteract = true;
pp.interactRadius = 3;
pp.interactHint = '冲锋喵';
pp.onInteract(async({entity})=>{
if(entity.qg === 0){
entity.player.dialog({
type:Box3DialogType.TEXT,
title:`冲锋喵`,
content:`恭喜你获得:冲锋喵!(无子弹)`,
});
entity.things.push('冲锋喵')
entity.qg += 1
}
else{
entity.player.directMessage(`冲锋喵已经拿走了~`)
}
})
dievoxel=['lava02']
world.onVoxelContact(async({ x, y, z, voxel,entity}) => {
const voxelName = voxels.name(voxel); // 将方块id转换名称
if (dievoxel.includes(voxelName)){
entity.hurt(100)
}
})
world.onDie(async({ entity, attacker }) => {
world.say(`${entity.player.name}不幸在越狱过程中趋势!`)
for(t=5;t>=1;--t){
entity.player.directMessage(t+'秒后复活')
await sleep(1000)
};
entity.hp=15;
entity.position.set(250,8,246);
});
const gz = world.querySelector('#关注一下-1')
gz.enableInteract = true;
gz.interactRadius = 4;
gz.interactHint = '关注';
gz.onInteract(async({entity})=>{
entity.player.dialog({
type:Box3DialogType.TEXT,
title:'关注一下',
content:`关注作者,享受更多作品!`,
});
})
slvoxel=['palace_eaves_04']
world.onVoxelContact(async({ x, y, z, voxel,entity}) => {
const voxelName = voxels.name(voxel); // 将方块id转换名称
if (slvoxel.includes(voxelName)){
if(entity.cg === 0){
world.say(`恭喜${entity.player.name}成功越狱!`)
entity.player.dialog({
type:Box3DialogType.TEXT,
title:'成功',
content:`恭喜你,成功到达终点!!`,
});
entity.cg = 1
}
}
})
const door = world.querySelector('#火箭-1')
door.enableInteract = true;
door.interactRadius = 5;
door.interactHint = `回到 超时空对决`;
door.onInteract(async({ entity }) => {
entity.player.link('https://box3.codemao.cn/p/cyberwar?recommend_by=4700008')
})
好了,注意:
这是本人发布的第一个代码岛作品,
代码还很不好,
大佬勿喷!!!!!!
好,记得去玩哦~
源码极客第一次就做的这么好,已经很不错了!imgsrc="https://static.cod喵/emoji/codemao/%E7%BC%96%E7%A8%8B%E7%8C%AB_%E5%8A%A0%E6%B2%B9.gif"alt="emotion_编程猫_加油"(我的第一个作品就是把官方教程的代码改了下而已)
点赞1
评论