Exemple #1
0
 def update(self, pacx, pacy, pac_dir):
     self.update_nxy()
     if self.rect.x % const.BLOCK_WIDTH == 0 and self.rect.y % const.BLOCK_HEIGHT == 0:
         x = pacx // const.BLOCK_WIDTH
         y = pacy // const.BLOCK_HEIGHT
         if pac_dir == 1:
             y -= 4
         elif pac_dir == 2:
             x += 4
         elif pac_dir == 3:
             y += 4
         elif pac_dir == 4:
             x -= 4
         p = self.near_cell(x, y)
         if p != None:
             x, y = p.x, p.y
             myx, myy = self.nxy
             if Point(myx, myy) == Point(x, y):
                 self.dir = 0
             else:
                 next = path_alg.path_to_points(self.graph.get_path(path_alg.point_to_num(Point(myx, myy)),
                                                                    path_alg.point_to_num(Point(x, y)))[-1:])[0]
                 self.dir = self.path_to_dirs(Point(myx, myy), [next])[0]
         else:
             self.dir = 0
     self.move_dir()
Exemple #2
0
 def near_cell(self, x, y):
     minx, miny = 9, 13
     for i in range(100):
         rx = random.randint(0, const.WIN_BLOCK_WIDTH - 1)
         ry = random.randint(0, const.WIN_BLOCK_HEIGHT - 1)
         if MapTile.show_map()[ry][rx] != '-' and path_alg.dist(
                 Point(minx, miny), Point(x, y)) > path_alg.dist(
                     Point(rx, ry), Point(x, y)):
             minx, miny = rx, ry
     return Point(minx, miny)
Exemple #3
0
 def update_death(self, pacx, pacy):
     self.update_nxy()
     if self.rect.x % const.BLOCK_WIDTH == 0 and self.rect.y % const.BLOCK_HEIGHT == 0:
         x = pacx // const.BLOCK_WIDTH
         y = pacy // const.BLOCK_HEIGHT
         myx, myy = self.nxy
         if Point(myx, myy) == Point(x, y):
             self.dir = 0
         else:
             next = path_alg.path_to_points(self.graph.get_path(path_alg.point_to_num(Point(myx, myy)),
                                  path_alg.point_to_num(Point(x, y)))[-1:])[0]
             self.dir = self.path_to_dirs(Point(myx, myy), [next])[0]
     self.move_dir()
Exemple #4
0
    def update(self, pacx, pacy):
        self.update_nxy()
        if self.rect.x % const.BLOCK_WIDTH == 0 and self.rect.y % const.BLOCK_HEIGHT == 0:
            x = pacx // const.BLOCK_WIDTH
            y = pacy // const.BLOCK_HEIGHT
            if path_alg.dist(Point(x, y), Point(self.nxy[0],
                                                self.nxy[1])) <= 8:
                self.to = 0
            else:
                if path_alg.dist(Point(self.nxy[0], self.nxy[1]),
                                 self.ps[self.to]) <= 1:
                    self.to = (self.to + 1) % len(self.ps)
                target = self.ps[self.to]
                #target = self.near_cell(target.x, target.y)
                x, y = target.x, target.y
            myx, myy = self.nxy
            if Point(myx, myy) == Point(x, y):
                self.dir = 0
            else:
                next = path_alg.path_to_points(
                    self.graph.get_path(path_alg.point_to_num(Point(myx, myy)),
                                        path_alg.point_to_num(Point(
                                            x, y)))[-1:])[0]
                self.dir = self.path_to_dirs(Point(myx, myy), [next])[0]

        self.move_dir()
Exemple #5
0
 def update(self, pacx, pacy, blinkyx, blinkyy):
     self.update_nxy()
     if self.rect.x % const.BLOCK_WIDTH == 0 and self.rect.y % const.BLOCK_HEIGHT == 0:
         x, y = pacx // const.BLOCK_WIDTH, pacy // const.BLOCK_HEIGHT
         bx, by = blinkyx // const.BLOCK_WIDTH, blinkyy // const.BLOCK_HEIGHT
         pac, bl = Point(x, y), Point(bx, by)
         target = (pac - bl) * 2 + bl
         target = self.near_cell(target.x, target.y)
         if target != None:
             x, y = target.x, target.y
             myx, myy = self.nxy
             if Point(myx, myy) == Point(x, y):
                 self.dir = 0
             else:
                 next = path_alg.path_to_points(
                     self.graph.get_path(
                         path_alg.point_to_num(Point(myx, myy)),
                         path_alg.point_to_num(Point(x, y)))[-1:])[0]
                 self.dir = self.path_to_dirs(Point(myx, myy), [next])[0]
         else:
             self.dir = 0
     self.move_dir()
Exemple #6
0
 def __init__(self, x, y, img, finder):
     super().__init__(x, y, img, finder)
     self.ps = (Point(9, 14), Point(18, 14), Point(18, 20), Point(9, 20))
     self.to = 0