LayerRootAction.ts 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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. random_pin() {
  34. let arr: PinAction[] = [];
  35. if(this.lvl_action) {
  36. arr = this.lvl_action.get_pin_color();
  37. }
  38. let t = 0.05;
  39. let y = this.node.getPosition().y;
  40. tween(this.node)
  41. .to(t, { position: new Vec3(30, y,0) },Global.our_easing)
  42. .to(t, { position: new Vec3(-30, y,0) },Global.our_easing)
  43. .to(t, { position: new Vec3(30, y,0) },Global.our_easing)
  44. .to(t, { position: new Vec3(-30, y,0) },Global.our_easing)
  45. .to(t, { position: new Vec3(20, y,0) },Global.our_easing)
  46. .to(t, { position: new Vec3(-20, y,0) }, Global.our_easing)
  47. .to(t, { position: new Vec3(20, y,0) }, Global.our_easing)
  48. .to(t, { position: new Vec3(-20, y,0) },Global.our_easing)
  49. .to(t, { position: new Vec3(10, y,0) },Global.our_easing)
  50. .to(t, { position: new Vec3(-10, y,0) },Global.our_easing)
  51. .to(t, { position: new Vec3(2, y,0) },Global.our_easing)
  52. .to(t, { position: new Vec3(-2, y,0) },Global.our_easing)
  53. .to(t, { position: new Vec3(0, y,0) },Global.our_easing)
  54. .delay(0.3)
  55. .call(() => {
  56. this.node.setPosition(new Vec3(0, y,0));
  57. let arr_color: ColorDate[] = [];
  58. arr.forEach(element => {
  59. let c = element.pin_color;
  60. arr_color.push(c.clone());
  61. });
  62. arr_color.sort(() => {
  63. return 0.5 - Math.random();
  64. });
  65. if (arr.length == arr_color.length) {
  66. for (let i = 0; i < arr.length; i++) {
  67. let pin_color = arr[i].pin_color;
  68. let c = arr_color[i];
  69. pin_color.r = c.r;
  70. pin_color.g = c.g;
  71. pin_color.b = c.b;
  72. pin_color.id = c.id;
  73. arr[i].reset_img();
  74. }
  75. }
  76. })
  77. .start();
  78. }
  79. }