def getRandomImageFacingUp(images): """Given an image dictionary (commonly the character.images structure data) return a random image. This image will be rotated randomly 90 degree left or right. This is used to draw dead charas. """ image = cbrandom.choice(images.values()) l_or_r = cbrandom.randint(1,2) if l_or_r==1: return pygame.transform.rotate(image, -90) return pygame.transform.rotate(image, 90)
def _generateRaindrop(self, totallyRandom=False): """Generate a raindrop, changing the raindrop position or generating a new one. Set totallyRandom parameter to False if you don't want to generate the raindrop outside the screen. The default value (True) is used in level init, where some raindrops can be on the screen yet. """ raindrop = self.emptyRainDrop raindrop['position'][0] = cbrandom.randint(0, self._surface_size[0]+50) if totallyRandom: raindrop['position'][1] = cbrandom.randint(-70, self._surface_size[1]) else: raindrop['position'][1] = -70 raindrop['speed'] = cbrandom.randint(500, 800) raindrop['length'] = cbrandom.randint(20, 50) raindrop['width'] = cbrandom.choice( (1,2) ) raindrop['end_y'] = cbrandom.randint(10, int(self._surface_size[1]*1.1)) return raindrop
def getCloserEnemy(self, character): """Return an enemy in the character sight range, or None""" sight = character.sightRange group = self['charas'] enemies = [] for charas in group.sprites(): distanceFromCharas = character.distanceFrom(charas) if character.side!=charas.side and distanceFromCharas<=sight: # Check now if he can see the character if character.hasFreeSightOn(charas): if charas.stealth: # A rogue charas reduce the character sight range if distanceFromCharas <= int(sight * charas.getPreySightRangeReductionFactor()): # ... and now the real check for the anti-stealth if character.check_antiStealth(charas): enemies.append(charas) else: enemies.append(charas) if enemies: return cbrandom.choice(enemies) return None
def __init__(self, position, size, *containers): GameSprite.__init__(self, *containers) self.rect = pygame.Rect(position, size) self._image = None self._wave_phase = cbrandom.choice([0,1,2,3]) self._timeCollected = self._nextRandomWaveTime()
def changeWindStrength(self): self._time_wind_strength = cbrandom.randint(10,20) wind = self._wind wind = cbrandom.choice( (-.4,-.3,-.2,-.1,0) ) logging.info("Wind strength changed from %s to %s" % (self._wind, wind)) self._wind = wind