| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312 |
- import { InterFullAdType, VideoAdType } from "../data/GameData";
- const { ccclass, property } = cc._decorator;
- @ccclass
- export default class AniControl extends cc.Component {
- @property({ displayName: 'bird_1', type: cc.Animation })
- private flyBird_1: cc.Animation = null;
- @property({ displayName: 'bird_2', type: cc.Animation })
- private flyBird_2: cc.Animation = null;
- @property({ displayName: 'star_1', type: cc.Animation })
- private star_1: cc.Animation = null;
- @property({ displayName: 'star_2', type: cc.Animation })
- private star_2: cc.Animation = null;
- @property({ displayName: 'star_3', type: cc.Animation })
- private star_3: cc.Animation = null;
- @property({ displayName: 'dog', type: cc.Animation })
- private dogMove: cc.Animation = null;
- @property({ displayName: 'duck', type: cc.Animation })
- private moveDuck: cc.Animation = null;
- @property({ displayName: 'moveSheep', type: cc.Animation })
- private moveSheep: cc.Animation = null;
- @property({ displayName: 'sheep', type: cc.Animation })
- private sheep: cc.Animation = null;
- @property({ displayName: '红包按钮', type: cc.Node })
- private hb_btn: cc.Node = null;
- private starPos_1: cc.Vec2 = cc.Vec2.ZERO;
- private starPos_2: cc.Vec2 = cc.Vec2.ZERO;
- private starPos_3: cc.Vec2 = cc.Vec2.ZERO;
- private time_1: number = 8;
- private time_2: number = 16;
- private time_3: number = 22;
- private isShow_1: boolean = false;
- private isShow_2: boolean = false;
- private isShow_3: boolean = false;
- private sheepMoveEnd: boolean = false;
- start() {
- this.doFlyBirdLogic();
- //this.doStarLogic();
- this.doDogMoveLogic();
- //this.doDuckMoveLogic();
-
- let data = gData.gameData.funOpenData;
- if(data[9] == '1')
- {
- this.doSheepMoveLogic();
- }
- }
- private doFlyBirdLogic() {
- let time = mk.math.random(5, 15);
- cc.tween(this.flyBird_1.node).delay(time).call(() => {
- this.flyBird_1.node.active = true;
- }).start();
- this.flyBird_1.on('finished', this.flyBirdFinished_1, this);
- time = mk.math.random(5, 15);
- cc.tween(this.flyBird_2.node).delay(time).call(() => {
- this.flyBird_2.node.active = true;
- }).start();
- this.flyBird_2.on('finished', this.flyBirdFinished_2, this)
- }
- private flyBirdFinished_1() {
- let time = mk.math.random(5, 15);
- this.flyBird_1.node.active = false;
- cc.Tween.stopAllByTarget(this.flyBird_1.node);
- cc.tween(this.flyBird_1.node).delay(time).call(() => {
- this.flyBird_1.node.active = true;
- this.flyBird_1.play();
- }).start();
- }
- private flyBirdFinished_2() {
- let time = mk.math.random(5, 15);
- this.flyBird_2.node.active = false;
- cc.Tween.stopAllByTarget(this.flyBird_2.node);
- cc.tween(this.flyBird_2.node).delay(time).call(() => {
- this.flyBird_2.node.active = true;
- this.flyBird_2.play();
- }).start();
- }
- private doStarLogic() {
- this.starPos_1 = this.star_1.node.getPosition();
- this.starPos_2 = this.star_2.node.getPosition();
- this.starPos_3 = this.star_3.node.getPosition();
- }
- private doDogMoveLogic() {
- let time = mk.math.random(5, 8);
- cc.tween(this.dogMove.node).delay(time).call(() => {
- this.dogMove.node.active = true;
- this.dogMove.play();
- }).start();
- this.dogMove.on('finished', this.moveDogFinished, this);
- }
- private moveDogFinished() {
- let time = mk.math.random(5, 8);
- this.dogMove.node.active = false;
- this.dogMove.node.scaleX = 1;
- cc.Tween.stopAllByTarget(this.dogMove.node);
- cc.tween(this.dogMove.node).delay(time).call(() => {
- this.dogMove.node.active = true;
- this.dogMove.play();
- }).start();
- }
- private doDuckMoveLogic() {
- let time = mk.math.random(5, 8);
- cc.tween(this.moveDuck.node).delay(time).call(() => {
- this.moveDuck.node.active = true;
- this.moveDuck.play();
- }).start();
- this.moveDuck.on('finished', this.moveDuckFinished, this);
- }
- private moveDuckFinished(event) {
- let time = mk.math.random(5, 8);
- cc.tween(this.moveDuck.node).delay(time).call(() => {
- this.moveDuck.play();
- }).start();
- }
- private doSheepMoveLogic() {
- this.sheepMoveEnd = false;
- let time = mk.math.random(5, 8);
- cc.tween(this.moveSheep.node).delay(time).call(() => {
- this.moveSheep.node.active = true;
- this.sheep.play('sheepMove');
- this.moveSheep.play();
- }).start();
- this.moveSheep.on('finished', this.moveSheepFinished, this);
- }
- private moveSheepFinished(event) {
- this.sheepMoveEnd = true;
- // let time = mk.math.random(5, 8);
- // cc.tween(this.moveSheep.node).delay(time).call(()=>{
- // this.moveSheep.play();
- // }).start();
- }
- private clickSheepBtn() {
- if (this.sheepMoveEnd) {
- mk.audio.playEffect("button");
- mk.ad.videoAdType = VideoAdType.video_init_10;
- mk.ui.openPanel('module/newOpenRedBag/newOpenRedBag');
- this.sheepMoveEnd = false;
- this.hb_btn.active = false;
- this.moveSheep.node.active = false;
- let time = mk.math.random(5, 8);
- cc.tween(this.moveSheep.node).delay(time).call(() => {
- this.moveSheep.node.active = true;
- this.sheep.play('sheepMove');
- this.moveSheep.play();
- }).start();
- }
- }
- // update(dt)
- // {
- // if(this.time_1 <= 0)
- // {
- // if(!this.isShow_1)
- // {
- // this.isShow_1 = true;
- // this.time_1 = 8;
- // this.star_1.stop();
- // cc.tween(this.star_1.node).to(0.2, {opacity: 0}).start();
- // }else{
- // this.isShow_1 = false;
- // this.time_1 = 8;
- // this.star_1.play();
- // let p = mk.math.random(5, 40);
- // this.star_1.node.setPosition(this.starPos_1.subtract(cc.v2(p, p)));
- // cc.tween(this.star_1.node).to(0.2, {opacity: 255}).start();
- // }
- // }else{
- // this.time_1 = this.time_1-dt;
- // }
- // if(this.time_2 <= 0)
- // {
- // if(!this.isShow_2)
- // {
- // this.isShow_2 = true;
- // this.time_2 = 16;
- // this.star_2.stop();
- // cc.tween(this.star_2.node).to(0.2, {opacity: 0}).start();
- // }else{
- // this.isShow_2 = false;
- // this.time_2 = 16;
- // this.star_2.play();
- // let p = mk.math.random(5, 40);
- // this.star_2.node.setPosition(this.starPos_2.subtract(cc.v2(p, p)));
- // cc.tween(this.star_2.node).to(0.2, {opacity: 255}).start();
- // }
- // }else{
- // this.time_2 = this.time_2-dt;
- // }
- // if(this.time_3 <= 0)
- // {
- // if(!this.isShow_3)
- // {
- // this.isShow_3 = true;
- // this.time_3 = 22;
- // this.star_3.stop();
- // cc.tween(this.star_3.node).to(0.2, {opacity: 0}).start();
- // }else{
- // this.isShow_3 = false;
- // this.time_3 = 22;
- // this.star_3.play();
- // let p = mk.math.random(5, 40);
- // this.star_3.node.setPosition(this.starPos_3.subtract(cc.v2(p, p)));
- // cc.tween(this.star_3.node).to(0.2, {opacity: 255}).start();
- // }
- // }else{
- // this.time_3 = this.time_3-dt;
- // }
- // }
- private clickAnimalIconBtn(event, customEvenData) {
- mk.audio.playEffect("button");
- if (customEvenData == 'bird_1') {
- this.flyBirdFinished_1();
- this.getRewardByHttp("bird_1");
- } else if (customEvenData == 'bird_2') {
- this.flyBirdFinished_2();
- this.getRewardByHttp("bird_2");
- //mk.fly.PlayCoinAnim(1, 5, this.flyBird_2.node, '', null, -1, 2);
- } else if (customEvenData == 'dog') {
- this.moveDogFinished();
- this.getRewardByHttp("dog");
- // mk.fly.PlayCoinAnim(1, 5, this.dogMove.node, '', null, -1, 2);
- }
- gData.adData.checkShowFullInter(1, InterFullAdType.interstitial2_init_3);
- }
- private async getRewardByHttp(type: string) {
- let data = { animalType: 1 };
- let response = await mk.http.sendData('redMoney/addRedMoneyByAnimal', data);
- if (response.errcode != 0) {
- return;
- }
- let add = response.data.redMoneyAddition;
- console.log('addCoin===============>', add);
- if (add > 0) {
- const several = 3;
- let intV = Math.floor(add / several);
- let r = add % several;
- mk.audio.playEffect('redmoney');
- if (type == 'bird_1') {
- if (intV > 0) {
- for (let i = 0; i != several; ++i) {
- mk.fly.PlayCoinAnim(1, 1, this.flyBird_1.node, '', null, -1, intV);
- }
- }
- if (r > 0) {
- mk.fly.PlayCoinAnim(1, 1, this.flyBird_1.node, '', null, -1, r);
- }
- } else if (type == 'bird_2') {
- if (intV > 0) {
- for (let i = 0; i != several; ++i) {
- mk.fly.PlayCoinAnim(1, 1, this.flyBird_2.node, '', null, -1, intV);
- }
- }
- if (r > 0) {
- mk.fly.PlayCoinAnim(1, 1, this.flyBird_2.node, '', null, -1, r);
- }
- } else if (type == 'dog') {
- if(intV > 0)
- {
- for (let i = 0; i != several; ++i) {
- mk.fly.PlayCoinAnim(1, 1, this.dogMove.node, '', null, -1, intV);
- }
- }
-
- if (r > 0) {
- mk.fly.PlayCoinAnim(1, 1, this.dogMove.node, '', null, -1, r);
- }
- }
- }
- }
- }
|