|
@@ -0,0 +1,127 @@
|
|
|
+import { _decorator, CircleCollider2D, Component, log, Node, RigidBody2D, Vec2, Vec3 } from 'cc';
|
|
|
+import { EventManager } from './EventManager';
|
|
|
+import { PropBase } from './Prop/Base/PropBase';
|
|
|
+import { diban } from './Prop/Type/diban';
|
|
|
+const { ccclass, property } = _decorator;
|
|
|
+
|
|
|
+@ccclass('RoleControl')
|
|
|
+export class RoleControl extends Component {
|
|
|
+ @property(Node)
|
|
|
+ Role: Node = null;
|
|
|
+
|
|
|
+ @property(Node)
|
|
|
+ LeftBtn: Node = null;
|
|
|
+
|
|
|
+ @property(Node)
|
|
|
+ RightBtn: Node = null;
|
|
|
+
|
|
|
+
|
|
|
+ private UpSpeed: number = 20;
|
|
|
+ private G: number = 20;
|
|
|
+
|
|
|
+
|
|
|
+ MyDir: number = 0;
|
|
|
+
|
|
|
+ protected onLoad(): void {
|
|
|
+ EventManager.instance.et.on(EventManager.EventType.Reset_Role, this.Reset_Role, this);
|
|
|
+ EventManager.instance.et.on(EventManager.EventType.Die_Role, this.Die_Role, this);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ Die_Role() {
|
|
|
+ this.scheduleOnce(() => {
|
|
|
+ this.Role.active = false
|
|
|
+ }, 0)
|
|
|
+ }
|
|
|
+ Reset_Role() {
|
|
|
+ this.Role.active = true
|
|
|
+ let Nodes = this.getComponentsInChildren(PropBase).filter((item) => {
|
|
|
+ return item.node.position.y < 0
|
|
|
+ })
|
|
|
+
|
|
|
+ let Nodes1 = Nodes.filter((item) => {
|
|
|
+ return item.node.name == 'diban'
|
|
|
+ })
|
|
|
+
|
|
|
+
|
|
|
+ let SortNodes = Nodes1.sort((a, b) => {
|
|
|
+ return a.node.position.y - b.node.position.y
|
|
|
+ })
|
|
|
+
|
|
|
+ let TempNode = SortNodes.pop()
|
|
|
+
|
|
|
+ this.scheduleOnce(() => {
|
|
|
+ this.Role.setPosition(new Vec3(TempNode.node.position.x, TempNode.node.position.y + 45, 0))
|
|
|
+ this.Role.getComponent(RigidBody2D).linearVelocity = new Vec2(0, -this.G); // 速度值可以根据需要调整
|
|
|
+ }, 0)
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ protected start(): void {
|
|
|
+
|
|
|
+
|
|
|
+ this.Role.getComponent(RigidBody2D).linearVelocity = new Vec2(0, -this.G); // 速度值可以根据需要调整
|
|
|
+
|
|
|
+
|
|
|
+ this.LeftBtn.on(Node.EventType.TOUCH_START, this.LeftStart, this);
|
|
|
+ this.RightBtn.on(Node.EventType.TOUCH_START, this.RightStart, this);
|
|
|
+
|
|
|
+
|
|
|
+ this.LeftBtn.on(Node.EventType.TOUCH_END, this.LeftEnd, this);
|
|
|
+ this.RightBtn.on(Node.EventType.TOUCH_END, this.RightEnd, this);
|
|
|
+ }
|
|
|
+ LeftStart() {
|
|
|
+ this.MyDir = -1
|
|
|
+ }
|
|
|
+ RightStart() {
|
|
|
+ this.MyDir = 1
|
|
|
+ }
|
|
|
+
|
|
|
+ LeftEnd() {
|
|
|
+ if (this.MyDir == 1) {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ this.MyDir = 0
|
|
|
+ }
|
|
|
+
|
|
|
+ RightEnd() {
|
|
|
+ if (this.MyDir == -1) {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ this.MyDir = 0
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ updateTime: number;
|
|
|
+ update(deltaTime: number) {
|
|
|
+ this.updateTime += deltaTime;
|
|
|
+ let _time = 1 / 60//60FPS
|
|
|
+ if (this.updateTime < _time) return;
|
|
|
+ this.updateTime = this.updateTime - _time;
|
|
|
+ this.FixUpdate()
|
|
|
+ }
|
|
|
+ FixUpdate() {
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ if (!this.Role.getComponent(RigidBody2D)) {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ switch (this.MyDir) {
|
|
|
+ case 0:
|
|
|
+ this.Role.getComponent(RigidBody2D).linearVelocity = new Vec2(0, -this.G); // 速度值可以根据需要调整
|
|
|
+ break;
|
|
|
+ case -1:
|
|
|
+ this.Role.getComponent(RigidBody2D).linearVelocity = new Vec2(-this.UpSpeed, -this.G); // 速度值可以根据需要调整
|
|
|
+ break;
|
|
|
+ case 1:
|
|
|
+ this.Role.getComponent(RigidBody2D).linearVelocity = new Vec2(this.UpSpeed, -this.G); // 速度值可以根据需要调整
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+
|