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)
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.}
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))
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)))
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)
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
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
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
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
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
def update(self, game): VGDLSprite.update(self, game) self._aim(game) self._shoot(game)
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)))
def update(self, game): VGDLSprite.update(self, game) self.physics.activeMovement(self, choice(BASEDIRS))
def update(self, game): VGDLSprite.update(self, game) action = self._readAction(game) if action in [UP, DOWN]: self.physics.activeMovement(self, action)
def __init__(self, **kwargs): self._age = 0 VGDLSprite.__init__(self, **kwargs)
def update(self, game): VGDLSprite.update(self, game) if self._age > self.limit: killSprite(self, None, game) self._age += 1
def update(self, game): VGDLSprite.update(self, game) self.direction = choice(BASEDIRS) self.physics.activeMovement(self, self.direction)