Exemplo n.º 1
0
    def draw(self):
        libtcod.console_clear(self.console)
        libtcod.console_hline(self.console, 0, 0, self.width)

        libtcod.console_set_alignment(self.console, libtcod.LEFT)
        libtcod.console_print(self.console, 0, 0, "COMMANDS")

        libtcod.console_hline(self.console, 0, self.height - 1, self.width)
        libtcod.console_blit(self.console, 0, 0, self.width, self.height, 0, self.start_x, 0)
Exemplo n.º 2
0
    def draw(self):
        libtcod.console_clear(self.console)
        libtcod.console_hline(self.console, 0, 0, self.width)

        libtcod.console_set_alignment(self.console, libtcod.LEFT)
        libtcod.console_print(self.console, 0, 0, "COMMANDS")

        libtcod.console_hline(self.console, 0, self.height - 1, self.width)
        libtcod.console_blit(self.console, 0, 0, self.width, self.height, 0,
                             self.start_x, 0)
Exemplo n.º 3
0
def display_inventory(source):
    # Set up indent space and header
    indent_space = '    '
    header = 'Inventory vol: %s/%s weight:%s/%s' % (str(
        source.volume()), str(source.max_volume()), str(
            source.carry_weight()), str(source.max_carry_weight()))
    header_height = libtcod.console_get_height_rect(c.con, 0, 0,
                                                    c.screen_width,
                                                    c.screen_height, header)
    height = source.inventory_size() + header_height + len(c.order) + 1
    width = 50

    inventory_window = libtcod.console_new(width, height)
    libtcod.console_set_default_foreground(inventory_window, libtcod.white)
    libtcod.console_print_rect_ex(inventory_window, 0, 0, width, height,
                                  libtcod.BKGND_NONE, libtcod.LEFT, header)
    libtcod.console_hline(inventory_window, 0, header_height, width)

    y = header_height + 1
    category_index = 0
    inventory = source.stats.inventory
    selector_val = 1

    for category in inventory:
        if len(inventory[category_index]) > 0:
            libtcod.console_print_ex(inventory_window, 0, y,
                                     libtcod.BKGND_NONE, libtcod.LEFT,
                                     c.order[category_index])
            y += 1
        for item in inventory[category_index]:
            current_item, amount = item.items()[0]

            name = item.name
            if amount > 1:
                name += " (%s)" % str(amount)

            selector = token_to_index(selector_val)
            option = '%s%s%s' % (selector, indent_space, name)
            libtcod.console_print_ex(inventory_window, 2, y,
                                     libtcod.BKGND_NONE, libtcod.LEFT, option)

            y += 1
            selector_val += 1

        category_index += 1

    xdst = int((1.0 / 10) * c.screen_width)
    ydst = int((1.0 / 20) * c.screen_height)

    libtcod.console_blit(inventory_window, 0, 0, c.screen_width,
                         c.screen_height, 0, xdst, ydst, 1.0, 0.7)
    libtcod.console_flush()
Exemplo n.º 4
0
def render_ui(con, player, turn_state):
    tcod.console_set_default_foreground(con, tcod.white)
    render_bar(con, MAX_MAP_WIDTH + 1, 2, SCREEN_WIDTH - MAX_MAP_WIDTH - 2,
               'HP', player.hp, player.max_hp, tcod.dark_green, tcod.red)
    tcod.console_print(con, MAX_MAP_WIDTH + 1, 1,
                       'Turn: {}'.format(turn_state.current_turn))

    tcod.console_hline(con, 0, MAX_MAP_HEIGHT, MAX_MAP_WIDTH)
    tcod.console_vline(con, MAX_MAP_WIDTH, 0, tcod.console_get_height(con))

    row = 0
    tcod.console_print(con, MAX_MAP_WIDTH + 1, 5, 'Inventory:')
    for item in player.inventory:
        tcod.console_print(con, MAX_MAP_WIDTH + 2, row + 6,
                           chr(ord('a') + row) + ' - ' + item.kind)
        row += 1
Exemplo n.º 5
0
def draw_messages_panel():
    # draw the boundary of the panel with a gold line
    old_foreground_color = libtcod.console_get_default_foreground(msg_con)
    libtcod.console_set_default_foreground(msg_con, libtcod.gold)
    libtcod.console_hline(msg_con, 0, 0, MSG_PANEL_WIDTH)
    libtcod.console_set_default_foreground(msg_con, old_foreground_color)

    # print the last many messages to the message console that will fit in the console.
    for i, msg_and_color in enumerate(reversed(messages)):
        if (i + 1) > MSG_PANEL_HEIGHT:
            break
        else:
            msg, color = msg_and_color
            libtcod.console_set_default_foreground(msg_con, color)
            libtcod.console_print(msg_con, 1, (i + 1), msg)
            libtcod.console_set_default_foreground(msg_con, old_foreground_color)
Exemplo n.º 6
0
def draw_messages_panel():
    # draw the boundary of the panel with a gold line
    old_foreground_color = libtcod.console_get_default_foreground(msg_con)
    libtcod.console_set_default_foreground(msg_con, libtcod.gold)
    libtcod.console_hline(msg_con, 0, 0, MSG_PANEL_WIDTH)
    libtcod.console_set_default_foreground(msg_con, old_foreground_color)

    # print the last many messages to the message console that will fit in the console.
    for i, msg_and_color in enumerate(reversed(messages)):
        if (i + 1) > MSG_PANEL_HEIGHT:
            break
        else:
            msg, color = msg_and_color
            libtcod.console_set_default_foreground(msg_con, color)
            libtcod.console_print(msg_con, 1, (i + 1), msg)
            libtcod.console_set_default_foreground(msg_con,
                                                   old_foreground_color)
Exemplo n.º 7
0
def display_inventory(source):
    # Set up indent space and header
    indent_space = '    '
    header = 'Inventory vol: %s/%s weight:%s/%s' % (str(source.volume()), str(source.max_volume()),
                                                    str(source.carry_weight()), str(source.max_carry_weight()))
    header_height = libtcod.console_get_height_rect(c.con, 0, 0, c.screen_width, c.screen_height, header)
    height = source.inventory_size() + header_height + len(c.order) + 1
    width = 50

    inventory_window = libtcod.console_new(width, height)
    libtcod.console_set_default_foreground(inventory_window, libtcod.white)
    libtcod.console_print_rect_ex(inventory_window, 0, 0, width, height, libtcod.BKGND_NONE, libtcod.LEFT,
                                  header)
    libtcod.console_hline(inventory_window, 0, header_height, width)

    y = header_height + 1
    category_index = 0
    inventory = source.stats.inventory
    selector_val = 1

    for category in inventory:
        if len(inventory[category_index]) > 0:
            libtcod.console_print_ex(inventory_window, 0, y, libtcod.BKGND_NONE, libtcod.LEFT, c.order[category_index])
            y += 1
        for item in inventory[category_index]:
            current_item, amount = item.items()[0]

            name = item.name
            if amount > 1:
                name += " (%s)" % str(amount)

            selector = token_to_index(selector_val)
            option = '%s%s%s' % (selector, indent_space, name)
            libtcod.console_print_ex(inventory_window, 2, y, libtcod.BKGND_NONE, libtcod.LEFT, option)

            y += 1
            selector_val += 1
            
        category_index += 1

    xdst = int((1.0 / 10) * c.screen_width)
    ydst = int((1.0 / 20) * c.screen_height)

    libtcod.console_blit(inventory_window, 0, 0, c.screen_width, c.screen_height, 0, xdst, ydst, 1.0, 0.7)
    libtcod.console_flush()
Exemplo n.º 8
0
 def render(self,
       draw_frame=False, draw_index=False,
       align='left', fgalpha=.9, bgalpha=.3):
   if len(self.opts) > MAX_OPTS:
     raise ValueError('No more than %d options allowed.' % MAX_OPTS)
   # calculate height, set options window, print header
   _w, _h = self.width+2, self.h+2   #total width and height
   window = tl.console_new(_w, _h)
   tl.console_clear(window)
   tl.console_set_default_background(window, tl.violet)
   tl.console_set_default_foreground(window, tl.lightest_grey)
   if draw_frame: tl.console_print_frame(window, 0, 0, _w, _h)
   tl.console_print_rect_ex(window, 1,1, self.width,self.h, tl.BKGND_NONE,tl.LEFT,
               self.header)
   if self.opts != []:  # draw a separator line if options are not empty
     tl.console_hline(window, 1, self.headerHeight+1, self.width)
     if draw_frame:
       tl.console_put_char(window, 0, self.headerHeight+1, tl.CHAR_TEEE)
       tl.console_put_char(window, self.width+1, self.headerHeight+1, tl.CHAR_TEEW)
     # print all options
     n,y = 0,self.headerHeight+2
     sel = self.highlightedItemIdx if self.highlightedItemIdx >= 0 else MAX_OPTS+self.highlightedItemIdx
     for txt in self.opts:
       txt = txt.rjust(self.width) if align=='right'\
         else txt.center(self.width) if align=='center'\
         else '   '+txt.ljust(self.width)[:-3] if draw_index\
         else txt.ljust(self.width)
       if draw_index:
         txt = ' %d %s' % (n, txt)
         txt = '{'+txt[1]+'}'+txt[6:] if sel == n else txt[3:]
       scolor = 'amber' if sel == n else 'light_grey'
       if self.isAnimated and sel == n:
         # hicky-hacky color animation
         scolor = tl.amber*(self.phase/PHASES)
         tl.console_set_color_control(tl.COLCTRL_1, scolor, tl.black)
         txt = '%c%s%c'%(tl.COLCTRL_1,txt.ljust(self.width),tl.COLCTRL_STOP)
       else:
         txt = tc.parse('{{%s}}%s{{stop}}'%(scolor,txt.ljust(self.width)))
       tl.console_print(window, 1, y, txt)
       n += 1; y += 1
   # calculate window position, blit window to screen & flush
   x = SCREEN_W/2 - self.width/2
   y = SCREEN_H/2 - self.h/2
   tl.console_blit(window, 0, 0, _w, _h, 0, x, y, fgalpha, bgalpha)
Exemplo n.º 9
0
def menu(header, options, width, color=None, text_color=libtcod.white, alpha=1, center=False, additional_line=0, option_descriptions=None, flush=True, hidden=False, xOffset=0, yOffset=0):
	""" |  Render a Full-Screen menu, overwriting the console.
		|  @TODO Add multi-page support
	"""

	if len(options) > 26: raise ValueError('Cannot have a menu with more than 26 options.')

	header_height = libtcod.console_get_height_rect(gvar.con, 0, 0, width, gvar.SCREEN_HEIGHT, header)+1
 	height = gvar.SCREEN_HEIGHT

 	if flush == True:
 		gvar.window = libtcod.console_new(gvar.SCREEN_WIDTH, gvar.SCREEN_HEIGHT)

	if not hidden:

		#print the background
		libtcod.console_set_default_foreground(gvar.window, text_color)
		if color is not None:
			libtcod.console_set_default_background(gvar.window, color)
			libtcod.console_rect(gvar.window, 1, 1, gvar.SCREEN_WIDTH-2, height-2, False, libtcod.BKGND_SET)
		#print the header with separating line
		if header != '':
			libtcod.console_print_rect_ex(gvar.window, 2, 2, width, height, libtcod.BKGND_NONE, libtcod.LEFT, header)
			libtcod.console_hline(gvar.window,1,header_height+1,gvar.SCREEN_WIDTH-2,libtcod.BKGND_NONE)

		#print options
		y = header_height+2
		letter_index = ord('a')
		for option_text in options:
			index = options.index(option_text)
			if index == additional_line and additional_line != 0:
				libtcod.console_hline(gvar.window,1,y,gvar.SCREEN_WIDTH-2,libtcod.BKGND_NONE)
				y+= 1
			text = chr(letter_index).upper() + ' - ' + option_text
			libtcod.console_print_ex(gvar.window, 2, y, libtcod.BKGND_NONE, libtcod.LEFT, text)
			if option_descriptions is not None:
				libtcod.console_print_ex(gvar.window, 25, y, libtcod.BKGND_NONE, libtcod.LEFT, option_descriptions[index])
			y += 1
			letter_index += 1

	#blit the contents of "window" to the root console
	if center == True:
		x = (gvar.SCREEN_WIDTH/2 - width/2)-2
		y = (gvar.SCREEN_HEIGHT/2 - height/2)-2
	else:
		x=0
		y=0

	libtcod.console_blit(gvar.window, 0, 0, width, height, 0, xOffset+x, yOffset+y, 1.0, alpha)

	#present the root console to the player and wait for a key-press
	libtcod.console_flush()
	key = libtcod.Key()
	mouse = libtcod.Mouse()
	key_pressed = libtcod.sys_wait_for_event(libtcod.EVENT_KEY_PRESS,key,mouse,True)
	if not key_pressed:
		return None

	if key.vk == libtcod.KEY_F10:
		libtcod.console_set_fullscreen(not libtcod.console_is_fullscreen())
	if key.vk == libtcod.KEY_ESCAPE:
		return 'exit'

	#convert the ASCII code to an index; if it corresponds to an option, return it
	index = key.c - ord('a')
	if index >= 0 and index < len(options): return index
	return None
Exemplo n.º 10
0
def test_console_printing_advanced(console):
    libtcodpy.console_rect(console, 0, 0, 4, 4, False, libtcodpy.BKGND_SET)
    libtcodpy.console_hline(console, 0, 0, 4)
    libtcodpy.console_vline(console, 0, 0, 4)
    libtcodpy.console_print_frame(console, 0, 0, 11, 11)
Exemplo n.º 11
0
def do_season_overview(key, mouse):
  bottom_selector_panel_h = 9
  bottom_selector_panel = tcod.console_new(g.screen_width, bottom_selector_panel_h)
  tcod.console_set_alignment(bottom_selector_panel, tcod.CENTER)
  tcod.console_set_default_foreground(bottom_selector_panel, tcod.lightest_magenta)

  nearly_full_panel = tcod.console_new(g.screen_width, g.screen_height - bottom_selector_panel_h)
  tcod.console_set_alignment(nearly_full_panel, tcod.LEFT)
  tcod.console_set_default_foreground(nearly_full_panel, tcod.sea)

  print_season_overview(nearly_full_panel, g.screen_width, g.season)
  tcod.console_blit(nearly_full_panel, 0, 0, g.screen_width, g.screen_height - bottom_selector_panel_h, 0, 0, 0)

  confirm = False
  selected_option = 1
  while not confirm:
    tcod.sys_check_for_event(tcod.EVENT_KEY_PRESS, key, mouse)

    spacing = 6

    options = []
    if g.season.current_race >= len(g.season.circuits):
      options = [
        ('exit', 'Retire!'),
        ('start over', 'Play again')
      ]
    else:
      options = [
        ('exit', 'I quit'),
        ('go forward', 'Let\'s rock')
      ]
    selection = options[0][0]
    
    tcod.console_clear(bottom_selector_panel)

    option0_text = options[0][1]
    option1_text = options[1][1]

    # Currently only supports exactly 2 options
    xy0 = (int(g.screen_width / 2) - len(option0_text) - int(spacing / 2), int(bottom_selector_panel_h / 2))
    xy1 = (int(g.screen_width / 2) + int(spacing / 2), int(bottom_selector_panel_h / 2))
    tcod.console_print_ex(bottom_selector_panel, xy0[0], xy0[1], tcod.BKGND_SET, tcod.LEFT, option0_text)
    tcod.console_print_ex(bottom_selector_panel, xy1[0], xy1[1], tcod.BKGND_SET, tcod.LEFT, option1_text)

    if selected_option == 0:
      tcod.console_hline(bottom_selector_panel, xy0[0] - 2, xy0[1] - 1, len(option0_text) + 4)
      tcod.console_hline(bottom_selector_panel, xy0[0] - 2, xy0[1] + 1, len(option0_text) + 4)

    elif selected_option == 1:
      tcod.console_hline(bottom_selector_panel, xy1[0] - 2, xy1[1] - 1, len(option1_text) + 4)
      tcod.console_hline(bottom_selector_panel, xy1[0] - 2, xy1[1] + 1, len(option1_text) + 4)

    action = handle_keys(key, 'simple selection')
    select = action.get('select')
    enter = action.get('enter')
    if select:
      selected_option += select
      if selected_option > len(options) - 1:
        selected_option = 0
      elif selected_option < 0:
        selected_option = len(options) - 1
    if enter:
      selection = options[selected_option][0]
      confirm = True
    
    tcod.console_blit(bottom_selector_panel, 0, 0, g.screen_width, bottom_selector_panel_h, 0, 0, g.screen_height - bottom_selector_panel_h)  
    tcod.console_flush()

  if selection == 'exit':
    g.context = Context.MAIN_MENU
    tcod.console_clear(bottom_selector_panel)
    tcod.console_clear(nearly_full_panel)
    tcod.console_blit(bottom_selector_panel, 0, 0, g.screen_width, bottom_selector_panel_h, 0, 0, g.screen_height - bottom_selector_panel_h)  
    tcod.console_blit(nearly_full_panel, 0, 0, g.screen_width, g.screen_height - bottom_selector_panel_h, 0, 0, 0)
    tcod.console_flush()
  elif selection == 'go forward':
    g.context = Context.RACE
    tcod.console_clear(bottom_selector_panel)
    tcod.console_clear(nearly_full_panel)
    tcod.console_blit(bottom_selector_panel, 0, 0, g.screen_width, bottom_selector_panel_h, 0, 0, g.screen_height - bottom_selector_panel_h)  
    tcod.console_blit(nearly_full_panel, 0, 0, g.screen_width, g.screen_height - bottom_selector_panel_h, 0, 0, 0)
    tcod.console_flush()
  elif selection == 'start over':
    g.context = Context.TEAM_CREATION
    tcod.console_clear(bottom_selector_panel)
    tcod.console_clear(nearly_full_panel)
    tcod.console_blit(bottom_selector_panel, 0, 0, g.screen_width, bottom_selector_panel_h, 0, 0, g.screen_height - bottom_selector_panel_h)  
    tcod.console_blit(nearly_full_panel, 0, 0, g.screen_width, g.screen_height - bottom_selector_panel_h, 0, 0, 0)
    tcod.console_flush()    
Exemplo n.º 12
0
def do_race(key, mouse):
  bottom_viewport_height = 7  
  main_viewport_height = g.screen_height - bottom_viewport_height
  main_viewport_width = g.MAIN_VIEWPORT_WIDTH
  side_viewport_width = g.screen_width - main_viewport_width
  main_viewport = tcod.console_new(main_viewport_width, main_viewport_height)

  bottom_viewport_y = g.screen_height - bottom_viewport_height
  bottom_viewport = tcod.console_new(main_viewport_width, bottom_viewport_height)
  tcod.console_set_alignment(bottom_viewport, tcod.LEFT)

  side_viewport_x = g.screen_width - side_viewport_width  
  side_viewport = tcod.console_new(side_viewport_width, g.screen_height)

  intro_w = int(g.screen_width * .35)
  intro_h = int(g.screen_height * .20)
  intro_x = int(g.screen_width * 0.5 - intro_w * 0.5)
  intro_y = int(g.screen_height * 0.5 - intro_h * 0.5)
  intro_window = tcod.console_new(intro_w, intro_h)
  tcod.console_set_alignment(intro_window, tcod.CENTER)
  tcod.console_set_default_foreground(intro_window, tcod.sea)

  lexicon = lex.genres_lexicons[g.lexicon_counter][0]
  title_and_song = build_song(lexicon)
  race = Race(g.season.teams, g.season.circuits[g.season.current_race], title_and_song[1], title_and_song[0])

  # Reset stuff
  for x in range(0, len(race.teams)):
    race.teams[x].reset()

  teams = race.teams
  player_team_index = 0
  lane_count = len(race.teams)
  track_width = ((race.lane_size + 1) * lane_count) + 1
  BASE_OFFSET_TO_CENTER = int((g.MAIN_VIEWPORT_WIDTH - track_width) / 2)
  for x in range(0, len(teams)):
    if (teams[x].isPlayer):
      player_team_index = x
    teams[x].vehicle.x = BASE_OFFSET_TO_CENTER + (x * (race.lane_size + 1)) + 2

  exit_game = False
  lyrics = race.lyrics
  vehicles_collided = set([])
  active_lyrics_character = 0
  keypress_timer = 99999
  race_finished = False
  race_started = False
  verse = 0
  song_completed = False
  barricade_locations = [] # holds tuples of x, y barricade locations
  intro_lines = get_race_intro(title_and_song[0], lexicon, race.circuit)
  current_intro_line = 0
  first_frame = True
  time_elapsed_last_frame = 0
  race_start_time = tcod.sys_elapsed_seconds()
  while not race_finished and not exit_game:
    tcod.sys_check_for_event(tcod.EVENT_KEY_PRESS, key, mouse)
    keypress_timer += tcod.sys_get_last_frame_length()
    total_time_elapsed = tcod.sys_elapsed_seconds()
        
    if race_started:
      if not first_frame:
        time_elapsed_last_frame = tcod.sys_get_last_frame_length()
      for team in teams:
        team.ai_run_counters()
        # Apply collision physics if needed
        if team.vehicle in vehicles_collided:
          handle_post_collision(team)

        else:
          if team.vehicle.distance_traveled >= len(race.circuit.track_shape) and not team.finished_current_race:
            finish_race(race, team, total_time_elapsed - race_start_time)

          # Control player vehicle
          if team.isPlayer and not team.finished_current_race:
            action = handle_keys(key)
            pressed_key_char = action.get('key_char')
            steer = action.get('steer')
            exit = action.get('exit')
            if not song_completed:
              powerpct = g.get_powerpct_from_keyspeed(keypress_timer)
            else:
              powerpct = 1
            team.vehicle.apply_power(powerpct)

            if pressed_key_char and not song_completed:
              correct = check_key_char_input(pressed_key_char, race.lyrics[verse], active_lyrics_character)
              if correct:
                keypress_timer = 0.0
                active_lyrics_character += 1
                if (active_lyrics_character >= len(lyrics[verse])):
                  active_lyrics_character = 0
                  verse += 1
                  if verse >= len(lyrics):
                    song_completed = True

              else:
                # TODO: mis-steer
                pass

            if steer and team.vehicle.speed > 0: # Can only steer if moving
              teams[player_team_index].vehicle.x += steer
            
            if exit:
              exit_game = True

          # If team is not player
          elif not team.finished_current_race:
            direction = team.ai_determine_direction()
            if direction == td.LEFT:
              team.vehicle.x += -1
            elif direction == td.RIGHT:
              team.vehicle.x += 1
            team.ai_apply_power()

          # If team has reached the finish line
          else:
            team.vehicle.apply_power(0)
            # Don't have time to do proper checks to wait for all teams to
            # finsh race. For now, just wait until the player team's vehicle
            # has coasted to a stop, and then take everyone's place from that
            # moment.
            if team.isPlayer and team.vehicle.speed == 0:
              race_finished = True

        # Apply acceleration, determine speed
        speed_to_add = time_elapsed_last_frame * team.vehicle.acceleration
        team.vehicle.speed += speed_to_add
        if team.vehicle.speed > team.vehicle.current_max_speed_from_power:
          team.vehicle.speed -= 0.1
        if team.vehicle.speed > team.vehicle.max_speed:
          team.vehicle.speed = team.vehicle.max_speed
        elif team.vehicle.speed < 0:
          team.vehicle.speed = 0
        distance_traveled_this_frame = time_elapsed_last_frame * team.vehicle.speed

        team.ai_observe_curves(race.circuit.track_layout, int(team.vehicle.distance_traveled + distance_traveled_this_frame) - int(team.vehicle.distance_traveled)) # This HAS to come first
        team.vehicle.distance_traveled += distance_traveled_this_frame
        

      # Check for collisions
      vehicles_collided.clear()
      handle_collisions(race, vehicles_collided, barricade_locations)

      first_frame = False

    # Render
    tcod.console_clear(main_viewport)
    print_race(main_viewport, race, int(teams[player_team_index].vehicle.y), int(teams[player_team_index].vehicle.distance_traveled), barricade_locations)
    tcod.console_blit(main_viewport, 0, 0, g.screen_width, g.screen_height, 0, 0, 0,)

    tcod.console_clear(bottom_viewport)
    if not song_completed:
      print_lyrics(bottom_viewport, race.lyrics[verse], active_lyrics_character)
    tcod.console_blit(bottom_viewport, 0, 0, main_viewport_width, bottom_viewport_height, 0, 0, bottom_viewport_y)

    tcod.console_clear(side_viewport)
    print_panel_side(side_viewport, build_race_stats(race), side_viewport_width)
    tcod.console_blit(side_viewport, 0, 0, side_viewport_width, g.screen_height - bottom_viewport_height, 0, side_viewport_x, 0)

    if not race_started:
      # This structure is pretty ugly, but no time to clean it up
      if current_intro_line == len(intro_lines):
        time.sleep(intro_lines[current_intro_line - 1][1])
      elif current_intro_line >= len(intro_lines):
        race_started = True
      else:
        tcod.console_clear(intro_window)
        tcod.console_hline(intro_window, 0, 0, intro_w)
        tcod.console_hline(intro_window, 0, intro_h - 1, intro_w)
        tcod.console_vline(intro_window, 0, 0, intro_h)
        tcod.console_vline(intro_window, intro_w - 1, 0, intro_h)
        tcod.console_print_rect_ex(intro_window, int(intro_w/2), 1, intro_w - 3, intro_h - 2, tcod.BKGND_SET, tcod.CENTER, intro_lines[current_intro_line][0])
        tcod.console_blit(intro_window, 0, 0, intro_w, intro_h, 0, intro_x, intro_y)
        if current_intro_line > 0:
          time.sleep(intro_lines[current_intro_line - 1][1])
      current_intro_line += 1

    tcod.console_flush()

  # Race is finished
  if exit_game:
    tcod.console_clear(main_viewport)
    tcod.console_blit(main_viewport, 0, 0, g.screen_width, g.screen_height, 0, 0, 0,)
    tcod.console_clear(bottom_viewport)
    tcod.console_blit(bottom_viewport, 0, 0, main_viewport_width, bottom_viewport_height, 0, 0, bottom_viewport_y)
    tcod.console_flush()
    g.context = Context.MAIN_MENU
  else:
    final_stats = build_race_stats(race)
    place = 1
    for stat in final_stats:
      race.places[place] = stat.team
      place += 1
    g.season.races.append(race)
    g.lexicon_counter += 1
    if g.lexicon_counter >= len(lex.genres_lexicons):
      g.lexicon_counter = 0
    g.context = Context.POST_RACE
Exemplo n.º 13
0
def test_console_lines(console):
    libtcodpy.console_hline(console, 0, 0, 4)
    libtcodpy.console_vline(console, 0, 0, 4)
Exemplo n.º 14
0
def menu(header,
         options,
         width,
         color=None,
         text_color=libtcod.white,
         alpha=1,
         center=False,
         additional_line=0,
         option_descriptions=None,
         flush=True,
         hidden=False,
         xOffset=0,
         yOffset=0):
    """ |  Render a Full-Screen menu, overwriting the console.
		|  @TODO Add multi-page support
	"""

    if len(options) > 26:
        raise ValueError('Cannot have a menu with more than 26 options.')

    header_height = libtcod.console_get_height_rect(
        gvar.con, 0, 0, width, gvar.SCREEN_HEIGHT, header) + 1
    height = gvar.SCREEN_HEIGHT

    if flush == True:
        gvar.window = libtcod.console_new(gvar.SCREEN_WIDTH,
                                          gvar.SCREEN_HEIGHT)

    if not hidden:

        #print the background
        libtcod.console_set_default_foreground(gvar.window, text_color)
        if color is not None:
            libtcod.console_set_default_background(gvar.window, color)
            libtcod.console_rect(gvar.window, 1, 1, gvar.SCREEN_WIDTH - 2,
                                 height - 2, False, libtcod.BKGND_SET)
        #print the header with separating line
        if header != '':
            libtcod.console_print_rect_ex(gvar.window, 2, 2, width, height,
                                          libtcod.BKGND_NONE, libtcod.LEFT,
                                          header)
            libtcod.console_hline(gvar.window, 1, header_height + 1,
                                  gvar.SCREEN_WIDTH - 2, libtcod.BKGND_NONE)

        #print options
        y = header_height + 2
        letter_index = ord('a')
        for option_text in options:
            index = options.index(option_text)
            if index == additional_line and additional_line != 0:
                libtcod.console_hline(gvar.window, 1, y, gvar.SCREEN_WIDTH - 2,
                                      libtcod.BKGND_NONE)
                y += 1
            text = chr(letter_index).upper() + ' - ' + option_text
            libtcod.console_print_ex(gvar.window, 2, y, libtcod.BKGND_NONE,
                                     libtcod.LEFT, text)
            if option_descriptions is not None:
                libtcod.console_print_ex(gvar.window, 25, y,
                                         libtcod.BKGND_NONE, libtcod.LEFT,
                                         option_descriptions[index])
            y += 1
            letter_index += 1

    #blit the contents of "window" to the root console
    if center == True:
        x = (gvar.SCREEN_WIDTH / 2 - width / 2) - 2
        y = (gvar.SCREEN_HEIGHT / 2 - height / 2) - 2
    else:
        x = 0
        y = 0

    libtcod.console_blit(gvar.window, 0, 0, width, height, 0, xOffset + x,
                         yOffset + y, 1.0, alpha)

    #present the root console to the player and wait for a key-press
    libtcod.console_flush()
    key = libtcod.Key()
    mouse = libtcod.Mouse()
    key_pressed = libtcod.sys_wait_for_event(libtcod.EVENT_KEY_PRESS, key,
                                             mouse, True)
    if not key_pressed:
        return None

    if key.vk == libtcod.KEY_F10:
        libtcod.console_set_fullscreen(not libtcod.console_is_fullscreen())
    if key.vk == libtcod.KEY_ESCAPE:
        return 'exit'

    #convert the ASCII code to an index; if it corresponds to an option, return it
    index = key.c - ord('a')
    if index >= 0 and index < len(options): return index
    return None
Exemplo n.º 15
0
 def add_border(self):
     libtcod.console_hline(self.dialog_con, 0, 0, self.width)
     libtcod.console_vline(self.dialog_con, 0, 0, self.height)
     libtcod.console_hline(self.dialog_con, 0, self.height - 1, self.width)
     libtcod.console_vline(self.dialog_con, self.width - 1, 0, self.height)