| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391 |
- // Learn cc.Class:
- // - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/class.html
- // - [English] http://www.cocos2d-x.org/docs/creator/en/scripting/class.html
- // Learn Attribute:
- // - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/reference/attributes.html
- // - [English] http://www.cocos2d-x.org/docs/creator/en/scripting/reference/attributes.html
- // Learn life-cycle callbacks:
- // - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/life-cycle-callbacks.html
- // - [English] http://www.cocos2d-x.org/docs/creator/en/scripting/life-cycle-callbacks.html
- cc.Class({
- extends: cc.Component,
- properties: {
- // foo: {
- // // ATTRIBUTES:
- // default: null, // The default value will be used only when the component attaching
- // // to a node for the first time
- // type: cc.SpriteFrame, // optional, default is typeof default
- // serializable: true, // optional, default is true
- // },
- // bar: {
- // get () {
- // return this._bar;
- // },
- // set (value) {
- // this._bar = value;
- // }
- // },
- },
- // LIFE-CYCLE CALLBACKS:
- onLoad () {
- },
- start () {
- },
- setMap : function(Map,type){
- this.actorsNode = Map;
- this._an(type);
- this._init();
- },
- _an :function (type){
- this.ansName = [];
- if (type == 0) {
- this.ansName.push("RedIdleAnim");
- this.ansName.push("RedJumpAnim");
- this.ansName.push("RedDownCryAnim");
- this.ansName.push("RedLoseCryAnim");
- this.ansName.push("RedWinAnim");
- }
- if (type == 1) {
- this.ansName.push("BlueIdleAnim");
- this.ansName.push("BlueJumpAnim");
- this.ansName.push("BlueDownCryAnim");
- this.ansName.push("BlueLoseCryAnim");
- this.ansName.push("BlueWinAnim");
- }
- },
- _init : function(){
- this.indexes = 0;
- this.addY = 0;
- this.node.setPosition(this.actorsNode[0].x,this.actorsNode[0].y+this.addY);
- this.inputTag = true;
- // 一步两步的 基本记录数组位置的索引
- this.indexes = 0;
- //记录所有操作 索引的数组
- this.Records = [];
- //按了多少次
- this.Recordsindex = 0;
- this.Records.push(this.indexes);
- this.player = UtilsNode.getNode("player",this.node);
- this.gameOverTag = true;
- },
- addOne : function () {
- if (!this.gameOverTag) {
- return;
- }
- if (!this.inputTag) {
- return;
- }
- let temp = this.indexes;
- this.Records.push(temp);
- this.indexes++;
- app.bgm.playha();
- this.playerSetPosition();
- },
- addTwo : function () {
- if (!this.gameOverTag) {
- return;
- }
- if (!this.inputTag) {
- return;
- }
- let temp = this.indexes;
- this.Records.push(temp);
- this.indexes+=2;
- app.bgm.playhei();
- this.playerSetPosition();
- },
- addAuto : function () {
- if (!this.gameOverTag) {
- return;
- }
- if (!this.inputTag) {
- return;
- }
- let temp = this.indexes;
- this.Records.push(temp);
- let actor = this.actorsNode[this.indexes+1].getComponent("actor");
- if (actor.type == 2) {
- let x = UtilsNode.getRandom(2,0,10);
- if (x < 8) {
- this.indexes+=2;
- }else{
- this.indexes+=1;
- }
- }else{
- this.indexes+=1;
- }
- this.playerSetPosition();
- },
- playerSetPosition : function () {
- if (this.indexes >= this.actorsNode.length-1) {
- this.indexes = this.actorsNode.length-1;
- }
- this.checkType();
- // console.log("记录数组日常遍历",this.Records);
- var finished = cc.callFunc(function(target, score) {
- // app.camera.y = this.node.y-640;
- // var myAction = cc.sequence(cc.moveTo(1, cc.v2(this.actorsNode[this.indexes].x,this.actorsNode[this.indexes].y)))
- // console.log("镜头现在高度",app.camera.y);
- // console.log("玩家现在高度",this.node.y);
- if (this.callBackCameraMove!=null) {
- this.callBackCameraMove(this.node);
- }
- if (this.callBackMove!=null) {
- this.callBackMove(this.indexes);
- }
- //播放动画
- this.playAnEnd();
- this.playAnEnd_bg();
- if (this.indexes==8) {
- if (this.callBackInfo) {
- this.callBackInfo();
- }
- }
- // setTimeout(function () {
- // this.inputTag = true;
- // }.bind(this),500);
- // console.log("现在的位置",this.node);
- }, this);//动作完成后会给玩家加100分
- // var myAction = cc.sequence(cc.jumpTo(1, cc.v2(this.actorsNode[this.indexes].x,this.actorsNode[this.indexes].y)), finished);
- var myAction = cc.sequence(
- cc.jumpTo(0.1, cc.v2(this.actorsNode[this.indexes].x,this.actorsNode[this.indexes].y+this.addY-20), 200, 1),
- cc.moveTo(0.05,cc.v2(this.actorsNode[this.indexes].x,this.actorsNode[this.indexes].y+this.addY+10)),
- finished);
- // this.node.setPosition(this.actorsNode[this.indexes].x,this.actorsNode[this.indexes].y);
- this.node.runAction(myAction);
- this.inputTag = false;
- this.playAnStart();
- },
- playAnStart : function(){
- let actor = this.actorsNode[this.indexes].getComponent("actor");
- let an = this.player.getComponent(cc.Animation);
- let Clips = an.getClips();
- console.log("当前动画列表",Clips);
- // console.log("地板什么类型的",actor.type);
- an.play(this.ansName[1]);
- // switch (actor.type) {
- // case 2:
- // if (this.actorsNode[this.indexes].userData==null ) {
- // let data = {type : true};
- // this.actorsNode[this.indexes].userData = data;
- // //要掉下去了
- // an.play();
- // }
- //
- // break;
- // case 0:
- // case 1:
- // an.play();
- // break;
- // case 3:
- // an.play();
- // break;
- // }
- },
- playAnEnd : function(){
- let actor = this.actorsNode[this.indexes].getComponent("actor");
- let an = this.player.getComponent(cc.Animation);
- let Clips = an.getClips();
- console.log("地板什么类型的",actor.type);
- let temp = app.bg.actorps[this.indexes];
- switch (actor.type) {
- case 2:
- // if (this.actorsNode[this.indexes].userData==null ) {
- // let data = {type : true};
- // this.actorsNode[this.indexes].userData = data;
- // //要掉下去了
- // an.play();
- // }
- an.play(this.ansName[2]);
- break;
- case 0:
- case 1:
- an.play();
- let temp1 = app.bg.actorps[this.indexes-1];
- console.log("落地之后这个是什么类型的",temp,"上个类型",temp1);
- if (temp.q != null || temp1.q!=null) {
- this.node.setScale(1,-1);
- this.node.setRotation(180);
- console.log("我应该脸往左",temp,temp1);
- }
- if (temp.w!= null || temp1.w!=null) {
- this.node.setScale(1,1);
- this.node.setRotation(0);
- console.log("我应该脸往右",temp,temp1);
- }
- if (this.callBackJump!=null) {
- this.callBackJump(temp);
- }
- break;
- case 3:
- if (this.callBackJump!=null) {
- this.callBackJump(temp);
- }
- an.play(this.ansName[4]);
- break;
- }
- },
- showsSmoke : function(b){
- let node = UtilsNode.getNode("qi",this.node);
- node.getComponent("kill").setActive(b);
- },
- playAnEnd_bg : function(){
- let actor = this.actorsNode[this.indexes].getComponent("actor");
- let an = this.actorsNode[this.indexes].getComponent("itemmanager");
- this.showsSmoke(true);
- console.log("地板什么类型的",actor.type);
- switch (actor.type) {
- case 2:
- if (this.actorsNode[this.indexes].userData==null ) {
- let data = {type : true};
- this.actorsNode[this.indexes].userData = data;
- //要掉下去了
- an.play();
- }
- an.playwater();
- break;
- case 0:
- case 1:
- an.play();
- break;
- case 3:
- an.play();
- break;
- }
- },
- startGame : function(b){
- this.gameOverTag = b;
- },
- //检查地板类型
- checkType : function () {
- let actor = this.actorsNode[this.indexes].getComponent("actor");
- let an = this.player.getComponent(cc.Animation);
- let Clips = an.getClips();
- console.log("地板什么类型的",actor.type);
- switch (actor.type) {
- case 2:
- //要掉下去了
- if (this.callBackTrap!=null) {
- this.callBackTrap();
- }
- this.inputTag = false;
- // console.log("记录数组陷阱",this.Records);
- setTimeout(function () {
- this.indexes = this.Records[this.Records.length-1];
- this.node.setPosition(this.actorsNode[this.indexes].x,this.actorsNode[this.indexes].y+this.addY);
- UtilsNode.getNode("player",this.node).setPosition(0,0);
- this.inputTag = true;
- an.play(this.ansName[0]);
- this.playAnEnd_bg();
- }.bind(this),1500);
- break;
- case 0:
- case 1:
- this.inputTag = false;
- // console.log("记录数组陷阱",this.Records);
- setTimeout(function () {
- // this.indexes = this.Records[this.Records.length-1];
- // this.node.setPosition(this.actorsNode[this.indexes].x,this.actorsNode[this.indexes].y);
- this.inputTag = true;
- an.play(this.ansName[0]);
- }.bind(this),200);
- break;
- case 3:
- setTimeout(function () {
- if (this.callBackGameOver != null) {
- this.callBackGameOver();
- }
- // an.play(this.ansName[4]);
- this.winOrLose(true);
- // actor.setGameOverShow(false);
- let star = UtilsNode.getNode("star",this.actorsNode[this.indexes]);
- star.getComponent("endstart").endGame();
- }.bind(this),200);
- break;
- }
- },
- winOrLose : function(b){
- this.gameOverTag = false;
- let an = this.player.getComponent(cc.Animation);
- if (b) {
- an.play(this.ansName[4]);
- }else{
- an.play(this.ansName[3]);
- }
- },
- //todo 回调区域------------------------------------------------------
- callBackGameOver : function(){},
- setCallBackGameOver : function (callBackGameOver) {
- this.callBackGameOver = callBackGameOver;
- },
- callBackTrap : function(){},
- setCallBackTrap : function (callBackTrap) {
- this.callBackTrap = callBackTrap;
- },
- callBackInfo : function(){},
- setCallBackInfo : function (callBackInfo) {
- this.callBackInfo = callBackInfo;
- },
- callBackJump : function(){},
- setCallBackJump : function (callBackJump) {
- this.callBackJump = callBackJump;
- },
- callBackCameraMove : function(){},
- setCallBackCameraMove : function (callBackCameraMove) {
- this.callBackCameraMove = callBackCameraMove;
- },
- callBackMove : function(){},
- setCallBackMove : function (callBackMove) {
- this.callBackMove = callBackMove;
- },
- // update (dt) {},
- });
|