PinAction.ts 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. import { _decorator, BoxCollider2D, CircleCollider2D, Color, Component, EventTouch, find, Input, instantiate, Node, PolygonCollider2D, Rect, RigidBody2D, Sprite, tween, UITransform, Vec2, Vec3 } from 'cc';
  2. import { ElementAction } from './ElementAction';
  3. import { LayerRootAction } from './LayerRootAction';
  4. import { Clips } from './Enums';
  5. import { AudioMgr } from './AudioMgr';
  6. import { LayerCatAction } from './LayerCatAction';
  7. import { ColorDate } from './ColorDate';
  8. import { Global } from './Global';
  9. const { ccclass, property } = _decorator;
  10. @ccclass('PinAction')
  11. export class PinAction extends Component {
  12. pin_color:ColorDate = null;
  13. start() {
  14. this.node.on(Input.EventType.TOUCH_START, this.touch_start, this);
  15. }
  16. update(deltaTime: number) {
  17. }
  18. public init_date(group_id:number,pin_color:ColorDate){
  19. this.node.getComponent(RigidBody2D).group = group_id;
  20. this.node.getComponents(BoxCollider2D).forEach(element => {
  21. element.group = group_id;
  22. });
  23. this.node.getComponents(CircleCollider2D).forEach(element => {
  24. element.group = group_id;
  25. });
  26. this.node.getComponents(PolygonCollider2D).forEach(element => {
  27. element.group = group_id;
  28. });
  29. this.pin_color = pin_color;
  30. //set color
  31. this.reset_img();
  32. }
  33. touch_start(e: EventTouch) {
  34. AudioMgr.ins.playSound(Clips.open_screw);
  35. // ret?boolean ,return put result,true=success,false=failure
  36. if(Global.layer_cat_action.put_pin(this)){
  37. // 需要检查,关卡是否结束
  38. return;
  39. }
  40. Global.layer_empty_action.put_pin(this);
  41. if(Global.layer_empty_action.is_pin_full()){
  42. //TODO 游戏结束,这里有个bug,用延迟处理,后面处理
  43. tween(this.node).delay(0.75).call(()=>{
  44. if(Global.layer_empty_action.is_pin_full()){
  45. Global.game_over_action.open();
  46. }else{
  47. console.log("$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$");
  48. }
  49. }).start();
  50. }
  51. }
  52. public remove_collider(){
  53. this.node.getComponent(RigidBody2D).enabled =false;
  54. this.node.getComponent(CircleCollider2D).enabled = false;
  55. this.node.off(Input.EventType.TOUCH_START);
  56. }
  57. reset_img(){
  58. if(!this.pin_color){
  59. return;
  60. }
  61. let img = this.node.getComponent(Sprite);
  62. img.color = new Color(this.pin_color.r,this.pin_color.g,this.pin_color.b,255);
  63. let holering = this.node.getChildByName("holering")
  64. if(holering){
  65. tween(holering)
  66. .to(0.35,{scale:new Vec3(1.2,1.2,1)},Global.our_easing)
  67. .to(0.35,{scale:new Vec3(0.8,0.8,1)},Global.our_easing)
  68. .to(0.25,{scale:new Vec3(1,1,1)},Global.our_easing)
  69. .call(()=>{
  70. holering.scale = new Vec3(1,1,1);
  71. })
  72. .start();
  73. }
  74. }
  75. // get_pin_color(arr:ColorDate[]){
  76. // if(!this.pin_color){
  77. // return;
  78. // }
  79. // arr.push(this.pin_color);
  80. // }
  81. }