123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302 |
- var cityList = require('../data/city');
- var cityIncomeList = require('../data/cityIncome');
- var GameModule = require('../utils/GameModule');
- const GameNotificationKey = require('../utils/GameEnum').GameNotificationKey;
- const DWTool = require("../utils/DWTool");
- const CityMapApi = require('../net/CityMapApi');
- cc.Class({
- extends: cc.Component,
- properties: {
- scrollView: cc.ScrollView,
- view: cc.Node,
- mapbg: cc.Node,
- content: cc.Node,
- cityItemPrefab: cc.Prefab,
- myMoneyLayout: cc.Node,
- coinNode: cc.Node,
- coinSkeleton: sp.Skeleton,
- myMoneyLabel: cc.Label,
- moneyCatNode: cc.Node,
- moneyCatSkeleton: sp.Skeleton,
- backNode: cc.Node,
- myCompanyNode: cc.Node,
- companyText: cc.RichText,
- incomeText: cc.RichText,
- progressBar: cc.ProgressBar,
- currentIncomeLabel: cc.Label,
- airplane: cc.Node,
- coinPrefab: cc.Prefab,
- topBg: cc.Node,
- grossIncome: {
- get: function () {
- return this._grossIncome;
- },
- set: function (value) {
- this._grossIncome = value;
- this.myMoneyLabel.string = DWTool.coinParse(this._grossIncome);
- }
- },
- },
- onLoad() {
- this.moneyCatNode.on(cc.Node.EventType.TOUCH_END, _.debounce(() => {
- this.showCollectAnim(50);
- }, 1000, true), this);
- this.cityScriptList = [];
- let scaleSize = cc.view.getVisibleSize().height / this.scrollView.node.height;
- this.scrollView.node.height = this.view.height = cc.view.getVisibleSize().height;
- this.topBg.y = this.topBg.y * scaleSize;
- this.myMoneyLayout.y = scaleSize * this.myMoneyLayout.y;
- this.moneyCatNode.y = scaleSize * this.moneyCatNode.y;
- this.backNode.y = scaleSize * this.backNode.y;
- this.myCompanyNode.y = scaleSize * this.myCompanyNode.y;
- this.myCompanyNode.active = false;
- for (let i = 0; i < cityList.length; i++) {
- let cityInfo = cityList[i];
- // if (cityInfo.id < Global.cityId) {
- // cityInfo.unlock = true;
- // } else if (cityInfo.id == Global.cityId) {
- // cityInfo.selected = true;
- // this.incomeSpeed = cityIncomeList[i].income;
- // this.incomeMax = cityIncomeList[i].incomeLimit;
- // this.companyText.string = '<outline color=#ffffff width=2><b>当前拥有' + (i + 1) + '家公司</b></outline>';
- // this.incomeText.string = '<outline color=#ffffff width=2><b>' + this.incomeSpeed + '/小时</b></outline>';
- // }
- let item = cc.instantiate(this.cityItemPrefab);
- item.x = i % 2 === 0 ? 110 : -110;
- item.on(cc.Node.EventType.TOUCH_END, () => {
- if (cityInfo.id <= Global.cityId) {
- this.gameFSM.visitcity(cityInfo.id);
- }
- }, this);
- let cityScript = item.getComponent('CityItem');
- // cityScript.init(cityInfo);
- this.content.addChild(item);
- this.cityScriptList.push(cityScript);
- }
- },
- init(game) {
- this.game = game
- this.gameFSM = game.gameFSM
- console.log(this.gameFSM);
- },
- show(move) {
- this.node.x = 400;
- this.node.active = true;
- let finish = cc.callFunc(() => {
- if (move) {
- this._showMoveAnimation();
- }
- });
- this.node.runAction(cc.sequence(cc.moveTo(0.3, 0, 0).easing(cc.easeBackOut()), finish));
- if (move) {
- this.myCompanyNode.active = false;
- this.moneyCatNode.active = false;
- this.backNode.active = false;
- } else {
- this.myCompanyNode.active = false;
- this.moneyCatNode.active = true;
- this.backNode.active = true;
- this.moneyCatSkeleton.setAnimation(0, 'maomi', true);
- let totalIncomeSpeed = 0;
- for (let i = 0; i < cityList.length; i++) {
- let cityInfo = cityList[i];
- let cityScript = this.cityScriptList[i];
- let incomeSpeed = 0;
- if (cityInfo.id < Global.cityId) {
- cityInfo.unlock = true;
- incomeSpeed = cityIncomeList[i].income;
- totalIncomeSpeed += incomeSpeed;
- this.incomeMax = cityIncomeList[i].incomeLimit;
- } else if (cityInfo.id === Global.cityId) {
- cityInfo.selected = true;
- }
- cityScript.init(cityInfo, incomeSpeed);
- }
- CityMapApi.getMapInfo(
- (response) => {
- this.income = response.cityIncomeTime * totalIncomeSpeed / 1000;
- this._setProgressbar();
- }
- , (code, msg) => {
- });
- this.myMoneyLabel.string = GameModule.userInfo.grossIncomeLabel.string;
- }
- },
- _setProgressbar() {
- if (this.income > this.incomeMax) {
- this.income = this.incomeMax;
- }
- this.currentIncomeLabel.string = DWTool.coinParse(this.income);
- this.progressBar.progress = this.income / this.incomeMax * this.progressBar.totalLength;
- },
- _showMoveAnimation() {
- for (let i = 0; i < this.cityScriptList.length; i++) {
- let cityInfo = cityList[i];
- if (cityInfo.id == Global.cityId) {
- let lastCity = this.cityScriptList[i - 1];
- let currentCity = this.cityScriptList[i];
- var lastPosition = this.getPositionInView(lastCity.node);
- let scrollOffset = this.scrollView.getScrollOffset().y - lastPosition.y + 200;
- this.scrollView.scrollToOffset(cc.v2(0, scrollOffset));
- this.scrollView.vertical = false;
- this.scheduleOnce(() => {
- this.startMoveAnimation(lastCity, currentCity);
- }, 0.4);
- }
- }
- },
- startMoveAnimation(lastCity, currentCity) {
- let lastPosition = this.getPositionInView(lastCity.node);
- var currentPosition = this.getPositionInView(currentCity.node);
- let self = this;
- lastCity.showFinishAnimation(() => {
- this.airplaneAnimation(lastPosition, currentPosition, () => {
- self.airplane.x = 600;
- currentCity.fakeUnLock();
- self.scrollView.vertical = true;
- self.scheduleOnce(() => {
- self.gameFSM.visitcity(Global.cityId);
- }, 0.4);
- });
- });
- },
- getPositionInView(item) { // get item position in scrollview's node space
- let worldPos = item.parent.convertToWorldSpaceAR(item.position);
- let viewPos = this.scrollView.node.convertToNodeSpaceAR(worldPos);
- return viewPos;
- },
- airplaneAnimation(position1, position2, cb) {
- var angle = this.getAngle(position1, position2);
- this.airplane.setRotation(angle);
- this.airplane.setPosition(position1);
- let end = cc.callFunc(cb, this);
- this.airplane.runAction(cc.sequence(cc.moveTo(3, position2), end));
- },
- close() {
- this.gameFSM.historyBack();
- },
- getAngle(p1, p2) {
- // 直角的边长
- var x = p2.x - p1.x;
- var y = p2.y - p1.y;
- // 斜边长
- var z = Math.sqrt(Math.pow(x, 2) + Math.pow(y, 2));
- // 余弦
- var cos = y / z;
- // 弧度
- var radina = Math.acos(cos);
- // 角度
- var angle = 180 / (Math.PI / radina);
- if (x < 0) {
- angle = - angle;
- }
- return angle;
- },
- showCollectAnim(colNums) {
- if (this.income > 0) {
- this.moneyCatSkeleton.setAnimation(0, 'maomi_hit', false);
- this.moneyCatSkeleton.setCompleteListener(() => {
- this.moneyCatSkeleton.setAnimation(0, 'maomi', true);
- })
- GameModule.userInfo.grossIncome += this.income * 10000;
- this.grossIncome = GameModule.userInfo.grossIncome;
- this.income = 0;
- this._setProgressbar();
- CityMapApi.reportCityIncome().then(() => {
- });
- let canvasNode = cc.find("Canvas");
- let coinNode = this.coinNode;
- let grossCoinPos = coinNode.convertToWorldSpace(cc.v2(coinNode.width / 2, coinNode.height / 2));
- let pos = this.moneyCatNode.convertToWorldSpace(cc.v2(this.moneyCatNode.width / 2, this.moneyCatNode.height / 2 - 80));
- // let colNums = 5
- let vSize = cc.view.getVisibleSize();
- let target = cc.v2(grossCoinPos.x - vSize.width / 2, grossCoinPos.y - vSize.height / 2);
- let i = 0;
- let runSt = setInterval(() => {
- if (i == colNums) {
- clearInterval(runSt)
- } else {
- let ranX = (Math.random() - 0.5) * 2 * 8;
- let ranY = (Math.random() - 0.5) * 2 * 3;
- let newCoin = cc.instantiate(this.coinPrefab);
- let posX = pos.x - vSize.width / 2;
- let posY = pos.y - vSize.height / 2;
- canvasNode.addChild(newCoin)
- newCoin.x = posX + ranX * 15;
- newCoin.y = posY + 30 + ranY * 15;
- newCoin.active = true;
- newCoin = newCoin.getComponent("LevelHomeCoin")
- newCoin.initAnim()
- let cbNotiStart = cc.callFunc(() => {
- this.coinSkeleton.setAnimation(0, 'jinbi_huoqu2', false);
- })
- let cbDestroy = cc.callFunc(() => {
- newCoin.node.destroy();
- })
- let act = cc.sequence(cc.moveTo(1, target), cbDestroy, cbNotiStart)
- newCoin.node.runAction(act.easing(cc.easeIn(2.1)));
- i++
- }
- }, 25);
- }
- },
- });
|