def update(self, player): # execute if this stage isAlive if self.isAlive: # Thoroughly kill the bullet generated by last stage if self.timer < 10: for i in parameter.getEnemyBulletSprites(): i.kill() # Generate Boss self.generateBoss() # If player has dead in this stage, no bonus if player.rect.top < 0 and self.timer > 100: self.ifBonus = False self.bonus = 0 # Turn of this stage if boss's Hp < 0 or run out of time if self.boss.Hp <= 0: self.isAlive = False self.isDead = True for i in (parameter.getEnemySprites() or parameter.getEnemyBulletSprites()): i.kill() if self.ifBonus: parameter.addPoint(self.bonus) elif self.timer > self.time: self.isAlive = False self.isDead = True for i in (parameter.getEnemySprites() or parameter.getEnemyBulletSprites()): i.kill() # bonus decay by time if self.ifBonus: self.bonus -= int(self.bonus_origin / 4000) self.timer += 1
def newEnemy_4(): enemy = classes.Enemy(name = "enemy", \ Hp = 4000, \ image = enemyImgList[0], \ movePattern = custom.enemyMovePattern_4, \ enemyBulletImage = [enemyBulletImgList[9]], \ putBulletPattern = [custom.enemyPutBulletPattern_4], \ shootBulletPattern = [custom.enemyshootBulletPattern_4], \ dropItem = (8, 10)) parameter.getAllSprites().add(enemy) parameter.getEnemySprites().add(enemy)
def newEnemy_3(): enemy = classes.Enemy(name = "enemy", \ Hp = 30, \ image = enemyImgList[1], \ movePattern = custom.enemyMovePattern_3, \ enemyBulletImage = [enemyBulletImgList[8]], \ putBulletPattern = [custom.enemyPutBulletPattern_3], \ shootBulletPattern = [custom.enemyshootBulletPattern_3], \ dropItem = (1, 4)) parameter.getAllSprites().add(enemy) parameter.getEnemySprites().add(enemy)
def generateBoss(self): if not self.ifGenerateBoss: self.boss = Enemy(name = self.order, \ Hp = self.Hp, \ image = self.bossImage, \ movePattern = self.bossMovement, \ enemyBulletImage = self.bossBulletImage, \ putBulletPattern = self.bossPutBulletPattern, \ shootBulletPattern = self.bossShootBulletPattern, \ dropItem = self.dropItem) parameter.getEnemySprites().add(self.boss) parameter.getBossSprites().add(self.boss) parameter.getAllSprites().add(self.boss) self.ifGenerateBoss = True
def findMostCloseEnemy(playerCenter): enemyList = [i for i in parameter.getEnemySprites()] enemyDistanceList = [ distance(i.rect.center, playerCenter) for i in enemyList ] minimun = enemyDistanceList[0] minimunIndex = 0 for i in range(len(enemyDistanceList)): if enemyDistanceList[i] < minimun: minimun = enemyDistanceList[i] minimunIndex = i return enemyList[minimunIndex].rect.center
stageInitiated = False for i in range(len(stageList)): if stageList[i].isDead: if i == len(stageList) - 1: parameter.addPoint(10000000 * player.lifes) goodending = True running = False else: stageList[i + 1].isAlive = True stageList[i].isDead = False stageList[i].update(player) # Move background fast if no enemy if parameter.getTimer() > 50 and not bool( parameter.getEnemySprites()): for i in parameter.getBackgroundSprites(): i.speed = 5 else: for i in parameter.getBackgroundSprites(): i.speed = 2 parameter.getBackgroundSprites().update() parameter.getAllSprites().update() # Collidision Destction # Player_Bullet v.s. Enemy for e in parameter.getEnemySprites(): for pb in parameter.getPlayerBulletSprites(): if pygame.sprite.collide_rect(e, pb):