示例#1
0
 def update(self, game):
     VGDLSprite.update(self, game)
     
     world = AStarWorld(game)
     path = world.getMoveFor(self)
     
     # Uncomment below to draw debug paths.
     # self._setDebugVariables(world,path)
     
     if len(path)>1:
         move = path[1]
         
         nextX, nextY = world.get_sprite_tile_position(move.sprite)
         nowX, nowY = world.get_sprite_tile_position(self)
         
         movement = None
         
         if nowX == nextX:
             if nextY > nowY:
                 #logToFile('DOWN')
                 movement = DOWN
             else:
                 #logToFile('UP')
                 movement = UP
         else:
             if nextX > nowX:
                 #logToFile('RIGHT')
                 movement = RIGHT
             else:
                 #logToFile('LEFT')
                 movement = LEFT
                 
         self.physics.activeMovement(self, movement)
示例#2
0
 def update(self, game):
     VGDLSprite.update(self, game)
     
     world = AStarWorld(game)
     path = world.getMoveFor(self)
     
     # Uncomment below to draw debug paths.
     # self._setDebugVariables(world,path)
     
     if len(path)>1:
         move = path[1]
         
         nextX, nextY = world.get_sprite_tile_position(move.sprite)
         nowX, nowY = world.get_sprite_tile_position(self)
         
         movement = None
         
         if nowX == nextX:
             if nextY > nowY:
                 #logToFile('DOWN')
                 movement = DOWN
             else:
                 #logToFile('UP')
                 movement = UP
         else:
             if nextX > nowX:
                 #logToFile('RIGHT')
                 movement = RIGHT
             else:
                 #logToFile('LEFT')
                 movement = LEFT
                 
     self.physics.activeMovement(self, movement)
示例#3
0
    def updateOptions(self, game):
        VGDLSprite.update(self, game)  #TODO: Need to make sure to feed in a copy of the game, so as not to actually update the current game? 

        world = AStarWorld(game)
        path = world.getMoveFor(self)
        
        # Uncomment below to draw debug paths.
        # self._setDebugVariables(world,path)
        
        if len(path)>1:
            move = path[1]
            
            nextX, nextY = world.get_sprite_tile_position(move.sprite)
            nowX, nowY = world.get_sprite_tile_position(self)
            
            movement = None
            
            if nowX == nextX:
                if nextY > nowY:
                    #logToFile('DOWN')
                    movement = DOWN
                else:
                    #logToFile('UP')
                    movement = UP
            else:
                if nextX > nowX:
                    #logToFile('RIGHT')
                    movement = RIGHT
                else:
                    #logToFile('LEFT')
                    movement = LEFT
        left, top = self.physics.calculateActiveMovement(self, movement)
        return {(left, top): 1.} 
示例#4
0
 def update(self, game):
     VGDLSprite.update(self, game)
     options = []
     for target in self._closestTargets(game):
         options.extend(self._movesToward(game, target))
     if len(options) == 0:
         options = BASEDIRS
     self.physics.activeMovement(self, choice(options))
示例#5
0
 def update(self, game):
     VGDLSprite.update(self, game)
     options = []
     for target in self._closestTargets(game):
         options.extend(self._movesToward(game, target))
     if len(options) == 0:
         options = BASEDIRS
     self.physics.activeMovement(self, choice(options))
示例#6
0
 def _draw(self, game):
     """ With a triangle that shows the orientation. """
     VGDLSprite._draw(self, game)
     if self.draw_arrow:
         col = (self.color[0], 255 - self.color[1], self.color[2])
         pygame.draw.polygon(
             game.screen, col,
             triPoints(self.rect, unitVector(self.orientation)))
示例#7
0
 def update(self, game):
     action = self._readAction(game)
     if action is None:
         action = (0, 0)
     from pygame.locals import K_SPACE
     if game.keystate[K_SPACE] and self.orientation[1] == 0:
         action = (action[0] * sqrt(self.strength), -self.strength)
     elif self.orientation[1] == 0 or self.airsteering:
         action = (action[0] * sqrt(self.strength), 0)
     else:
         action = (0, 0)
     self.physics.activeMovement(self, action)
     VGDLSprite.update(self, game)
示例#8
0
 def update(self, game):
     tmp = self.orientation
     self.orientation = (0, 0)
     VGDLSprite.update(self, game)
     action = self._readAction(game)
     if action:
         self.physics.activeMovement(self, action)
     d = self.lastdirection
     if sum(map(abs, d)) > 0:
         # only update if the sprite moved.
         self.orientation = d
     else:
         self.orientation = tmp
示例#9
0
 def update(self, game):
     tmp = self.orientation
     self.orientation = (0, 0)
     VGDLSprite.update(self, game)
     action = self._readAction(game)
     if action:
         self.physics.activeMovement(self, action)
     d = self.lastdirection
     if sum(map(abs, d)) > 0:
         # only update if the sprite moved.
         self.orientation = d
     else:
         self.orientation = tmp
示例#10
0
 def update(self, game):
     action = self._readAction(game)
     if action is None:
         action = (0, 0)
     from pygame.locals import K_SPACE
     if game.keystate[K_SPACE] and self.orientation[1] == 0:
         action = (action[0] * sqrt(self.strength), -self.strength)
     elif self.orientation[1] == 0 or self.airsteering:
         action = (action[0] * sqrt(self.strength), 0)
     else:
         action = (0, 0)
     self.physics.activeMovement(self, action)
     VGDLSprite.update(self, game)
示例#11
0
 def update(self, game):
     actions = self._readMultiActions(game)
     if UP in actions:
         self.speed = 1
     elif DOWN in actions:
         self.speed = -1
     if LEFT in actions:
         i = BASEDIRS.index(self.orientation)
         self.orientation = BASEDIRS[(i + 1) % len(BASEDIRS)]
     elif RIGHT in actions:
         i = BASEDIRS.index(self.orientation)
         self.orientation = BASEDIRS[(i - 1) % len(BASEDIRS)]
     VGDLSprite.update(self, game)
     self.speed = 0
示例#12
0
 def update(self, game):
     actions = self._readMultiActions(game)
     if UP in actions:
         self.speed = 1
     elif DOWN in actions:
         self.speed = -1
     if LEFT in actions:
         i = BASEDIRS.index(self.orientation)
         self.orientation = BASEDIRS[(i + 1) % len(BASEDIRS)]
     elif RIGHT in actions:
         i = BASEDIRS.index(self.orientation)
         self.orientation = BASEDIRS[(i - 1) % len(BASEDIRS)]
     VGDLSprite.update(self, game)
     self.speed = 0
示例#13
0
    def updateOptions(self, game): #TODO: Need to make sure to feed in a copy of the game, so as not to actually update the current game? 
        VGDLSprite.update(self, game)
        options = []
        position_options = {}
        for target in self._closestTargets(game):
            options.extend(self._movesToward(game, target))
        if len(options) == 0:
            options = BASEDIRS

        for option in options:
            left, top = self.physics.calculateActiveMovement(self, option)
            if (left, top) in position_options.keys():
                position_options[(left, top)] += 1.0/len(options) 
            else:
                position_options[(left, top)] = 1.0/len(options)
        
        return position_options
示例#14
0
 def update(self, game):
     actions = self._readMultiActions(game)
     if len(actions) > 0 and self.noiseLevel > 0:
         # pick a random one instead
         if random() < self.noiseLevel*4:
             actions = [choice([UP, LEFT, DOWN, RIGHT])]
     if UP in actions:
         self.speed = 1
     elif DOWN in actions:
         i = BASEDIRS.index(self.orientation)
         self.orientation = BASEDIRS[(i + 2) % len(BASEDIRS)]
     elif LEFT in actions:
         i = BASEDIRS.index(self.orientation)
         self.orientation = BASEDIRS[(i + 1) % len(BASEDIRS)]
     elif RIGHT in actions:
         i = BASEDIRS.index(self.orientation)
         self.orientation = BASEDIRS[(i - 1) % len(BASEDIRS)]
     VGDLSprite.update(self, game)
     self.speed = 0
示例#15
0
 def update(self, game):
     actions = self._readMultiActions(game)
     if len(actions) > 0 and self.noiseLevel > 0:
         # pick a random one instead
         if random() < self.noiseLevel*4:
             actions = [choice([UP, LEFT, DOWN, RIGHT])]
     if UP in actions:
         self.speed = 1
     elif DOWN in actions:
         i = BASEDIRS.index(self.orientation)
         self.orientation = BASEDIRS[(i + 2) % len(BASEDIRS)]
     elif LEFT in actions:
         i = BASEDIRS.index(self.orientation)
         self.orientation = BASEDIRS[(i + 1) % len(BASEDIRS)]
     elif RIGHT in actions:
         i = BASEDIRS.index(self.orientation)
         self.orientation = BASEDIRS[(i - 1) % len(BASEDIRS)]
     VGDLSprite.update(self, game)
     self.speed = 0
示例#16
0
    def update(self, game):
        VGDLSprite.update(self, game) # This makes the sprite start to move?

        options = []
        position_options = {}

        for target in self._closestTargets(game):
            options.extend(self._movesToward(game, target))
        if len(options) == 0:
            options = BASEDIRS
        # c = choice(options)
        # print "CHOICE: ", c

        for option in options:
            pos = self.physics.activeMovement(self, option)
            if pos in position_options.keys():
                position_options[pos] += 1.0/len(options) 
            else:
                position_options[pos] = 1.0/len(options)
        
        return position_options
示例#17
0
 def update(self, game):
     VGDLSprite.update(self, game)
     self._aim(game)
     self._shoot(game)
示例#18
0
 def _draw(self, game):
     """ With a triangle that shows the orientation. """
     VGDLSprite._draw(self, game)
     if self.draw_arrow:
         col = (self.color[0], 255 - self.color[1], self.color[2])
         pygame.draw.polygon(game.screen, col, triPoints(self.rect, unitVector(self.orientation)))
示例#19
0
 def update(self, game):
     VGDLSprite.update(self, game)
     self.physics.activeMovement(self, choice(BASEDIRS))
示例#20
0
 def update(self, game):
     VGDLSprite.update(self, game)
     self._aim(game)
     self._shoot(game)
示例#21
0
 def update(self, game):
     VGDLSprite.update(self, game)
     action = self._readAction(game)
     if action in [UP, DOWN]:
         self.physics.activeMovement(self, action)
示例#22
0
 def __init__(self, **kwargs):
     self._age = 0
     VGDLSprite.__init__(self, **kwargs)
示例#23
0
 def __init__(self, **kwargs):
     self._age = 0
     VGDLSprite.__init__(self, **kwargs)
示例#24
0
 def update(self, game):
     VGDLSprite.update(self, game)
     if self._age > self.limit:
         killSprite(self, None, game)
     self._age += 1
示例#25
0
 def update(self, game):
     VGDLSprite.update(self, game)
     if self._age > self.limit:
         killSprite(self, None, game)
     self._age += 1
示例#26
0
 def update(self, game):
     VGDLSprite.update(self, game)
     action = self._readAction(game)
     if action in [UP, DOWN]:
         self.physics.activeMovement(self, action)
示例#27
0
 def update(self, game):
     VGDLSprite.update(self, game)
     self.direction = choice(BASEDIRS)
     self.physics.activeMovement(self, self.direction)