| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379 |
- import DataObj from "../../configData/DataObj";
- import GameConfig from "../../configData/GameConfig";
- import path from "../../configData/path";
- import path1 from "../../configData/path1";
- import path2 from "../../configData/path2";
- import gameManger from "./gameManger";
- import monsterManger from ".././monster/monsterManger";
- import TapNode from "./TapNode";
- import towerManger from ".././tower/towerManger";
- import skillManger from "../tower/skillManger";
- import SkillSolate from "../tower/SkillSolate";
- import path3 from "../../configData/path3";
- import mainManager from "../../mainFace/mainManager";
- import { AudioManager } from "../../configData/AudioManager";
- const { ccclass, property } = cc._decorator;
- @ccclass
- export default class gameUI extends cc.Component {
- @property(cc.Node)
- private pausedbg: cc.Node = null;
- @property(cc.Label)
- private HpLabel: cc.Label = null;
- @property(cc.Label)
- private GoupLabel: cc.Label = null;
- @property(cc.Label)
- private GoldLabel: cc.Label = null;
- /**陨石技能 */
- @property(cc.Sprite)
- private yunshi: cc.Sprite = null;
- /**援兵技能 */
- @property(cc.Sprite)
- private yuanBin: cc.Sprite = null;
- /**加速按钮 */
- @property(cc.Button)
- private soonStep: cc.Button = null;
- @property(cc.SpriteFrame)
- private soonStep1: cc.SpriteFrame = null;
- @property(cc.SpriteFrame)
- private soonStep2: cc.SpriteFrame = null;
- private GoPos: cc.Vec3[] = [];
- private yunshiCoint = 0;
- private yuanbinCoint = 0;
- private isCanPlayYunshi = false;
- private isCanPlayYuanbin = false;
- private yunshiDelay = 1;
- private yuanbinDelay = 1;
- private hpnum = 0;
- private groupNow = 0;
- private groupTotal = 0;
- private goldnum = 0;
- public myDataObj: DataObj = null;
- public static instance: gameUI = null;
- protected onLoad(): void {
- gameUI.instance = this;
- this.node.opacity = 255;
- this.pausedbg.active = false;
- this.pausedbg.opacity = 255;
- this.yunshi.node.active = false;
- this.yuanBin.node.active = false;
- this.pausedbg.on(cc.Node.EventType.TOUCH_START, this.onTouchStart, this);
- this.myDataObj = new DataObj();
- // this.node.getChildByName("pause").getComponent(cc.Button).enabled = false;
- // this.node.getChildByName("pause").getComponent(cc.Button).disabledColor = cc.color(0,0,0);
- }
- /**初始化关卡数据 */
- public initData() {
- this.myDataObj.writeLevel_Config(GameConfig.instance().palyLevel);
- this.hpnum = this.myDataObj.LevelData.level_hp;
- let maptype = this.myDataObj.LevelData.map_type;
- AudioManager.palyAudio(maptype + 2);
- this.HpLabel.string = this.hpnum.toString();
- this.goldnum = 0;
- this.AddGold(this.myDataObj.LevelData.start_gold);
- // this.soonStep.normalSprite = this.soonStep2;
- // this.soonStep.pressedSprite = this.soonStep2;
- this.soonStep.node.getChildByName('Background').getComponent(cc.Sprite).spriteFrame = this.soonStep1;
- }
- /** 游戏加速*/
- private setSpeedSoon() {
- let timescale = cc.director.getScheduler().getTimeScale();
- if (timescale < 4) {
- timescale += 1;
- GameConfig.instance().speed = timescale;
- cc.director.getScheduler().setTimeScale(timescale);
- if (timescale == 4) {
- this.soonStep.node.getChildByName('Background').getComponent(cc.Sprite).spriteFrame = this.soonStep2;
- }
- }
- else {
- timescale = 1;
- GameConfig.instance().speed = timescale;
- cc.director.getScheduler().setTimeScale(timescale);
- this.soonStep.node.getChildByName('Background').getComponent(cc.Sprite).spriteFrame = this.soonStep1;
- }
- }
- /**获取所有路径点 */
- public getGoPos(): cc.Vec3[] {
- return this.GoPos;
- }
- /**本关卡最高塔级数 */
- public getLevelLimit(): number[] {
- return this.myDataObj.LevelData.tower_limit;
- }
- /**设置波次 */
- public setTotalGroup(nownum: number, totalnum: number) {
- this.groupNow = nownum;
- this.groupTotal = totalnum;
- this.GoupLabel.string = this.groupNow.toString() + "/" + this.groupTotal.toString();
- }
- /**血量减少 */
- public HpCut(num: number) {
- this.hpnum -= num;
- if (this.hpnum < 0) {
- this.hpnum = 0;
- }
- this.HpLabel.string = this.hpnum.toString();
- if (this.hpnum == 0) {
- gameManger.instance.gameOver(this.hpnum);
- }
- }
- /**获取血量 */
- public getHp(): number {
- return this.hpnum;
- }
- /**获取金币数 */
- public getGold(): number {
- return this.goldnum;
- }
- /**增加金币数 */
- public AddGold(num: number) {
- this.goldnum += num;
- this.goldnum = Math.floor(this.goldnum);
- this.GoldLabel.string = this.goldnum.toString();
- }
- /**获取钻石数 */
- public getDiamind(): number {
- return GameConfig.instance().storageData.Diamond;
- }
- /**增加钻石数 */
- public addDiamind(num: number, pacent: number) {
- let raaom = Math.random() * 100;
- if (raaom <= pacent) {
- GameConfig.instance().storageData.Diamond += num;
- GameConfig.instance().setStorage();
- }
- }
- /**暂停、开始游戏 */
- private pauseGame() {
- AudioManager.palyAudio(6);
- GameConfig.instance().isPause = !GameConfig.instance().isPause;
- this.pausedbg.active = true;
- this.pauseFun();
- }
- /**暂停 */
- public pauseFun() {
- towerManger.instance.setAniGo(GameConfig.instance().isPause);
- cc.director.pause();
- }
- /**释放暂停 */
- public ClosepauseFun() {
- cc.director.resume();
- }
- /**返回主界面 */
- private backtomain() {
- AudioManager.palyAudio(6);
- mainManager.instance.node.active = true;
- mainManager.instance.backInit();
- this.pausedbg.active = false;
- }
- /**重玩 */
- private repaly() {
- AudioManager.palyAudio(6);
- gameManger.instance.initLevel();
- this.pausedbg.active = false;
- // cc.director.loadScene("gameScence");
- }
- /**继续 */
- private goongame() {
- AudioManager.palyAudio(6);
- GameConfig.instance().isPause = !GameConfig.instance().isPause;
- cc.director.resume();
- towerManger.instance.setAniGo(GameConfig.instance().isPause);
- this.pausedbg.active = false;
- }
- /**打开技能按钮 */
- public openSkillBtn() {
- this.myDataObj.writeSkill_Config(60);
- this.yunshiDelay = this.myDataObj.SkillData.parameter_4;
- if (towerManger.instance.talantData[22].length > 0) {
- this.yunshiDelay -= towerManger.instance.talantData[22][2];
- }
- if (towerManger.instance.talantData[23].length > 0) {
- this.yunshiDelay -= towerManger.instance.talantData[23][2];
- }
- this.myDataObj.writeSkill_Config(61);
- this.yuanbinDelay = this.myDataObj.SkillData.parameter_4;
- this.yunshi.node.active = true;
- this.yuanBin.node.active = true;
- this.yunshiCoint = 0;
- this.yuanbinCoint = 0;
- this.yunshiSchle();
- this.yuanbinSchle();
- }
- /**陨石技能进度条 */
- private yunshiSchle() {
- if (this.yunshiCoint >= 10000) {
- return;
- }
- this.yunshiCoint++;
- let myprogress = this.yunshi.getComponent(cc.ProgressBar);
- let total: number = this.yunshiDelay;
- // let total: number = 2;
- myprogress.progress = 1 - this.yunshiCoint / (total * 10);
- if (this.yunshiCoint >= total * 10) {
- this.yunshi.node.on(cc.Node.EventType.TOUCH_START, this.yunshiTouchOn, this);
- return;
- }
- this.scheduleOnce(function () {
- this.yunshiSchle();
- }, 0.1);
- }
- /**援兵技能进度条 */
- private yuanbinSchle() {
- if (this.yuanbinCoint >= 10000) {
- return;
- }
- this.yuanbinCoint++;
- let myprogress = this.yuanBin.getComponent(cc.ProgressBar);
- let total: number = this.yuanbinDelay;
- // let total = 2;
- myprogress.progress = 1 - this.yuanbinCoint / (total * 10);
- if (this.yuanbinCoint >= total * 10) {
- this.yuanBin.node.on(cc.Node.EventType.TOUCH_START, this.yuanbingTouchOn, this);
- return;
- }
- this.scheduleOnce(function () {
- this.yuanbinSchle();
- }, 0.1);
- }
- /**记录路径点 */
- public loadGoPos() {
- this.GoPos = path.instance.getPathData().concat();
- if (path1.instance.getpathData().length > 0) {
- this.GoPos = this.GoPos.concat(path1.instance.getpathData());
- }
- if (path2.instance.getpathData().length > 0) {
- this.GoPos = this.GoPos.concat(path2.instance.getpathData());
- }
- if (path3.instance.getpathData().length > 0) {
- this.GoPos = this.GoPos.concat(path3.instance.getpathData());
- }
- }
- /**点击援兵和陨石位置判断 */
- private getIsInGopos(location: cc.Vec2): boolean {
- let leth = 73;
- let laca = cc.v3(location.x, location.y);
- for (let i = 0; i < this.GoPos.length; i++) {
- const element = this.GoPos[i];
- if (element.sub(laca).mag() < leth) {
- return true;
- }
- }
- return false;
- }
- /**发动陨石技能 */
- private yunshiTouchOn() {
- AudioManager.palyAudio(6);
- this.yunshiCoint = 0;
- this.yunshi.node.off(cc.Node.EventType.TOUCH_START, this.yunshiTouchOn, this);
- this.isCanPlayYunshi = true;
- TapNode.instance.node.active = true;
- }
- /**发动援兵技能 */
- private yuanbingTouchOn() {
- AudioManager.palyAudio(6);
- this.yuanbinCoint = 0;
- this.yuanBin.node.off(cc.Node.EventType.TOUCH_START, this.yuanbingTouchOn, this);
- this.isCanPlayYuanbin = true;
- TapNode.instance.node.active = true;
- }
- /**陨石、援兵坐标 */
- public SkillTap(location: cc.Vec2) {
- if (this.isCanPlayYunshi == true || this.isCanPlayYuanbin == true) {
- if (this.getIsInGopos(location)) {
- TapNode.instance.node.active = false;
- if (this.isCanPlayYunshi == true) {
- this.isCanPlayYunshi = false;
- this.yunshiSchle();
- skillManger.instance.yunshiBuild(location);
- if (towerManger.instance.talantData[24].length > 0) {
- for (let i = 0; i < towerManger.instance.talantData[24][1]; i++) {
- let ppos = this.GoPos[Math.floor(this.GoPos.length * Math.random())];
- skillManger.instance.yunshiBuild(cc.v2(ppos));
- }
- }
- }
- if (this.isCanPlayYuanbin == true) {
- this.isCanPlayYuanbin = false;
- this.yuanbinSchle();
- cc.resources.load("prefabs/skillSolate", cc.Prefab, function (err, prefab: cc.Prefab) {
- var newNode = cc.instantiate(prefab);
- newNode.setPosition(location);
- towerManger.instance.node.addChild(newNode, 1006);
- let calssName = newNode.getComponent(SkillSolate);
- calssName.towerType = 4;
- calssName.initID();
- towerManger.instance.towerArr.push(calssName);
- });
- }
- }
- else {
- monsterManger.instance.updatest(location);
- }
- }
- }
- /**
- * touchstart 回调
- * @param e 参数
- */
- private onTouchStart(e: cc.Event.EventTouch): void {
- }
- }
|