本帖最后由 脑的研发记录 于 2023-11-25 20:09 编辑
“数据结构课作业笔记”#010-数组-多组冲击层改烟花-并发的预兆
所用编辑器版本0.27.0.0
目录总览:
零.用代码创造新代码的实验环境
壹.第一个二维数组
贰.所需语法
叁.应用说明
肆.相关参考链接 (返回主站
17:30-22:50代码+文案
篇幅较长,踩坑较多,最终成果代码在最后
零.用代码创造开发新代码的实验环境
这个是源于写PTA代码作业遇到的问题,这个PTA网站写代码,有一类题目类型是写代码的一部分,就是大半个代码写的差不多了,就差几行代码自己补上。自己补上代码,然后通过了题目。但是线下复制那给出的大半个代码,和自己补充的几行代码。运行不起来,原因是有些代码执行过程在线下没有对应的代码。就比如之前的this.out()这样的。就导致线下写代码几乎不可能,只能线上写代码,而且限制到某几行代码。线下不能调试,也不能输入自己的数据。
所以当时一个想法就是,把完整代码贴出来。不用限制成线上调试。希望就是有理由的发展出来新代码。也就是用已有的代码创造新的代码用法所需的情景,然后使用代码应对,自然而然地进入到新代码的认识中。这也是目前帖子都是从上一个帖子的代码开始改写起来的原因。保证先有新的需求,需求翻译成代码,由此引发新的代码尝试,或者是经常重复旧代码过程,意外显现了新代码。尽量堵住“为什么要这样写代码?”的问题,因为其他还没来得及想,就着现有的有啥写啥,奔着现有的直接开发,没有碰壁就一直走下去。
壹.第一个二维数组
首先是旧代码适配新版本,旧代码来源“数据结构课作业笔记”#006-数组-从地刺到冲击层-队列的预兆 口袋方舟论坛|面向全年龄的UGC互动内容平台与交流社区 (ark.online)
修改了class成员的类型来适配物理模拟,this.i起始由-1调整为从0开始。在009的修改经验下,in,out函数也改了。
class ooh {
n: Model;
id: string;
}
@Component
export default class adds extends Script {
protected build: Array<ooh> = new Array(10);
protected i: number = 0;
protected flag_grow: number = 0;
/** 当脚本被实例后,会在第一帧更新前调用此函数 */
protected onStart(): void {
for (var j = 0; j < this.build.length; j++) {
this.build[j] = new ooh();
}
AssetUtil.asyncDownloadAsset("197386");
setTimeout(() => {
for (var j = 0; j < this.build.length; j++) {
let box = GameObject.spawn("197386", {
transform: new Transform(new Vector(0, j * 50, 25), new Rotation(0, 0, 0),new Vector((1 + j * j) / 90, 1, (1 + j * j) / 90)),
replicates: true
}) as Model;
this.in(box);
}
this.i = 0;
// 标号回到开头
}, 3000);
// this.i = 0;
// 生成速度把this.i=0的使用时间挤没了
setTimeout(() => {
var timer = setInterval(() => {
if (this.flag_grow == 0) {
if (this.i == this.build.length) {
this.flag_grow = 1;
this.i = 0;
}
var have: ooh = this.out();
have.n.setCollision(PropertyStatus.Off, true);
have.n.setVisibility(PropertyStatus.Off, true);
} else if (this.flag_grow == 1) {
if (this.i == this.build.length) {
this.flag_grow = 0;
this.i = 0;
}
var have: ooh = this.show();
have.n.setCollision(PropertyStatus.On, true);
have.n.setVisibility(PropertyStatus.On, true);
}
console.log(this.i);
}, 100);
}, 3000);
}
public in(obj: Model) {
this.build[this.i].n = obj;
this.i++;
}
public show(): ooh {
var have: ooh = this.build[this.i];
this.i++;
return have;
}
public out(): ooh {
var have: ooh = this.build[this.i];
this.i++;
return have;
}
}
跑起来代码,发现总是有一端开头的一个方块不能消失,原来以为是范围没有覆盖,删除上限小了,只能删除0-8,0-9刚好漏了一个。但是改了if(this.i<build.lenth+1)增加一个,然后发现还是不行。跑了三四遍,排除是编辑器卡顿问题,还是觉得代码有问题,后来改多了,觉得还是删除问题,就读代码,读着读着发现,this.i=10之后,会变成0,但是还是执行了控制显示的代码。导致第一个方块压根没有删除。
如此如此,代码修改如下,一看改出来的代码,确实没有觉察到这个问题,目前阶段,穷举法人脑执行代码确实还是很靠谱。
else就保证了二选一功能
if (this.flag_grow == 0) {
// if (this.i == this.build.length) {
// this.flag_grow = 1;
// this.i = 0;
// }
// var have: ooh = this.out();
// have.n.setCollision(PropertyStatus.Off, true);
// have.n.setVisibility(PropertyStatus.Off, true);
if (this.i == this.build.length) {
this.flag_grow = 1;
this.i = 0;
} else {
var have: ooh = this.out();
have.n.setCollision(PropertyStatus.Off, true);
have.n.setVisibility(PropertyStatus.Off, true);
}
} else if (this.flag_grow == 1) {
// if (this.i == this.build.length) {
// this.flag_grow = 0;
// this.i = 0;
// }
// var have: ooh = this.show();
// have.n.setCollision(PropertyStatus.On, true);
// have.n.setVisibility(PropertyStatus.On, true);
if (this.i == this.build.length) {
this.flag_grow = 0;
this.i = 0;
} else {
var have: ooh = this.show();
have.n.setCollision(PropertyStatus.On, true);
have.n.setVisibility(PropertyStatus.On, true);
}
这次是复制粘贴出两个冲击波,原来是想出四个冲击波,发现代码太多了,就一共俩冲击波,然后第二个新的冲击波的代码复制粘贴位置错了,再重新复制粘贴就复制更大块的代码
然后跑代码,只生成,不消失,于是就在看代码,发现报错数据不存在,就看新重复粘贴的代码,读着读着发现变量名称没改。改了再跑,过了消失又重现。
复制粘贴也需要消耗一点精力选择代码复制的范围和粘贴的位置了。
class ooh {
n: Model;
id: string;
}
@Component
export default class adds extends Script {
protected build: Array<ooh> = new Array(10);
protected i: number = 0;
protected flag_grow: number = 0;
protected build1: Array<ooh> = new Array(10);
protected i1: number = 0;
protected flag_grow1: number = 0;
// protected build2: Array<ooh> = new Array(10);
// protected i2: number = 0;
// protected flag_grow2: number = 0;
// protected build3: Array<ooh> = new Array(10);
// protected i3: number = 0;
// protected flag_grow3: number = 0;
/** 当脚本被实例后,会在第一帧更新前调用此函数 */
protected onStart(): void {
for (var j = 0; j < this.build.length; j++) {
this.build[j] = new ooh();
}
for (var j = 0; j < this.build.length; j++) {
this.build1[j] = new ooh();
}
AssetUtil.asyncDownloadAsset("197386");
setTimeout(() => {
for (var j = 0; j < this.build.length; j++) {
let box = GameObject.spawn("197386", {
transform: new Transform(new Vector(0, j * 50, 25), new Rotation(0, 0, 0), new Vector((1 + j * j) / 90, 1, (1 + j * j) / 90)),
replicates: true
}) as Model;
this.in(box);
}
this.i = 0;
for (var j = 0; j < this.build1.length; j++) {
let box = GameObject.spawn("197386", {
transform: new Transform(new Vector(0, -j * 50, 25), new Rotation(0, 0, 0), new Vector((1 + j * j) / 90, 1, (1 + j * j) / 90)),
replicates: true
}) as Model;
this.in1(box);
}
this.i1 = 0;
// 标号回到开头
}, 3000);
// this.i = 0;
// 生成速度把this.i=0的使用时间挤没了
setTimeout(() => {
var timer = setInterval(() => {
if (this.flag_grow == 0) {
if (this.i == this.build.length) {
this.flag_grow = 1;
this.i = 0;
} else {
var have: ooh = this.out();
have.n.setCollision(PropertyStatus.Off, true);
have.n.setVisibility(PropertyStatus.Off, true);
}
// if (this.i1 == this.build1.length) {
// this.flag_grow1 = 1;
// this.i1 = 0;
// } else {
// var have1: ooh = this.out1();
// have1.n.setCollision(PropertyStatus.Off, true);
// have1.n.setVisibility(PropertyStatus.Off, true);
// }
} else if (this.flag_grow == 1) {
if (this.i == this.build.length) {
this.flag_grow = 0;
this.i = 0;
} else {
var have: ooh = this.show();
have.n.setCollision(PropertyStatus.On, true);
have.n.setVisibility(PropertyStatus.On, true);
}
// if (this.i1 == this.build1.length) {
// this.flag_grow1 = 0;
// this.i1 = 0;
// } else {
// var have1: ooh = this.show1();
// have1.n.setCollision(PropertyStatus.On, true);
// have1.n.setVisibility(PropertyStatus.On, true);
// }
}
if (this.flag_grow1 == 0) {
if (this.i1 == this.build1.length) {
this.flag_grow1 = 1;
this.i1 = 0;
} else {
var have1: ooh = this.out1();
have1.n.setCollision(PropertyStatus.Off, true);
have1.n.setVisibility(PropertyStatus.Off, true);
}
} else if (this.flag_grow1 == 1) {
if (this.i1 == this.build1.length) {
this.flag_grow1 = 0;
this.i1 = 0;
} else {
var have1: ooh = this.show1();
have1.n.setCollision(PropertyStatus.On, true);
have1.n.setVisibility(PropertyStatus.On, true);
}
}
console.log(this.i);
console.log(this.i1);
}, 100);
}, 3000);
}
public in(obj: Model) {
this.build[this.i].n = obj;
this.i++;
}
public show(): ooh {
var have: ooh = this.build[this.i];
this.i++;
return have;
}
public out(): ooh {
var have: ooh = this.build[this.i];
this.i++;
return have;
}
public in1(obj: Model) {
this.build1[this.i1].n = obj;
this.i1++;
}
public show1(): ooh {
var have1: ooh = this.build1[this.i1];
this.i1++;
return have1;
}
public out1(): ooh {
var have1: ooh = this.build1[this.i1];
this.i1++;
return have1;
}
}
目前就是实现了两个冲击波同时产生,同时消失。虽然冲击波代码一行一行执行,但是玩家看不出来哪个冲击波代码先执行。
然后具体说明冲击波,还需要调整代码位置,简单合并。
g1和g2只有一个符号的不同。class是类型不仅能够如ooh保存数值,也能像g1,g2保存函数。注意Onstrat()中,space函数的注释“分配内存的作用等效,因为本来就是代码复制粘贴,只是套壳了名称,作为引用凭证,引用名称为“space"的代码。”
封装函数的实现原理。
class ooh {
n: Model;
id: string;
}
class g1 {
public build: Array<ooh> = new Array(10);
public i: number = 0;
protected flag_grow: number = 0;
public space() {
for (var j = 0; j < this.build.length; j++) {
this.build[j] = new ooh();
}
}
public in(obj: Model) {
this.build[this.i].n = obj;
this.i++;
}
public grow() {
for (var j = 0; j < this.build.length; j++) {
let box = GameObject.spawn("197386", {
transform: new Transform(new Vector(0, j * 50, 25), new Rotation(0, 0, 0), new Vector((1 + j * j) / 90, 1, (1 + j * j) / 90)),
replicates: true
}) as Model;
this.in(box);
}
this.i = 0;
}
public show(): ooh {
var have: ooh = this.build[this.i];
this.i++;
return have;
}
public out(): ooh {
var have: ooh = this.build[this.i];
this.i++;
return have;
}
}
class g2 {
public build1: Array<ooh> = new Array(10);
public i1: number = 0;
protected flag_grow1: number = 0;
public space1() {
for (var j = 0; j < this.build1.length; j++) {
this.build1[j] = new ooh();
}
}
public in1(obj: Model) {
this.build1[this.i1].n = obj;
this.i1++;
}
public grow1() {
for (var j = 0; j < this.build1.length; j++) {
let box = GameObject.spawn("197386", {
transform: new Transform(new Vector(0, -j * 50, 25), new Rotation(0, 0, 0), new Vector((1 + j * j) / 90, 1, (1 + j * j) / 90)),
replicates: true
}) as Model;
this.in1(box);
}
this.i1 = 0;
}
public show1(): ooh {
var have1: ooh = this.build1[this.i1];
this.i1++;
return have1;
}
public out1(): ooh {
var have1: ooh = this.build1[this.i1];
this.i1++;
return have1;
}
}
@Component
export default class adds extends Script {
// protected build: Array<ooh> = new Array(10);
// protected i: number = 0;
// protected flag_grow: number = 0;
protected k: g1 = new g1();
// protected build1: Array<ooh> = new Array(10);
// protected i1: number = 0;
// protected flag_grow1: number = 0;
protected k1: g2 = new g2();
protected i: number = 0;
protected flag_grow: number = 0;
/** 当脚本被实例后,会在第一帧更新前调用此函数 */
protected onStart(): void {
// for (var j = 0; j < this.build.length; j++) {
// this.build[j] = new ooh();
// }
this.k.space();
// 分配内存的作用等效,因为本来就是代码复制粘贴,只是套壳了名称,作为引用凭证,引用名称为“space"的代码。
// for (var j = 0; j < this.build.length; j++) {
// this.build1[j] = new ooh();
// }
this.k1.space1();
// 分配内存的作用等效,因为本来就是代码复制粘贴,只是套壳了名称,作为引用凭证,引用名称为“space1"的代码。
AssetUtil.asyncDownloadAsset("197386");
setTimeout(() => {
// for (var j = 0; j < this.build.length; j++) {
// let box = GameObject.spawn("197386", {
// transform: new Transform(new Vector(0, j * 50, 25), new Rotation(0, 0, 0), new Vector((1 + j * j) / 90, 1, (1 + j * j) / 90)),
// replicates: true
// }) as Model;
// this.in(box);
// }
// this.i = 0;
this.k.grow();
// 暂存方块数据的作用等效,因为本来就是代码复制粘贴,只是套壳了名称,作为引用凭证,引用名称为“grow"的代码。
// for (var j = 0; j < this.build1.length; j++) {
// let box = GameObject.spawn("197386", {
// transform: new Transform(new Vector(0, -j * 50, 25), new Rotation(0, 0, 0), new Vector((1 + j * j) / 90, 1, (1 + j * j) / 90)),
// replicates: true
// }) as Model;
// this.in1(box);
// }
// this.i1 = 0;
// 标号回到开头
this.k1.grow1();
// 暂存方块数据的作用等效,因为本来就是代码复制粘贴,只是套壳了名称,作为引用凭证,引用名称为“grow1"的代码。
}, 3000);
// this.i = 0;
// 生成速度把this.i=0的使用时间挤没了
setTimeout(() => {
var timer = setInterval(() => {
if (this.flag_grow == 0) {
if (this.i == 10) {
// 改成固定长度限制,10次一波生成,第二个10次一波消失
this.flag_grow = 1;
this.i = 0;
} else {
// var have: ooh = this.k.out();
var have: ooh = this.k.build[this.i];
have.n.setCollision(PropertyStatus.Off, true);
have.n.setVisibility(PropertyStatus.Off, true);
// var have1: ooh = this.k1.out1();
var have1: ooh = this.k1.build1[this.i];
have1.n.setCollision(PropertyStatus.Off, true);
have1.n.setVisibility(PropertyStatus.Off, true);
this.i++;
}
} else if (this.flag_grow == 1) {
if (this.i == 10) {
this.flag_grow = 0;
this.i = 0;
} else {
// var have: ooh = this.k.show();
var have: ooh = this.k.build[this.i];
have.n.setCollision(PropertyStatus.On, true);
have.n.setVisibility(PropertyStatus.On, true);
// var have1: ooh = this.k1.show1();
var have1: ooh = this.k1.build1[this.i];
have1.n.setCollision(PropertyStatus.On, true);
have1.n.setVisibility(PropertyStatus.On, true);
this.i++;
}
}
// if (this.flag_grow1 == 0) {
// if (this.i1 == this.build1.length) {
// this.flag_grow1 = 1;
// this.i1 = 0;
// } else {
// var have1: ooh = this.out1();
// have1.n.setCollision(PropertyStatus.Off, true);
// have1.n.setVisibility(PropertyStatus.Off, true);
// }
// } else if (this.flag_grow1 == 1) {
// if (this.i1 == this.build1.length) {
// this.flag_grow1 = 0;
// this.i1 = 0;
// } else {
// var have1: ooh = this.show1();
// have1.n.setCollision(PropertyStatus.On, true);
// have1.n.setVisibility(PropertyStatus.On, true);
// }
// }
// console.log(this.k.i);
// console.log(this.k1.i1);
}, 100);
}, 3000);
}
// public in(obj: Model) {
// this.build[this.i].n = obj;
// this.i++;
// }
// public show(): ooh {
// var have: ooh = this.build[this.i];
// this.i++;
// return have;
// }
// public out(): ooh {
// var have: ooh = this.build[this.i];
// this.i++;
// return have;
// }
// public in1(obj: Model) {
// this.build1[this.i1].n = obj;
// this.i1++;
// }
// public show1(): ooh {
// var have1: ooh = this.build1[this.i1];
// this.i1++;
// return have1;
// }
// public out1(): ooh {
// var have1: ooh = this.build1[this.i1];
// this.i1++;
// return have1;
// }
}
注释的代码太多了,删除一些注释的代码,封装的效果才能比较明显地看到,当然如果是四个冲击波,封装的效果就更明显了,现在是两个冲击波。
新的注释的绿色代码行是没有用到的代码。
class ooh {
n: Model;
id: string;
}
class g1 {
public build: Array<ooh> = new Array(10);
public i: number = 0;
protected flag_grow: number = 0;
public space() {
for (var j = 0; j < this.build.length; j++) {
this.build[j] = new ooh();
}
}
public in(obj: Model) {
this.build[this.i].n = obj;
this.i++;
}
public grow() {
for (var j = 0; j < this.build.length; j++) {
let box = GameObject.spawn("197386", {
transform: new Transform(new Vector(0, j * 50, 25), new Rotation(0, 0, 0), new Vector((1 + j * j) / 90, 1, (1 + j * j) / 90)),
replicates: true
}) as Model;
this.in(box);
}
this.i = 0;
}
// public show(): ooh {
// var have: ooh = this.build[this.i];
// this.i++;
// return have;
// }
// public out(): ooh {
// var have: ooh = this.build[this.i];
// this.i++;
// return have;
// }
}
class g2 {
public build1: Array<ooh> = new Array(10);
public i1: number = 0;
protected flag_grow1: number = 0;
public space1() {
for (var j = 0; j < this.build1.length; j++) {
this.build1[j] = new ooh();
}
}
public in1(obj: Model) {
this.build1[this.i1].n = obj;
this.i1++;
}
public grow1() {
for (var j = 0; j < this.build1.length; j++) {
let box = GameObject.spawn("197386", {
transform: new Transform(new Vector(0, -j * 50, 25), new Rotation(0, 0, 0), new Vector((1 + j * j) / 90, 1, (1 + j * j) / 90)),
replicates: true
}) as Model;
this.in1(box);
}
this.i1 = 0;
}
// public show1(): ooh {
// var have1: ooh = this.build1[this.i1];
// this.i1++;
// return have1;
// }
// public out1(): ooh {
// var have1: ooh = this.build1[this.i1];
// this.i1++;
// return have1;
// }
}
@Component
export default class adds extends Script {
// protected build: Array<ooh> = new Array(10);
// protected i: number = 0;
// protected flag_grow: number = 0;
protected k: g1 = new g1();
// protected build1: Array<ooh> = new Array(10);
// protected i1: number = 0;
// protected flag_grow1: number = 0;
protected k1: g2 = new g2();
protected i: number = 0;
protected flag_grow: number = 0;
/** 当脚本被实例后,会在第一帧更新前调用此函数 */
protected onStart(): void {
// for (var j = 0; j < this.build.length; j++) {
// this.build[j] = new ooh();
// }
this.k.space();
// 分配内存的作用等效,因为本来就是代码复制粘贴,只是套壳了名称,作为引用凭证,引用名称为“space"的代码。
// for (var j = 0; j < this.build.length; j++) {
// this.build1[j] = new ooh();
// }
this.k1.space1();
// 分配内存的作用等效,因为本来就是代码复制粘贴,只是套壳了名称,作为引用凭证,引用名称为“space1"的代码。
AssetUtil.asyncDownloadAsset("197386");
setTimeout(() => {
this.k.grow();
// 暂存方块数据的作用等效,因为本来就是代码复制粘贴,只是套壳了名称,作为引用凭证,引用名称为“grow"的代码。
this.k1.grow1();
// 暂存方块数据的作用等效,因为本来就是代码复制粘贴,只是套壳了名称,作为引用凭证,引用名称为“grow1"的代码。
}, 3000);
setTimeout(() => {
var timer = setInterval(() => {
if (this.flag_grow == 0) {
if (this.i == 10) {
// 改成固定长度限制,10次一波生成,第二个10次一波消失
this.flag_grow = 1;
this.i = 0;
} else {
// var have: ooh = this.k.out();
var have: ooh = this.k.build[this.i];
have.n.setCollision(PropertyStatus.Off, true);
have.n.setVisibility(PropertyStatus.Off, true);
// var have1: ooh = this.k1.out1();
var have1: ooh = this.k1.build1[this.i];
have1.n.setCollision(PropertyStatus.Off, true);
have1.n.setVisibility(PropertyStatus.Off, true);
this.i++;
}
} else if (this.flag_grow == 1) {
if (this.i == 10) {
this.flag_grow = 0;
this.i = 0;
} else {
// var have: ooh = this.k.show();
var have: ooh = this.k.build[this.i];
have.n.setCollision(PropertyStatus.On, true);
have.n.setVisibility(PropertyStatus.On, true);
// var have1: ooh = this.k1.show1();
var have1: ooh = this.k1.build1[this.i];
have1.n.setCollision(PropertyStatus.On, true);
have1.n.setVisibility(PropertyStatus.On, true);
this.i++;
}
}
}, 100);
}, 3000);
}
}
因为是第一次大规模合并,g1 g2有很多相同的部分,除了一个sapce函数不同,其他都相同。可以继续删除合并
class ooh {
n: Model;
id: string;
}
class g1 {
public build: Array<ooh> = new Array(10);
public i: number = 0;
protected flag_grow: number = 0;
public space() {
for (var j = 0; j < this.build.length; j++) {
this.build[j] = new ooh();
}
}
// public in(obj: Model) {
// this.build[this.i].n = obj;
// this.i++;
// }
// public grow() {
// for (var j = 0; j < this.build.length; j++) {
// let box = GameObject.spawn("197386", {
// transform: new Transform(new Vector(0, j * 50, 25), new Rotation(0, 0, 0), new Vector((1 + j * j) / 90, 1, (1 + j * j) / 90)),
// replicates: true
// }) as Model;
// this.in(box);
// }
// this.i = 0;
// }
}
// class g2 {
// public build1: Array<ooh> = new Array(10);
// public i1: number = 0;
// protected flag_grow1: number = 0;
// public space1() {
// for (var j = 0; j < this.build1.length; j++) {
// this.build1[j] = new ooh();
// }
// }
// public in1(obj: Model) {
// this.build1[this.i1].n = obj;
// this.i1++;
// }
// public grow1() {
// for (var j = 0; j < this.build1.length; j++) {
// let box = GameObject.spawn("197386", {
// transform: new Transform(new Vector(0, -j * 50, 25), new Rotation(0, 0, 0), new Vector((1 + j * j) / 90, 1, (1 + j * j) / 90)),
// replicates: true
// }) as Model;
// this.in1(box);
// }
// this.i1 = 0;
// }
// }
@Component
export default class adds extends Script {
// protected build: Array<ooh> = new Array(10);
// protected i: number = 0;
// protected flag_grow: number = 0;
protected k: g1 = new g1();
// protected build1: Array<ooh> = new Array(10);
// protected i1: number = 0;
// protected flag_grow1: number = 0;
// protected k1: g2 = new g2();
protected k1: g1 = new g1();
protected i: number = 0;
protected flag_grow: number = 0;
/** 当脚本被实例后,会在第一帧更新前调用此函数 */
protected onStart(): void {
// for (var j = 0; j < this.build.length; j++) {
// this.build[j] = new ooh();
// }
this.k.space();
// 分配内存的作用等效,因为本来就是代码复制粘贴,只是套壳了名称,作为引用凭证,引用名称为“space"的代码。
// for (var j = 0; j < this.build1.length; j++) {
// this.build1[j] = new ooh();
// }
// this.k1.space1();
this.k1.space();
// 分配内存的作用等效,因为本来就是代码复制粘贴,只是套壳了名称,作为引用凭证,引用名称为“space1"的代码。
AssetUtil.asyncDownloadAsset("197386");
setTimeout(() => {
// this.k.grow();
// 暂存方块数据的作用等效,因为本来就是代码复制粘贴,只是套壳了名称,作为引用凭证,引用名称为“grow"的代码。
for (var j = 0; j < this.k.build.length; j++) {
let box = GameObject.spawn("197386", {
transform: new Transform(new Vector(0, j * 50, 25), new Rotation(0, 0, 0), new Vector((1 + j * j) / 90, 1, (1 + j * j) / 90)),
replicates: true
}) as Model;
this.k.build[j].n = box;
}
// this.k1.grow1();
// 暂存方块数据的作用等效,因为本来就是代码复制粘贴,只是套壳了名称,作为引用凭证,引用名称为“grow1"的代码。
for (var j = 0; j < this.k.build.length; j++) {
let box = GameObject.spawn("197386", {
transform: new Transform(new Vector(0, -j * 50, 25), new Rotation(0, 0, 0), new Vector((1 + j * j) / 90, 1, (1 + j * j) / 90)),
replicates: true
}) as Model;
this.k1.build[j].n = box;
}
}, 3000);
setTimeout(() => {
var timer = setInterval(() => {
if (this.flag_grow == 0) {
if (this.i == 10) {
// 改成固定长度限制,10次一波生成,第二个10次一波消失
this.flag_grow = 1;
this.i = 0;
} else {
// var have: ooh = this.k.out();
var have: ooh = this.k.build[this.i];
have.n.setCollision(PropertyStatus.Off, true);
have.n.setVisibility(PropertyStatus.Off, true);
// var have1: ooh = this.k1.out1();
// var have1: ooh = this.k1.build1[this.i];
var have1: ooh = this.k1.build[this.i];
have1.n.setCollision(PropertyStatus.Off, true);
have1.n.setVisibility(PropertyStatus.Off, true);
this.i++;
}
} else if (this.flag_grow == 1) {
if (this.i == 10) {
this.flag_grow = 0;
this.i = 0;
} else {
// var have: ooh = this.k.show();
var have: ooh = this.k.build[this.i];
have.n.setCollision(PropertyStatus.On, true);
have.n.setVisibility(PropertyStatus.On, true);
// var have1: ooh = this.k1.show1();
// var have1: ooh = this.k1.build1[this.i];
var have1: ooh = this.k1.build[this.i];
have1.n.setCollision(PropertyStatus.On, true);
have1.n.setVisibility(PropertyStatus.On, true);
this.i++;
}
}
}, 100);
}, 3000);
}
}
旧代码还得删除,清理视野
class ooh {
n: Model;
id: string;
}
class g1 {
public build: Array<ooh> = new Array(10);
public i: number = 0;
protected flag_grow: number = 0;
public space() {
for (var j = 0; j < this.build.length; j++) {
this.build[j] = new ooh();
}
}
}
@Component
export default class adds extends Script {
protected k: g1 = new g1();
protected k1: g1 = new g1();
protected i: number = 0;
protected flag_grow: number = 0;
// 公共的数据,用于控制二选一
/** 当脚本被实例后,会在第一帧更新前调用此函数 */
protected onStart(): void {
this.k.space();
// 分配内存的作用等效,因为本来就是代码复制粘贴,只是套壳了名称,作为引用凭证,引用名称为“space"的代码。
// for (var j = 0; j < this.build1.length; j++) {
// this.build1[j] = new ooh();
// }
// this.k1.space1();
// 分配内存的作用等效,因为本来就是代码复制粘贴,只是套壳了名称,作为引用凭证,引用名称为“space1"的代码。
this.k1.space();
// 是g1类型,所以具有相同的凭证,引用的目标也从space1回到space了 g1相当于一个模板了,以这个模板刻出来的对象,都有这个space方法
AssetUtil.asyncDownloadAsset("197386");
setTimeout(() => {
// this.k.grow();
// 暂存方块数据的作用等效,因为本来就是代码复制粘贴,只是套壳了名称,作为引用凭证,引用名称为“grow"的代码。
for (var j = 0; j < this.k.build.length; j++) {
let box = GameObject.spawn("197386", {
transform: new Transform(new Vector(0, j * 50, 25), new Rotation(0, 0, 0), new Vector((1 + j * j) / 90, 1, (1 + j * j) / 90)),
replicates: true
}) as Model;
this.k.build[j].n = box;
}
// this.k1.grow1();
// 暂存方块数据的作用等效,因为本来就是代码复制粘贴,只是套壳了名称,作为引用凭证,引用名称为“grow1"的代码。
for (var j = 0; j < this.k.build.length; j++) {
let box = GameObject.spawn("197386", {
transform: new Transform(new Vector(0, -j * 50, 25), new Rotation(0, 0, 0), new Vector((1 + j * j) / 90, 1, (1 + j * j) / 90)),
replicates: true
}) as Model;
this.k1.build[j].n = box;
}
}, 3000);
setTimeout(() => {
var timer = setInterval(() => {
if (this.flag_grow == 0) {
if (this.i == 10) {
// 改成固定长度限制,10次一波生成,第二个10次一波消失
this.flag_grow = 1;
this.i = 0;
} else {
// var have: ooh = this.k.out();
var have: ooh = this.k.build[this.i];
have.n.setCollision(PropertyStatus.Off, true);
have.n.setVisibility(PropertyStatus.Off, true);
// var have1: ooh = this.k1.out1();
// var have1: ooh = this.k1.build1[this.i];
var have1: ooh = this.k1.build[this.i];
have1.n.setCollision(PropertyStatus.Off, true);
have1.n.setVisibility(PropertyStatus.Off, true);
this.i++;
}
} else if (this.flag_grow == 1) {
if (this.i == 10) {
this.flag_grow = 0;
this.i = 0;
} else {
// var have: ooh = this.k.show();
var have: ooh = this.k.build[this.i];
have.n.setCollision(PropertyStatus.On, true);
have.n.setVisibility(PropertyStatus.On, true);
// var have1: ooh = this.k1.show1();
// var have1: ooh = this.k1.build1[this.i];
var have1: ooh = this.k1.build[this.i];
have1.n.setCollision(PropertyStatus.On, true);
have1.n.setVisibility(PropertyStatus.On, true);
this.i++;
}
}
}, 100);
}, 3000);
}
}
现在可以产生四个冲击波了,因为有模板缩短了代码长度的现象,稍微合并代码。
class ooh {
n: Model;
id: string;
}
class g1 {
public build: Array<ooh> = new Array(10);
public i: number = 0;
protected flag_grow: number = 0;
public space() {
for (var j = 0; j < this.build.length; j++) {
this.build[j] = new ooh();
}
}
public hide(x: number) {
var have: ooh = this.build[x];
have.n.setCollision(PropertyStatus.Off, true);
have.n.setVisibility(PropertyStatus.Off, true);
}
public show(x: number) {
var have1: ooh = this.build[x];
have1.n.setCollision(PropertyStatus.On, true);
have1.n.setVisibility(PropertyStatus.On, true);
}
}
@Component
export default class adds extends Script {
protected k: g1 = new g1();
protected k1: g1 = new g1();
protected i: number = 0;
protected flag_grow: number = 0;
// 公共的数据,用于控制二选一
/** 当脚本被实例后,会在第一帧更新前调用此函数 */
protected onStart(): void {
this.k.space();
// 分配内存的作用等效,因为本来就是代码复制粘贴,只是套壳了名称,作为引用凭证,引用名称为“space"的代码。
// for (var j = 0; j < this.build1.length; j++) {
// this.build1[j] = new ooh();
// }
// this.k1.space1();
// 分配内存的作用等效,因为本来就是代码复制粘贴,只是套壳了名称,作为引用凭证,引用名称为“space1"的代码。
this.k1.space();
// 是g1类型,所以具有相同的凭证,引用的目标也从space1回到space了 g1相当于一个模板了,以这个模板刻出来的对象,都有这个space方法
AssetUtil.asyncDownloadAsset("197386");
setTimeout(() => {
// this.k.grow();
// 暂存方块数据的作用等效,因为本来就是代码复制粘贴,只是套壳了名称,作为引用凭证,引用名称为“grow"的代码。
for (var j = 0; j < this.k.build.length; j++) {
let box = GameObject.spawn("197386", {
transform: new Transform(new Vector(0, j * 50, 25), new Rotation(0, 0, 0), new Vector((1 + j * j) / 90, 1, (1 + j * j) / 90)),
replicates: true
}) as Model;
this.k.build[j].n = box;
}
// this.k1.grow1();
// 暂存方块数据的作用等效,因为本来就是代码复制粘贴,只是套壳了名称,作为引用凭证,引用名称为“grow1"的代码。
for (var j = 0; j < this.k.build.length; j++) {
let box = GameObject.spawn("197386", {
transform: new Transform(new Vector(0, -j * 50, 25), new Rotation(0, 0, 0), new Vector((1 + j * j) / 90, 1, (1 + j * j) / 90)),
replicates: true
}) as Model;
this.k1.build[j].n = box;
}
}, 3000);
setTimeout(() => {
var timer = setInterval(() => {
if (this.flag_grow == 0) {
if (this.i == 10) {
// 改成固定长度限制,10次一波生成,第二个10次一波消失
this.flag_grow = 1;
this.i = 0;
} else {
// var have: ooh = this.k.out();
// var have: ooh = this.k.build[this.i];
// have.n.setCollision(PropertyStatus.Off, true);
// have.n.setVisibility(PropertyStatus.Off, true);
this.k.hide(this.i);
// 同样是复制粘贴原来的代码,同样是通过凭证名来引用代码,但是在引用过程中多了数据,this.i给到x,x代替this.i去执行代码
// var have1: ooh = this.k1.out1();
// var have1: ooh = this.k1.build1[this.i];
// var have1: ooh = this.k1.build[this.i];
// have1.n.setCollision(PropertyStatus.Off, true);
// have1.n.setVisibility(PropertyStatus.Off, true);
this.k1.hide(this.i);
// 同样是复制粘贴原来的代码,同样是通过凭证名来引用代码,但是在引用过程中多了数据,this.i给到x,x代替this.i去执行代码
this.i++;
}
} else if (this.flag_grow == 1) {
if (this.i == 10) {
this.flag_grow = 0;
this.i = 0;
} else {
// var have: ooh = this.k.show();
// var have: ooh = this.k.build[this.i];
// have.n.setCollision(PropertyStatus.On, true);
// have.n.setVisibility(PropertyStatus.On, true);
this.k.show(this.i);
// var have1: ooh = this.k1.show1();
// var have1: ooh = this.k1.build1[this.i];
// var have1: ooh = this.k1.build[this.i];
// have1.n.setCollision(PropertyStatus.On, true);
// have1.n.setVisibility(PropertyStatus.On, true);
this.k1.show(this.i);
this.i++;
}
}
}, 100);
}, 3000);
}
}
删除所有注释。
class ooh {
n: Model;
id: string;
}
class g1 {
public build: Array<ooh> = new Array(10);
public i: number = 0;
protected flag_grow: number = 0;
public space() {
for (var j = 0; j < this.build.length; j++) {
this.build[j] = new ooh();
}
}
public hide(x: number) {
var have: ooh = this.build[x];
have.n.setCollision(PropertyStatus.Off, true);
have.n.setVisibility(PropertyStatus.Off, true);
}
public show(x: number) {
var have1: ooh = this.build[x];
have1.n.setCollision(PropertyStatus.On, true);
have1.n.setVisibility(PropertyStatus.On, true);
}
}
@Component
export default class adds extends Script {
protected k: g1 = new g1();
protected k1: g1 = new g1();
protected i: number = 0;
protected flag_grow: number = 0;
// 公共的数据,用于控制二选一
/** 当脚本被实例后,会在第一帧更新前调用此函数 */
protected onStart(): void {
this.k.space();
this.k1.space();
AssetUtil.asyncDownloadAsset("197386");
setTimeout(() => {
for (var j = 0; j < this.k.build.length; j++) {
let box = GameObject.spawn("197386", {
transform: new Transform(new Vector(0, j * 50, 25), new Rotation(0, 0, 0), new Vector((1 + j * j) / 90, 1, (1 + j * j) / 90)),
replicates: true
}) as Model;
this.k.build[j].n = box;
}
for (var j = 0; j < this.k.build.length; j++) {
let box = GameObject.spawn("197386", {
transform: new Transform(new Vector(0, -j * 50, 25), new Rotation(0, 0, 0), new Vector((1 + j * j) / 90, 1, (1 + j * j) / 90)),
replicates: true
}) as Model;
this.k1.build[j].n = box;
}
}, 3000);
setTimeout(() => {
var timer = setInterval(() => {
if (this.flag_grow == 0) {
if (this.i == 10) {
// 改成固定长度限制,10次一波生成,第二个10次一波消失
this.flag_grow = 1;
this.i = 0;
} else {
this.k.hide(this.i);
this.k1.hide(this.i);
this.i++;
}
} else if (this.flag_grow == 1) {
if (this.i == 10) {
this.flag_grow = 0;
this.i = 0;
} else {
this.k.show(this.i);
this.k1.show(this.i);
this.i++;
}
}
}, 100);
}, 3000);
}
}
复制粘贴,运用模板,实现扩增
实现了四个冲击波同时产生,同时消失。虽然冲击波代码一行一行执行,但是玩家看不出来哪个冲击波代码先执行。
class ooh {
n: Model;
id: string;
}
class g1 {
public build: Array<ooh> = new Array(10);
public i: number = 0;
protected flag_grow: number = 0;
public space() {
for (var j = 0; j < this.build.length; j++) {
this.build[j] = new ooh();
}
}
public hide(x: number) {
var have: ooh = this.build[x];
have.n.setCollision(PropertyStatus.Off, true);
have.n.setVisibility(PropertyStatus.Off, true);
}
public show(x: number) {
var have1: ooh = this.build[x];
have1.n.setCollision(PropertyStatus.On, true);
have1.n.setVisibility(PropertyStatus.On, true);
}
}
@Component
export default class adds extends Script {
protected k: g1 = new g1();
protected k1: g1 = new g1();
protected k2: g1 = new g1();
protected k3: g1 = new g1();
protected i: number = 0;
protected flag_grow: number = 0;
// 公共的数据,用于控制二选一
/** 当脚本被实例后,会在第一帧更新前调用此函数 */
protected onStart(): void {
this.k.space();
this.k1.space();
this.k2.space();
this.k3.space();
AssetUtil.asyncDownloadAsset("197386");
setTimeout(() => {
for (var j = 0; j < this.k.build.length; j++) {
let box = GameObject.spawn("197386", {
transform: new Transform(new Vector(0, j * 50, 25), new Rotation(0, 0, 0), new Vector((1 + j * j) / 90, 1, (1 + j * j) / 90)),
replicates: true
}) as Model;
this.k.build[j].n = box;
}
for (var j = 0; j < this.k.build.length; j++) {
let box = GameObject.spawn("197386", {
transform: new Transform(new Vector(0, -j * 50, 25), new Rotation(0, 0, 0), new Vector((1 + j * j) / 90, 1, (1 + j * j) / 90)),
replicates: true
}) as Model;
this.k1.build[j].n = box;
}
for (var j = 0; j < this.k.build.length; j++) {
let box = GameObject.spawn("197386", {
transform: new Transform(new Vector(-j * 50,0 , 25), new Rotation(0, 0, 0), new Vector((1 + j * j) / 90, 1, (1 + j * j) / 90)),
replicates: true
}) as Model;
this.k2.build[j].n = box;
}
for (var j = 0; j < this.k.build.length; j++) {
let box = GameObject.spawn("197386", {
transform: new Transform(new Vector(j * 50, 0, 25), new Rotation(0, 0, 0), new Vector((1 + j * j) / 90, 1, (1 + j * j) / 90)),
replicates: true
}) as Model;
this.k3.build[j].n = box;
}
}, 3000);
setTimeout(() => {
var timer = setInterval(() => {
if (this.flag_grow == 0) {
if (this.i == 10) {
// 改成固定长度限制,10次一波生成,第二个10次一波消失
this.flag_grow = 1;
this.i = 0;
} else {
this.k.hide(this.i);
this.k1.hide(this.i);
this.k2.hide(this.i);
this.k3.hide(this.i);
this.i++;
}
} else if (this.flag_grow == 1) {
if (this.i == 10) {
this.flag_grow = 0;
this.i = 0;
} else {
this.k.show(this.i);
this.k1.show(this.i);
this.k2.show(this.i);
this.k3.show(this.i);
this.i++;
}
}
}, 100);
}, 3000);
}
}
改改方块拉伸方向,更像一点
class ooh {
n: Model;
id: string;
}
class g1 {
public build: Array<ooh> = new Array(10);
public i: number = 0;
protected flag_grow: number = 0;
public space() {
for (var j = 0; j < this.build.length; j++) {
this.build[j] = new ooh();
}
}
public hide(x: number) {
var have: ooh = this.build[x];
have.n.setCollision(PropertyStatus.Off, true);
have.n.setVisibility(PropertyStatus.Off, true);
}
public show(x: number) {
var have1: ooh = this.build[x];
have1.n.setCollision(PropertyStatus.On, true);
have1.n.setVisibility(PropertyStatus.On, true);
}
}
@Component
export default class adds extends Script {
protected k: g1 = new g1();
protected k1: g1 = new g1();
protected k2: g1 = new g1();
protected k3: g1 = new g1();
protected i: number = 0;
protected flag_grow: number = 0;
// 公共的数据,用于控制二选一
/** 当脚本被实例后,会在第一帧更新前调用此函数 */
protected onStart(): void {
this.k.space();
this.k1.space();
this.k2.space();
this.k3.space();
AssetUtil.asyncDownloadAsset("197386");
setTimeout(() => {
for (var j = 0; j < this.k.build.length; j++) {
let box = GameObject.spawn("197386", {
transform: new Transform(new Vector(0, j * 50, 25), new Rotation(0, 0, 0), new Vector((1 + j * j) / 90, 1, (1 + j * j) / 90)),
replicates: true
}) as Model;
this.k.build[j].n = box;
}
for (var j = 0; j < this.k.build.length; j++) {
let box = GameObject.spawn("197386", {
transform: new Transform(new Vector(0, -j * 50, 25), new Rotation(0, 0, 0), new Vector((1 + j * j) / 90, 1, (1 + j * j) / 90)),
replicates: true
}) as Model;
this.k1.build[j].n = box;
}
// for (var j = 0; j < this.k.build.length; j++) {
// let box = GameObject.spawn("197386", {
// transform: new Transform(new Vector(-j * 50,0 , 25), new Rotation(0, 0, 0), new Vector((1 + j * j) / 90, 1, (1 + j * j) / 90)),
// replicates: true
// }) as Model;
// this.k2.build[j].n = box;
// }
// for (var j = 0; j < this.k.build.length; j++) {
// let box = GameObject.spawn("197386", {
// transform: new Transform(new Vector(j * 50, 0, 25), new Rotation(0, 0, 0), new Vector((1 + j * j) / 90, 1, (1 + j * j) / 90)),
// replicates: true
// }) as Model;
// this.k3.build[j].n = box;
// }
for (var j = 0; j < this.k.build.length; j++) {
let box = GameObject.spawn("197386", {
transform: new Transform(new Vector(-j * 50,0 , 25), new Rotation(0, 0, 0), new Vector(1, (1 + j * j) / 90, (1 + j * j) / 90)),
// 某一方向的放缩长度不变,就是1,想到z轴方向肯定是高度变化,所以第三个参数,也就是(1 + j * j) / 90,不变,前面两个参数交换一下,这样x恢复原长度,y变化
replicates: true
}) as Model;
this.k2.build[j].n = box;
}
for (var j = 0; j < this.k.build.length; j++) {
let box = GameObject.spawn("197386", {
transform: new Transform(new Vector(j * 50, 0, 25), new Rotation(0, 0, 0), new Vector(1,(1 + j * j) / 90 , (1 + j * j) / 90)),
replicates: true
}) as Model;
this.k3.build[j].n = box;
}
}, 3000);
setTimeout(() => {
var timer = setInterval(() => {
if (this.flag_grow == 0) {
if (this.i == 10) {
// 改成固定长度限制,10次一波生成,第二个10次一波消失
this.flag_grow = 1;
this.i = 0;
} else {
this.k.hide(this.i);
this.k1.hide(this.i);
this.k2.hide(this.i);
this.k3.hide(this.i);
this.i++;
}
} else if (this.flag_grow == 1) {
if (this.i == 10) {
this.flag_grow = 0;
this.i = 0;
} else {
this.k.show(this.i);
this.k1.show(this.i);
this.k2.show(this.i);
this.k3.show(this.i);
this.i++;
}
}
}, 100);
}, 3000);
}
}
悬空高一点,改成1525,然后打开物理模拟,用靠谱的物理数据
class ooh {
n: Model;
id: string;
}
class g1 {
public build: Array<ooh> = new Array(10);
public i: number = 0;
protected flag_grow: number = 0;
public space() {
for (var j = 0; j < this.build.length; j++) {
this.build[j] = new ooh();
}
}
public hide(x: number) {
var have: ooh = this.build[x];
have.n.setCollision(PropertyStatus.Off, true);
have.n.setVisibility(PropertyStatus.Off, true);
}
public show(x: number) {
var have1: ooh = this.build[x];
have1.n.setCollision(PropertyStatus.On, true);
have1.n.setVisibility(PropertyStatus.On, true);
}
}
@Component
export default class adds extends Script {
protected k: g1 = new g1();
protected k1: g1 = new g1();
protected k2: g1 = new g1();
protected k3: g1 = new g1();
protected i: number = 0;
protected flag_grow: number = 0;
// 公共的数据,用于控制二选一
/** 当脚本被实例后,会在第一帧更新前调用此函数 */
protected onStart(): void {
this.k.space();
this.k1.space();
this.k2.space();
this.k3.space();
AssetUtil.asyncDownloadAsset("197386");
setTimeout(() => {
for (var j = 0; j < this.k.build.length; j++) {
let box = GameObject.spawn("197386", {
transform: new Transform(new Vector(0, j * 50, 1525), new Rotation(0, 0, 0), new Vector((1 + j * j) / 90, 1, (1 + j * j) / 90)),
replicates: true
}) as Model;
// box.mass=200;
// box.friction =1;
// box.gravityEnabled = true;
// box.physicsEnabled=true;
// // 物理模拟复制粘贴
// 控制质量
box.massEnabled = true;
// 设置质量
box.mass = 200;
// 使用质量
box.gravityEnabled = true;
// 设置摩擦力
box.friction = 0.1;
// 设置弹力
box.restitution = 1;
// 开启物理模拟
box.physicsEnabled = true;
this.k.build[j].n = box;
}
for (var j = 0; j < this.k.build.length; j++) {
let box = GameObject.spawn("197386", {
transform: new Transform(new Vector(0, -j * 50, 1525), new Rotation(0, 0, 0), new Vector((1 + j * j) / 90, 1, (1 + j * j) / 90)),
replicates: true
}) as Model;
// 控制质量
box.massEnabled = true;
// 设置质量
box.mass = 200;
// 使用质量
box.gravityEnabled = true;
// 设置摩擦力
box.friction = 0.1;
// 设置弹力
box.restitution = 1;
// 开启物理模拟
box.physicsEnabled = true;
this.k1.build[j].n=box;
}
// for (var j = 0; j < this.k.build.length; j++) {
// let box = GameObject.spawn("197386", {
// transform: new Transform(new Vector(-j * 50,0 , 25), new Rotation(0, 0, 0), new Vector((1 + j * j) / 90, 1, (1 + j * j) / 90)),
// replicates: true
// }) as Model;
// this.k2.build[j].n = box;
// }
// for (var j = 0; j < this.k.build.length; j++) {
// let box = GameObject.spawn("197386", {
// transform: new Transform(new Vector(j * 50, 0, 25), new Rotation(0, 0, 0), new Vector((1 + j * j) / 90, 1, (1 + j * j) / 90)),
// replicates: true
// }) as Model;
// this.k3.build[j].n = box;
// }
for (var j = 0; j < this.k.build.length; j++) {
let box = GameObject.spawn("197386", {
transform: new Transform(new Vector(-j * 50,0 , 1525), new Rotation(0, 0, 0), new Vector(1, (1 + j * j) / 90, (1 + j * j) / 90)),
// 某一方向的放缩长度不变,就是1,想到z轴方向肯定是高度变化,所以第三个参数,也就是(1 + j * j) / 90,不变,前面两个参数交换一下,这样x恢复原长度,y变化
replicates: true
}) as Model;
// box.mass=200;
// box.friction =1;
// box.gravityEnabled = true;
// box.physicsEnabled=true;
// 控制质量
box.massEnabled = true;
// 设置质量
box.mass = 200;
// 使用质量
box.gravityEnabled = true;
// 设置摩擦力
box.friction = 0.1;
// 设置弹力
box.restitution = 1;
// 开启物理模拟
box.physicsEnabled = true;
this.k2.build[j].n = box;
}
for (var j = 0; j < this.k.build.length; j++) {
let box = GameObject.spawn("197386", {
transform: new Transform(new Vector(j * 50, 0, 1525), new Rotation(0, 0, 0), new Vector(1,(1 + j * j) / 90 , (1 + j * j) / 90)),
replicates: true
}) as Model;
// box.mass=200;
// box.friction =1;
// box.gravityEnabled = true;
// box.physicsEnabled=true;
// 控制质量
box.massEnabled = true;
// 设置质量
box.mass = 200;
// 使用质量
box.gravityEnabled = true;
// 设置摩擦力
box.friction = 0.1;
// 设置弹力
box.restitution = 1;
// 开启物理模拟
box.physicsEnabled = true;
this.k3.build[j].n = box;
}
}, 3000);
setTimeout(() => {
var timer = setInterval(() => {
if (this.flag_grow == 0) {
if (this.i == 10) {
// 改成固定长度限制,10次一波生成,第二个10次一波消失
this.flag_grow = 1;
this.i = 0;
} else {
this.k.hide(this.i);
this.k1.hide(this.i);
this.k2.hide(this.i);
this.k3.hide(this.i);
this.i++;
}
} else if (this.flag_grow == 1) {
if (this.i == 10) {
this.flag_grow = 0;
this.i = 0;
} else {
this.k.show(this.i);
this.k1.show(this.i);
this.k2.show(this.i);
this.k3.show(this.i);
this.i++;
}
}
}, 5000);
}, 3000);
}
}
复位有些麻烦,但是不复位一次性的话,基本效果就是这样。同时向四个方向延伸
class ooh {
n: Model;
id: string;
}
class g1 {
public build: Array<ooh> = new Array(10);
public i: number = 0;
protected flag_grow: number = 0;
public space() {
for (var j = 0; j < this.build.length; j++) {
this.build[j] = new ooh();
}
}
public hide(x: number) {
var have: ooh = this.build[x];
have.n.setCollision(PropertyStatus.Off, true);
have.n.setVisibility(PropertyStatus.Off, true);
}
public show(x: number) {
var have1: ooh = this.build[x];
have1.n.setCollision(PropertyStatus.On, true);
have1.n.setVisibility(PropertyStatus.On, true);
}
}
@Component
export default class adds extends Script {
protected k: g1 = new g1();
protected k1: g1 = new g1();
protected k2: g1 = new g1();
protected k3: g1 = new g1();
protected i: number = 0;
protected flag_grow: number = 0;
// 公共的数据,用于控制二选一
/** 当脚本被实例后,会在第一帧更新前调用此函数 */
protected onStart(): void {
this.k.space();
this.k1.space();
this.k2.space();
this.k3.space();
AssetUtil.asyncDownloadAsset("197386");
setTimeout(() => {
for (var j = 0; j < this.k.build.length; j++) {
let box = GameObject.spawn("197386", {
transform: new Transform(new Vector(0, j * 50, 1525), new Rotation(0, 0, 0), new Vector((1 + j * j) / 90, 1, (1 + j * j) / 90)),
replicates: true
}) as Model;
// 控制质量
box.massEnabled = true;
// 设置质量
box.mass = 200;
// 使用质量
box.gravityEnabled = true;
// 设置摩擦力
box.friction = 0.1;
// 设置弹力
box.restitution = 1;
// 开启物理模拟
box.physicsEnabled = true;
this.k.build[j].n = box;
}
for (var j = 0; j < this.k.build.length; j++) {
let box = GameObject.spawn("197386", {
transform: new Transform(new Vector(0, -j * 50, 1525), new Rotation(0, 0, 0), new Vector((1 + j * j) / 90, 1, (1 + j * j) / 90)),
replicates: true
}) as Model;
// 控制质量
box.massEnabled = true;
// 设置质量
box.mass = 200;
// 使用质量
box.gravityEnabled = true;
// 设置摩擦力
box.friction = 0.1;
// 设置弹力
box.restitution = 1;
// 开启物理模拟
box.physicsEnabled = true;
this.k1.build[j].n = box;
}
for (var j = 0; j < this.k.build.length; j++) {
let box = GameObject.spawn("197386", {
transform: new Transform(new Vector(-j * 50, 0, 1525), new Rotation(0, 0, 0), new Vector(1, (1 + j * j) / 90, (1 + j * j) / 90)),
// 某一方向的放缩长度不变,就是1,想到z轴方向肯定是高度变化,所以第三个参数,也就是(1 + j * j) / 90,不变,前面两个参数交换一下,这样x恢复原长度,y变化
replicates: true
}) as Model;
// 控制质量
box.massEnabled = true;
// 设置质量
box.mass = 200;
// 使用质量
box.gravityEnabled = true;
// 设置摩擦力
box.friction = 0.1;
// 设置弹力
box.restitution = 1;
// 开启物理模拟
box.physicsEnabled = true;
this.k2.build[j].n = box;
}
for (var j = 0; j < this.k.build.length; j++) {
let box = GameObject.spawn("197386", {
transform: new Transform(new Vector(j * 50, 0, 1525), new Rotation(0, 0, 0), new Vector(1, (1 + j * j) / 90, (1 + j * j) / 90)),
replicates: true
}) as Model;
// 控制质量
box.massEnabled = true;
// 设置质量
box.mass = 200;
// 使用质量
box.gravityEnabled = true;
// 设置摩擦力
box.friction = 0.1;
// 设置弹力
box.restitution = 1;
// 开启物理模拟
box.physicsEnabled = true;
this.k3.build[j].n = box;
}
}, 3000);
setTimeout(() => {
// var timer = setInterval(() => {
for (var j = 0; j < this.k.build.length; j++) {
this.k.hide(this.i);
this.k1.hide(this.i);
this.k2.hide(this.i);
this.k3.hide(this.i);
this.i++;
}
// if (this.flag_grow == 0) {
// if (this.i == 10) {
// // 改成固定长度限制,10次一波生成,第二个10次一波消失
// this.flag_grow = 1;
// this.i = 0;
// } else {
// this.k.hide(this.i);
// this.k1.hide(this.i);
// this.k2.hide(this.i);
// this.k3.hide(this.i);
// this.i++;
// }
// else if (this.flag_grow == 1) {
// if (this.i == 10) {
// this.flag_grow = 0;
// this.i = 0;
// } else {
// this.k.show(this.i);
// this.k1.show(this.i);
// this.k2.show(this.i);
// this.k3.show(this.i);
// this.i++;
// }
// setTimeout(() => {
// for (var j = 0; j < this.k.build.length; j++) {
// this.k.show(this.i);
// this.k1.show(this.i);
// this.k2.show(this.i);
// this.k3.show(this.i);
// }
// }, 5000);
}, 5000);
// }, 3000);
}
}
增加复位,重新初始化数据,然后重新借原来注释掉的框架。
最终成果。感觉不如方块喷泉,可能把四个方块放一起靠弹力效果好一些。总之就是模拟四个方向同时生成方块。
class ooh {
n: Model;
id: string;
}
class g1 {
public build: Array<ooh> = new Array(10);
public i: number = 0;
protected flag_grow: number = 0;
public space() {
for (var j = 0; j < this.build.length; j++) {
this.build[j] = new ooh();
}
}
public hide(x: number) {
var have: ooh = this.build[x];
have.n.setCollision(PropertyStatus.Off, true);
have.n.setVisibility(PropertyStatus.Off, true);
}
public show(x: number) {
var have1: ooh = this.build[x];
have1.n.setCollision(PropertyStatus.On, true);
have1.n.setVisibility(PropertyStatus.On, true);
}
}
@Component
export default class adds extends Script {
protected k: g1 = new g1();
protected k1: g1 = new g1();
protected k2: g1 = new g1();
protected k3: g1 = new g1();
protected i: number = 0;
protected flag_grow: number = 0;
// 公共的数据,用于控制二选一
/** 当脚本被实例后,会在第一帧更新前调用此函数 */
protected onStart(): void {
this.k.space();
this.k1.space();
this.k2.space();
this.k3.space();
AssetUtil.asyncDownloadAsset("197386");
setTimeout(() => {
for (var j = 0; j < this.k.build.length; j++) {
let box = GameObject.spawn("197386", {
transform: new Transform(new Vector(0, j * 50, 1525), new Rotation(0, 0, 0), new Vector((1 + j * j) / 90, 1, (1 + j * j) / 90)),
replicates: true
}) as Model;
// 控制质量
box.massEnabled = true;
// 设置质量
box.mass = 200;
// 使用质量
box.gravityEnabled = true;
// 设置摩擦力
box.friction = 0.1;
// 设置弹力
box.restitution = 1;
// 开启物理模拟
// box.physicsEnabled = true;
box.physicsEnabled = false;
this.k.build[j].n = box;
}
for (var j = 0; j < this.k.build.length; j++) {
let box = GameObject.spawn("197386", {
transform: new Transform(new Vector(0, -j * 50, 1525), new Rotation(0, 0, 0), new Vector((1 + j * j) / 90, 1, (1 + j * j) / 90)),
replicates: true
}) as Model;
// 控制质量
box.massEnabled = true;
// 设置质量
box.mass = 200;
// 使用质量
box.gravityEnabled = true;
// 设置摩擦力
box.friction = 0.1;
// 设置弹力
box.restitution = 1;
// 开启物理模拟
// box.physicsEnabled = true;
box.physicsEnabled = false;
this.k1.build[j].n = box;
}
for (var j = 0; j < this.k.build.length; j++) {
let box = GameObject.spawn("197386", {
transform: new Transform(new Vector(-j * 50, 0, 1525), new Rotation(0, 0, 0), new Vector(1, (1 + j * j) / 90, (1 + j * j) / 90)),
// 某一方向的放缩长度不变,就是1,想到z轴方向肯定是高度变化,所以第三个参数,也就是(1 + j * j) / 90,不变,前面两个参数交换一下,这样x恢复原长度,y变化
replicates: true
}) as Model;
// 控制质量
box.massEnabled = true;
// 设置质量
box.mass = 200;
// 使用质量
box.gravityEnabled = true;
// 设置摩擦力
box.friction = 0.1;
// 设置弹力
box.restitution = 1;
// 开启物理模拟
// box.physicsEnabled = true;
box.physicsEnabled = false;
this.k2.build[j].n = box;
}
for (var j = 0; j < this.k.build.length; j++) {
let box = GameObject.spawn("197386", {
transform: new Transform(new Vector(j * 50, 0, 1525), new Rotation(0, 0, 0), new Vector(1, (1 + j * j) / 90, (1 + j * j) / 90)),
replicates: true
}) as Model;
// 控制质量
box.massEnabled = true;
// 设置质量
box.mass = 200;
// 使用质量
box.gravityEnabled = true;
// 设置摩擦力
box.friction = 0.1;
// 设置弹力
box.restitution = 1;
// 开启物理模拟
// box.physicsEnabled = true;
box.physicsEnabled = false;
this.k3.build[j].n = box;
}
for (var j = 0; j < this.k.build.length; j++) {
this.k.hide(this.i);
this.k1.hide(this.i);
this.k2.hide(this.i);
this.k3.hide(this.i);
this.i++;
}
}, 3000);
setTimeout(() => {
var c: number = 0;
var timer = setInterval(() => {
if (this.flag_grow == 0) {
if (this.i == 10) {
// 改成固定长度限制,10次一波生成,第二个10次一波消失
this.flag_grow = 1;
this.i = 0;
} else {
var j = this.i;
this.k.hide(this.i);
this.k.build[this.i].n.worldTransform = new Transform(new Vector(0, j * 50, 1525), new Rotation(0, 0, 0), new Vector((1 + j * j) / 90, 1, (1 + j * j) / 90))
this.k.build[this.i].n.physicsEnabled = false;
this.k1.hide(this.i);
this.k.build[this.i].n.worldTransform = new Transform(new Vector(0, -j * 50, 1525), new Rotation(0, 0, 0), new Vector((1 + j * j) / 90, 1, (1 + j * j) / 90))
this.k.build[this.i].n.physicsEnabled = false;
this.k2.hide(this.i);
this.k.build[this.i].n.worldTransform = new Transform(new Vector(0+j * 50, 0, 1525), new Rotation(0, 0, 0), new Vector(1,(1 + j * j) / 90 , (1 + j * j) / 90))
this.k.build[this.i].n.physicsEnabled = false;
this.k3.hide(this.i);
this.k.build[this.i].n.worldTransform = new Transform(new Vector(0- j * 50,0, 1525), new Rotation(0, 0, 0), new Vector(1,(1 + j * j) / 90 , (1 + j * j) / 90))
this.k.build[this.i].n.physicsEnabled = false;
this.i++;
}
}
else if (this.flag_grow == 1) {
if (this.i == 10) {
this.flag_grow = 0;
this.i = 0;
} else {
// this.k.show(this.i);
// this.k1.show(this.i);
// this.k2.show(this.i);
// this.k3.show(this.i);
this.k.show(this.i);
this.k.build[this.i].n.physicsEnabled = true;
this.k1.show(this.i);
this.k1.build[this.i].n.physicsEnabled = true;
this.k2.show(this.i);
this.k2.build[this.i].n.physicsEnabled = true;
this.k3.show(this.i);
this.k3.build[this.i].n.physicsEnabled = true;
this.i++;
}
}
// for (var j = 0; j < this.k.build.length; j++) {
// this.k.show(this.i);
// this.k.build[this.i].n.physicsEnabled = true;
// this.k1.show(this.i);
// this.k1.build[this.i].n.physicsEnabled = true;
// this.k2.show(this.i);
// this.k2.build[this.i].n.physicsEnabled = true;
// this.k3.show(this.i);
// this.k3.build[this.i].n.physicsEnabled = true;
// }
}, 300);
}, 3000);
}
}
class ooh {
n: Model;
id: string;
}
class g1 {
public build: Array<ooh> = new Array(10);
public i: number = 0;
protected flag_grow: number = 0;
public space() {
for (var j = 0; j < this.build.length; j++) {
this.build[j] = new ooh();
}
}
public hide(x: number) {
var have: ooh = this.build[x];
have.n.setCollision(PropertyStatus.Off, true);
have.n.setVisibility(PropertyStatus.Off, true);
}
public show(x: number) {
var have1: ooh = this.build[x];
have1.n.setCollision(PropertyStatus.On, true);
have1.n.setVisibility(PropertyStatus.On, true);
}
}
@Component
export default class adds extends Script {
protected k: g1 = new g1();
protected k1: g1 = new g1();
protected k2: g1 = new g1();
protected k3: g1 = new g1();
protected i: number = 0;
protected flag_grow: number = 0;
// 公共的数据,用于控制二选一
/** 当脚本被实例后,会在第一帧更新前调用此函数 */
protected onStart(): void {
this.k.space();
this.k1.space();
this.k2.space();
this.k3.space();
AssetUtil.asyncDownloadAsset("197386");
setTimeout(() => {
for (var j = 0; j < this.k.build.length; j++) {
let box = GameObject.spawn("197386", {
transform: new Transform(new Vector(0, j * 50, 1525), new Rotation(0, 0, 0), new Vector((1 + j * j) / 90, 1, (1 + j * j) / 90)),
replicates: true
}) as Model;
// 控制质量
box.massEnabled = true;
// 设置质量
box.mass = 200;
// 使用质量
box.gravityEnabled = true;
// 设置摩擦力
box.friction = 0.1;
// 设置弹力
box.restitution = 1;
// 开启物理模拟
// box.physicsEnabled = true;
box.physicsEnabled = false;
this.k.build[j].n = box;
}
for (var j = 0; j < this.k.build.length; j++) {
let box = GameObject.spawn("197386", {
transform: new Transform(new Vector(0, -j * 50, 1525), new Rotation(0, 0, 0), new Vector((1 + j * j) / 90, 1, (1 + j * j) / 90)),
replicates: true
}) as Model;
// 控制质量
box.massEnabled = true;
// 设置质量
box.mass = 200;
// 使用质量
box.gravityEnabled = true;
// 设置摩擦力
box.friction = 0.1;
// 设置弹力
box.restitution = 1;
// 开启物理模拟
// box.physicsEnabled = true;
box.physicsEnabled = false;
this.k1.build[j].n = box;
}
for (var j = 0; j < this.k.build.length; j++) {
let box = GameObject.spawn("197386", {
transform: new Transform(new Vector(-j * 50, 0, 1525), new Rotation(0, 0, 0), new Vector(1, (1 + j * j) / 90, (1 + j * j) / 90)),
// 某一方向的放缩长度不变,就是1,想到z轴方向肯定是高度变化,所以第三个参数,也就是(1 + j * j) / 90,不变,前面两个参数交换一下,这样x恢复原长度,y变化
replicates: true
}) as Model;
// 控制质量
box.massEnabled = true;
// 设置质量
box.mass = 200;
// 使用质量
box.gravityEnabled = true;
// 设置摩擦力
box.friction = 0.1;
// 设置弹力
box.restitution = 1;
// 开启物理模拟
// box.physicsEnabled = true;
box.physicsEnabled = false;
this.k2.build[j].n = box;
}
for (var j = 0; j < this.k.build.length; j++) {
let box = GameObject.spawn("197386", {
transform: new Transform(new Vector(j * 50, 0, 1525), new Rotation(0, 0, 0), new Vector(1, (1 + j * j) / 90, (1 + j * j) / 90)),
replicates: true
}) as Model;
// 控制质量
box.massEnabled = true;
// 设置质量
box.mass = 200;
// 使用质量
box.gravityEnabled = true;
// 设置摩擦力
box.friction = 0.1;
// 设置弹力
box.restitution = 1;
// 开启物理模拟
// box.physicsEnabled = true;
box.physicsEnabled = false;
this.k3.build[j].n = box;
}
for (var j = 0; j < this.k.build.length; j++) {
this.k.hide(this.i);
this.k1.hide(this.i);
this.k2.hide(this.i);
this.k3.hide(this.i);
this.i++;
}
}, 3000);
setTimeout(() => {
var c: number = 0;
var timer = setInterval(() => {
if (this.flag_grow == 0) {
if (this.i == 10) {
// 改成固定长度限制,10次一波生成,第二个10次一波消失
this.flag_grow = 1;
this.i = 0;
} else {
var j = this.i;
// 复位
this.k.hide(this.i);
this.k.build[this.i].n.worldTransform = new Transform(new Vector(0, j * 30, 1525), new Rotation(0, 0, 0), new Vector((1 + j * j) / 90, 1, (1 + j * j) / 90))
this.k.build[this.i].n.physicsEnabled = false;
this.k1.hide(this.i);
this.k1.build[this.i].n.worldTransform = new Transform(new Vector(0, -j * 30, 1525), new Rotation(0, 0, 0), new Vector((1 + j * j) / 90, 1, (1 + j * j) / 90))
this.k1.build[this.i].n.physicsEnabled = false;
this.k2.hide(this.i);
this.k2.build[this.i].n.worldTransform = new Transform(new Vector(j * 30, 0, 1525), new Rotation(0, 0, 0), new Vector(1,(1 + j * j) / 90 , (1 + j * j) / 90))
this.k2.build[this.i].n.physicsEnabled = false;
this.k3.hide(this.i);
this.k3.build[this.i].n.worldTransform = new Transform(new Vector(-j * 30,0, 1525), new Rotation(0, 0, 0), new Vector(1,(1 + j * j) / 90 , (1 + j * j) / 90))
this.k3.build[this.i].n.physicsEnabled = false;
this.i++;
}
}
else if (this.flag_grow == 1) {
if (this.i == 10) {
this.flag_grow = 0;
this.i = 0;
} else {
// this.k.show(this.i);
// this.k1.show(this.i);
// this.k2.show(this.i);
// this.k3.show(this.i);
this.k.show(this.i);
this.k.build[this.i].n.physicsEnabled = true;
this.k1.show(this.i);
this.k1.build[this.i].n.physicsEnabled = true;
this.k2.show(this.i);
this.k2.build[this.i].n.physicsEnabled = true;
this.k3.show(this.i);
this.k3.build[this.i].n.physicsEnabled = true;
this.i++;
}
}
// for (var j = 0; j < this.k.build.length; j++) {
// this.k.show(this.i);
// this.k.build[this.i].n.physicsEnabled = true;
// this.k1.show(this.i);
// this.k1.build[this.i].n.physicsEnabled = true;
// this.k2.show(this.i);
// this.k2.build[this.i].n.physicsEnabled = true;
// this.k3.show(this.i);
// this.k3.build[this.i].n.physicsEnabled = true;
// }
}, 300);
}, 3000);
}
}
贰.所需语法
TypeScript 类 | 菜鸟教程 (runoob.com)
哪里不会点哪里,实在不行复制粘贴直接跑
叁.应用说明
场景交互上:烟花,函数动画,
代码开发上:双技能同时释放。
数据生成上:技能编辑器预制暂存技能。
肆.相关参考链接 (返回主站
普通大学生“数据结构”课作业笔记#000-目录-逻辑结构与存储结构 口袋方舟论坛|面向全年龄的UGC互动内容平台与交流社区 (ark.online)
|