用户:
云游de军长渡查看:5 回复:10 评论:5 创建时间:2022-08-22T11:10:01
永军第二届创作节开启!

本次创作节是为了庆祝超时空一年不更新!
下面我说一下规则。
本次创作节是地图创作。
创作类型是跑酷,跑酷必须是宇宙类型的跑酷。示例:
Lolita的星空跑酷
要求:场景必须是黑夜,地形必须清除,必须有存档。
人数:1-4人(非永军人士也可以参加)
给简介里面加入:永宁宇宙跑酷
奖励地图:最后的江湖
奖励(每人分多少创作小队自己决定):
第一名:创作小队总共给10亿
第二名:创作小队总共给5亿
第三名:创作小队总共给3亿
赞助商:MRZ 队长小猫(军长渡一共还不到1千江湖币)
好,那么各位代码屑们不会代码怎么办?
且听下文分解。
不会代码怎么办?
军长渡把代码都公布出来,有的是别人的代码,有的是军长渡用API做的代码。

存档代码:
1.普通模型存档:
for (const e of world.querySelectorAll('*')) {
if (e.id.startsWith('存档点')) {
e.collides = true
e.fixed = true
e.onEntityContact(({ other }) => {
if (other.isPlayer) {
other.player.directMessage('到达新的存档点')
other.player.spawnPoint = e.position
}
})
}
}
2.普通方块存档:
world.onVoxelContact(({entity,voxel})=>{
if(voxel==voxels.id('S')){
entity.player.spawnPoint.copy(entity.position)
entity.player.directMessage('存档成功')
}
})
3.模型SQL存档:
const SpawnPoint = new Box3Vector3(29,8,60);
const points = world.querySelectorAll('.存档点');
const INIT = {
hp: 100,
maxHp: 100,
enableDamage: true,
x: SpawnPoint.x,
y: SpawnPoint.y,
z: SpawnPoint.z,
qx: SpawnPoint.x,
qy: SpawnPoint.y,
qz: SpawnPoint.z,
jumpcounttime: 2,
level: 0,
}
db.sql`CREATE TABLE IF NOT EXISTS leaderboard(
id CHAR(16) NOT NULL,
record TEXT NOT NULL
)`
world.addCollisionFilter('player','player');
world.onPlayerJoin(async({entity})=>{
function init(){
Object.assign(entity,INIT);
}
if(entity.player.userKey){
const rows = await db.sql`SELECT * FROM leaderboard WHERE id = ${entity.player.userKey}`;
if(rows && !rows.length){
init();
db.sql`INSERT INTO leaderboard VALUES(${entity.player.userKey},${getRecord.call(entity)})`;
}else{
Object.assign(entity,JSON.parse(rows[0].record));
}
}else init();
entity.position.set(entity.x,entity.y,entity.z);
entity.player.spawnPoint.set(entity.qx,entity.qy,entity.qz);
Object.assign(entity.player,{
scale: 0.7,
jumpPower: 0.5,
doubleJumpPower: 0.4,
runSpeed: 0.3,
})
entity.player.onPress(async({button})=>{
if(button === Box3ButtonType.ACTION0){
entity.hurt(100);
}else if(button === Box3ButtonType.ACTION1){
const result = await entity.player.dialog({
type: Box3DialogType.SELECT,
title: '控制面板',
content: '加油',
options: ['重新开始','切换视角',`可跳关次数:${entity.jumpcounttime}`,'取消'],
})
if(!result)return;
switch(result.index){
case 0:
Object.assign(entity,INIT);
entity.position.set(entity.x,entity.y,entity.z);
entity.player.spawnPoint.set(entity.qx,entity.qy,entity.qz);
update.call(entity);
break;
case 1:
if(entity.player.cameraMode === 'follow'){
entity.player.cameraMode = 'fps';
}else{
entity.player.cameraMode = 'follow';
}
break;
case 2:
entity.player.cancelDialogs();
if(entity.jumpcounttime){
let found = false;
points.forEach((e)=>{
if(found)return;
if(e.level === entity.level + 1){
found = true;
entity.position = e.position.add({x: 0,y: 3,z: 0});
entity.player.spawnPoint.copy(entity.position);
entity.level = e.level;
entity.jumpcounttime--;
}
})
if(!found){
entity.player.dialog({
type: Box3DialogType.TEXT,
title: '跳关失败',
content: '没有可跳过的关卡',
})
}
}else{
entity.player.dialog({
type: Box3DialogType.TEXT,
title: '跳关失败',
content: '你已没有了跳关次数',
})
}
break;
default:
return;
}
}
})
})
world.onDie(({entity})=>{
if(entity.isPlayer){
entity.player.forceRespawn();
}
})
points.forEach((e)=>{
e.level = Number(e.tags()[0]);
e.onEntityContact(({other})=>{
const spawnPoint = e.position.add({x: 0,y: 2.5,z: 0});
if(spawnPoint.equals(other.player.spawnPoint))return;
other.player.spawnPoint = spawnPoint;
other.player.directMessage('存档成功!');
other.level = e.level;
update.call(other);
})
})
function getRecord(){
const result = {};
Object.keys(INIT).forEach((e)=>{
result[e] = this[e];
})
return JSON.stringify(result);
}
function update(){
if(!this.player.userKey)return;
this.x = this.position.x;
this.y = this.position.y;
this.z = this.position.z;
this.qx = this.player.spawnPoint.x;
this.qy = this.player.spawnPoint.y;
this.qz = this.player.spawnPoint.z;
db.sql`UPDATE leaderboard SET record = ${getRecord.call(this)} WHERE id = ${this.player.userKey}`;
}
world.onPlayerLeave(({entity})=>{
update.call(entity);
})
计喵码:
console.clear()
class Box3Timed {
constructor() {
(async () => {
this.time = 0;
this.over = false;
while (!this.over) {
await sleep(1);
this.time += 1;
}
})()
}
stop() {
return this.over = true
}
getTime() {
return this.time
}
}
//让玩家知道自己进入地图多久了
world.onPlayerJoin(({ entity }) => {
entity.timer = new Box3Timed()
});
//获取进入多久的时间
world.onChat(({ entity, message }) => {
if (message !== "获取时间") return;
world.say("你已进入地图:" + entity.timer.get() / 1000 + "秒");//如果要化成秒就除以1000
});
//停止计时
world.onPlayerLeave(async ({ entity }) => {
entity.timer.stop()
});
world.onVoxelContact(async ({ entity, voxel }) => {
// 将方块id转换名称
const voxelName = voxels.name(voxel)
// 如果方块名称是carpet_08
if (voxelName === 'carpet_08') {
entity.player.directMessage('恭喜你跑完全程,获得飞行能力,在聊天框输入 获取时间 查看自己的时间。')
world.say(`恭喜${entity.player.name}跑完全程!用时${entity.timer.getTime() / 1000}秒`)
entity.timer.stop()
}
});
触碰方块即喵亡的代码:
console.clear()
world.onVoxelContact(({other,entity,player,voxel, x, y, z }) => { //当触碰方块
entity.enableDamage = true
if (voxel === voxels.id('polar_ice')) {
entity.hurt(100) //受伤
}}
)
// 玩家喵亡时,等待5秒后复活。
world.onDie(async({ entity }) => { // 等待事件需要用 async
if (!entity.isPlayer) return; // 不处理非玩家的喵亡事件
entity.player.forceRespawn(); // 让玩家重生
})
world.onChat(({entity,message}) => {
if (message == "zuozhexihuanweiliang") entity.player.canFly=true
if (message == "weiliangyyds") entity.player.canFly=false
})
world.onChat(({ entity, message }) => {
world.querySelectorAll('player').forEach((x) => {
if (x.player.name == message) {
world.querySelectorAll("player").forEach((c) => {
if (c.player.name == entity.player.name) { c.player.cameraEntity = x; }
})
}
});
})
密码传送代码:
const npc = world.querySelector('#阿塔');
npc.enableInteract = true; // 允许进行互动
npc.interactRadius = 16; // 实体的互动范围
npc.interactHint = npc.id; // 互动提示框显示实体的名称
npc.interactColor = new Box3RGBColor(1,1,1); // 互动提示的文字颜色
npc.onInteract(async({entity}) => {
const result = await entity.player.dialog({
type: Box3DialogType.INPUT,
title: '阿塔',
titleTextColor: new Box3RGBAColor(1, 1, 1, 1),
titleBackgroundColor: new Box3RGBAColor(0, 0, 0, 0.98),
content: `${entity.player.name},密码是什么?`,
confirmText: '确定', // 确定按钮上面的文字。按下确定按钮后,提交回答。
placeholder: '注意观察。', // 输入框背景上的提示文字。
contentTextColor: new Box3RGBAColor(1, 1, 1, 1),
contentBackgroundColor: new Box3RGBAColor(0, 0, 0, 0.98),
lookEye: entity.position.add(entity.player.facingDirection.scale(5)),
lookTarget: entity,
});
// 如果玩家点击了屏幕其他区域,取消了对话框。
if(!result || result === null){
entity.player.directMessage('注意观察');
return;
}
const surprise = ['243112']
if(surprise.includes(result)){
entity.player.directMessage(`回答正确` );
entity.position.set(133,10,183)
}
});