Props4Action.ts 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. import { _decorator, Color, Component, Label, Node, Sprite, tween, Vec2, Vec3 } from 'cc';
  2. import { Global } from './Global';
  3. import { PropsAction } from './PropsAction';
  4. import { Clips } from './Enums';
  5. import { AudioMgr } from './AudioMgr';
  6. import { CatAction } from './CatAction';
  7. import { DataModel } from './DataModel';
  8. import { AdManger } from './ad/AdManger';
  9. const { ccclass, property } = _decorator;
  10. @ccclass('Props4Action')
  11. export class Props4Action extends Component {
  12. @property(Node)
  13. target:Node = null;
  14. @property(Sprite)
  15. cat_img:Sprite = null;
  16. color_arr = [];
  17. color_arr_index = 0;
  18. cat_action:CatAction
  19. @property({ type: Label })
  20. conis_label: Label;
  21. start() {
  22. this.conis_label.string = Global.get_need_coins() + "";
  23. for(let i = 0;i<DataModel.base_color_arr.length;i++){
  24. this.color_arr.push(DataModel.base_color_arr[i].clone());
  25. }
  26. }
  27. dt:number = 0;
  28. times:number = 0;
  29. update(deltaTime: number) {
  30. if(!this.node.active){
  31. return;
  32. }
  33. if(this.times==0){
  34. this.times++;
  35. this.play_tween();
  36. }else{
  37. this.dt+=deltaTime;
  38. if(this.dt>=1){
  39. this.dt = 0;
  40. this.play_tween();
  41. }
  42. }
  43. }
  44. private play_tween(){
  45. this.color_arr_index++;
  46. if(this.color_arr_index>=this.color_arr.length){
  47. this.color_arr_index = 0;
  48. }
  49. let c = this.color_arr[this.color_arr_index];
  50. this.cat_img.color = new Color(c.r,c.g,c.b,255);
  51. }
  52. show_box(cat_action:CatAction){
  53. this.cat_action = cat_action;
  54. }
  55. //开启一个盒子
  56. open_box_coins(){
  57. AudioMgr.ins.playSound(Clips.btn_1);
  58. if(Global.cur_coins<Global.get_need_coins()){
  59. Global.tips_action.show("Diamond Quantity Insufficient");//钻石数量不够
  60. return;
  61. }
  62. //消耗
  63. Global.use_coins(Global.get_need_coins());
  64. {
  65. //解开
  66. this.cat_action.set_lock_unlock(false);
  67. this.cat_action.into_scence(new Vec2(0,400));
  68. }
  69. Global.coins_action.refrush_coins();
  70. this.node.parent.getComponent(PropsAction)?.close();
  71. }
  72. open_box_video(){
  73. AudioMgr.ins.playSound(Clips.btn_1);
  74. if(!this.cat_action){
  75. return;
  76. }
  77. //检查上锁情况
  78. // if (!Global.used_cur_level_props_(4)) {
  79. // Global.tips_action.show("当前关卡次数已经用完");
  80. // return;
  81. // }
  82. AdManger.show_video((data) => {
  83. if (data == 1) {
  84. console.log("open_box_video 获取奖励成功");
  85. this.node.parent.getComponent(PropsAction)?.close();
  86. //解锁
  87. this.cat_action.set_lock_unlock(false);
  88. this.cat_action.into_scence(new Vec2(0,400));
  89. } else {
  90. Global.tips_action.show("获取奖励失败5");
  91. //退款
  92. // Global.return_used_cur_level_props_(4);
  93. }
  94. })
  95. }
  96. open(){
  97. this.conis_label.string = Global.get_need_coins() + "";
  98. }
  99. }