def collideEnemy(self): for enemy in Player.page.mActors['enemy']: if self.mAction != 'Die' and enemy.mAction != 'Die' and \ enemy.mAction != 'Inb' and physics.collidesBox(self, enemy): self.mAction = 'Die' self.mLife -= 1 self.mHasItem = [False for _ in range(4)] actorhelper.resetImageIndex(self) self.mDieSound.play() return
def collideEnemy(self): for enemy in Bubble.page.mActors['enemy']: if physics.collides(self, enemy.getBB()) and self.mEnemy is None and \ hasattr(enemy, 'mBubble') and enemy.mBubble is None: enemy.mAction = 'Inb' enemy.mBubble = self enemy.mBubTime = 30 self.mEnemy = enemy self.mAction = 'Move' self.mSpeed = 100 actorhelper.resetImageIndex(enemy)
def collidePlayer(self): for player in Bubble.page.mActors['player']: if physics.collides(self, player.getBB()): if player.mYDelta != 0: self.mAction = 'Die' self.sound.play() actorhelper.resetImageIndex(self) break else: self.mXDelta = player.mXDelta if abs(self.mYPos - player.mYPos) != 0: self.mYDelta = (self.mYPos - player.mYPos ) / abs(self.mYPos - player.mYPos)
def update(self): # 중력 설정 if self.mYDelta > -5: self.mYDelta -= 10 * Player.page.mGame.deltaTime if not self.mAction == 'Die': # 공통 부분 업데이트 actorhelper.commonUpdate(self) # 공격 딜레이 감소 if self.mAttackDelay > 0: self.mAttackDelay = max( 0, self.mAttackDelay - Player.page.mGame.deltaTime) # 공격 발사 if self.mAttackInput and self.mImageIndex == 1 and not Player.page.map.mStageChange: bubbleSpeed = 350 + self.mHasItem[2] * 50 b = bubble.Bubble(Player.page, bubbleSpeed) Player.page.addActor('bubble', b) self.mAttackInput = False # 이동 xMove = self.mXDelta * (self.mXSpeed + 100 * self.mHasItem[0] ) * Player.page.mGame.deltaTime yMove = self.mYDelta * self.mYSpeed / 2 * Player.page.mGame.deltaTime # 로딩중일 경우 if Player.page.map.mStageChange: xMove = 0 yMove = 0 self.mAttackInput = False self.mAction = 'Move' else: self.mNoHitTime = max( 0.0, self.mNoHitTime - Player.page.mGame.deltaTime) self.collideBlock(xMove, yMove) self.collideItem() if self.mNoHitTime == 0.0: self.collideEnemy() else: if self.mImageIndex >= Player.imageIndexs[self.mAction]: if self.mLife == 0: Player.page.mEndGame = True else: self.mAction = 'Stop' actorhelper.resetImageIndex(self) self.mXPos = 100 self.mYPos = 100 self.mNoHitTime = 3.0
def doMove(self): if self.mAction != 'Move': return BehaviorTree.FAIL actorhelper.commonSetAttackDelay(self) actorhelper.commonDiagonalMove(self) if self.mAttackDelay == 0.0: self.mAction = 'Attack' self.mAttackDelay = random.randint(5, 10) * 0.2 fire = invatorAT.InvatorAT(Invator.page, self.mXPos, self.mYPos) Invator.page.addActor('enemy', fire) actorhelper.resetImageIndex(self) return BehaviorTree.SUCCESS
def doMove(self): if self.mAction != 'Move': return BehaviorTree.FAIL actorhelper.commonSetJumpDelay(self) actorhelper.commonSetAttackDelay(self) actorhelper.commonMove(self, True, True) if self.mYPos - 10 < Hidegons.player.mYPos < self.mYPos + 10 and \ 0 < self.mXDelta * (Hidegons.player.mXPos - self.mXPos) < 600 and \ self.mAttackDelay == 0.0: self.mAction = 'Attack' self.mAttackDelay = 3.0 fire = hidegonsAT.HidegonsAT(Hidegons.page, self.mXPos, self.mYPos, self.mXDelta) Hidegons.page.addActor('enemy', fire) actorhelper.resetImageIndex(self) return BehaviorTree.SUCCESS
def doDie(self): if self.mAction != 'Die': return BehaviorTree.FAIL if self.mEnemy is not None and self.mTime > 0.1: self.mEnemy.mAction = 'Die' self.mEnemy.mYDelta = 3 actorhelper.resetImageIndex(self.mEnemy) self.mEnemy = None # 일정 확률로 공격 보조 아이템 생성 rd = random.randint(1, 20) if rd <= 2: t = item.Item(Bubble.page, True) Bubble.page.addActor('item', t) if self.mImageIndex >= Bubble.imageIndexs['Die']: Bubble.page.mUI.score += 10 self.unLoad() return BehaviorTree.SUCCESS
def collideBubble(self, xMove, yMove): count = 0 for bub in Bubble.page.mActors['bubble']: if bub != self and bub.mAction != 'Attack' and physics.collidesBTB( self, bub): if bub.mAction == 'Die' and bub.mTime < 0.4 and physics.collidesBox( self, bub): count = 10 else: self.mXPos -= xMove bub.mXPos += xMove self.mYPos -= yMove bub.mYPos += yMove if xMove != 0: self.mXDelta *= -1 bub.mXDelta *= -1 if yMove != 0: self.mYDelta *= -1 bub.mYDelta *= -1 count += 1 if count >= 6 and self.mEnemy is None: self.mAction = 'Die' self.sound.play() actorhelper.resetImageIndex(self)