Ball.ts 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. /** @format */
  2. import {Data} from '../GameControl'
  3. import {ZumaUI} from '../ui/ZumaUI'
  4. import {IBanConfig} from '../config/BanConfig'
  5. import {IZumaballConfig, ZumaballConfig} from '../config/ZumaballConfig'
  6. import {ZumamapConfig} from '../config/ZumamapConfig'
  7. import {ZumaCore} from './ZumaCore'
  8. const {ccclass, property} = cc._decorator
  9. export enum BALL_COLOR {
  10. green = 1,
  11. blue,
  12. purple,
  13. red,
  14. orange,
  15. }
  16. @ccclass
  17. export class Ball extends cc.Component {
  18. //小球的颜色
  19. private _ballID: number = 0
  20. //在地图曲线中的位置
  21. private _posIndex: number
  22. private zumaCore: ZumaCore
  23. public ballCfg: IZumaballConfig
  24. init(ballID: number, zumaCore: ZumaCore) {
  25. this._ballID = ballID
  26. this.ballCfg = ZumaballConfig[ballID]
  27. this.zumaCore = zumaCore
  28. cc.find('icon', this.node).getComponent(cc.Sprite).spriteFrame = Data.game.gameAssetMap.get(
  29. `texture/zuma/balls/${this.ballCfg.icon}`,
  30. ) as cc.SpriteFrame
  31. }
  32. public get ballID(): number {
  33. return this._ballID
  34. }
  35. //------------设置小球的位置--------------
  36. public set posIndex($pos: number) {
  37. this._posIndex = $pos
  38. if (!Data.zuma.mapData[this._posIndex]) {
  39. console.error('posIndex is error')
  40. return
  41. }
  42. this.node.x = Data.zuma.mapData[this._posIndex][0]
  43. this.node.y = Data.zuma.mapData[this._posIndex][1]
  44. this.node.angle = -Data.zuma.mapData[this._posIndex][2] + 90
  45. }
  46. //------------小球爆炸-------------------
  47. public explode(): void {
  48. this.explodeComplete()
  49. }
  50. //------------爆炸结束--------------------
  51. private explodeComplete(): void {
  52. this.node.parent.removeChild(this.node)
  53. }
  54. //------------访问小球的位置 在地图曲线中的位置--------------
  55. public get posIndex(): number {
  56. return this._posIndex
  57. }
  58. }