Example #1
0
    def update(self):
        self.currentCell = util.world_to_grid(self.xy)
        if self.currentCell != self.destCell:
            self.speed = 8 - (self.size)
            if self.currentCell == self.nextCell:
                #if self.pathBlocked():
                #    self.pathSet(self.destCell)
                #else:
                self.pathPos -= 1
                self.nextCell = self.path[self.pathPos - 1]
                self.setDirection(util.point_direction(self.xy, util.grid_to_world(self.nextCell)))
                    #print 'pathpos ' + str(self.pathPos)
                    #print 'current cell ' + str(self.currentCell)
                    #print 'next cell ' + str(self.nextCell)
                    #print 'new direction ' + str(self.direction)
                    #print ' '
        else: #we've reached the destination
            self.speed = 0
            self.index = 0
            if self in movingGroup:
                blocked.append(self.currentCell)
                self.remove(movingGroup)
        self.image = self.imageList[self.index]
        self.index = ((self.index + 1) % 17) + (5 * (self.index == 16))

        self.gunDirection = int(round(self.direction) % 16)

        self.xy = util.add2(self.xy, util.speedDir_xy(self.speed, self.direction)) #move xy
        self.rect.center = (self.xy[0], self.xy[1] - (12 + (6 * self.size))) #move rect to xy
        self.hitRect.center = self.xy #move hitbox to xy

        allspritesGroup.change_layer(self, self.currentCell[1] * 10)
        botsGroup.change_layer(self, self.currentCell[1] * 10)
Example #2
0
     
 #load animation for int direction d to imageList
 def loadAnim(self, _dir):
     for iLoop in range(19):
         self.imageList[iLoop] = load_image(os.path.join(str(self.size), str(_dir), str(iLoop + 1) + '.bmp'), -1)
         
 #set the path with dest=(x, y)
 def pathSet(self, (x, y)):
     self.destCell = (x, y)
     if self.currentCell in blocked:
         blocked.remove(self.currentCell)
     astar.findpath(self.currentCell, self.destCell, blocked)
     self.path = astar.path #POINTS STORED IN REVERSE ORDER
     self.pathPos = len(self.path) - 1
     self.nextCell = self.path[len(self.path) - 2]
     self.setDirection(util.point_direction(self.xy, util.grid_to_world(self.nextCell)))
     #print self.currentCell
     #print blocked
     
 #check if any path cells are blocked
 def pathBlocked(self):
     for i in self.path:
         if i in blocked:
             if i != self.currentCell:
                 print 'Path Blocked at ' + str(i)
                 return True
     return False
     
 #set the direction dir=0-16
 def setDirection(self, _dir):
     if _dir != self.direction: