| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163 |
- import GameConfig from "../../configData/GameConfig";
- import { TowerType } from "../../configData/Enum";
- import gameData from "../../configData/gameData";
- import path from "../../configData/path";
- import path1 from "../../configData/path1";
- import path2 from "../../configData/path2";
- import gameUI from "./gameUI";
- import monsterManger from ".././monster/monsterManger";
- import towerManger from ".././tower/towerManger";
- import viewComtent from "./viewComtent";
- import path3 from "../../configData/path3";
- import { AudioManager } from "../../configData/AudioManager";
- const {ccclass, property} = cc._decorator;
- @ccclass
- export default class gameManger extends cc.Component {
-
- public static instance:gameManger = null;
- private _touchId = null;
- private beijing:cc.Node = null;
- protected onLoad (): void {
- gameManger.instance = this;
- this.beijing = this.node.getChildByName("beijing");
- let self = this;
- gameData.instance().readGameData(function(){
- // self.initLevel();
- AudioManager.palyAudio(1);
- });
- this.bindTouchEvents();
- }
- onDestroy(){
- // gameManger.instance = null;
- }
- /**加载底图 */
- private loadGamebg()
- {
- let self = this;
- cc.resources.load("gamebg/game_"+gameUI.instance.myDataObj.LevelData.scene_path, cc.SpriteFrame, function (err, myspriteFrame: cc.SpriteFrame) {
- self.beijing.getComponent(cc.Sprite).spriteFrame = myspriteFrame;
- });
- }
-
- public initLevel()
- {
- // console.log("--------------------ceshi");
- GameConfig.instance().isPause = false;
- cc.director.getScheduler().setTimeScale(1);
- GameConfig.instance().speed = 1;
- cc.director.resume();
- GameConfig.instance().levelDiff = 0;
- gameUI.instance.initData();
-
- this.loadGamebg();
- path.instance.changeLevelData();
- path1.instance.changeLevelData();
- path2.instance.changeLevelData();
- path3.instance.changeLevelData();
- gameUI.instance.loadGoPos();
-
-
- monsterManger.instance.initMonster();
- towerManger.instance.initTowerTaside();
- towerManger.instance.updateTowerActionSchle();
- }
- /**游戏结算 */
- public gameOver(HpNum:number){
- towerManger.instance.setAniGo(true);
- viewComtent.instance.gameOver(HpNum);
- }
-
- /**
- * touchstart 回调
- * @param e 参数
- */
- private onTouchStart(e: cc.Event.EventTouch): void {
- if (this._touchId !== null) {
- return;
- }
- // console.log("坐标:"+e.getLocation());
- this._touchId = e.getID();
-
- // let turnPos = e.getLocation().sub(cc.v2(960,540));
-
- towerManger.instance.closedHuan();
- // towerManger.instance.chaqiGetPos(turnPos.add(cc.v2(0,viewComtent.instance.getOff())));
-
- }
- /**
- * touchend 回调
- */
- private onTouchMoved(e: cc.Event.EventTouch): void {
- if (e.getID() !== this._touchId) {
- return;
- }
- }
- /**
- * touchend 回调
- */
- private onTouchEnd(e: cc.Event.EventTouch): void {
- this.touchEnd(e);
- }
- /**
- * touchcancel 回调
- * @param e 参数
- */
- private onTouchCancel(e: cc.Event.EventTouch): void {
- // console.log("取消触摸");
- this.touchEnd(e);
- }
- private touchEnd(e: cc.Event.EventTouch): void{
- if (e.getID() !== this._touchId) {
- return;
- }
- this._touchId = null;
- }
- /**
- * 绑定点击事件
- */
- private bindTouchEvents(): void {
- this.beijing.on(cc.Node.EventType.TOUCH_START, this.onTouchStart, this);
- this.beijing.on(cc.Node.EventType.TOUCH_MOVE, this.onTouchMoved, this);
- this.beijing.on(cc.Node.EventType.TOUCH_CANCEL, this.onTouchCancel, this);
- this.beijing.on(cc.Node.EventType.TOUCH_END, this.onTouchEnd, this);
- // console.log("加载触摸");
- }
- /**
- * 解绑点击事件
- */
- private unbindTouchEvents(): void {
- this.beijing.off(cc.Node.EventType.TOUCH_START, this.onTouchStart, this);
- this.beijing.off(cc.Node.EventType.TOUCH_MOVE, this.onTouchMoved, this);
- this.beijing.off(cc.Node.EventType.TOUCH_CANCEL, this.onTouchCancel, this);
- this.beijing.off(cc.Node.EventType.TOUCH_END, this.onTouchEnd, this);
- // console.log("关闭触摸");
- }
- }
|