コード例 #1
0
ファイル: character.py プロジェクト: keul/Cheese-Boys
    def generatePhysicalAttackEffect(self, attacker, criticity=None):
        """Called for animate a character hit by a physical blow.
        Character will innaturally move away in a direction opposite to blow origin.
        """
        damage = cbrandom.throwDices(attacker.attackDamage)
        critic = ""

        if criticity and criticity==module_th0.TH0_SURPRISE_HIT:
            critic = "BACKSTAB! "
            damage*=cbrandom.randint(3,4)
        elif criticity and criticity==module_th0.TH0_HIT_CRITICAL:
            if cbrandom.randint(1,2)==1:
                self.shout(_("Ouch!"))
            damage = int(damage * 1.5)
            critic = "CRITICAL! "
        elif criticity and criticity==module_th0.TH0_HIT_SURPRISE_CRITICAL:
            damage*=cbrandom.randint(4,6)
            critic = "DEADLY! "

        self.hitPointsLeft-= damage
        print "  %s%s wounded for %s points. %s left" % (critic, self.name, damage, self.hitPointsLeft)
        # Below I use lastAttackHeading because may be that attackHeading is now None (enemy ends the attack)
        self.damageHeading = attacker.lastAttackHeading
        if self.brain:
            self.brain.setState("hitten")
        if not self.checkAliveState():
            print "%s is dead." % self.name
        elif attacker.stealth and not self.canSeeHiddenCharacter(attacker):
            # The attacker was hidden in shadows and unseen, but the character (the target) is not dead! Now the character can see it!
            self.noticeForHiddenCharacter(attacker)
        # however the character has been hit, so I need to reset it's stealth state
        if self.stealth:
            self.stealth = False
コード例 #2
0
ファイル: rain.py プロジェクト: keul/Cheese-Boys
 def changeRainFrequency(self):
     self._time_rain_frequency = cbrandom.randint(20,60)
     ndrops = self._raindrops_length
     ndrops = ndrops + cbrandom.randint(-20,20)
     if ndrops<MIN_RAINDROPS:
         ndrops = MIN_RAINDROPS
     elif ndrops>MAX_RAINDROPS:
         ndrops = MAX_RAINDROPS
     logging.debug("Rain frequence changed from %s to %s" % (self._raindrops_length, ndrops))
     self._raindrops_length = ndrops
コード例 #3
0
ファイル: rain.py プロジェクト: keul/Cheese-Boys
 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
コード例 #4
0
ファイル: level.py プロジェクト: keul/Cheese-Boys
 def generateRandomPoint(self, fromPoint=(), maxdistance=0):
     """Generate a random point on the level.
     You can use this giving a distance and a start point to get a random point near that position.
     Normally the point is taken at random on level size.
     """
     if fromPoint and maxdistance:
         offset_x = cbrandom.randint(-maxdistance,maxdistance)
         offset_y = cbrandom.randint(-maxdistance,maxdistance)
         startX = fromPoint[0] - maxdistance
         endX = fromPoint[0] + maxdistance
         startY = fromPoint[1] - maxdistance
         endY = fromPoint[1] + maxdistance
     else:
         # If one of the not required param is missing, always use the normal feature
         startX = 1
         endX = self.levelSize[0]-1
         startY = 1
         endY = self.levelSize[1]-1
     return self.normalizePointOnLevel(cbrandom.randint(startX,endX), cbrandom.randint(startY,endY))
コード例 #5
0
ファイル: image.py プロジェクト: keul/Cheese-Boys
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)
コード例 #6
0
ファイル: character.py プロジェクト: keul/Cheese-Boys
 def moveBasedOnRetreatAction(self, time_passed):
     """This is similar to moveBasedOnNavPoint, but is called to animate a character that wanna retreat.
     The movement is done in the direction opposite to the heading, but with an offeset of +/- 50° degree.
     """
     heading = -self.heading
     heading.rotate(cbrandom.randint(-50,50))
     distance = time_passed * self.speed
     movement = heading * distance
     x = movement.get_x()
     y = movement.get_y()
     if not self.checkCollision(x, y) and self.checkValidCoord(x, y):
         self.move(x, y)
コード例 #7
0
ファイル: base_brain.py プロジェクト: keul/Cheese-Boys
 def check_conditions(self):
     character = self.character
     enemy = character.enemyTarget
     if not enemy or not enemy.isAlive:
         return "waiting"
     
     if character.distanceFrom(enemy)>character.sightRange or not character.hasFreeSightOn(enemy):
         self.character.navPoint.set(enemy.position)
         return "exploring"
     
     # BBB: withdraw
     if cbrandom.randint(1,100)<=25 and enemy.active_state=='attacking' and enemy.enemyTarget is character and \
             enemy.distanceFrom(character) < enemy.attackRange:
         return "retreat"
     
     if cbrandom.rool100() < self._getChanceForAttackBasedOnDistance(character.distanceFrom(enemy), character.attackRange):
         return "attacking"
     
     return None
コード例 #8
0
ファイル: base_brain.py プロジェクト: keul/Cheese-Boys
 def entry_actions(self, old_state_name):
     self.waiting_time = cbrandom.randint(0, 20)
コード例 #9
0
ファイル: base_brain.py プロジェクト: keul/Cheese-Boys
 def __init__(self, character):
     State.__init__(self, "waiting", character)
     self.waiting_time = cbrandom.randint(0, 20)
コード例 #10
0
ファイル: base_brain.py プロジェクト: keul/Cheese-Boys
 def entry_actions(self, old_state_name):
     self.character.speed = cbrandom.randint(cblocals.HIT_MOVEMENT_SPEED/2, cblocals.HIT_MOVEMENT_SPEED)
     self.distance_to_move = 20
     self.old_state_name = old_state_name
コード例 #11
0
ファイル: rain.py プロジェクト: keul/Cheese-Boys
 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