Commit 840f4ea2 authored by Tt's avatar Tt

NGT10提交

parent e67f3f18
......@@ -5,32 +5,21 @@
// Learn life-cycle callbacks:
// - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html
import pg from "./tool/pg";
const { ccclass, property } = cc._decorator;
@ccclass
export default class Box2d extends cc.Component {
@property(cc.Label)
label: cc.Label = null;
@property
text: string = 'hello';
// LIFE-CYCLE CALLBACKS:
private layout_item: cc.Node;
onLoad() {
cc.director.getPhysicsManager().enabled = true;
cc.director.getPhysicsManager().debugDrawFlags =
// cc.PhysicsManager.DrawBits.e_aabbBit |
// cc.PhysicsManager.DrawBits.e_pairBit |
// cc.PhysicsManager.DrawBits.e_centerOfMassBit |
cc.PhysicsManager.DrawBits.e_jointBit |
cc.PhysicsManager.DrawBits.e_shapeBit;
// cc.director.getPhysicsManager().gravity = cc.v2(0, -320);
// cc.director.getPhysicsManager().debugDrawFlags = cc.PhysicsManager.DrawBits.e_jointBit | cc.PhysicsManager.DrawBits.e_shapeBit;
cc.director.getPhysicsManager().debugDrawFlags = 0;
cc.director.getPhysicsManager().gravity = cc.v2(0, -640);
// 开启物理步长的设置
var manager = cc.director.getPhysicsManager();
manager.enabledAccumulator = true;
......@@ -41,41 +30,37 @@ export default class Box2d extends cc.Component {
// 每次更新物理系统处理位置的迭代次数,默认为 10
cc.PhysicsManager.POSITION_ITERATIONS = 8;
// setTimeout(() => {
// let item = this.node.getChildByName("item2")
// let rigid = item.getComponent(cc.RigidBody)
// rigid.linearVelocity = cc.v2(-100, 0)
// }, 1500);
this.layout_item = this.node.getChildByName('layout_item')
this.initOrange();
// setTimeout(() => {
// this.jumpOrange();
// }, 1000);
// setTimeout(() => {
// this.jumpOrange();
// }, 6000);
// setTimeout(() => {
// this.jumpOrange();
// }, 11000);
// setTimeout(() => {
// this.jumpOrange();
// }, 16000);
// setTimeout(() => {
// this.jumpOrange();
// }, 21000);
// setTimeout(() => {
// this.jumpRoll();
// }, 26000);
pg.event.on("box2d_init", (len: number) => {
let arr = [];
for (let i = 0; i < len; i++) {
arr.push(100 + i);
}
this.initOrange(arr);
})
pg.event.on("box2d_next", () => {
this.jumpOrange();
})
pg.event.on("box2d_roll", () => {
this.jumpRoll();
})
pg.event.on("box2d_hide", () => {
this.hideJump();
})
}
current: number;
initOrange() {
ids: Array<number>;
jumpedNodes: Array<cc.Node>;
initOrange(ids = [101, 102, 103, 104, 105]) {
this.current = 0;
this.jumpedNodes = [];
this.ids = ids.concat();
this.layout_item.removeAllChildren();
let item = this.node.getChildByName("item");
let p0 = cc.v2(-320, 305);
let pSpace = cc.v2(120, 0)
let ids = [101, 102, 103, 104, 105]
this.current = 0;
for (let i = 0; i < ids.length; i++) {
let node = cc.instantiate(item);
node.active = true;
......@@ -89,13 +74,12 @@ export default class Box2d extends cc.Component {
return this.layout_item.children.filter(node => ids.some(id => id == node.data))
}
jumpOrange() {
this.current;
let baffle = this.node.getChildByName('baffle')
baffle.active = false;
let lid = this.node.getChildByName('lid')
lid.active = false;
// 根据current来找橘子及后续的内容
let ids = [101, 102, 103, 104, 105].concat();
let ids = this.ids.concat();
let jumping: any = [ids[this.current++]];
let moveing: any = []
for (let i = this.current; i < ids.length; i++) {
......@@ -105,37 +89,48 @@ export default class Box2d extends cc.Component {
moveing = this.findItemByIds(moveing)
jumping.forEach(node => {
node.getComponent(cc.RigidBody).linearVelocity = cc.v2(-200, 0)
this.jumpedNodes.push(node);
})
moveing.forEach(node => {
node.getComponent(cc.RigidBody).linearVelocity = cc.v2(-100, 0)
this.scheduleOnce(() => {
// node.getComponent(cc.RigidBody).linearVelocity = cc.v2(0, 0)
baffle.active = true;
}, 1.2)
node.getComponent(cc.RigidBody).linearDamping = 2
}, 1.3)
})
setTimeout(() => {
pg.event.emit("box2d_next_successed")
}, 2000);
}
jumpRoll() {
let lid = this.node.getChildByName('lid')
lid.active = true;
this.layout_item.children.forEach(node => {
let list = this.jumpedNodes;
list.forEach(node => {
node.getComponent(cc.RigidBody).linearVelocity = cc.v2(370, 500)
})
setTimeout(() => {
this.layout_item.children.forEach(node => {
list.forEach(node => {
node.getComponent(cc.RigidBody).linearVelocity = cc.v2(-370, 500)
})
}, 1000);
setTimeout(() => {
this.layout_item.children.forEach(node => {
list.forEach(node => {
node.getComponent(cc.RigidBody).linearVelocity = cc.v2(370, 500)
})
}, 2000);
setTimeout(() => {
this.layout_item.children.forEach(node => {
list.forEach(node => {
node.getComponent(cc.RigidBody).linearVelocity = cc.v2(-370, 500)
})
setTimeout(() => {
pg.event.emit("box2d_roll_successed")
}, 1000);
}, 3000);
}
hideJump() {
this.jumpedNodes.forEach(node => node.active = false)
}
start() {
}
......
......@@ -111,7 +111,6 @@ export default class SceneComponent extends MyCocosSceneComponent {
private showQuestion() {
let question = Game.getIns().getCurrentPage();
this.question_word.getComponent(cc.Label).string = question.text;
}
......@@ -220,7 +219,7 @@ export default class SceneComponent extends MyCocosSceneComponent {
this.playLocalAudio("right").then(() => {
this.playLocalAudio("diaoluo");
});
this.box2d.getComponent(Box2d).jumpOrange();
pg.event.emit("box2d_next")
pg.event.emit("mouse_10_add");
} else {
this.playLocalAudio("error").then(() => {
......@@ -250,6 +249,8 @@ export default class SceneComponent extends MyCocosSceneComponent {
private checkRoundEnd() {
Game.getIns().addPage();
if (!Game.getIns().getCurrentPage()) {
pg.event.on("box2d_roll_successed", () => {
pg.event.emit("box2d_hide")
// this.gameOver();
let zjz_ske = cc.find("zjz_ske", this.node);
zjz_ske.active = true;
......@@ -260,6 +261,8 @@ export default class SceneComponent extends MyCocosSceneComponent {
zjz_ske.active = false;
this.showFind();
}, this);
})
pg.event.emit("box2d_roll")
} else {
this.playLocalAudio("next");
this.record_word.getComponent(cc.Label).string = "";
......@@ -290,6 +293,8 @@ export default class SceneComponent extends MyCocosSceneComponent {
}
private initStart() {
//生成橘子
pg.event.emit('box2d_init', Game.getIns().getTotalPageNum())
this.layout_start.active = true;
cc.find("layout_top/label_title", this.node).getComponent(cc.Label).string = Game.getIns().title;
pg.event.emit("mouse_10_num", Game.getIns().total);
......
......@@ -4588,6 +4588,7 @@ declare namespace cc {
/** !#en Returns a normalized vector representing the forward direction (Z axis) of the node in world space.
!#zh 获取节点正前方(z 轴)面对的方向,返回值为世界坐标系下的归一化向量 */
forward: Vec3;
data: number;
/**
@param name name
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment