示例#1
0
    def __init__(self,
                 screen,
                 x=None,
                 y=None,
                 set="brown",
                 itemclass="key",
                 max_activations=1,
                 trigger=TRIGGER_FLIP):
        Gameobject.__init__(self, screen, True, False, x, y)
        self.animations["default"] = Animation(set, itemclass)

        try:
            self.animations["broken"] = Animation(set, itemclass + "_broken")
        except:
            self.animations["broken"] = self.animations["default"]

        self.image = self.animations[
            self.current_animation].update_and_get_image()
        self.rect = self.image.get_rect()
        self.itemclass = itemclass
        self.activated_times = 0
        self.max_activations = max_activations
        self.trigger = TRIGGER_NONE
        if self.itemclass == "key":
            self.pickable = True
        if self.itemclass == "lever":
            self.trigger = trigger
        return
示例#2
0
 def flip(self):
   self.x = self.x - 2
   Gameobject.flip(self)
   self.on_ground = False
   if self.current_animation == "arrow":
     self.current_animation = "default"
   return
示例#3
0
 def update(self, level = None):
   Gameobject.update(self, level)
   if self.y < 0 and self.current_animation != "dying":  #This kills projectiles that wander off the screen from the top
     self.current_animation = "dying"
   if self.dx == 0 and self.dy == 0 and self.saveddx != None:
     self.dx = self.saveddx
     self.dy = self.saveddy
   return
示例#4
0
 def update(self, level=None):
     Gameobject.update(self, level)
     if self.y < 0 and self.current_animation != "dying":  #This kills projectiles that wander off the screen from the top
         self.current_animation = "dying"
     if self.dx == 0 and self.dy == 0 and self.saveddx != None:
         self.dx = self.saveddx
         self.dy = self.saveddy
     return
示例#5
0
 def __init__(self, screen, tilex, tiley, set = "brown", tileclass = "wall"):
   Gameobject.__init__(self, screen, True)
   self.animations["default"] = Animation(set, tileclass)
   self.image = self.animations[self.current_animation].update_and_get_image()
   self.rect = self.image.get_rect()
   self.tilex = tilex
   self.tiley = tiley
   self.x = (tilex - (FULL_TILES_HOR - TILES_HOR) + 0.5) * TILE_DIM
   self.y = (tiley - (FULL_TILES_VER - TILES_VER) + 0.5) * TILE_DIM
   return
示例#6
0
 def __init__(self, screen, x = None, y = None, dx = None, dy = None, damage = 5, set = "energy"):
   Gameobject.__init__(self, screen, False, False, x, y, -1)
   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
示例#7
0
 def render(self):
   self.rect.centerx = int(self.x)
   self.rect.centery = int(self.y)
   if self.rect.bottom > 0:
     Gameobject.render(self)
   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
   return
示例#8
0
  def __init__(self, screen, x = None, y = None, attached = RIGHT):
    Gameobject.__init__(self, screen, True, False, x, y, 30, True)
    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.life = 10
    self.itemclass = "spider"

    self.attached = attached
    self.move_target = STAY
    self.fire_delay = 0

    return
示例#9
0
    def __init__(self, screen, x=None, y=None, attached=RIGHT):
        Gameobject.__init__(self, screen, True, False, x, y, 30, True)
        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.life = 10
        self.itemclass = "spider"

        self.attached = attached
        self.move_target = STAY
        self.fire_delay = 0

        return
示例#10
0
 def add_decoration(self, texture, pos):
     """
     Función que agrega una decoración
     :param texture: Textura del objeto
     :param pos: Posición (x,y) en el mundo
     :return: void
     """
     self.decorations.append(Gameobject(texture, 2, pos))
示例#11
0
  def __init__(self, screen, x = None, y = None):
    Gameobject.__init__(self, screen, False, True, x, y, PLAYER_LIFE)
    #Changing some of the values from gameobject:
    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.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.on_ground = False
    self.umbrella_on = False
    return
示例#12
0
  def __init__(self, screen, x = None, y = None, set = "brown", itemclass = "key", max_activations = 1, trigger = TRIGGER_FLIP):
    Gameobject.__init__(self, screen, True, False, x, y)
    self.animations["default"] = Animation(set, itemclass)

    try:
      self.animations["broken"] = Animation(set, itemclass + "_broken")
    except:
      self.animations["broken"] = self.animations["default"]
      
    self.image = self.animations[self.current_animation].update_and_get_image()
    self.rect = self.image.get_rect()
    self.itemclass = itemclass
    self.activated_times = 0
    self.max_activations = max_activations
    self.trigger = TRIGGER_NONE
    if self.itemclass == "key":
      self.pickable = True
    if self.itemclass == "lever":
      self.trigger = trigger
    return
示例#13
0
 def __init__(self,
              screen,
              x=None,
              y=None,
              dx=None,
              dy=None,
              damage=5,
              set="energy"):
     Gameobject.__init__(self, screen, False, False, x, y, -1)
     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
示例#14
0
 def update(self, level = None):
   blood = Gameobject.update(self, 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.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 != "dying":
     self.current_animation = "jumping"
   return blood
示例#15
0
 def add_track(self, texture, pos):
     """
     Función que agrega una pista al circuito.
     :param texture: Textura de la pista
     :param pos: Posición (x,y) en el mundo
     :return: void
     """
     image = texture
     width, height = image.get_size()
     self.track.append(Gameobject(image, 1, pos))
     self.track_coords.append(
         [(self.window.get_window_width() / 2 - pos[0],
           self.window.get_window_height() / 2 - pos[1]),
          (self.window.get_window_width() / 2 - pos[0] + width,
           self.window.get_window_height() / 2 - pos[1] + height)])
示例#16
0
  def update(self, level = None):
    blood = Gameobject.update(self, level)

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

    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)
    if self.attached == LEFT:
      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)
    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)
    if self.attached == UP:
      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)

    if (not level.ground_check(self.top_leg_attach_point[0], self.top_leg_attach_point[1])) and (not level.ground_check(self.bottom_leg_attach_point[0], self.bottom_leg_attach_point[1])):
      self.gravity = True
    else:
      self.gravity = False

    self.move_target = STAY
    if self.attached == RIGHT or self.attached == LEFT:
      if (level.player.rect.top > (self.y - 2)):
        self.move_target = DOWN
      if (level.player.rect.bottom < (self.y + 2)):
        self.move_target = UP

    if self.attached == DOWN or self.attached == UP:
      if (level.player.rect.left > (self.x - 2)):
        self.move_target = RIGHT
      if (level.player.rect.right < (self.x + 2)):
        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
      if self.move_target == DOWN:
        if (level.ground_check(self.bottom_leg_attach_point[0], self.bottom_leg_attach_point[1] + 1)):
          self.dy = 1
      if self.move_target == LEFT:
        if (level.ground_check(self.top_leg_attach_point[0] - 1, self.top_leg_attach_point[1])):
          self.dx = -1
      if self.move_target == RIGHT:
        if (level.ground_check(self.bottom_leg_attach_point[0] + 1, self.bottom_leg_attach_point[1])):
          self.dx = 1
      if self.move_target == STAY and not level.player.dead:
        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 and 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 blood
示例#17
0
 def flip(self):
     self.saveddx = -self.dy
     self.saveddy = self.dx
     Gameobject.flip(self)
     return
示例#18
0
 def dec(self, direction):
   if not self.on_ground:
     direction = (direction[0] * PLAYER_ACC_AIR_MULTIPLIER, direction[1])
   Gameobject.dec(self, direction)
   return
示例#19
0
 def flip(self):
   self.attached = cycle_clockwise(self.attached)
   Gameobject.flip(self)
   return
示例#20
0
 def flip(self):
     self.attached = cycle_clockwise(self.attached)
     Gameobject.flip(self)
     return
示例#21
0
 def flip(self):
   self.saveddx = -self.dy
   self.saveddy = self.dx
   Gameobject.flip(self)
   return
示例#22
0
 def update(self, level = None):
   Gameobject.update(self, level)
   if not self.flipping:
     self.x = round((self.x/TILE_DIM), 1)*TILE_DIM
     self.y = round((self.y/TILE_DIM), 1)*TILE_DIM
   return
示例#23
0
    def update(self, level=None):
        blood = Gameobject.update(self, level)

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

        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)
        if self.attached == LEFT:
            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)
        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)
        if self.attached == UP:
            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)

        if (not level.ground_check(self.top_leg_attach_point[0],
                                   self.top_leg_attach_point[1])
            ) and (not level.ground_check(self.bottom_leg_attach_point[0],
                                          self.bottom_leg_attach_point[1])):
            self.gravity = True
        else:
            self.gravity = False

        self.move_target = STAY
        if self.attached == RIGHT or self.attached == LEFT:
            if (level.player.rect.top > (self.y - 2)):
                self.move_target = DOWN
            if (level.player.rect.bottom < (self.y + 2)):
                self.move_target = UP

        if self.attached == DOWN or self.attached == UP:
            if (level.player.rect.left > (self.x - 2)):
                self.move_target = RIGHT
            if (level.player.rect.right < (self.x + 2)):
                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
            if self.move_target == DOWN:
                if (level.ground_check(self.bottom_leg_attach_point[0],
                                       self.bottom_leg_attach_point[1] + 1)):
                    self.dy = 1
            if self.move_target == LEFT:
                if (level.ground_check(self.top_leg_attach_point[0] - 1,
                                       self.top_leg_attach_point[1])):
                    self.dx = -1
            if self.move_target == RIGHT:
                if (level.ground_check(self.bottom_leg_attach_point[0] + 1,
                                       self.bottom_leg_attach_point[1])):
                    self.dx = 1
            if self.move_target == STAY and not level.player.dead:
                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 and 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 blood