LayerRootAction.ts 3.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. import { _decorator, BoxCollider2D, CircleCollider2D, Component, EventTouch, Input, instantiate, Node, PolygonCollider2D, Prefab, RigidBody2D, tween, UITransform, Vec2, Vec3 } from 'cc';
  2. import { LayerAction } from './LayerAction';
  3. import { ElementAction } from './ElementAction';
  4. import { HoleAction } from './HoleAction';
  5. import { PinAction } from './PinAction';
  6. import { LevelAction } from './LevelAction';
  7. import { PoolMgr } from './PoolMagr';
  8. import { Tools } from './Tools';
  9. import { ColorDate } from './ColorDate';
  10. import { Global } from './Global';
  11. const { ccclass, property } = _decorator;
  12. @ccclass('LayerRootAction')
  13. export class LayerRootAction extends Component {
  14. lvl_action: LevelAction
  15. update(deltaTime: number) {
  16. }
  17. public init_root(lvl: number) {
  18. Tools.clearFromParent(this.node, LevelAction);
  19. let level_prebab = PoolMgr.ins.getPrefab("lvl_" + lvl);
  20. if (!level_prebab) {
  21. console.log("没有这个关卡》〉》〉》", lvl);
  22. //return
  23. console.log("重置一个等级1");
  24. Global.restart_default(0);
  25. lvl = Global.next_level();
  26. level_prebab = PoolMgr.ins.getPrefab("lvl_" + lvl);
  27. }
  28. let lvl_node = instantiate(level_prebab);
  29. this.lvl_action = lvl_node.getComponent(LevelAction)
  30. this.lvl_action.init_level();
  31. this.node.addChild(lvl_node);
  32. }
  33. /**
  34. * 随机打乱钉子颜色
  35. */
  36. random_pin() {
  37. let arr: PinAction[] = [];
  38. if (this.lvl_action) {
  39. arr = this.lvl_action.get_pin_color();
  40. }
  41. let t = 0.05;
  42. let y = this.node.getPosition().y;
  43. tween(this.node)
  44. .to(t, { position: new Vec3(30, y, 0) }, Global.our_easing)
  45. .to(t, { position: new Vec3(-30, y, 0) }, Global.our_easing)
  46. .to(t, { position: new Vec3(30, y, 0) }, Global.our_easing)
  47. .to(t, { position: new Vec3(-30, y, 0) }, Global.our_easing)
  48. .to(t, { position: new Vec3(20, y, 0) }, Global.our_easing)
  49. .to(t, { position: new Vec3(-20, y, 0) }, Global.our_easing)
  50. .to(t, { position: new Vec3(20, y, 0) }, Global.our_easing)
  51. .to(t, { position: new Vec3(-20, y, 0) }, Global.our_easing)
  52. .to(t, { position: new Vec3(10, y, 0) }, Global.our_easing)
  53. .to(t, { position: new Vec3(-10, y, 0) }, Global.our_easing)
  54. .to(t, { position: new Vec3(2, y, 0) }, Global.our_easing)
  55. .to(t, { position: new Vec3(-2, y, 0) }, Global.our_easing)
  56. .to(t, { position: new Vec3(0, y, 0) }, Global.our_easing)
  57. .delay(0.3)
  58. .call(() => {
  59. this.node.setPosition(new Vec3(0, y, 0));
  60. let arr_color: ColorDate[] = [];
  61. arr.forEach(element => {
  62. let c = element.pin_color;
  63. arr_color.push(c.clone());
  64. });
  65. arr_color.sort(() => {
  66. return 0.5 - Math.random();
  67. });
  68. if (arr.length == arr_color.length) {
  69. for (let i = 0; i < arr.length; i++) {
  70. let pin_color = arr[i].pin_color;
  71. let c = arr_color[i];
  72. pin_color.r = c.r;
  73. pin_color.g = c.g;
  74. pin_color.b = c.b;
  75. pin_color.id = c.id;
  76. arr[i].reset_img();
  77. }
  78. }
  79. })
  80. .start();
  81. }
  82. }