| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521 |
- import { RoadType } from "../../configData/Enum";
- import monsterNode from "./monsterNode";
- import path from "../../configData/path";
- import ReadCsv from "../../configData/ReadCsv";
- import GameConfig from "../../configData/GameConfig";
- import gameData from "../../configData/gameData";
- import gameUI from "../UIFace/gameUI";
- import DataObj from "../../configData/DataObj";
- import gameManger from "../UIFace/gameManger";
- import path1 from "../../configData/path1";
- import path2 from "../../configData/path2";
- import path3 from "../../configData/path3";
- const { ccclass, property } = cc._decorator;
- @ccclass
- export default class monsterManger extends cc.Component {
- @property(cc.Sprite)
- private testspr: cc.Sprite = null;
- @property(cc.Sprite)
- private chaqi: cc.Sprite = null;
- private kulou: cc.Node[] = [];
- private monsterArr: monsterNode[] = [];
- public myDataObj: DataObj = null;
- private road_group_1 = [];
- private road_group_2 = [];
- private road_group_3 = [];
- private road_group_4 = [];
- private kulou_pos_1 = [];
- private kulou_pos_2 = [];
- private kulou_pos_3 = [];
- private kulou_pos_4 = [];
- private birth_rate_1: number[] = [];
- private birth_rate_2: number[] = [];
- private birth_rate_3: number[] = [];
- private birth_rate_4: number[] = [];
- private next_time: number[] = [];
- private isKuloushow = [[], [], [], []];
- private step: number[] = [0, 0, 0];
- private group_dex: number = 0;
- private roadcount = 0;
- private kuloucount = 0;
- /**是否可以判断结算 */
- private isCanOver: boolean = false;
- public static instance: monsterManger = null;
- protected onLoad() {
- monsterManger.instance = this;
- this.myDataObj = new DataObj();
- this.chaqi.node.zIndex = 1007;
- this.testspr.node.zIndex = 1007;
- this.Loadkulou();
- }
- /**加载骷髅 */
- private Loadkulou() {
- var self = this;
- cc.resources.load("prefabs/kulou", cc.Prefab, function (err, prefab: cc.Prefab) {
- for (let i = 0; i < 4; i++) {
- var newNode = cc.instantiate(prefab);
- self.node.addChild(newNode, 1008);
- newNode.active = false;
- self.kulou.push(newNode);
- newNode.on(cc.Node.EventType.TOUCH_START, self.tapOrTimeUp, self);
- }
- });
- }
- /**初始化数据 */
- public resetData() {
- this.road_group_1 = [];
- this.road_group_2 = [];
- this.road_group_3 = [];
- this.road_group_4 = [];
- this.kulou_pos_1 = [];
- this.kulou_pos_2 = [];
- this.kulou_pos_3 = [];
- this.kulou_pos_4 = [];
- this.birth_rate_1 = [];
- this.birth_rate_2 = [];
- this.birth_rate_3 = [];
- this.birth_rate_4 = [];
- this.next_time = [];
- this.isKuloushow = [[], [], [], []];
- this.step = [0, 0, 0, 0];
- this.group_dex = -1;
- this.kuloucount = 0;
- this.unscheduleAllCallbacks();
- this.node.stopAllActions();
- for (let i = 0; i < this.monsterArr.length; i++) {
- const element = this.monsterArr[i];
- element.node.destroy();
- }
- this.monsterArr = [];
- for (let i = 0; i < 4; i++) {
- this.kulou[i].active = false;
- let myprogress = this.kulou[i].getComponent(cc.ProgressBar);
- myprogress.progress = 1;
- }
- }
- /**加载怪物出现时机数据 */
- public initMonster() {
- this.resetData();
- let self = this;
- gameData.instance().readLevel(gameUI.instance.myDataObj.LevelData.scene_path, function () {
- self.readData();
- });
- }
- private readData() {
- let data = gameData.instance().timeLevel_Config;
- let nameArr = [];
- for (let i = 0; i < data.length; i++) {
- let rowArr = data[i];
- if (i == 2) {
- for (let k = 0; k < rowArr.length; k++) {
- const element = rowArr[k];
- nameArr.push(element);
- }
- }
- if (i >= 3) {
- for (let k = 0; k < rowArr.length; k++) {
- const element = rowArr[k];
- let name = nameArr[k];
- if (name == 'group_num') {
- }
- if (name == 'road_1_group') {
- let grouparr: number[] = element.split("*");
- this.road_group_1.push(grouparr);
- }
- if (name == 'road_2_group') {
- let grouparr: number[] = element.split("*");
- this.road_group_2.push(grouparr);
- }
- if (name == 'road_3_group') {
- let grouparr: number[] = element.split("*");
- this.road_group_3.push(grouparr);
- }
- if (name == 'road_4_group') {
- let grouparr: number[] = element.split("*");
- this.road_group_4.push(grouparr);
- }
- if (name == 'road_next_time') {
- this.next_time.push(element);
- }
- if (name == 'road_1_birth_rate') {
- this.birth_rate_1.push(Number(element));
- }
- if (name == 'road_2_birth_rate') {
- this.birth_rate_2.push(Number(element));
- }
- if (name == 'road_3_birth_rate') {
- this.birth_rate_3.push(Number(element));
- }
- if (name == 'road_4_birth_rate') {
- this.birth_rate_4.push(Number(element));
- }
- if (name == 'road_1_position') {
- let grouparr = element.split("*");
- this.kulou_pos_1.push(grouparr);
- if (grouparr != '') {
- this.isKuloushow[0].push(grouparr);
- }
- }
- if (name == 'road_2_position') {
- let grouparr = element.split("*");
- this.kulou_pos_2.push(grouparr);
- if (grouparr != '') {
- this.isKuloushow[1].push(grouparr);
- }
- }
- if (name == 'road_3_position') {
- let grouparr = element.split("*");
- this.kulou_pos_3.push(grouparr);
- if (grouparr != '') {
- this.isKuloushow[2].push(grouparr);
- }
- }
- if (name == 'road_4_position') {
- let grouparr = element.split("*");
- this.kulou_pos_4.push(grouparr);
- if (grouparr != '') {
- this.isKuloushow[3].push(grouparr);
- }
- }
- }
- }
- }
- this.initKulou();
- gameUI.instance.setTotalGroup(0, this.road_group_1.length);
- }
- /**设置骷髅坐标方向 */
- private initKulou() {
- for (let i = 0; i < 4; i++) {
- let jiantou = this.kulou[i].getChildByName('monsterIndir');
- let pos = cc.v2();
- let monpos = cc.v2();
- if (this.isKuloushow[i].length > 0) {
- pos = cc.v2(Number(this.isKuloushow[i][0][0]), Number(this.isKuloushow[i][0][1]));
- let isShow = false;
- if (i == 0) {
- monpos = cc.v2(path.instance.getPathData()[0]);
- isShow = this.kulou_pos_1[0][0] != '';
- }
- if (i == 1) {
- monpos = cc.v2(path1.instance.getpathData()[0]);
- isShow = this.kulou_pos_2[0][0] != '';
- }
- if (i == 2) {
- monpos = cc.v2(path2.instance.getpathData()[0]);
- isShow = this.kulou_pos_3[0][0] != '';
- }
- if (i == 3) {
- monpos = cc.v2(path3.instance.getpathData()[0]);
- isShow = this.kulou_pos_4[0][0] != '';
- }
- if (isShow) {
- this.kulou[i].active = true;
- this.kulou[i].runAction(cc.repeatForever(cc.sequence(cc.scaleTo(0.4, 1.1), cc.scaleTo(0.4, 1))));
- }
- this.kulou[i].setPosition(pos);
- }
- if (monpos.y > 540) {
- //上
- jiantou.setPosition(0, 70);
- jiantou.angle = 0;
- }
- if (monpos.y < -540) {
- //下
- jiantou.setPosition(0, -70);
- jiantou.angle = 180;
- }
- if (monpos.x > 960) {
- //右
- jiantou.setPosition(70, 0);
- jiantou.angle = 270;
- }
- if (monpos.x < -960) {
- //左
- jiantou.setPosition(-70, 0);
- jiantou.angle = 90;
- }
- }
- }
- /**怪物开始刷新进场 */
- public startMonsterGo() {
- this.group_dex++;
- gameUI.instance.setTotalGroup(this.group_dex + 1, this.road_group_1.length);
- this.roadcount = 0;
- this.step = [0, 0, 0, 0];
- this.roadOne();
- this.roadTwo();
- this.roadThree();
- this.roadFour();
- }
- /**道路一 */
- private roadOne() {
- let leth = this.road_group_1[this.group_dex].length;
- if (leth - 1 >= this.step[0] && this.road_group_1[this.group_dex][this.step[0]] != '') {
- let montype: number = Number(this.road_group_1[this.group_dex][this.step[0]]);
- if (montype != 0) {
- this.seleMinster(1, Math.floor(Math.random() * 6), montype);
- }
- this.scheduleOnce(function () {
- this.roadOne();
- }, this.birth_rate_1[this.group_dex]);
- this.step[0]++;
- }
- else {
- this.roadcount++;
- if (this.roadcount == 4) {
- this.delayedTime();
- }
- }
- }
- private roadTwo() {
- let leth = this.road_group_2[this.group_dex].length;
- if (leth - 1 >= this.step[1] && this.road_group_2[this.group_dex][this.step[1]] != '') {
- let montype: number = Number(this.road_group_2[this.group_dex][this.step[1]]);
- if (montype != 0) {
- this.seleMinster(2, Math.floor(Math.random() * 6), montype);
- }
- this.scheduleOnce(function () {
- this.roadTwo();
- }, this.birth_rate_2[this.group_dex]);
- this.step[1]++;
- }
- else {
- this.roadcount++;
- if (this.roadcount == 4) {
- this.delayedTime();
- }
- }
- }
- private roadThree() {
- let leth = this.road_group_3[this.group_dex].length;
- if (leth - 1 >= this.step[2] && this.road_group_3[this.group_dex][this.step[2]] != '') {
- let montype: number = Number(this.road_group_3[this.group_dex][this.step[2]]);
- if (montype != 0) {
- this.seleMinster(3, Math.floor(Math.random() * 6), montype);
- }
- this.scheduleOnce(function () {
- this.roadThree();
- }, this.birth_rate_3[this.group_dex]);
- this.step[2]++;
- }
- else {
- this.roadcount++;
- if (this.roadcount == 4) {
- this.delayedTime();
- }
- }
- }
- private roadFour() {
- let leth = this.road_group_4[this.group_dex].length;
- if (leth - 1 >= this.step[3] && this.road_group_4[this.group_dex][this.step[3]] != '') {
- let montype: number = Number(this.road_group_4[this.group_dex][this.step[3]]);
- if (montype != 0) {
- this.seleMinster(4, Math.floor(Math.random() * 6), montype);
- }
- this.scheduleOnce(function () {
- this.roadFour();
- }, this.birth_rate_4[this.group_dex]);
- this.step[3]++;
- }
- else {
- this.roadcount++;
- if (this.roadcount == 4) {
- this.delayedTime();
- }
- }
- }
- /**延时 */
- private delayedTime() {
- if (this.group_dex < this.road_group_1.length - 1) {
- this.scheduleOnce(function () {
- //展示骷髅
- this.kulou[0].active = false;
- this.kulou[1].active = false;
- this.kulou[2].active = false;
- this.kulou[3].active = false;
- if (this.kulou_pos_1[this.group_dex + 1][0] != '') {
- this.kulou[0].active = true;
- this.kulou[0].runAction(cc.repeatForever(cc.sequence(cc.scaleTo(0.4, 1.1), cc.scaleTo(0.4, 1))));
- let myprogress = this.kulou[0].getComponent(cc.ProgressBar);
- myprogress.progress = 1;
- }
- if (this.kulou_pos_2[this.group_dex + 1][0] != '') {
- this.kulou[1].active = true;
- this.kulou[1].runAction(cc.repeatForever(cc.sequence(cc.scaleTo(0.4, 1.1), cc.scaleTo(0.4, 1))));
- let myprogress = this.kulou[1].getComponent(cc.ProgressBar);
- myprogress.progress = 1;
- }
- if (this.kulou_pos_3[this.group_dex + 1][0] != '') {
- this.kulou[2].active = true;
- this.kulou[2].runAction(cc.repeatForever(cc.sequence(cc.scaleTo(0.4, 1.1), cc.scaleTo(0.4, 1))));
- let myprogress = this.kulou[2].getComponent(cc.ProgressBar);
- myprogress.progress = 1;
- }
- if (this.kulou_pos_4[this.group_dex + 1][0] != '') {
- this.kulou[3].active = true;
- this.kulou[3].runAction(cc.repeatForever(cc.sequence(cc.scaleTo(0.4, 1.1), cc.scaleTo(0.4, 1))));
- let myprogress = this.kulou[3].getComponent(cc.ProgressBar);
- myprogress.progress = 1;
- }
- this.kuloucount = 0;
- this.showKulou();
- }, this.next_time[this.group_dex]);
- }
- else {
- //判断结算
- this.isCanOver = true;
- }
- }
- /**出现骷髅 */
- public showKulou() {
- if (this.kuloucount >= 10000) {
- return;
- }
- this.kuloucount++;
- let total: number = Number(gameData.instance().game_Const[4][2]);
- for (let i = 0; i < this.kulou.length; i++) {
- if (this.kulou[i].active == true) {
- let myprogress = this.kulou[i].getComponent(cc.ProgressBar);
- myprogress.progress = 1 - this.kuloucount / (total * 10);
- }
- }
- if (this.kuloucount >= total * 10) {
- this.TimeUp();
- return;
- }
- this.scheduleOnce(function () {
- this.showKulou();
- }, 0.1);
- }
- /**计时完 */
- public TimeUp() {
- for (let i = 0; i < this.kulou.length; i++) {
- this.kulou[i].active = false;
- this.kulou[i].stopAllActions();
- }
- this.kuloucount = 10000;
- this.startMonsterGo();
- }
- /**点击骷髅或倒计时完 */
- public tapOrTimeUp() {
- for (let i = 0; i < this.kulou.length; i++) {
- this.kulou[i].active = false;
- this.kulou[i].stopAllActions();
- }
- this.kuloucount = 10000;
- this.startMonsterGo();
- }
- private sddd = 0;
- /**创建怪物 */
- private seleMinster(way: number, road: RoadType, monsterId: number): void {
- var self = this;
- this.myDataObj.writeMonster_Config(monsterId);
- cc.resources.load("prefabs/" + this.myDataObj.monsterData.name1, cc.Prefab, function (err, prefab: cc.Prefab) {
- let guainode = cc.instantiate(prefab);
- let monster = guainode.getComponent(monsterNode);
- self.sddd++;
- monster.name = "name_" + self.sddd;
- self.node.addChild(guainode, 2);
- monster.initLevelData(way, road, monsterId);
- self.monsterArr.push(monster);
- });
- }
- /**不能插旗 */
- public updatest(poss: cc.Vec2) {
- this.testspr.node.opacity = 255;
- this.testspr.node.setPosition(poss);
- this.testspr.node.stopAllActions();
- cc.tween(this.testspr.node)
- .to(0.3, { scale: 1.2 })
- .to(0.3, { scale: 1 })
- .to(0.3, { scale: 1.2 })
- .to(0.3, { scale: 1, opacity: 0 })
- .start();
- }
- /**插旗 */
- public chaqidian(poss: cc.Vec2) {
- this.chaqi.node.opacity = 255;
- this.chaqi.node.setPosition(poss);
- this.chaqi.node.stopAllActions();
- cc.tween(this.chaqi.node)
- .delay(2)
- .to(0.3, { opacity: 0 })
- .start();
- }
- /**删除怪物 */
- public dieDelatemonster(monter: monsterNode) {
- let index = this.monsterArr.indexOf(monter);
- if (index >= 0) {
- this.monsterArr.splice(index, 1);
- }
- }
- /**获取所有怪物 */
- public GetMonsterArr(): monsterNode[] {
- return this.monsterArr;
- }
- /**判断游戏结束结算 */
- public getIsCanOver(): boolean {
- return this.isCanOver;
- }
- /**判断游戏结束结算 */
- public isGameOver() {
- if (this.isCanOver) {
- //结算
- this.isCanOver = false;
- // this.node.pauseAllActions();
- // this.unscheduleAllCallbacks();
- gameManger.instance.gameOver(gameUI.instance.getHp());
- }
- }
- }
|