Пример #1
0
  def update(self, level = None):
    DynamicObject.update(self, level)

    blood = []

    if not self.active:
      return blood

    if self.on_ground:
      if self.current_animation != "dying":
        self.current_animation = "default"
      if self.jump_queue:
        self.true_jump()
        count = 0
        while (count < 5):
          count += 1
          blood.append(Particle(self.screen, 10, self.rect.centerx + random.uniform(-7, 7), self.rect.bottom, 0.0, -0.5, 0.3, level.dust_color, 4))
    else:
      self.dy = self.dy - BLOB_AIR_JUMP
      if self.dy > 0 and self.current_animation == "jumping":
        self.current_animation = "default"
      if self.dy > 2 and self.current_animation == "default":
        self.current_animation = "falling"
      self.jump_queue = False

    if self.current_animation != "dying" and self.rect.colliderect(self.player.rect):
      self.die()
      blood = self.player.take_damage(BLOB_DAMAGE)

    return blood
Пример #2
0
  def update(self, level = None):
    DynamicObject.update(self, level)

    if self.dx == 0 and self.dy == 0 and self.saveddx != None: #Restores values saved on flipping
      self.dx = self.saveddx
      self.dy = self.saveddy
      self.saveddx = None

    if level.ground_check(self.x - 1, self.y - 1) or level.ground_check(self.x + 1, self.y + 1): #Simplified collision detection
      self.die()
      self.dx = 0
      self.dy = 0
    return
Пример #3
0
  def update(self, level = None):

    #Automatic animation selection:
    if self.animations[self.current_animation].finished:
      if self.current_animation == "dying":
        pass
      elif self.current_animation == "exit":
        self.current_animation = "gone"
      else:
        #Special animation has finished, falling back to automatic selection
        self.animations[self.current_animation].reset()
        self.current_animation = "default"
    if self.on_ground:
      if self.current_animation == "jumping":
        self.current_animation = "default"
      if self.dx != 0 and self.current_animation == "default":
        self.current_animation = "walking"
      if (self.dx == 0) and self.current_animation == "walking" :
        self.current_animation = "default"
    elif self.current_animation == "default" or self.current_animation == "walking":
      self.current_animation = "jumping"

    collision_type = DynamicObject.update(self, level)

    blood = []

    if collision_type > 0:
      blood = self.take_damage(collision_type)
      if self.current_animation != "dying":
        self.dy -= collision_type*PLAYER_JUMP_ACC / 4.5
    return blood
Пример #4
0
  def update(self, level = None):
    DynamicObject.update(self, level)

    if self.x < 0 or self.y < 0 or self.flipping:
      return

    if self.attached == RIGHT or self.attached == LEFT:
      self.top_collide_point = (self.rect.centerx, self.rect.top + SPIDER_TOO_WIDE - 2)
      self.bottom_collide_point = (self.rect.centerx, self.rect.bottom - SPIDER_TOO_WIDE + 2)
      if self.attached == RIGHT:
        self.top_leg_attach_point = (self.rect.right + 2, self.rect.top + SPIDER_TOO_WIDE)
        self.bottom_leg_attach_point = (self.rect.right + 2, self.rect.bottom - SPIDER_TOO_WIDE)
      else:
        self.top_leg_attach_point = (self.rect.left - 2, self.rect.top + SPIDER_TOO_WIDE)
        self.bottom_leg_attach_point = (self.rect.left - 2, self.rect.bottom - SPIDER_TOO_WIDE)
    else:
      self.top_collide_point = (self.rect.left + SPIDER_TOO_WIDE - 2, self.rect.centery)
      self.bottom_collide_point = (self.rect.right - SPIDER_TOO_WIDE + 2, self.rect.centery)
      if self.attached == DOWN:
        self.top_leg_attach_point = (self.rect.left + SPIDER_TOO_WIDE, self.rect.bottom + 2)
        self.bottom_leg_attach_point = (self.rect.right - SPIDER_TOO_WIDE, self.rect.bottom + 2)
      else:
        self.top_leg_attach_point = (self.rect.left + SPIDER_TOO_WIDE, self.rect.top - 2)
        self.bottom_leg_attach_point = (self.rect.right - SPIDER_TOO_WIDE, self.rect.top - 2)

    fire = True

    self.move_target = STAY
    if self.attached == RIGHT or self.attached == LEFT:
      if level.player.rect.top > (self.y - 2):
        fire = False
        if not level.ground_check(self.bottom_collide_point[0], self.bottom_collide_point[1]):
          self.move_target = DOWN
      if level.player.rect.bottom < (self.y + 2):
        fire = False
        if not level.ground_check(self.top_collide_point[0], self.top_collide_point[1]):
          self.move_target = UP
    else:
      if level.player.rect.left > (self.x - 2):
        fire = False
        if not level.ground_check(self.bottom_collide_point[0], self.bottom_collide_point[1]):
          self.move_target = RIGHT
      if level.player.rect.right < (self.x + 2):
        fire = False
        if not level.ground_check(self.top_collide_point[0], self.top_collide_point[1]):
          self.move_target = LEFT

    if not self.gravity:
      if self.fire_delay > 0:
        self.fire_delay -= 1
      self.dy = 0
      self.dx = 0
      if self.move_target == UP:
        if (level.ground_check(self.top_leg_attach_point[0], self.top_leg_attach_point[1] - 1)):
          self.dy = -1
      elif self.move_target == DOWN:
        if (level.ground_check(self.bottom_leg_attach_point[0], self.bottom_leg_attach_point[1] + 1)):
          self.dy = 1
      elif self.move_target == LEFT:
        if (level.ground_check(self.top_leg_attach_point[0] - 1, self.top_leg_attach_point[1])):
          self.dx = -1
      elif self.move_target == RIGHT:
        if (level.ground_check(self.bottom_leg_attach_point[0] + 1, self.bottom_leg_attach_point[1])):
          self.dx = 1
      elif fire and not level.player.dead:
        if (self.attached == RIGHT) and (level.player.x > self.x + 20):
          fire = False
        if (self.attached == LEFT) and (level.player.x < self.x - 20):
          fire = False
        if (self.attached == UP) and (level.player.y < self.y - 20):
          fire = False
        if (self.attached == DOWN) and (level.player.y > self.y + 20):
          fire = False
        if fire:
          self.fire(level)

    if self.animations[self.current_animation].finished and self.current_animation != "dying":
      self.animations[self.current_animation].reset()
      self.current_animation = "default"
    if self.dx != 0 or self.dy != 0 and self.current_animation == "default":
      self.current_animation = "walking"
    if self.dx == 0 and self.dy == 0 and self.current_animation == "walking":
      self.current_animation = "default"

    return