示例#1
0
 def __init__(self, root_window=None):
     """Init the SDL surface and prepare for draw calls."""
     flags = libtcod.FONT_TYPE_GREYSCALE | libtcod.FONT_LAYOUT_ASCII_INROW
     libtcod.console_set_custom_font(b"resources/terminal10x18_gs_ro.png", flags)
     rows, cols = WindowSystem.game_dimensions
     libtcod.console_init_root(cols, rows, GameConf.default_game_name.encode(), False,
                               libtcod.RENDERER_SDL)
示例#2
0
	def __init__ (self):
		""" Initialise the game """
		# Setup logging
		self.log = getlog(self.__class__.__name__)

		# Console size
		self.width = 80
		self.height = 50

		# libtcod initialization
		libtcod.console_set_custom_font('consolas10x10_gs_tc.png', libtcod.FONT_TYPE_GREYSCALE | libtcod.FONT_LAYOUT_TCOD)
		libtcod.console_init_root(self.width, self.height, 'Darkness', False)

		# Command initialization
		self.commands = {
			# Commands that do not cause the player to take a turn
			libtcod.KEY_ESCAPE: lambda self: self.stop(),
		}
		self.ingame_commands = {
			# Commands that are a player turn
			libtcod.KEY_UP:		lambda self: self.player.move(dy = -1),
			libtcod.KEY_DOWN:	lambda self: self.player.move(dy = +1),
			libtcod.KEY_LEFT:	lambda self: self.player.move(dx = -1),
			libtcod.KEY_RIGHT:	lambda self: self.player.move(dx = +1),
		}

		# Select options
		self.options = {
			'fov_torch_radius': 6,
			'fov_light_walls': True,
		}

		# Create player
		self.player = Player()

		# Load map
		map_type, map_args = RandomDungeon, ()
		self.load_map(map_type, *map_args)
示例#3
0
TORCH_RADIUS = 8

void_color = libtcod.Color(0, 0, 0)
color_pairs = {
    "void": (libtcod.Color(0, 0, 0), libtcod.Color(0, 0, 0)),
    "bg_wall": (libtcod.Color(25, 25, 25), libtcod.Color(50, 50, 25)),
    "fg_wall": (libtcod.Color(50, 50, 50), libtcod.Color(75, 75, 50)),
    "bg_floor": (libtcod.Color(50, 50, 50), libtcod.Color(75, 75, 50)),  
    "fg_floor": (libtcod.Color(75, 75, 75), libtcod.Color(100, 100, 75)),
    "fg_stairs": (libtcod.Color(100, 100, 75), libtcod.Color(125, 125, 75)),
    }
    

libtcod.console_set_custom_font('consolas_unicode_12x12.png', libtcod.FONT_LAYOUT_ASCII_INROW | libtcod.FONT_TYPE_GREYSCALE, nb_char_horiz=32, nb_char_vertic=64)

libtcod.console_init_root(SCREEN_WIDTH, SCREEN_HEIGHT, 'rbowl', False)
libtcod.sys_set_fps(LIMIT_FPS)

class Game:
    def __init__(self):
        self.state = 'playing'
        self.player_action = None

        self.map = Map()
        self.player = Object(self.map, 
                             self.map.start_x,
                             self.map.start_y, 
                             '@', 'player', blocks=True)
        self.screen = Screen(self, self.map)
        self.screen.move(self.map.start_x - SCREEN_WIDTH/2,
                         self.map.start_y - SCREEN_HEIGHT/2)
示例#4
0
文件: rogue.py 项目: phss/playground
      input.MovementInputHandler(player, dungeon_map),
      input.GeneralInputHandler())

  def main_loop(self):
    while not libtcod.console_is_window_closed():
      self.render_all()

      should_exit = self.handle_keys()
      if should_exit:
        break

  def render_all(self):
    self.environment.dungeon_map.draw(self.renderer)
    for object in self.environment.objects:
      object.draw(self.renderer)

    self.renderer.render()

    for object in self.environment.objects:
      object.clear(self.renderer)

  def handle_keys(self):
    return self.input_handler.handle()


if __name__ == '__main__':
  libtcod.console_set_custom_font('arial10x10.png', libtcod.FONT_TYPE_GREYSCALE | libtcod.FONT_LAYOUT_TCOD)
  libtcod.console_init_root(SCREEN_WIDTH, SCREEN_HEIGHT, 'python/libtcod tutorial', False)
  libtcod.sys_set_fps(LIMIT_FPS)
  Game().main_loop()
示例#5
0
          forcemindims          : forces screen dimensions to maximum allowed by the
                                  terminal. Default: False

        Returns:
          tuple with screen size in (x,y), negative numbers if
          terminal doesn't satisfies minimum requirements
        """
        libtcod.console_set_custom_font(fontFile='data/fonts/terminal12x12_gs_ro.png', flags=libtcod.FONT_TYPE_GREYSCALE | libtcod.FONT_LAYOUT_ASCII_INROW)

        if forcedim:
            (width, height) = libtcod.sys_get_current_resolution()
            (chw, chh) = libtcod.sys_get_char_size()
            width = (width / chw)
            height = (height / chh)

        libtcod.console_init_root(w=width, h=height, title='RogueLike', fullscreen=maximize)
        libtcod.sys_set_fps(LIMIT_FPS)

        # consoles
        w = width
        h = height*10//100
        x = 0
        y = 0
        map_ = { 'w': w, 'h': h, 'x': x, 'y': y, 'con': libtcod.console_new(w, h), 'name': 'messages' }
        areas['messages'] = map_

        w = width*80//100 + (1 if width % 5 != 0 else 0)
        h = height*80//100 + (2 if height % 10 > 5 else 1)
        x = 0
        y = height*10//100
        map_ = { 'w': w, 'h': h, 'x': x, 'y': y, 'con': libtcod.console_new(w, h), 'name': 'main' }
示例#6
0
def main():
    # setup screen
    ltc.console_set_custom_font('lucida10x10_gs_tc.png',
                                ltc.FONT_TYPE_GREYSCALE | ltc.FONT_LAYOUT_TCOD)
    ltc.console_init_root(SCREEN_WIDTH,
                          SCREEN_HEIGHT,
                          'python/ltc tutorial',
                          fullscreen=False)
    ltc.sys_set_fps(LIMIT_FPS)

    con = ltc.console_new(LEVEL_WIDTH, LEVEL_HEIGHT)
    gui_panel = ltc.console_new(PANEL_WIDTH, PANEL_HEIGHT)

    # setup level
    leveldata, start_pos = leveltools.make_level(LEVEL_WIDTH, LEVEL_HEIGHT)
    fov_recompute = True

    # setup player
    leveldata.player = rlplayer.create_player(start_pos[0], start_pos[1])
    leveldata.objects.insert(0, leveldata.player)

    rlmobs.populate_enemies(leveldata)
    rlitems.populate_items(leveldata)

    src.rlmsglog.m('Welcome to the dungeon!')

    # game state
    game_state = GS_PLAYING

    # MAIN LOOP
    while not ltc.console_is_window_closed():

        # get user input
        mouse = ltc.Mouse()
        key = ltc.Key()
        ltc.sys_check_for_event(ltc.EVENT_KEY_PRESS | ltc.EVENT_MOUSE, key,
                                mouse)

        if fov_recompute:
            leveldata.recompute_fov(TORCH_RADIUS)

        # draw level
        draw_level(con, leveldata)
        # noinspection PyTypeChecker
        draw_gui(gui_panel, con, leveldata, mouse)

        # display level
        ltc.console_blit(con, 0, 0, LEVEL_WIDTH, LEVEL_HEIGHT, 0, 0, 0)
        ltc.console_blit(gui_panel, 0, 0, PANEL_WIDTH, PANEL_HEIGHT, 0, 0,
                         PANEL_Y)
        ltc.console_flush()
        clear_console(con)
        clear_console(gui_panel)

        # handle user input
        # noinspection PyTypeChecker
        player_taken_turn = handle_input(key, mouse, game_state, leveldata,
                                         con)

        if should_exit:
            break

        # all objects take their turn - player is first
        if game_state == GS_PLAYING and player_taken_turn:
            fov_recompute = True
            for o in leveldata.objects:
                o.take_turn(leveldata)

        if not leveldata.player.fighter.is_alive():
            game_state = GS_DEAD
示例#7
0
import os

from libtcod import libtcodpy as libtcod

import map_vars as M

# Set the fps.
libtcod.sys_set_fps(45)
# Font path
font = os.path.join(b'data', b'fonts', b'consolas10x10_gs_tc.png')
# Set the custom font.
libtcod.console_set_custom_font(font,
    libtcod.FONT_TYPE_GREYSCALE | libtcod.FONT_LAYOUT_TCOD)
# Initialize the root console.
libtcod.console_init_root (M.SCREEN_WIDTH, M.SCREEN_HEIGHT, b'zombie.py', False)
# Create the game console.
game_console = libtcod.console_new(M.MAP_WIDTH, M.MAP_HEIGHT)
gun_console  = libtcod.console_new(M.MAP_WIDTH, M.MAP_HEIGHT)
# Make the background of gun_console transparent on black.
libtcod.console_set_key_color(gun_console,libtcod.black)
# Create an items console
items_console = libtcod.console_new(30, 40)
menu_console = libtcod.console_new(M.SCREEN_WIDTH, M.SCREEN_HEIGHT)
示例#8
0
文件: IO.py 项目: initrl/MinecraftRL
 def __init__(self):
     libtcod.console_set_custom_font("./font.png",
                                         libtcod.FONT_LAYOUT_ASCII_INROW
                                         | libtcod.FONT_TYPE_GREYSCALE)
     self.console = libtcod.console_init_root(W, H, TITLE)