import { TankBettle } from "../data/TankBattleGameData" ; import TankBettleTank , { TankBettleTankEnemy , TankBettleTankPlayer } from "./TankBattleTank" ; const { ccclass , property } = cc . _decorator ; @ ccclass export default class TankBettleBullet extends cc . Component { description public owner : TankBettleTank = null ; private addBullet ( ) { TankBettle . gameData . gameMap . addBullet ( this ) ; if ( this . owner . direction == TankBettle . Direction . UP ) { this . node . x = this . owner . node . x ; this . node . y = this . owner . node . y + this . owner . node . height / 2 ; this . node . angle = 0 ; } else if ( this . owner . direction == TankBettle . Direction . DOWN ) { this . node . x = this . owner . node . x ; this . node . y = this . owner . node . y - this . owner . node . height / 2 ; this . node . angle = 180 ; } else if ( this . owner . direction == TankBettle . Direction . RIGHT ) { this . node . x = this . owner . node . x + this . owner . node . width / 2 ; this . node . y = this . owner . node . y ; this . node . angle = - 90 ; } else if ( this . owner . direction == TankBettle . Direction . LEFT ) { this . node . x = this . owner . node . x - this . owner . node . width / 2 ; this . node . y = this . owner . node . y ; this . node . angle = 90 ; } } move ( owner ) { this . owner = owner ; this . addBullet ( ) ; if ( this . owner . direction == TankBettle . Direction . UP ) { cc . tween ( this . node ) . delay ( 0 ) . by ( this . owner . config . bulletTime , { y : this . owner . config . bulletDistance } ) . repeatForever ( ) . start ( ) ; } else if ( this . owner . direction == TankBettle . Direction . DOWN ) { cc . tween ( this . node ) . delay ( 0 ) . by ( this . owner . config . bulletTime , { y : - this . owner . config . bulletDistance } ) . repeatForever ( ) . start ( ) ; } else if ( this . owner . direction == TankBettle . Direction . RIGHT ) { cc . tween ( this . node ) . delay ( 0 ) . by ( this . owner . config . bulletTime , { x : this . owner . config . bulletDistance } ) . repeatForever ( ) . start ( ) ; } else if ( this . owner . direction == TankBettle . Direction . LEFT ) { cc . tween ( this . node ) . delay ( 0 ) . by ( this . owner . config . bulletTime , { x : - this . owner . config . bulletDistance } ) . repeatForever ( ) . start ( ) ; } } description param other private onCollisionEnter ( other , me ) { if ( other . node . group == TankBettle . GROUP . Wall || other . node . group == TankBettle . GROUP . StoneWall || other . node . group == TankBettle . GROUP . Boundary || other . node . group == TankBettle . GROUP . Home ) { this . removeSelf ( ) ; } else if ( other . node . group == TankBettle . GROUP . Bullet ) { let bullet = other . node . getComponent ( TankBettleBullet ) ; if ( this . owner . isAI ) { if ( ! bullet . owner . isAI ) { this . removeSelf ( ) ; } } else { if ( bullet . owner . isAI ) { this . removeSelf ( ) ; } } } else if ( other . node . group == TankBettle . GROUP . Player ) { let tank = this . getPlayer ( other . node ) ; if ( this . owner . isAI ) { if ( ! tank . isAI ) { this . removeSelf ( ) ; } } else { if ( tank . isAI ) { this . removeSelf ( ) ; } } } else { } } private removeSelf ( ) { this . node . stopAllActions ( ) ; this . owner . bullet = null ; this . node . removeFromParent ( ) ; this . node . destroy ( ) ; } private getPlayer ( node ) { let player = node . getComponent ( TankBettleTankPlayer ) ; if ( player ) { return player ; } return node . getComponent ( TankBettleTankEnemy ) ; } description param other private onCollisionStay ( other , me ) { } description param other private onCollisionExit ( other , me ) { } }