Exemplo n.º 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)
Exemplo n.º 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)
Exemplo n.º 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.} 
Exemplo n.º 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))
Exemplo n.º 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))
Exemplo n.º 6
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
Exemplo n.º 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)
Exemplo n.º 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
Exemplo n.º 9
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)
Exemplo n.º 10
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
Exemplo n.º 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
Exemplo n.º 12
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
Exemplo n.º 13
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
Exemplo n.º 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
Exemplo n.º 15
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
Exemplo n.º 16
0
 def update(self, game):
     VGDLSprite.update(self, game)
     if self._age > self.limit:
         killSprite(self, None, game)
     self._age += 1
Exemplo n.º 17
0
 def update(self, game):
     VGDLSprite.update(self, game)
     self._aim(game)
     self._shoot(game)
Exemplo n.º 18
0
 def update(self, game):
     VGDLSprite.update(self, game)
     action = self._readAction(game)
     if action in [UP, DOWN]:
         self.physics.activeMovement(self, action)
Exemplo n.º 19
0
 def update(self, game):
     VGDLSprite.update(self, game)
     self.physics.activeMovement(self, choice(BASEDIRS))
Exemplo n.º 20
0
 def update(self, game):
     VGDLSprite.update(self, game)
     action = self._readAction(game)
     if action in [UP, DOWN]:
         self.physics.activeMovement(self, action)
Exemplo n.º 21
0
 def update(self, game):
     VGDLSprite.update(self, game)
     self.direction = choice(BASEDIRS)
     self.physics.activeMovement(self, self.direction)
Exemplo n.º 22
0
 def update(self, game):
     VGDLSprite.update(self, game)
     if self._age > self.limit:
         killSprite(self, None, game)
     self._age += 1
Exemplo n.º 23
0
 def update(self, game):
     VGDLSprite.update(self, game)
     self._aim(game)
     self._shoot(game)