| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697 |
- import Bird from "./Bird";
- import MatchPanel from "../Common/MatchPanel/MatchPanel";
- import TouchPanel from "./TouchPanel";
- import { Tool } from "./JCLibrary";
- const {ccclass, property} = cc._decorator;
- @ccclass
- export default class Game extends cc.Component {
- @property({type:cc.Prefab})
- private matchPanelPrefab = null;
- @property({type:cc.Prefab})
- private birdPrefab = null;
- @property({type:cc.AudioClip})
- private bgMusic = null;
- @property(cc.String)
- public serverUrl:string = "";
- @property(cc.Boolean)
- public appGame:boolean = false;
- public birds:Bird[] = new Array(2);
- //flag
- public isGameOver:boolean;
- public onLoad():void{
- window.gm = this;
- // this.serverUrl = "ws://192.168.101.14:9999/birdServer";
- cc.director.getPhysicsManager().enabled = true;
- cc.director.getCollisionManager().enabled = true;
- cc.audioEngine.playMusic(this.bgMusic, true);
- if (Tool.openInWebview()) {
- this.appGame = true;
- } else {
- this.appGame = false;
- }
- }
- addMatchPanel() {
- this.node.addChild(cc.instantiate(this.matchPanelPrefab));
- window.matchPanel.node.on(MatchPanel.EVENT_MATCH_SUCCESS, () => {
- this.startGame();
- });
- }
- startGame():void{
- window.gc.startMode();
- this.createBird(0);
- this.createBird(1);
- window.fruitGroove.show();
- window.progressBar.show();
- window.topBar.show();
- this.node.addComponent(TouchPanel);
- this.isGameOver = false;
- window.player.call('checkAI');
- }
- createBird(index:number):void{
- this.birds[index] = (cc.instantiate(this.birdPrefab) as cc.Node).getComponent(Bird);
- this.birds[index].init(index);
- this.node.addChild(this.birds[index].node);
- }
- controlFlyUp(hitPower: number = 30) {
- window.appGame.jumpCount++;
-
- this.birds[window.myPlayerInfo.index].flyUp(hitPower);
- let x = Math.floor(this.birds[window.myPlayerInfo.index].node.x);
- let y = Math.floor(this.birds[window.myPlayerInfo.index].node.y);
- window.player.call('flyUp',[x,y,hitPower]);
- }
- update(){
- if(this.isGameOver==false){
- let myBirdNode = this.birds[window.myPlayerInfo.index].node;
- window.player.call('updateBirdPosition',[
- Math.floor(myBirdNode.x),
- Math.floor(myBirdNode.y)
- ]);
- }
- }
- gameOver(winnerIndex:number):void{
- if(this.isGameOver)return;
- this.isGameOver = true;
- this.birds[0].stop();
- this.birds[1].stop();
- window.fruitGroove.hide();
- window.settlePanel.show(winnerIndex);
- }
- }
-
|