Пример #1
0
 def flip(self, flip_direction = CLOCKWISE):
   if flip_direction == CLOCKWISE:
     self.attached = cycle_clockwise(self.attached)
   else:
     self.attached = cycle_counter_clockwise(self.attached)
   DynamicObject.flip(self, flip_direction)
   return
Пример #2
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
Пример #3
0
 def flip(self, flip_direction = CLOCKWISE):
   if flip_direction == CLOCKWISE:
     self.saveddx = -self.dy
     self.saveddy = self.dx
   else:
     self.saveddx = self.dy
     self.saveddy = -self.dx
   DynamicObject.flip(self, flip_direction)
   return
Пример #4
0
  def __init__(self, screen, x = None, y = None, attached = RIGHT):
    DynamicObject.__init__(self, screen, x, y, 10, False, False)
    self.animations["default"] = Animation("spider", "standing")
    self.animations["walking"] = Animation("spider", "walking")
    self.image = self.animations[self.current_animation].update_and_get_image()
    self.rect = self.image.get_rect()
    self.itemclass = "spider"

    self.attached = attached
    self.move_target = STAY
    self.fire_delay = 0
Пример #5
0
 def __init__(self, screen, x, y, dx, dy, damage = 5, set = "energy"):
   DynamicObject.__init__(self, screen, x, y, -1, False, False)
   self.animations["default"] = Animation(set, "flying")
   self.animations["dying"] = Animation(set, "dying")
   self.image = self.animations[self.current_animation].update_and_get_image()
   self.rect = self.image.get_rect()
   self.dx = dx
   self.dy = dy
   self.saveddx =  None
   self.damage = damage
   self.itemclass = "projectile"
   return
Пример #6
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
Пример #7
0
 def render(self, surface = None, topleft = None, static_render = False):
   self.rect.centerx = int(self.x)
   self.rect.centery = int(self.y)
   if self.rect.bottom > 0:
     DynamicObject.render(self, surface, topleft, static_render)
   else:
     self.arrowimage = self.animations["arrow"].update_and_get_image()
     self.arrowrect = self.arrowimage.get_rect()
     self.arrowrect.centerx = int(self.x)
     self.arrowrect.top = 5
     self.screen.blit(self.arrowimage, self.arrowrect)
   if self.umbrella_on:
     self.umbrella_on = False # This should be set again before next render by the jump function
Пример #8
0
  def flip(self, flip_direction = CLOCKWISE):
    #Position correction - Guy's collision shape isn't an exact square,
    #so this is needed to avoid unwanted collisions after flipping
    self.y += 2
    xmod = 20 - self.x % TILE_DIM
    if abs(xmod) < 6:
      #Guy hasn't crossed over to another (empty) tile, but isn't centered
      #- a chance of a post-flip collision
      self.x += xmod

    DynamicObject.flip(self, flip_direction)
    if self.current_animation == "arrow":
      self.current_animation = "default"
    return
Пример #9
0
 def __init__(self, screen, x, y, player):
   DynamicObject.__init__(self, screen, x, y, 10, True, True)
   self.animations["default"] = Animation("blob", "standing")
   self.animations["dying"] = Animation("blob", "dying")
   self.animations["jumping"] = Animation("blob", "jumping")
   self.animations["falling"] = Animation("blob", "falling")
   self.image = self.animations[self.current_animation].update_and_get_image()
   self.rect = self.image.get_rect()
   self.rect.centerx = int(self.x)
   self.rect.centery = int(self.y)
   self.jump_queue = False
   self.itemclass = "blob"
   self.player = player
   return
Пример #10
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
Пример #11
0
  def __init__(self, screen, character, x=None, y=None):
    DynamicObject.__init__(self, screen, x, y, PLAYER_LIFE, True, True)
    
    #Changing some of the values from DynamicObject, the animations should probably actually be parsed from a file:
    self.animations["default"] = Animation(character, "standing")
    self.animations["jumping"] = Animation(character, "standing")
    for anim in ('walking', 'arrow', 'dying', 'shouting', 'exit', 'gone'):
      self.animations[anim] = Animation(character, anim)
    
    self.image = self.animations[self.current_animation].update_and_get_image()
    self.rect = self.image.get_rect()
    self.itemclass = "player"

    #Variables specific to this class:
    self.inventory = []
    self.umbrella_on = False
Пример #12
0
 def take_damage(self, amount, x = None, y = None):
   last_life = self.life
   blood = DynamicObject.take_damage(self, amount, x, y)
   if self.current_animation != "dying":
     self.current_animation = "shouting"
     play_sound("augh")
   elif last_life > 0:
     play_sound("augh")
   return blood
Пример #13
0
 def to_str(self, verbose = True):
   string = DynamicObject.to_str(self, False)
   try:
     string += " " + str_from_dir(self.attached)
   except:
     pass
   if verbose:
     log_message("Obj converted to string: " + string)
   return string
Пример #14
0
  def __init__(self, screen, x = None, y = None):
    DynamicObject.__init__(self, screen, x, y, PLAYER_LIFE, True, True)
    #Changing some of the values from DynamicObject, the animations should probably actually be parsed from a file:
    self.animations["default"] = Animation("guy", "standing")
    self.animations["walking"] = Animation("guy", "walking")
    self.animations["arrow"] = Animation("guy", "arrow")
    self.animations["dying"] = Animation("guy", "dying")
    self.animations["shouting"] = Animation("guy", "shouting")
    self.animations["jumping"] = Animation("guy", "standing")
    self.animations["exit"] = Animation("guy", "exit")
    self.animations["gone"] = Animation("guy", "gone")
    self.image = self.animations[self.current_animation].update_and_get_image()
    self.rect = self.image.get_rect()
    self.itemclass = "player"

    #Variables spesific to this class:
    self.inventory = []
    self.umbrella_on = False
    return
Пример #15
0
 def dec(self, direction):
   if not self.on_ground:
     direction = (direction[0] * PLAYER_ACC_AIR_MULTIPLIER, direction[1])
   DynamicObject.dec(self, direction)
   return
Пример #16
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