def __init__(self, object, anim_name, frameno, frame_length):
     try:
         self.image = pygame.image.load(data.picpath(object, anim_name, frameno)).convert()
     except:
         try:
             self.image = pygame.image.load(
                 data.picpath("brown", anim_name, frameno)
             ).convert()  # Fallback to brown tileset
         except:
             self.image = pygame.image.load(
                 data.picpath("object", "idle", 0)
             ).convert()  # Fallback to default object image
             error_message("Object graphic missing: " + object + "_" + anim_name + "_" + str(frameno))
     self.frame_length = frame_length
     self.image.set_colorkey((255, 0, 255))
     return
示例#2
0
class Util:

    pygame.font.init()
    smallfont = pygame.font.Font(
        data.filepath(os.path.join("misc", "Vera.ttf")), FONT_SIZE)
    cached_text_images = {}
    cached_images = {}
    cached_images["dialogueskip"] = pygame.image.load(
        data.picpath("skip", "dialogue"))
示例#3
0
  def __init__(self, screen, level_name = "0"):
    self.screen = screen
    self.bgimage = pygame.image.load(data.picpath("background", "static"))
    self.image = None
    self.rect = self.bgimage.get_rect()
    self.rect.centerx = SCREEN_WIDTH / 2
    self.rect.centery = SCREEN_HEIGHT / 2
    self.flipping = False
    self.flipcounter = 0

    self.tiles = []
    self.objects = []

    self.scripted_events = []

    conffile = open(data.levelpath(level_name))
    tiley = 0
    values = []
    set = "brown"  #Parsing this from the conf file should be added

    trigger = False
    current_event = None

    for line in conffile.readlines():

      if tiley < FULL_TILES_VER:
        tilex = 0
        while tilex < FULL_TILES_VER:
          if (line[tilex] == "W"):
            self.tiles.append(Tile(self.screen, tilex, tiley))
          if (line[tilex] == "B"):
            self.tiles.append(Tile(self.screen, tilex, tiley, set, "bars"))
          if (line[tilex] == "S"):
            self.tiles.append(Spikes(self.screen, tilex, tiley))
          tilex += 1
        tiley += 1

      else:
      
        if line.strip() != "":
          values = line.split()

          if trigger:
            if values[0] == "end" and values[1] == "trigger":
              trigger = False
            else:
              current_event.add_element(line)
            continue
          if values[0] == "trigger":
            trigger = True
            current_event = Scripted_event(values[1], int(values[2]))
            self.scripted_events.append(current_event)
            continue

          x = (float(values[1]) - (FULL_TILES_HOR - TILES_HOR)) * TILE_DIM
          y = (float(values[2]) - (FULL_TILES_VER - TILES_VER))* TILE_DIM
          if values[0] == "player":
            self.player = Player(self.screen, x, y)
            continue
          if values[0] == "spider":
            self.objects.append(Spider(self.screen, x, y, dir_from_str(values[3])))
            continue
          if values[0] == "key":
            self.objects.append(Item(self.screen, x, y, set, values[0]))
            continue
          if values[0] == "lever":
            trigger_type = TRIGGER_NONE
            if values[4] == "TRIGGER_FLIP":
              trigger_type = TRIGGER_FLIP
            self.objects.append( Item(self.screen, x, y, set, values[0], int(values[3]), trigger_type) )
            continue

    self.reset_active_tiles()
    return
示例#4
0
 def __init__(self, object, anim_name, frameno, frame_length):
   self.image = pygame.image.load(data.picpath(object, anim_name, frameno)).convert_alpha()
   self.rect = self.image.get_rect()
   self.frame_length = frame_length
   return
def display_bg(key, screen):
  bg_image = pygame.image.load(data.picpath("bg", key))
  rect = bg_image.get_rect()
  screen.blit(bg_image, rect)
  return
示例#6
0
def display_bg(key, screen):
  bg_image = pygame.image.load(data.picpath("bg", key))
  rect = bg_image.get_rect()
  screen.blit(bg_image, rect)
  return
示例#7
0
  def run(self, menu_choice = 0):
    done = False

    clock = pygame.time.Clock()

    menu_items = ["Quit", "Sound: " + bool_to_str(Variables.vdict["sound"]), "Dialogue: " + bool_to_str(Variables.vdict["dialogue"]) ]

    count = 0

    while (count <= Variables.vdict["unlocked"] and count < TOTAL_LEVELS):
      menu_items.append("Level " + str(count + 1))
      count += 1
      
    if self.score != None:
      menu_image = render_text("Your final score: " + str(self.score), COLOR_GUI)
      rect = menu_image.get_rect()
      rect.centerx = SCREEN_WIDTH / 2
      rect.top = GUI_MENU_TOP - 25
      self.screen.blit(menu_image, rect)

    while not done:

      # Pygame event and keyboard input processing
      for event in pygame.event.get():
        if event.type == QUIT or (event.type == KEYDOWN and event.key == K_ESCAPE):
          menu_choice = MENU_QUIT
          done = True
        elif (event.type == KEYDOWN and event.key == K_DOWN) or (event.type == JOYAXISMOTION and event.axis == 1 and event.value > 0.7):
          if menu_choice + 4 < len(menu_items):
            menu_choice += 1
            play_sound("click")
        elif (event.type == KEYDOWN and event.key == K_UP) or (event.type == JOYAXISMOTION and event.axis == 1 and event.value < -0.7):
          if menu_choice + 3 > 0:
            menu_choice -= 1
            play_sound("click")
        elif (event.type == KEYDOWN and (event.key == K_z or event.key == K_SPACE or event.key == K_RETURN)) or (event.type == JOYBUTTONDOWN and (event.button == 0 or event.button == 1)):
          done = True

      #Menu rendering
      
      menu_offset =  -(len(menu_items) - 6) * 10

      menu_bg = pygame.image.load(data.picpath("menu", "bg")).convert_alpha()
      rect = menu_bg.get_rect()
      rect.centerx = SCREEN_WIDTH / 2
      rect.top = GUI_MENU_TOP
      self.screen.blit(menu_bg, rect)

      menu_head = render_text("Which way is up?")
      rect = menu_head.get_rect()
      rect.centerx = SCREEN_WIDTH / 2
      rect.top = GUI_MENU_TOP + 50 + menu_offset
      self.screen.blit(menu_head, rect)

      current_menu_index = -3

      for m in menu_items:
        if (menu_choice == current_menu_index):
          color = COLOR_GUI_HILIGHT
        else:
          color = COLOR_GUI
        menu_image = render_text(m, color)
        rect = menu_image.get_rect()
        rect.centerx = SCREEN_WIDTH / 2
        rect.top = GUI_MENU_TOP + 60 + (current_menu_index + 4) * 20 + menu_offset
        self.screen.blit(menu_image, rect)
        current_menu_index += 1

      #Display, clock

      pygame.display.flip()

      clock.tick(FPS)

    return menu_choice
示例#8
0
    def __init__(self, screen, level_name="0"):
        self.screen = screen
        self.bgimage = pygame.image.load(data.picpath("background", "static"))
        self.image = None
        self.rect = self.bgimage.get_rect()
        self.rect.centerx = SCREEN_WIDTH / 2
        self.rect.centery = SCREEN_HEIGHT / 2
        self.flipping = False
        self.flipcounter = 0

        self.tiles = []
        self.objects = []

        self.scripted_events = []

        conffile = open(data.levelpath(level_name))
        tiley = 0
        values = []
        set = "brown"  #Parsing this from the conf file should be added

        trigger = False
        current_event = None

        for line in conffile.readlines():

            if tiley < FULL_TILES_VER:
                tilex = 0
                while tilex < FULL_TILES_VER:
                    if (line[tilex] == "W"):
                        self.tiles.append(Tile(self.screen, tilex, tiley))
                    if (line[tilex] == "B"):
                        self.tiles.append(
                            Tile(self.screen, tilex, tiley, set, "bars"))
                    if (line[tilex] == "S"):
                        self.tiles.append(Spikes(self.screen, tilex, tiley))
                    tilex += 1
                tiley += 1

            else:

                if line.strip() != "":
                    values = line.split()

                    if trigger:
                        if values[0] == "end" and values[1] == "trigger":
                            trigger = False
                        else:
                            current_event.add_element(line)
                        continue
                    if values[0] == "trigger":
                        trigger = True
                        current_event = Scripted_event(values[1],
                                                       int(values[2]))
                        self.scripted_events.append(current_event)
                        continue

                    x = (float(values[1]) -
                         (FULL_TILES_HOR - TILES_HOR)) * TILE_DIM
                    y = (float(values[2]) -
                         (FULL_TILES_VER - TILES_VER)) * TILE_DIM
                    if values[0] == "player":
                        self.player = Player(self.screen, x, y)
                        continue
                    if values[0] == "spider":
                        self.objects.append(
                            Spider(self.screen, x, y, dir_from_str(values[3])))
                        continue
                    if values[0] == "key":
                        self.objects.append(
                            Item(self.screen, x, y, set, values[0]))
                        continue
                    if values[0] == "lever":
                        trigger_type = TRIGGER_NONE
                        if values[4] == "TRIGGER_FLIP":
                            trigger_type = TRIGGER_FLIP
                        self.objects.append(
                            Item(self.screen, x, y, set, values[0],
                                 int(values[3]), trigger_type))
                        continue

        self.reset_active_tiles()
        return
示例#9
0
 def __init__(self, object, anim_name, frameno, frame_length):
     self.image = pygame.image.load(data.picpath(object, anim_name,
                                                 frameno)).convert_alpha()
     self.rect = self.image.get_rect()
     self.frame_length = frame_length
     return
示例#10
0
  def run(self, menu_choice = 0):
    done = False

    clock = pygame.time.Clock()

    self.screen.blit(self.bgscreen, (0, 0))      #Renders the menu background, usually the faded out game display
                                                 #Or a black screen
    #Menu loop

    while not done:

      # Pygame event and keyboard input processing
      for event in pygame.event.get():
        if event.type == QUIT or (event.type == KEYDOWN and event.key == K_ESCAPE):
          menu_choice = MENU_QUIT
          done = True
        elif (event.type == KEYDOWN and event.key == K_DOWN) or (event.type == JOYAXISMOTION and event.axis == 1 and event.value > 0.7):
          if menu_choice + 1 < len(self.menu_items):
            menu_choice += 1
            play_sound("click")
        elif (event.type == KEYDOWN and event.key == K_UP) or (event.type == JOYAXISMOTION and event.axis == 1 and event.value < -0.7):
          if menu_choice > 0:
            menu_choice -= 1
            play_sound("click")
        elif (event.type == KEYDOWN and (event.key == K_z or event.key == K_SPACE or event.key == K_RETURN)) or (event.type == JOYBUTTONDOWN and (event.button == 0 or event.button == 1)):
          done = True

      #Menu rendering

      #Menu offset value centers the menu when the maximum amount of choices is not visible

      if len(self.menu_items) < MENU_MAX_VISIBLE:
        menu_offset = -(len(self.menu_items) - 5) * 10
      else:
        menu_offset = -(MENU_MAX_VISIBLE - 5) * 10

      menu_bg = pygame.image.load(data.picpath("menu", "bg")).convert_alpha()
      rect = menu_bg.get_rect()
      rect.centerx = SCREEN_WIDTH / 2
      rect.top = GUI_MENU_TOP
      self.screen.blit(menu_bg, rect)

      if self.heading_text != None:
        menu_head = render_text(self.heading_text)
        rect = menu_head.get_rect()
        rect.centerx = SCREEN_WIDTH / 2
        rect.top = GUI_MENU_TOP + 50 + menu_offset
        self.screen.blit(menu_head, rect)

      #If the menu choice is greater than the second last menu item on screen,
      #the menu must be scrolled:
      if menu_choice > (MENU_MAX_VISIBLE - 1):
        current_menu_index = menu_choice - MENU_MAX_VISIBLE
        if (menu_choice + 1) < len(self.menu_items):
          current_menu_index += 1
      else:
        current_menu_index = 0

      menu_visible = 0

      while (not (menu_visible > MENU_MAX_VISIBLE or (current_menu_index) == len(self.menu_items))):
        m = self.menu_items[current_menu_index]
        if (menu_choice == current_menu_index):
          menu_image = render_text(m, COLOR_GUI_HILIGHT, COLOR_GUI_DARK)
        else:
          menu_image = render_text(m, COLOR_GUI)
        rect = menu_image.get_rect()
        rect.centerx = SCREEN_WIDTH / 2
        rect.top = GUI_MENU_TOP + 60 + (menu_visible + 1) * 20 + menu_offset
        self.screen.blit(menu_image, rect)
        current_menu_index += 1
        menu_visible += 1

      #Display, clock

      pygame.display.flip()

      clock.tick(FPS)

    return menu_choice