| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154 |
- let webView = require("../../WebView");
- let library = require("../../Library");
- let gameConfig = require("../GameConfig");
- cc.Class({
- extends: cc.Component,
- properties: {
- gameStates: {
- default: null,
- type: cc.Node,
- serializable: true,
- },
- gameMode: {
- default: null,
- type: cc.Node,
- serializable: true,
- },
- topHole: {
- default: null,
- type: cc.Node,
- serializable: true,
- },
- leftHole: {
- default: null,
- type: cc.Node,
- serializable: true,
- },
- rightHole: {
- default: null,
- type: cc.Node,
- serializable: true,
- },
- avatar: {
- default: null,
- type: cc.Sprite,
- serializable: true,
- },
- playerName: {
- default: null,
- type: cc.Label,
- serializable: true,
- },
- score: {
- default: null,
- type: cc.Label,
- serializable: true,
- },
- gender: {
- default: null,
- type: cc.Node,
- serializable: true,
- },
- hp: {
- default: null,
- type: cc.Node,
- serializable: true,
- },
- bAi:true,
- id:0,
- },
- onLoad () {
- this.init();
- if(cc.sys.isMobile)
- {
- webView.register(this.node);
- }
- },
- init()
- {
- this.topHoleScp = this.topHole.getComponent('Actor');
- this.leftHoleScp = this.leftHole.getComponent('Actor');
- this.rightHoleScp = this.rightHole.getComponent('Actor');
- this.gStatesScp = this.gameStates.getComponent('GameStates');
- this.gameModeScp = this.gameMode.getComponent('GameMode');
- this.pStatesScp = this.node.getComponent('BasePlayerStates');
- this.hpScp = this.hp.getComponent('MaskedProgressBar');
- this.bCd = false;
- },
- start()
- {
- this.score.string = this.pStatesScp.hit.toString();
- },
- left()
- {
- if(this.gStatesScp.curretState == this.gStatesScp.finished) return;
- if(!this.leftHoleScp.bBeat)
- {
- this.wrong();
- return;
- }
- this.leftHoleScp.punch(this.bAi);
- this.hit();
- },
- top()
- {
- if(this.gStatesScp.curretState == this.gStatesScp.finished) return;
- if(!this.topHoleScp.bBeat)
- {
- this.wrong();
- return;
- }
- this.topHoleScp.punch(this.bAi);
- this.hit();
- },
- right()
- {
- if(this.gStatesScp.curretState == this.gStatesScp.finished) return;
- if(!this.rightHoleScp.bBeat)
- {
- this.wrong();
- return;
- }
- this.rightHoleScp.punch(this.bAi);
- this.hit();
- },
- noDirectionPunch()
- {
- if(this.gStatesScp.curretState == this.gStatesScp.finished) return;
- let arr = this.gStatesScp.appearMouseArr;
- for(let i=0;i<arr.length;i++)
- {
- let obj = arr[i].getComponent('Actor');
- if(!obj.bBeat) return;
- obj.punch(this.bAi);
- this.hit();
- }
- },
- wrong()
- {
- if(!this.pStatesScp.bPlayDirection) return;
- //if miss u will be damaged
- let damage = gameConfig.damage;
- this.pStatesScp.hp-=damage;
- this.hpScp.damage(damage);
- this.pStatesScp.miss++;
- //if hp = 0 game over
- if(this.pStatesScp.hp == 0)
- {
- this.gameModeScp.gameOver();
- }
- },
- actorComeOut(nameIndex,appearDur){},//for ai playerController
- });
|