| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163 |
- import { AudioManager } from "../configData/AudioManager";
- import GameConfig from "../configData/GameConfig";
- import gameManger from "../game/UIFace/gameManger";
- import viewComtent from "../game/UIFace/viewComtent";
- const { ccclass, property } = cc._decorator;
- @ccclass
- export default class mainManager extends cc.Component {
- @property(cc.Node)
- private view: cc.Node = null;
- /**当前最新关卡 */
- @property(cc.Node)
- private nowLevel: cc.Node = null;
- /**钻石数量 */
- @property(cc.Label)
- private dialabel: cc.Label = null;
- /**总星星数量 */
- @property(cc.Label)
- private starlabel: cc.Label = null;
- /**剩余星星数量 */
- @property(cc.Label)
- private nowstarlabel: cc.Label = null;
- private allTapBtn: cc.Node[] = [];
- private scroll: cc.ScrollView = null;
- public static instance: mainManager = null;
- protected onLoad() {
- mainManager.instance = this;
- this.node.opacity = 255;
- let hhh = cc.winSize.height * (1920 / cc.winSize.width);
- this.view.setContentSize(1920, hhh);
- this.scroll = this.node.getComponent(cc.ScrollView);
- this.scroll.scrollToOffset(cc.v2());
- localStorage.clear();
- this.initStorage();
-
- this.initData();
- this.initStartBtn();
- this.nowLevel.on(cc.Node.EventType.TOUCH_START, function () {
- this.startgame(GameConfig.instance().storageData.level);
- }, this);
- this.preLoadSprite();
- }
- /**钻石星星数量 */
- public initData() {
- this.dialabel.string = GameConfig.instance().storageData.Diamond.toString();
- this.starlabel.string = GameConfig.instance().storageData.TotalStarNum.toString();
- this.nowstarlabel.string = GameConfig.instance().storageData.starNum.toString();
- }
- /**返回主界面刷新 */
- public backInit() {
- for (let i = 0; i < this.allTapBtn.length; i++) {
- const element = this.allTapBtn[i];
- element.destroy();
- }
- this.allTapBtn = [];
- cc.director.resume();
- cc.director.getScheduler().setTimeScale(1);
- this.initData();
- this.initStartBtn();
- AudioManager.palyAudio(1);
- }
- /**初始化存储数据 */
- private initStorage() {
- let sore = GameConfig.instance().getStorage();
- if (sore) {
- GameConfig.instance().storageData = sore;
- }
- else {
- GameConfig.instance().setStorage();
- }
- }
- /**开始按钮加载 */
- private initStartBtn() {
- let self = this;
- let storeLevel = GameConfig.instance().storageData.level;
- let posArr = [cc.v2(801, 454), cc.v2(507, 463), cc.v2(423, 292), cc.v2(255, 451), cc.v2(127, 286), cc.v2(-12, 376), cc.v2(-86, 226),
- cc.v2(-332, 418), cc.v2(-634, 433), cc.v2(-877, 274), cc.v2(-591, 124), cc.v2(-713, -164), cc.v2(-524, -373),
- cc.v2(-256, -374), cc.v2(-37, -298), cc.v2(264, -329), cc.v2(580, -357), cc.v2(878, -284)];
- if (storeLevel > 1) {
- cc.resources.load("prefabs/level_last", cc.Prefab, function (err, prefab: cc.Prefab) {
- for (let i = 0; i < storeLevel - 1; i++) {
- const element = posArr[i];
- var newNode = cc.instantiate(prefab);
- self.nowLevel.parent.addChild(newNode, 1);
- newNode.setPosition(element);
- newNode.on(cc.Node.EventType.TOUCH_START, function () {
- self.startgame(i + 1);
- }, this);
- let star = newNode.getChildByName("star_" + GameConfig.instance().storageData.levelStar[i]);
- star.opacity = 255;
- self.allTapBtn.push(newNode);
- }
- });
- }
- this.nowLevel.setPosition(posArr[storeLevel - 1]);
- }
- /**天赋界面 */
- private openTalant() {
- AudioManager.palyAudio(6);
- let self = this;
- cc.resources.load("prefabs/talantNode", cc.Prefab, function (err, prefab: cc.Prefab) {
- var newNode = cc.instantiate(prefab);
- self.node.addChild(newNode, 10);
- newNode.setPosition(0, 0);
- });
- }
- /**设置界面 */
- private openSetFace() {
- AudioManager.palyAudio(6);
- let self = this;
- }
- /**开始游戏 */
- private startgame(level: number) {
- AudioManager.palyAudio(6);
- GameConfig.instance().palyLevel = level;
- this.loadLevelIntro();
- }
- /**加载关卡介绍界面 */
- public loadLevelIntro() {
- let self = this;
- cc.resources.load("prefabs/LevelIntro", cc.Prefab, function (err, prefab: cc.Prefab) {
- var newNode = cc.instantiate(prefab);
- self.node.addChild(newNode, 1);
- newNode.setPosition(cc.v2(0, 0));
- });
- }
- private preLoadSprite() {
- cc.resources.load("talant/itembg", cc.SpriteFrame, function (err, myspriteFrame: cc.SpriteFrame) {
- });
- for (let i = 0; i < 30; i++) {
- cc.resources.load("talant/talant_skill_" + (i + 1), cc.SpriteFrame, function (err, myspriteFrame: cc.SpriteFrame) {
- });
- }
- }
- }
|