예제 #1
0
    def onThink(self, ignoreme):
        self.ct = System.currentTimeMillis()

        if self.pos.pointEquals(self.dest):

            marg = ESG.randInt(0, 43)
            if marg == 42:
                ESG.entities.add(EntityShit(self.pos))

            self.positions = []
            self.directions = []

            for i in range(0, 4):
                if i == 0:
                    despos = Point(self.pos.x + 32, self.pos.y)
                    if ESG.navmesh.legalMove(self.pos, despos):
                        self.positions.append(despos)
                        self.directions.append(Point(1, 0))
                if i == 1:
                    despos = Point(self.pos.x - 32, self.pos.y)
                    if ESG.navmesh.legalMove(self.pos, despos):
                        self.positions.append(despos)
                        self.directions.append(Point(-1, 0))
                if i == 2:
                    despos = Point(self.pos.x, self.pos.y + 32)
                    if ESG.navmesh.legalMove(self.pos, despos):
                        self.positions.append(despos)
                        self.directions.append(Point(0, 1))
                if i == 3:
                    despos = Point(self.pos.x, self.pos.y - 32)
                    if ESG.navmesh.legalMove(self.pos, despos):
                        self.positions.append(despos)
                        self.directions.append(Point(0, -1))

            if len(self.directions) >= 1:
                chosen = ESG.randInt(0, (len(self.directions) - 1))
                self.dest = self.positions[chosen]
                self.direction = self.directions[chosen]
            else:
                self.dest = self.pos

        if self.ct - self.lt >= 25:
            newpos = Point(self.pos.x + (self.direction.x * self.speed),
                           self.pos.y + (self.direction.y * self.speed))
            self.lt = self.ct
            if ESG.navmesh.legalMove(self.pos, newpos):
                self.pos = newpos
 def onThink(self, ignoreme):
     self.ct = System.currentTimeMillis()
     
     if self.pos.pointEquals(self.dest):
         
         marg = ESG.randInt(0, 43)
         if marg == 42:
             ESG.entities.add(EntityShit(self.pos))
         
         self.positions = []
         self.directions = []
         
         for i in range(0, 4):
             if i == 0:
                 despos = Point(self.pos.x+32, self.pos.y)
                 if ESG.navmesh.legalMove(self.pos, despos):
                     self.positions.append(despos)
                     self.directions.append(Point(1, 0))
             if i == 1:
                 despos = Point(self.pos.x-32, self.pos.y)
                 if ESG.navmesh.legalMove(self.pos, despos):
                     self.positions.append(despos)
                     self.directions.append(Point(-1, 0))
             if i == 2:
                 despos = Point(self.pos.x, self.pos.y+32)
                 if ESG.navmesh.legalMove(self.pos, despos):
                     self.positions.append(despos)
                     self.directions.append(Point(0, 1))
             if i == 3:
                 despos = Point(self.pos.x, self.pos.y-32)
                 if ESG.navmesh.legalMove(self.pos, despos):
                     self.positions.append(despos)
                     self.directions.append(Point(0, -1))
         
         if len(self.directions) >= 1:
             chosen = ESG.randInt(0, (len(self.directions)-1))
             self.dest = self.positions[chosen]
             self.direction = self.directions[chosen]
         else:
             self.dest = self.pos
     
     if self.ct - self.lt >= 25:
         newpos = Point(self.pos.x + (self.direction.x * self.speed), self.pos.y + (self.direction.y * self.speed))
         self.lt = self.ct
         if ESG.navmesh.legalMove(self.pos, newpos):
             self.pos = newpos
예제 #3
0
    def onThink(self, ignoreme):
        self.ct = System.currentTimeMillis()

        for i in range(0, ESG.entities.size()):
            ent = ESG.entities.get(i)
            if ent.name == "happysheep":
                if (System.currentTimeMillis() - self.lastHit) >= 1000:
                    if ent.pos.inRange(2, self.pos):
                        self.lastHit = System.currentTimeMillis()
                        ESG.entities.get(i).destroy = True
                        ESG.entities.add(AIEvilSheep(ent.pos, [Point(0, 0)]))

        ppos = Point(-ESG.player.pos.x, -ESG.player.pos.y)

        if ppos.inRange(32, Point(self.pos.x + 16, self.pos.y + 16)):
            if (System.currentTimeMillis() - self.lastHit) >= 1000:
                self.lastHit = System.currentTimeMillis()
                ESG.player.onDamage(1)

        if self.pos.pointEquals(self.dest):

            if len(self.positions) - 1 >= self.cdest:
                self.dest = self.positions[self.cdest]
                self.direction = Point(0, 0)
                if self.dest.x > self.pos.x:
                    self.direction = Point(1, self.direction.y)
                elif self.dest.x < self.pos.x:
                    self.direction = Point(-1, self.direction.y)
                else:
                    self.direction = Point(0, self.direction.y)
                if self.dest.y > self.pos.y:
                    self.direction = Point(self.direction.x, 1)
                elif self.dest.y < self.pos.y:
                    self.direction = Point(self.direction.x, -1)
                else:
                    self.direction = Point(self.direction.x, 0)
                self.cdest = self.cdest + 1
            else:
                self.positions = []
                self.directions = []

                self.cdest = 0

                for i in range(0, 4):
                    if i == 0:
                        despos = Point(self.pos.x + 32, self.pos.y)
                        if ESG.navmesh.legalMove(self.pos, despos):
                            self.positions.append(despos)
                            self.directions.append(Point(1, 0))
                    if i == 1:
                        despos = Point(self.pos.x - 32, self.pos.y)
                        if ESG.navmesh.legalMove(self.pos, despos):
                            self.positions.append(despos)
                            self.directions.append(Point(-1, 0))
                    if i == 2:
                        despos = Point(self.pos.x, self.pos.y + 32)
                        if ESG.navmesh.legalMove(self.pos, despos):
                            self.positions.append(despos)
                            self.directions.append(Point(0, 1))
                    if i == 3:
                        despos = Point(self.pos.x, self.pos.y - 32)
                        if ESG.navmesh.legalMove(self.pos, despos):
                            self.positions.append(despos)
                            self.directions.append(Point(0, -1))

                if len(self.directions) >= 1:
                    chosen = ESG.randInt(0, (len(self.directions) - 1))
                    self.dest = self.positions[chosen]
                    self.direction = self.directions[chosen]
                else:
                    self.dest = self.pos

        if self.ct - self.lt >= 25:
            self.direction = Point(0, 0)
            if self.dest.x > self.pos.x:
                self.direction = Point(1, self.direction.y)
            elif self.dest.x < self.pos.x:
                self.direction = Point(-1, self.direction.y)
            else:
                self.direction = Point(0, self.direction.y)
            if self.dest.y > self.pos.y:
                self.direction = Point(self.direction.x, 1)
            elif self.dest.y < self.pos.y:
                self.direction = Point(self.direction.x, -1)
            else:
                self.direction = Point(self.direction.x, 0)
            newpos = Point(self.pos.x + (self.direction.x * self.speed),
                           self.pos.y + (self.direction.y * self.speed))
            self.lt = self.ct
            if ESG.navmesh.legalMove(self.pos, newpos):
                self.pos = newpos
 def onThink(self, ignoreme):
     self.ct = System.currentTimeMillis()
     
     for i in range(0, ESG.entities.size()):
         ent = ESG.entities.get(i)
         if ent.name == "happysheep":
             if (System.currentTimeMillis() - self.lastHit) >= 1000:
                 if ent.pos.inRange(2, self.pos):
                     self.lastHit = System.currentTimeMillis()
                     ESG.entities.get(i).destroy = True
                     ESG.entities.add(AIEvilSheep(ent.pos, [Point(0, 0)]))
     
     ppos = Point(-ESG.player.pos.x, -ESG.player.pos.y)
     
     if ppos.inRange(32, Point(self.pos.x+16, self.pos.y+16)):
         if (System.currentTimeMillis() - self.lastHit) >= 1000:
             self.lastHit = System.currentTimeMillis()
             ESG.player.onDamage(1)
     
     if self.pos.pointEquals(self.dest):
         
         if len(self.positions)-1 >= self.cdest:
             self.dest = self.positions[self.cdest]
             self.direction = Point(0, 0)
             if self.dest.x > self.pos.x:
                 self.direction = Point(1, self.direction.y)
             elif self.dest.x < self.pos.x:
                 self.direction = Point(-1, self.direction.y)
             else:
                 self.direction = Point(0, self.direction.y)
             if self.dest.y > self.pos.y:
                 self.direction = Point(self.direction.x, 1)
             elif self.dest.y < self.pos.y:
                 self.direction = Point(self.direction.x, -1)
             else:
                 self.direction = Point(self.direction.x, 0)
             self.cdest = self.cdest + 1
         else:
             self.positions = []
             self.directions = []
             
             self.cdest = 0
             
             for i in range(0, 4):
                 if i == 0:
                     despos = Point(self.pos.x+32, self.pos.y)
                     if ESG.navmesh.legalMove(self.pos, despos):
                         self.positions.append(despos)
                         self.directions.append(Point(1, 0))
                 if i == 1:
                     despos = Point(self.pos.x-32, self.pos.y)
                     if ESG.navmesh.legalMove(self.pos, despos):
                         self.positions.append(despos)
                         self.directions.append(Point(-1, 0))
                 if i == 2:
                     despos = Point(self.pos.x, self.pos.y+32)
                     if ESG.navmesh.legalMove(self.pos, despos):
                         self.positions.append(despos)
                         self.directions.append(Point(0, 1))
                 if i == 3:
                     despos = Point(self.pos.x, self.pos.y-32)
                     if ESG.navmesh.legalMove(self.pos, despos):
                         self.positions.append(despos)
                         self.directions.append(Point(0, -1))
             
             if len(self.directions) >= 1:
                 chosen = ESG.randInt(0, (len(self.directions)-1))
                 self.dest = self.positions[chosen]
                 self.direction = self.directions[chosen]
             else:
                 self.dest = self.pos
     
     if self.ct - self.lt >= 25:
         self.direction = Point(0, 0)
         if self.dest.x > self.pos.x:
             self.direction = Point(1, self.direction.y)
         elif self.dest.x < self.pos.x:
             self.direction = Point(-1, self.direction.y)
         else:
             self.direction = Point(0, self.direction.y)
         if self.dest.y > self.pos.y:
             self.direction = Point(self.direction.x, 1)
         elif self.dest.y < self.pos.y:
             self.direction = Point(self.direction.x, -1)
         else:
             self.direction = Point(self.direction.x, 0)
         newpos = Point(self.pos.x + (self.direction.x * self.speed), self.pos.y + (self.direction.y * self.speed))
         self.lt = self.ct
         if ESG.navmesh.legalMove(self.pos, newpos):
             self.pos = newpos