Props2Action.ts 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. import { _decorator, Component, Label, Node, tween, Vec3 } from 'cc';
  2. import { AudioMgr } from './AudioMgr';
  3. import { Clips, DJ, DJ_TYPE } from './Enums';
  4. import { Global } from './Global';
  5. import { PropsAction } from './PropsAction';
  6. import { AdManger } from './ad/AdManger';
  7. import { DjManger } from './DjManger';
  8. const { ccclass, property } = _decorator;
  9. @ccclass('Props2Action')
  10. export class Props2Action extends Component {
  11. @property([Node])
  12. pin_img_arr:Node[] = [];
  13. pos_:Vec3[] = [];
  14. @property({ type: Label })
  15. conis_label: Label;
  16. start() {
  17. this.conis_label.string = Global.get_need_coins() + "";
  18. if(this.pin_img_arr){
  19. this.pin_img_arr.forEach((ele)=>{
  20. if(ele){
  21. this.pos_.push(ele.getPosition().clone());
  22. }
  23. });
  24. }
  25. }
  26. dt:number = 0;
  27. times:number = 0;
  28. update(deltaTime: number) {
  29. if(!this.node.active){
  30. return;
  31. }
  32. if(this.times==0){
  33. this.times++;
  34. this.show_tween();
  35. }else{
  36. this.dt+=deltaTime;
  37. if(this.dt>=1.5){
  38. this.dt = 0;
  39. this.show_tween();
  40. }
  41. }
  42. }
  43. private show_tween(){
  44. this.pin_img_arr.sort(() => {
  45. return 0.5 - Math.random();
  46. });
  47. for(let i = 0;i<this.pin_img_arr.length;i++){
  48. this.play_tween(this.pin_img_arr[i],this.pos_[i]);
  49. }
  50. }
  51. private play_tween(pin:Node,pos:Vec3){
  52. tween(pin)
  53. .to(0.75, { position: pos },Global.our_easing)
  54. .call(() => {
  55. }).delay(0.3)
  56. .start();
  57. }
  58. random_pins_coins(){
  59. AudioMgr.ins.playSound(Clips.btn_1);
  60. if (Global.cur_coins < Global.get_need_coins()) {
  61. Global.tips_action.show("Diamond Quantity Insufficient");//钻石数量不够
  62. return;
  63. }
  64. if (!DjManger.use_dj(DJ.Btn_2,DJ_TYPE.Type_coin)) {
  65. Global.tips_action.show("Current Level: Props Exhausted");//当前关卡次数已经用完
  66. return;
  67. }
  68. //消耗
  69. Global.use_coins(Global.get_need_coins());
  70. Global.layer_root_action.random_pin();
  71. Global.coins_action.refrush_coins();
  72. this.node.parent.getComponent(PropsAction)?.close();
  73. }
  74. random_pins_videos(){
  75. console.log('zh:random_pins_videos 555')
  76. AudioMgr.ins.playSound(Clips.btn_1);
  77. if (!DjManger.use_dj(DJ.Btn_2,DJ_TYPE.Type_video)) {
  78. Global.tips_action.show("Current Level: Props Exhausted");//当前关卡次数已经用完
  79. return;
  80. }
  81. AdManger.show_video((data) => {
  82. if (data == 1) {
  83. console.log("random_pins_videos 获取奖励成功");
  84. this.node.parent.getComponent(PropsAction)?.close();
  85. //解锁
  86. Global.layer_root_action.random_pin();
  87. } else {
  88. Global.tips_action.show("Gain reward failure");//获取奖励失败
  89. //退款
  90. DjManger.return_used_dj(DJ.Btn_2,DJ_TYPE.Type_video);
  91. }
  92. })
  93. }
  94. open(){
  95. this.conis_label.string = Global.get_need_coins() + "";
  96. }
  97. }