Player.ts 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. import { JCEntity } from "./JCEngine";
  2. import Fruit from "./Fruit";
  3. import WebView from "./WebView";
  4. const {ccclass, property} = cc._decorator;
  5. @ccclass
  6. export default class Player extends JCEntity {
  7. onLoad(){
  8. window.player = this;
  9. window.appGame.initGame();
  10. }
  11. matchSuccess(playerInfo:any, modeInfo:ModeInfo){
  12. window.gc.modeInfo = modeInfo;
  13. if(playerInfo.index == 0){
  14. window.myPlayerInfo.index = 1;
  15. }else{
  16. window.myPlayerInfo.index = 0;
  17. }
  18. window.otherPlayerInfo = {
  19. index: playerInfo.index,
  20. nickName: undefined,
  21. gender: undefined,
  22. avatar: null
  23. }
  24. if (playerInfo.nickName == "none" && playerInfo.gender == 0 && playerInfo.avatarUrl == "none") {
  25. window.appGame.getAiInfo();
  26. } else {
  27. this.matchSuccessHandle(playerInfo);
  28. }
  29. }
  30. matchSuccessHandle(playerInfo:any) {
  31. window.otherPlayerInfo.nickName = playerInfo.nickName;
  32. window.otherPlayerInfo.gender = playerInfo.gender;
  33. WebView.loadSpriteFrame(playerInfo.avatarUrl, (spriteFrame: cc.SpriteFrame) => {
  34. window.otherPlayerInfo.avatar = spriteFrame;
  35. window.matchPanel.renderOtherInfo(
  36. window.otherPlayerInfo.nickName,
  37. window.otherPlayerInfo.gender,
  38. window.otherPlayerInfo.avatar
  39. );
  40. });
  41. }
  42. updateBirdPosition(x:number,y:number){
  43. window.gm.birds[window.otherPlayerInfo.index].node.setPosition(x,y);
  44. }
  45. flyUp(x:number,y:number,hitPower:number){
  46. window.gm.birds[window.otherPlayerInfo.index].node.setPosition(x,y);
  47. window.gm.birds[window.otherPlayerInfo.index].flyUp(hitPower);
  48. }
  49. quicken(strength:number){
  50. window.gm.birds[window.otherPlayerInfo.index].quicken(strength);
  51. }
  52. gameOver(index:number){
  53. window.gm.gameOver(index);
  54. }
  55. updateTime(time:number){
  56. window.topBar.updateTime(time);
  57. }
  58. eatFruit(fruitIndex){
  59. let args = window.gc.fruitNodes[fruitIndex].getComponent(Fruit).eat();
  60. if(window.fruitGroove.fruitCount<3){
  61. window.fruitGroove.addFruit.apply(window.fruitGroove,args);
  62. }
  63. }
  64. fruitEaten(fruitIndex){
  65. try {
  66. window.gc.fruitNodes[fruitIndex].getComponent(Fruit).eat();
  67. } catch {}
  68. }
  69. setAI() {
  70. window.gm.birds[window.otherPlayerInfo.index].setAI();
  71. }
  72. }