Ejemplo n.º 1
0
 def processAI(self):
     if self.leader.dead == True:
         pass
     elif self.leader.active and self.leader != self:
         tempVelocity = vector.vector2d(self.leader.velocity[0], self.leader.velocity[1])
         targetPoint = self.leader.position - (tempVelocity.makeNormal()) * vector.vector2d(150,150)
         aitools.goToPoint(self, targetPoint)
     else:
         if not self.changeDirection:
             self.target = vector.vector2d((random.random() * (SCREEN_WIDTH + 200)) - 100, (random.random() * (SCREEN_HEIGHT + 200)) - 100)
             self.changeDirection = 30
         self.changeDirection -= 1
         aitools.arcToPoint(self, self.target)
Ejemplo n.º 2
0
    def process_AI(self):
        if self.leaveScreen:
            pass
        elif self.myPosition != 1:
            flockChart = [False,False,False,False,False]
            for member in self.myFlock:
                if member.active:
                    if member.myPosition == self.myPosition and member != self and self.myPosition < 5:
                        member.myPosition += 1

                    flockChart[member.myPosition - 1] = True
                    
                    if member.myPosition == 1:
                        self.leader = member

            positionNumber = 0
            for element in flockChart:
                positionNumber += 1
                if positionNumber < self.myPosition and element == False:
                    self.myPosition = positionNumber
                    if self.myPosition == 1:
                        self.leader = self

    
                self.speed = 14.2
                leaderVelocity = vector.vector2d(self.leader.velocity[0], self.leader.velocity[1])
                leaderPerpendicular = self.leader.velocity.getPerpendicular()
                if self.myPosition % 2:
                    offset = -50
                else:
                    offset = 50
                targetPoint = self.leader.position - (leaderVelocity.makeNormal() * (100) * int(self.myPosition / 2)) + (leaderPerpendicular.makeNormal() * offset * int(self.myPosition / 2))

                if (targetPoint - self.position).getMagnitude() < self.speed:
                    aitools.goToPoint(self,targetPoint)
                else:
                    aitools.arcToPoint(self, targetPoint, 3)
    
        else:
            for element in self.myFlock:
                if element != self and element.myPosition == self.myPosition:
                    element.myPosition += 1

            self.speed = 11
            if not self.changeDirection:
                self.target = vector.vector2d((random.random() * (SCREEN_WIDTH + 200)) - 100, (random.random() * (SCREEN_HEIGHT + 200)) - 100)
                self.changeDirection = 30
            self.changeDirection -= 1
            aitools.arcToPoint(self, self.target)
Ejemplo n.º 3
0
    def actorUpdate(self):
        self.lifeTimer -= 1
        
        if not self.lifeTimer:
            self.leaveScreen = True
            self.speed = 7
            aitools.goToPoint(self,aitools.pointOffScreen())

        if self.active and self.health <= 0:
            self.active = False
            self.die()
        
        if not self.active and self.health:
            self.active = True

        self.processAI()