def update(self, time_passed): """Update method of pygame Sprite class. A non playing character check his own AI here. """ GameSprite.update(self, time_passed) if self.brain: self.brain.think(time_passed)
def update(self, time_passed): """Update methods does: 1) Check for mouse hover on the LevelExit area; if this is true, the sprite alpha value is changed and the area became a little visibile 2) Check for hero movement on the exit. If this is true then raise the LEVEL_CHANGE_EVENT event """ GameSprite.update(self, time_passed) if cblocals.global_controlsEnabled: # Mouse curson if self.physical_rect.collidepoint(pygame.mouse.get_pos()): if not self._focus: self.image.set_alpha(50) utils.changeMouseCursor(cblocals.IMAGE_CURSOR_CHANGELEVEL_TYPE) utils.drawCursor(cblocals.screen, pygame.mouse.get_pos()) self._focus = True else: if self._focus: self.image.set_alpha(0) if cblocals.global_mouseCursorType==cblocals.IMAGE_CURSOR_CHANGELEVEL_TYPE: utils.changeMouseCursor(None) self._focus = False # Change level if self.to_level and self.physical_rect.colliderect(self.currentLevel.hero.physical_rect) and \ self.currentLevel.timeIn > 5.: event = pygame.event.Event(cblocals.LEVEL_CHANGE_EVENT, {'exit':self, }) pygame.event.post(event)
def update(self, time_passed): """The update must do 2 task: follow the character and disappear after a while. The text remains visible some times, based on text length. """ self.position = self.toLevelCoordinate() GameSprite.update(self, time_passed) self._time_left -= time_passed if self._time_left <= 0: self.endSpeech()
def update(self, time_passed): """Update method of pygame Sprite class. check if the image must be changed here. """ GameSprite.update(self, time_passed) self._timeCollected-= time_passed if self._timeCollected<=0: self._timeCollected = self._nextRandomWaveTime() # More time for animation phase 0 if self._wave_phase==3: self._timeCollected*=3 self._image = None
def update(self, time_passed): """Update method of pygame Sprite class. Check if the image must be changed here. """ GameSprite.update(self, time_passed) self._timeCollected+= time_passed if self._timeCollected>=self._nextLightChange: self._timeCollected = 0 self._nextLightChange = randomTime() self._phase+=1 self._image = None if self._phase==3: self.kill()
def update(self, time_passed): """TODO: open/close animation will be handled here""" GameSprite.update(self, time_passed) if cblocals.global_controlsEnabled: # Mouse curson if self.collide_rect.collidepoint(pygame.mouse.get_pos()): if not self._focus: self.image.set_alpha(200) utils.changeMouseCursor(cblocals.IMAGE_CURSOR_OPENDOOR_TYPE) utils.drawCursor(cblocals.screen, pygame.mouse.get_pos()) self._focus = True else: if self._focus: self.image.set_alpha(255) if cblocals.global_mouseCursorType==cblocals.IMAGE_CURSOR_OPENDOOR_TYPE: utils.changeMouseCursor(None) self._focus = False
def update(self, time_passed): """Update method of pygame Sprite class. Overrided the one in Character main class because we need to handle user controls here. """ GameSprite.update(self, time_passed) if cblocals.global_lastMouseLeftClickPosition or cblocals.global_lastMouseRightClickPosition: self.stopThinking() if self._brain.active_state and self._brain.active_state.name!="controlled": return Character.update(self, time_passed) pressed_keys = pygame.key.get_pressed() # update stealth level if pressed_keys[K_LSHIFT] and self.canStealthAgain() and not self.stealth: self.stealth = True elif not pressed_keys[K_LSHIFT] and self.stealth: self.stealth = False # Check for mouse actions setted if cblocals.global_lastMouseLeftClickPosition: self.navPoint.set(self.currentLevel.transformToLevelCoordinate(cblocals.global_lastMouseLeftClickPosition)) cblocals.global_lastMouseLeftClickPosition = () if cblocals.global_lastMouseRightClickPosition and not self.isAttacking(): attackHeading = Vector2.from_points(self.position, self.currentLevel.transformToLevelCoordinate(cblocals.global_lastMouseRightClickPosition)) attackHeading.normalize() cblocals.global_lastMouseRightClickPosition = () # Right click on a distant enemy will move the hero towards him... if self.seeking: # enable the hero brain enemy = self.seeking print "Seeking %s" % enemy.name self.enemyTarget = enemy self._brain.setState("hunting") # ...or attack (even if moving)... else: self.setAttackState(attackHeading) if pygame.key.get_pressed()[K_z] and not self.stealth: self._brain.setState("retreat") if self.navPoint: self.moveBasedOnNavPoint(time_passed) if self._attackDirection: self.updateAttackState(time_passed)
def update(self, time_passed): """Check if something is touching the trigger, and if the trigger must be fired. """ GameSprite.update(self, time_passed) collide_rect = self.collide_rect for member in self.fireOnCollistionWith: if member is self: continue if hasattr(member, 'sprites'): # is a group for sprite in member.sprites(): if sprite.collide_rect.colliderect(collide_rect): self.fireTrigger(sprite) return else: # is a sprite if member.collide_rect.colliderect(collide_rect): self.fireTrigger(member) return
def update(self, time_passed): """Do nothing, but kill me when SPACE is hit""" GameSprite.update(self, time_passed) if pygame.key.get_pressed()[K_SPACE]: self.kill()