| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594 |
- // Learn cc.Class:
- // - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/class.html
- // - [English] http://www.cocos2d-x.org/docs/creator/en/scripting/class.html
- // Learn Attribute:
- // - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/reference/attributes.html
- // - [English] http://www.cocos2d-x.org/docs/creator/en/scripting/reference/attributes.html
- // Learn life-cycle callbacks:
- // - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/life-cycle-callbacks.html
- // - [English] http://www.cocos2d-x.org/docs/creator/en/scripting/life-cycle-callbacks.html
- cc.Class({
- extends: cc.Component,
- properties: {
- // foo: {
- // // ATTRIBUTES:
- // default: null, // The default value will be used only when the component attaching
- // // to a node for the first time
- // type: cc.SpriteFrame, // optional, default is typeof default
- // serializable: true, // optional, default is true
- // },
- // bar: {
- // get () {
- // return this._bar;
- // },
- // set (value) {
- // this._bar = value;
- // }
- // },
- },
- // LIFE-CYCLE CALLBACKS:
- // onLoad () {},
- start() {
- Global.strike = this;
- this._initView();
- this.scoreCoefficient = 1;
- utils.isMobile(function () {
- Manager.strike = this;
- this.scoreCoefficient = Manager.scoreCoefficient;
- }.bind(this));
- // if(Manager.scoreCoefficient){
- // this.scoreCoefficient = Manager.scoreCoefficient;
- // cc.log("lalallala");
- // }else{
- // this.scoreCoefficient = 4.5;
- // cc.log("lilililili");
- // }
- },
- _initView: function () {
- this.strikex = UtilsPrefabs.getNode("strikex", this.node);
- this.strikey = UtilsPrefabs.getNode("strikey", this.node);
- this.strikex4 = UtilsPrefabs.getNode("strikex4", this.node);
- this.strikey5 = UtilsPrefabs.getNode("strikey5", this.node);
- this.rest = UtilsPrefabs.getNode("rest", this.node);
- let Canvas = cc.find("Canvas");
- let score = UtilsPrefabs.getNode("score", Canvas);
- let scoreNum = this.scoreNum = UtilsPrefabs.getNode("scoreNum", score);
- let gamelayout = UtilsPrefabs.getNode("gamelayout", Canvas);
- this.gamelayoutManager = gamelayout.getComponent('gamelayoutManager');
- this.rest.on('click', function () {
- this._init();
- if (this.onRestClick != null) {
- this.onRestClick();
- }
- }.bind(this), this);
- this._init();
- },
- onRestClick: function () {
- },
- setOnRestClick: function (onRestClick) {
- this.onRestClick = onRestClick;
- },
- _init: function () {
- this.hits = 0;
- this.hitsMax = 3;
- this.hitFristTime = null;
- this.hitTime = null;
- this.power = 0;
- this.scoreMax = 1199999;
- UserInfo.PlayerGameData.powerMax = this.scoreMax;
- UserInfo.PlayerGameData.powerMaxKm = 5913520000;
- UserInfo.PlayerGameData.coefficient = UserInfo.PlayerGameData.powerMaxKm / UserInfo.PlayerGameData.powerMax;
- //分数=力量*100*间隔时间所得分*准确度所得分
- this.hits1 = [
- {
- //间隔
- time: 0,
- //间隔时间对应所得分数
- score: 100,
- //打偏 和 打正 的 分数
- type: [1, 2],
- }
- ];
- this.hits2 = [
- {
- time: 800,
- score: 6,
- type: [15, 18],
- },
- {
- time: 1200,
- score: 4,
- type: [9, 12],
- },
- {
- time: 1500,
- score: 2,
- type: [2, 6],
- },
- ];
- this.hits3 = [
- {
- time: 800,
- score: 6,
- type: [15, 18],
- },
- {
- time: 1200,
- score: 4,
- type: [9, 12],
- },
- {
- time: 1500,
- score: 2,
- type: [2, 6],
- },
- ];
- this.xishu = [
- 0.1,
- 0.4,
- 0.9
- ];
- utils.isMobile(function () {
- this.strikex.active = false;
- this.strikey.active = false;
- this.strikex4.active = false;
- this.strikey5.active = false;
- }.bind(this));
- this.scoreNum.getComponent(cc.Label).string = '0';
- // this.strikex.off('click',this.onclickcallbackx);
- // this.strikey.off('click',this.onclickcallbacky);
- // this.strikex4.off('click',this.onclickcallbackx);
- // this.strikey5.off('click',this.onclickcallbacky);
- this.strikex.on('click', this.onclickcallbackx, this);
- this.strikey.on('click', this.onclickcallbacky, this);
- this.strikex4.on('click', this.onclickcallbackx4, this);
- this.strikey5.on('click', this.onclickcallbacky5, this);
- this.setPowerCallBack(function (hits) {
- if (this.onPowerCallBackforMain != null) {
- this.p = 0;
- if (parseFloat(this.power / this.scoreMax) < 0.4) {
- this.p = 0;
- } else if (parseFloat(this.power / this.scoreMax) >= 0.4 && parseFloat(this.power / this.scoreMax) < 0.8) {
- this.p = 1;
- } else if (parseFloat(this.power / this.scoreMax) >= 0.8) {
- this.p = 2;
- }
- this.ChangeCallBack(this.scoreNum, this.power);
- this.onPowerCallBackforMain(parseFloat(this.power / this.scoreMax), this.p);
- switch (hits) {
- case 1 :
- // console.log("游戏结束 1",this.power,this.hits);
- break;
- case 2 :
- // console.log("游戏结束 2",this.power,this.hits);
- break;
- case 3 :
- // console.log("游戏结束 3 真结束了",this.power,this.hits);
- //总分数
- UserInfo.PlayerGameData.power = this.power;
- // console.log("游戏结束 3 所有数据",UserInfo);
- if (this.ongameoverCallBack != null) {
- this.ongameoverCallBack();
- }
- break;
- }
- // console.log("流浪地球*** 总分数power 是"+this.power+
- // ",次数hits是"+this.hits+
- // ",UserInfo.PlayerGameData.power is "+UserInfo.PlayerGameData.power);
- }
- }.bind(this));
- },
- onPowerCallBackforMain: function () {
- },
- setOnPowerCallBackforMain: function (onPowerCallBackforMain) {
- this.onPowerCallBackforMain = onPowerCallBackforMain;
- },
- ongameoverCallBack: function () {
- },
- setOnGameoverCallBack: function (ongameoverCallBack) {
- this.ongameoverCallBack = ongameoverCallBack;
- },
- //4000
- onclickcallbackx4: function (button) {
- var datastrike = {
- der: 3,
- pianyi: 100,
- power: 30,
- ballSpeed: 4,
- kitTime : 800,
- ATime : 280
- }
- this.onclickcallback(datastrike);
- },
- //5000
- onclickcallbacky5: function (button) {
- var datastrike = {
- der: 3,
- pianyi: 100,
- power: 50,
- ballSpeed: 15,
- kitTime : 800,
- ATime : 280
- }
- this.onclickcallback(datastrike);
- },
- //7500
- onclickcallbackx: function (button) {
- var datastrike = {
- der: 3,
- pianyi: 100,
- power: 40,
- ballSpeed: 10,
- kitTime : 800,
- ATime : 280
- }
- this.onclickcallback(datastrike);
- },
- //8000
- onclickcallbacky: function (button) {
- var datastrike = {
- der: 3,
- pianyi: 100,
- power: 35,
- ballSpeed: 8,
- kitTime : 800,
- ATime : 280
- }
- this.onclickcallback(datastrike);
- },
- onclickcallback: function (datastrike) {
- // console.log("当前是",num);
- /**
- *
- * @param der 方向 1234
- * @param pianyi 1 打中 0打偏
- * @param pow 力量值
- * @param ballSpeed 球速
- */
- //这一段是因为:后来传过来的pianyi是相对于der的,但是我们游戏需要的是相对于正前方是否打正或打偏,所以做出以下变动
- // if(datastrike.der == 3 && datastrike.pianyi == 1){
- // console.log("流浪地球,打正了");
- // }else{
- // datastrike.pianyi = 0;
- // console.log("流浪地球,打偏了");
- // }
- let time;
- if (this.hitFristTime == null) {
- this.hitFristTime = this.getTime();
- } else {
- this.hitTime = this.getTime();
- time = this.hitTime - this.hitFristTime;
- // console.log("现在打击了和上次 相隔",time,"当前打击次数",this.hits);
- this.hitFristTime = this.hitTime;
- }
- this.hits++;
- if (this.hits == 1) {
- this.currTime = 200;
- this.getInterval(this.hits1, null, datastrike);
- } else if (this.hits == 2) {
- this.currTime = 200;
- this.getInterval(this.hits2, time, datastrike);
- } else if (this.hits == 3) {
- this.currTime = 200;
- this.getInterval(this.hits3, time, datastrike);
- }
- },
- getInterval: function (arr, time, datastrike) {
- //1
- if (arr.length == 1) {
- //打偏或打正的所得分
- // let type = arr[0].type[datastrike.pianyi];
- let type = datastrike.pianyi;
- //两拳时间间隔所得分
- let score = arr[0].score;
- // let time = datastrike.time1;
- let temppower = Math.abs(datastrike.power-10)*10;
- let power = temppower *app.punchHitVars[this.hits-1] * type * score ;
- console.log("流浪地球 力量 运算1" +
- ",力量 " + temppower +
- ",偏移 " + type +
- ",系数"+app.punchHitVars[this.hits-1]+
- ",时间分 " + score +
- ",拳速 " + datastrike.ballSpeed +
- ",此次分数 " + power +
- ",次数hits是" + this.hits);
- // console.log("power" + power);
- this.setPower(power,datastrike);
- UserInfo.PlayerGameData.everypowerdata = [];
- let data = {
- //每次的力量
- everypower: datastrike.power,
- //相隔 时间
- time: 0,
- //是否打中 打偏
- type: datastrike.pianyi,
- datastrike: datastrike
- }
- UserInfo.PlayerGameData.everypowerdata.push(data);
- return;
- }
- //2 3
- // if (time != null) {
- // for (var i = 0; i < arr.length; i++) {
- // var a = arr[i];
- // // 小于
- // if (time < a.time) {
- // //打偏或打正的所得分
- // // let type = arr[i].type[datastrike.pianyi];
- // let type = datastrike.pianyi;
- // //两拳时间间隔所得分
- // // let score = arr[i].score;
- // let score = 6;
- //
- //
- // let power = datastrike.power * this.scoreCoefficient * type * score * datastrike.ballSpeed;
- // console.log("流浪地球 力量 运算2" +
- // ",datastrike.power is " + datastrike.power +
- // ",type is " + type +
- // ",score is " + score +
- // ",此次power is " + power +
- // ",次数hits是" + this.hits);
- // this.setPower(power,datastrike);
- //
- // let data = {
- // //每次的力量
- // everypower: datastrike.power,
- // //相隔 时间
- // time: time,
- // //是否打中 打偏
- // type: datastrike.pianyi,
- //
- // datastrike: datastrike
- // }
- // UserInfo.PlayerGameData.everypowerdata.push(data);
- // break;
- // }
- //
- // //大于等于
- // else {
- // if (i == arr.length - 1) {
- // //打偏或打正的所得分
- // // let type = arr[i].type[datastrike.pianyi];
- // let type = datastrike.pianyi;
- // //两拳时间间隔所得分
- // // let score = arr[i].score;
- // let score = 6;
- // let power = datastrike.power * this.scoreCoefficient * type * score * datastrike.ballSpeed;
- //
- //
- // console.log("流浪地球 力量 运算3" +
- // ",datastrike.power is " + datastrike.power +
- // ",type is " + type +
- // ",score is " + score +
- // ",此次power is " + power +
- // ",次数hits是" + this.hits);
- // this.setPower(power,datastrike);
- // let data = {
- // //每次的力量
- // everypower: datastrike.power,
- // //相隔 时间
- // time: time,
- // //是否打中 打偏
- // type: datastrike.pianyi,
- //
- // datastrike: datastrike
- // }
- // UserInfo.PlayerGameData.everypowerdata.push(data);
- // }
- //
- // }
- // }
- // }
- if (this.hits ==2 ||this.hits ==3 ) {
- //打偏或打正的所得分
- // let type = arr[i].type[datastrike.pianyi];
- let type = datastrike.pianyi;
- //两拳时间间隔所得分
- // let score = arr[i].score;
- let score = this.getTimeScore(datastrike.kitTime,datastrike.ATime);
- console.log("现在时间分是",score);
- let temppower = Math.abs(datastrike.power-10)*10;
- let power = temppower * app.punchHitVars[this.hits-1] * type * score ;
- // console.log("流浪地球 力量 运算2" +
- // ",datastrike.power is " + datastrike.power +
- // ",type is " + type +
- // ",score is " + score +
- // ",此次power is " + power +
- // ",次数hits是" + this.hits);
- console.log("流浪地球 力量 运算" +this.hits+
- ",力量 " + temppower +
- ",偏移 " + type +
- ",系数"+app.punchHitVars[this.hits-1]+
- ",时间分 " + score +
- ",拳速 " + datastrike.ballSpeed +
- ",此次分数 " + power +
- ",次数hits是" + this.hits);
- this.setPower(power,datastrike);
- let data = {
- //每次的力量
- everypower: datastrike.power,
- //相隔 时间
- time: time,
- //是否打中 打偏
- type: datastrike.pianyi,
- datastrike: datastrike
- }
- UserInfo.PlayerGameData.everypowerdata.push(data);
- }
- },
- getTimeScore : function(kitTime,ATime){
- let score = 2;
- let tagTime = 1000;
- let min = score;
- let max = 30;
- let AETime = app.AETime;
- let x = kitTime-ATime;
- console.log("kitTime",kitTime);
- console.log("ATime",ATime);
- console.log("kitTime-ATime = x",x);
- //小于最低
- if (x<AETime) {
- score = 5;
- console.log("x<AETime 时间分",score);
- }else if (x >= AETime && x <= tagTime) {
- let tempTime= x-AETime
- let tempScore = parseInt(max-Math.round(tempTime*(max-1)/(tagTime-AETime) ));
- console.log("x >= AETime && x <= tagTime tempScore",tempScore);
- // console.log("时间 精密计算","AETime",Math.round(x / tagTime * 10000) / max);
- if (tempScore > score) {
- score = tempScore;
- console.log("tempScore > score ",score);
- }else{
- score = 5;
- console.log("tempScore <= score ",score);
- }
- }else if (x > tagTime) {
- score = 2;
- console.log("x > tagTime score",score);
- }
- console.log("时间分返回 score",score);
- return score;
- },
- setPower: function (n,data) {
- this.gamelayoutManager.thisOneScore = n;
- this.gamelayoutManager.showData = data;
- this.power += n;
- UserInfo.PlayerGameData.power = this.power;
- console.log("流浪地球 总分数power 是" + this.power +
- ",次数hits是" + this.hits +
- ",UserInfo.PlayerGameData.power is " + UserInfo.PlayerGameData.power);
- if (this.onPowerCallBack != null) {
- this.onPowerCallBack(this.hits);
- }
- },
- onPowerCallBack: function () {
- },
- setPowerCallBack: function (onPowerCallBack) {
- this.onPowerCallBack = onPowerCallBack;
- },
- ChangeCallBack: function (NumNode, CurrentMoney) {
- let LastMoney = this.getNum(NumNode.getComponent(cc.Label).string);
- let Diff = CurrentMoney - LastMoney;
- let InitMoneyNum = LastMoney;
- let AnimTimes = 0;
- if (this.p == 2) {
- this.currTime = 630;
- }
-
- let Times = this.currTime;
- console.log("现在时间是", Times);
- this.unschedule(this.callback);
- this.callback = function () {
- if (Diff > 0) {
- InitMoneyNum += parseInt((CurrentMoney - LastMoney) / Times);
- } else {
- InitMoneyNum -= parseInt((CurrentMoney - LastMoney) / Times);
- }
- let result = this.FormatMoney(InitMoneyNum);
- if (AnimTimes == Times - 1) {
- this.scoreNum.getComponent(cc.Label).string = this.FormatMoney(CurrentMoney);
- this.unschedule(this.callback);
- return;
- }
- this.scoreNum.getComponent(cc.Label).string = result;
- RootNode.soundNode.getComponent("soundManage").playScore();
- AnimTimes++;
- }
- this.schedule(this.callback, 0.01, Times);
- },
- timeCallback: function () {
- },
- FormatMoney(s, n) {
- n = n > 0 && n <= 20 ? n : 2;
- s = parseFloat((s + "").replace(/[^\d\.-]/g, "")).toFixed(n) + "";
- var l = s.split(".")[0].split("").reverse(),
- r = s.split(".")[1];
- let t = "";
- for (let i = 0; i < l.length; i++) {
- t += l[i] + ((i + 1) % 3 == 0 && (i + 1) != l.length ? "," : "");
- }
- return t.split("").reverse().join(""); //+ "." + r;
- },
- getNum: function (num) {
- return parseInt(num.split(",").join(''));
- },
- getTime: function () {
- return new Date().getTime();
- }
- // update (dt) {},
- });
|