Ejemplo n.º 1
0
def play_game():
    player_action = None

    #mouse stuff
    Game.mouse = libtcod.Mouse()
    Game.key = libtcod.Key()

    (Game.camera_x, Game.camera_y) = (0, 0)

    while not libtcod.console_is_window_closed():
        #render the screen
        libtcod.sys_check_for_event(
            libtcod.EVENT_KEY_PRESS | libtcod.EVENT_MOUSE, Game.key,
            Game.mouse)

        #render the screen
        render_all(Game)

        libtcod.console_flush()
        check_level_up(Game)

        #erase objects from old position, before they move
        for object in Game.objects:
            object.clear(Game)

        #handle keys and exit game if needed
        player_action = handle_keys()
        if player_action == 'exit':
            break

        #give monsters a turn
        if Game.game_state == data.STATE_PLAYING and player_action != data.STATE_NOACTION:
            for object in Game.objects:
                if object.ai:
                    object.ai.take_turn(Game)
Ejemplo n.º 2
0
def play_game():
    global key, mouse

    player_action = None

    mouse = libtcod.Mouse()
    key = libtcod.Key()
    #main loop
    while not libtcod.console_is_window_closed():
        libtcod.sys_check_for_event(
            libtcod.EVENT_KEY_PRESS | libtcod.EVENT_MOUSE, key, mouse)
        #render the screen
        render_all()

        libtcod.console_flush()

        #level up if needed
        check_level_up()

        #erase all objects at their old locations, before they move
        for object in objects:
            object.clear()

        #handle keys and exit game if needed
        player_action = handle_keys()
        if player_action == 'exit':
            save_game()
            break

        #let monsters take their turn
        if game_state == 'playing' and player_action != 'didnt-take-turn':
            for object in objects:
                if object.ai:
                    object.ai.take_turn()
Ejemplo n.º 3
0
 def handleInput(self):
     key = rl.Key() # Set up the variables for mouse and key input.
     mouse = rl.Mouse()
     rl.sys_check_for_event(rl.EVENT_KEY_PRESS|rl.EVENT_MOUSE,key,mouse) # Update the key and mouse variables if a key or mouse button was pressed.
     if key.vk == rl.KEY_ENTER or key.vk == rl.KEY_KPENTER or mouse.lbutton_pressed:
         command = None
         if mouse.lbutton_pressed: # If the mouse was clicked, attempt to retrieve a result.
             command = self.box.handleClick(mouse)
         if (key.vk == rl.KEY_ENTER or key.vk == rl.KEY_KPENTER) and command == None: # If a key was pressed and a mouse click did not occur or yield any results:
             command = self.box.forward() # Retrieve the selected option.
         if command == "Exit":
             raise SystemExit # Exit
         elif command == "Modding":
             return "DevMenuScene"
         elif command == "New Game":
             return "BattleScene"
         return None
     elif key.vk == rl.KEY_DOWN or key.vk == rl.KEY_KP2:
         self.box.goDown() # Go down one item.
         return None
     elif key.vk == rl.KEY_UP or key.vk == rl.KEY_KP8:
         self.box.goUp() # Go up one item.
         return None
     elif key.vk == rl.KEY_ESCAPE or mouse.rbutton_pressed:
         raise SystemExit # Also exit
         return None
     return None
Ejemplo n.º 4
0
def play_game():
    global key, mouse

    player_action = None

    mouse = libtcod.Mouse()
    key = libtcod.Key()

    while not libtcod.console_is_window_closed():

        libtcod.sys_check_for_event(
            libtcod.EVENT_KEY_PRESS | libtcod.EVENT_MOUSE, key, mouse)

        render_all()

        libtcod.console_flush()

        for object in objects:
            object.clear()

        player_action = handle_keys()
        if player_action == 'exit':
            main_menu()
            break

        if game_state == 'playing':  # and player_action != 'didnt-take-turn':
            for object in objects:
                if object.ai:
                    if object.wait > 0:
                        object.wait -= 1
                    else:
                        object.ai.take_turn()
Ejemplo n.º 5
0
def play_game():
    global Key, Mouse, Fov_Recompute, Fov_Map, Message_Panel, Stats_Panel
    global Map_Objects
    Player_Action = None
    Mouse = libtcod.Mouse()
    Key = libtcod.Key()
    while not libtcod.console_is_window_closed():
        libtcod.sys_check_for_event(
            libtcod.EVENT_KEY_PRESS
            | libtcod.EVENT_MOUSE, Key, Mouse)
        if Fov_Recompute:
            Fov_Recompute = False
            libtcod.map_compute_fov(Fov_Map, Player.x, Player.y,
                                    consts.TORCH_RADIUS,
                                    consts.FOV_LIGHT_WALLS,
                                    consts.FOV_ALGORITHM)
        render_all(Console, Stats_Panel, Message_Panel, Mouse, Fov_Map, Player,
                   Map_Objects)
        libtcod.console_flush()
        for obj in Map_Objects:
            obj.clear(Console)
        libtcod.console_set_default_foreground(Console, libtcod.white)
        check_level_up()
        Player_Action = handle_keys(Console, Key, Player, Map_Objects,
                                    Message_Panel)
        if Player_Action == 'exit':
            save_game()
            break
        if Game_State == 'playing' and Player_Action != 'didnt-take-turn':
            for obj in Map_Objects:
                if obj.ai is not None:
                    obj.ai.take_turn(Fov_Map, Map_Tiles, Map_Objects,
                                     Message_Panel, Player)
Ejemplo n.º 6
0
 def handleInput(self):
     key = rl.Key() # Set up the variables for mouse and key input.
     mouse = rl.Mouse()
     rl.sys_check_for_event(rl.EVENT_KEY_PRESS|rl.EVENT_MOUSE,key,mouse) # Update the key and mouse variables if a key or mouse button was pressed.
     if key.vk == rl.KEY_ENTER or key.vk == rl.KEY_KPENTER or mouse.lbutton_pressed:
         if len(self.moveBoxes) == 0 or self.animPhase > 0: # Don't do anything if the menu isn't open or a animation is playing.
             return None
         command = None
         if mouse.lbutton_pressed: # If the mouse was clicked, attempt to retrieve a result.
             self.handleCommand(self.moveBoxes[len(self.moveBoxes)-1].handleClick(mouse))
         if (key.vk == rl.KEY_ENTER or key.vk == rl.KEY_KPENTER) and command == None: # If a key was pressed and a mouse click did not occur or yield any results:
             self.handleCommand(self.moveBoxes[len(self.moveBoxes)-1].forward()) # Retrieve the selected option, then send it to a separate function for processing.
         return None
     elif key.vk == rl.KEY_DOWN or key.vk == rl.KEY_KP2:
         if len(self.moveBoxes) > 0:
             self.moveBoxes[len(self.moveBoxes)-1].goDown() # Go down one item.
         return None
     elif key.vk == rl.KEY_UP or key.vk == rl.KEY_KP8:
         if len(self.moveBoxes) > 0:
             self.moveBoxes[len(self.moveBoxes)-1].goUp() # Go up one item.
         return None
     elif key.vk == rl.KEY_ESCAPE or mouse.rbutton_pressed: # Remove the latest move box, if there are more than one.
         if len(self.moveBoxes) > 1:
             self.moveBoxes.pop()
     elif key.vk == rl.KEY_F4 and rl.console_is_key_pressed(rl.KEY_ALT):
         raise SystemExit # Pressing Alt+F4 is against the laws of the game and is punishable with exile.
         return None
     else: # Let the box handle any other input.
         if len(self.moveBoxes) == 0 or self.animPhase > 0: # Don't do anything if the menu isn't open or a animation is playing.
             return None
         self.moveBoxes[len(self.moveBoxes)-1].miscInput(key)
     return None
Ejemplo n.º 7
0
def play_game():
    global key, mouse

    player_action = None

    mouse = libtcod.Mouse()
    key = libtcod.Key()
    while not libtcod.console_is_window_closed():
        
        libtcod.sys_check_for_event(libtcod.EVENT_KEY_PRESS|libtcod.EVENT_MOUSE,key,mouse)
        render_all()

        libtcod.console_flush()

        #Level up if needed
        check_level_up()

        for object in objects:
            object.clear()

        #Player turn
        player_action = handle_keys()
        if player_action == 'exit':
            save_game()
            break

        #Let monsters take their turn
        if game_state == 'playing' and player_action != 'didnt-take-turn':
            for object in objects:
                if object.ai:
                    object.ai.take_turn()
Ejemplo n.º 8
0
def play_game():
    global key, mouse

    mouse = libtcod.Mouse()
    key = libtcod.Key()

    while not libtcod.console_is_window_closed():

        libtcod.sys_check_for_event(
            libtcod.EVENT_KEY_PRESS | libtcod.EVENT_MOUSE, key, mouse)
        #render the screen
        render_all()
        #update_info_bar()

        #erase all objectsat their old locations, before they move
        #for object in objects:
        #    object.clear(con)

        for object_ in R.world_obj:
            object_.clear(cam_x, cam_y)

        for city in cities:
            for merchant in city.trade_house.caravans_out:
                merchant.clear(cam_x, cam_y)

        #handles the keys and exit if needed.
        player_action = handle_keys()
        if player_action == "exit":
            save_game()
            break

        if not pause:  #and not player_turn:
            advance_time()

        handle_mouse()
Ejemplo n.º 9
0
def play_game():
	global key, mouse
	player_action = None
	mouse = libtcod.Mouse()
	key = libtcod.Key()
	while not libtcod.console_is_window_closed():
		#render the screen
		libtcod.sys_check_for_event(libtcod.EVENT_KEY_PRESS | libtcod.EVENT_MOUSE, key, mouse)
		render_all()
		libtcod.console_flush()
		#did the player level up?
		check_level_up()
		#erase objects at old locations, before they move
		for object in objects:
			object.clear()
		#take player input
		player_action = handle_keys()
		if player_action == 'exit':
			save_game()
			break
		#monster turn
		if game_state == 'playing' and player_action != 'didnt-take-turn':
			for object in objects:
				if object.ai:
					object.ai.take_turn()
Ejemplo n.º 10
0
def play_game():
    global key, mouse, player_action

    player_action = None

    mouse = libtcod.Mouse()
    key = libtcod.Key()

    while not libtcod.console_is_window_closed():

        libtcod.sys_check_for_event(
            libtcod.EVENT_KEY_PRESS | libtcod.EVENT_MOUSE, key, mouse)

        draw_all()
        libtcod.console_flush()
        clear_all()

        # handle keys and exit game if needed
        player_action = handle_keys()
        if player_action == 'exit':
            save_game()
            break

        if game_state == 'playing' and player_action != 'didnt-take-turn':
            for object in objects:
                if object.AI:
                    object.AI.take_turn()
Ejemplo n.º 11
0
def main():
    global key, mouse, map_, con

    R.SCREEN_WIDTH = 100
    R.SCREEN_HEIGHT = 80
    libtcod.console_set_custom_font("data\ont_big.png",
                                    libtcod.FONT_LAYOUT_ASCII_INROW)
    libtcod.console_init_root(R.SCREEN_WIDTH, R.SCREEN_HEIGHT, "Trader-RL",
                              False)
    libtcod.sys_set_fps(R.LIMIT_FPS)
    con = libtcod.console_new(R.SCREEN_WIDTH, R.SCREEN_HEIGHT)

    map_ = Map(R.MAP_WIDTH, R.MAP_HEIGHT)
    map_.wind_gen.run_simulation(500)

    mouse = libtcod.Mouse()
    key = libtcod.Key()

    while not libtcod.console_is_window_closed():
        libtcod.sys_check_for_event(
            libtcod.EVENT_KEY_PRESS | libtcod.EVENT_MOUSE, key, mouse)
        render()

        player_action = handle_keys()
        if player_action == "exit":
            break

        handle_mouse()
Ejemplo n.º 12
0
def main():
    screen_width = 80
    screen_height = 80

    map_width = 80
    map_height = 70

    colors = {

        'dark_wall': libtcod.Color(45, 65, 100),
        'dark_ground': libtcod.Color(13, 23, 15)

    }


    player = Entity(int(screen_width / 2), int(screen_height / 2), '@', libtcod.white)
    entities = [player]

    libtcod.console_set_custom_font('arial10x10.png', libtcod.FONT_TYPE_GREYSCALE | libtcod.FONT_LAYOUT_TCOD)

    libtcod.console_init_root(screen_width, screen_height, 'table tosser', False)

    con = libtcod.console_new(screen_width, screen_height)

    game_map = GameMap(map_width, map_height)

    

    key = libtcod.Key()
    mouse = libtcod.Mouse()

    while not libtcod.console_is_window_closed():

        libtcod.sys_check_for_event(libtcod.EVENT_KEY_PRESS, key, mouse)


        render_all(con, entities, game_map, screen_width, screen_height, colors)


        libtcod.console_flush()
        
        clear_all(con, entities)

        action = handle_keys(key)

        move = action.get('move')
        exit = action.get('exit')
        fullscreen = action.get('fullscreen')

        if move:
            dx, dy = move
            if not game_map.is_blocked(player.x + dx, player.y +dy):
                player.move(dx, dy)

        if exit:
            return True

        if fullscreen:
            libtcod.console_set_fullscreen(not libtcod.console_is_fullscreen())
Ejemplo n.º 13
0
 def __init__(self):
     self.screens = []
     self.keybindings = {}
     self._keyboard = libtcod.Key()
     self.mouse = libtcod.Mouse()
     self.console = libtcod.console_new(MAP_WIDTH, MAP_HEIGHT)
     self.panel = libtcod.console_new(SCREEN_WIDTH, PANEL_HEIGHT)
     self._dirty = True
Ejemplo n.º 14
0
def boot():
	global KEY, MOUSE
	
	KEY = tcod.Key()
	MOUSE = tcod.Mouse()
	
	events.create_event('mouse_moved')
	events.create_event('mouse_pressed')
	events.create_event('mouse_held')
Ejemplo n.º 15
0
def main():
    screen_width = 80
    screen_height = 50
    map_width = 80
    map_height = 45

    colors = {
        "dark_wall": libtcod.Color(0, 0, 100),
        "dark_ground": libtcod.Color(50, 50, 150)
    }

    player = Entity(int(screen_width / 2), int(screen_height / 2), "@",
                    libtcod.fuchsia)
    npc = Entity(int(screen_width / 2 - 5), int(screen_height / 2), "@",
                 libtcod.yellow)
    entities = [npc, player]

    # http://roguecentral.org/doryen/data/libtcod/doc/1.5.1/html2/console_set_custom_font.html?c=false&cpp=false&cs=false&py=true&lua=false
    libtcod.console_set_custom_font(
        "arial10x10.png",
        libtcod.FONT_TYPE_GREYSCALE | libtcod.FONT_LAYOUT_TCOD)
    # Creates the window, title, and fullscreen
    libtcod.console_init_root(screen_width, screen_height, "B@rd", False)

    # Draw a new console
    con = libtcod.console_new(screen_width, screen_height)

    game_map = GameMap(map_width, map_height)

    # Holds keyboard and mouse input
    key = libtcod.Key()
    mouse = libtcod.Mouse()

    # Game loop (until screen is closed)
    while not libtcod.console_is_window_closed():
        libtcod.sys_check_for_event(libtcod.EVENT_KEY_PRESS, key, mouse)

        render_all(con, entities, game_map, screen_width, screen_height,
                   colors)
        libtcod.console_flush()
        clear_all(con, entities)

        action = handle_keys(key)
        move = action.get("move")
        exit = action.get("exit")
        fullscreen = action.get("fullscreen")

        if move:
            dx, dy = move
            if not game_map.is_blocked(player.x + dx, player.y + dy):
                player.move(dx, dy)

        if exit:
            return True

        if fullscreen:
            libtcod.console_set_fullscreen(not libtcod.console_is_fullscreen())
Ejemplo n.º 16
0
def new_game():
    global game_msgs, test_msgs, ui, game_state
    global world, world_obj, cities, player, selected
    global tiles, cam_x, cam_y
    global key, mouse

    mouse = libtcod.Mouse()
    key = libtcod.Key()

    cam_x, cam_y = 0, 0
    game_state = "playing"
    test_msgs = []
    world = R.world = worldMap.Map(R.MAP_WIDTH, R.MAP_HEIGHT)

    world_obj = R.world_obj = []
    tiles = R.tiles = world.tiles
    #make_map()

    cities = R.cities = world.cities
    R.ui.message(str(len(cities)) + " cities have been made!", libtcod.green)
    for city in cities:
        #print city.name + str(city.x) + "/" +  str(city.y)
        R.ui.message(city.name + str(city.x) + "/" + str(city.y),
                     libtcod.light_grey)
        city.createBaseRelationships(cities)


#    for n in range(5):
#        city = City(name = libtcod.namegen_generate("city"), resource_list =master_resource_list)
#        cities.append(city)
#    city = None
#    for city in cities:
#        city.createBaseRelationships(cities)
    selected = cities[0]
    player = R.player = entities.Object(name="player",
                                        player=entities.Player())
    world_obj.append(player)
    for a in range(5):
        x, y = worldMap.place_on_land()
        hero = R.hero = entities.Object(x=x,
                                        y=y,
                                        name="hero " + str(a),
                                        pather=entities.Pather(),
                                        ai=entities.AI_Hero())
        world_obj.append(hero)
    render_all()

    world.connect_cities()
    world.connect_cities()
    world.connect_cities()
    #    point = (0,0)
    #    diction = dict()
    #    diction[(0,0)] = 10
    #    print str(diction[point])

    #path = hero.pather.find_path((10,10),(0,0))
    R.ui.message("welcome and prepare your mind.", libtcod.blue)
Ejemplo n.º 17
0
def main():
	screen_width = 80
	screen_height = 50
	map_width = 80
	map_height = 45
	
	room_max_size = 10
	room_min_size = 6
	max_rooms = 30
	
	colors = {
		'dark_wall': libtcod.Color(0, 0, 100),
		'dark_ground': libtcod.Color(50, 50, 150)
	}
	
	player = Entity(int(screen_width / 2), int(screen_height / 2), '@', libtcod.white)
	npc = Entity(int(screen_width / 2), int(screen_height / 2), '@', libtcod.yellow)
	entities = [npc, player]
	
	libtcod.console_set_custom_font('arial10x10.png', libtcod.FONT_TYPE_GREYSCALE | libtcod.FONT_LAYOUT_TCOD)
	
	libtcod.console_init_root(screen_width, screen_height, 'libtcod tutorial revised', False)
	
	con = libtcod.console_new(screen_width, screen_height)
	
	game_map = GameMap(map_width, map_height)
	game_map.make_map(max_rooms, room_min_size, room_max_size, map_width, map_height, player)
	
	key = libtcod.Key()
	mouse = libtcod.Mouse()
	
	while not libtcod.console_is_window_closed():
		libtcod.sys_check_for_event(libtcod.EVENT_KEY_PRESS, key, mouse)
	
		render_all(con, entities, game_map, screen_width, screen_height, colors)
		
		libtcod.console_flush()
		
		clear_all(con, entities)
		
		action = handle_keys(key)
		
		move = action.get('move')
		exit = action.get('exit')
		fullscreen = action.get('fullscreen')
		
		if move:
			dx, dy = move
			if not game_map.is_blocked(player.x + dx, player.y + dy):
				player.move(dx, dy)
		
		if exit:
			return True
			
		if fullscreen:
			libtcod.console_set_fullscreen(not libtcod.console_is_fullscreen())
Ejemplo n.º 18
0
def main():
    screen_width = 80
    screen_height = 50

    player_x = int(screen_width / 2)
    player_y = int(screen_height / 2)

    libtcod.console_set_custom_font(
        'arial10x10.png',
        libtcod.FONT_TYPE_GREYSCALE | libtcod.FONT_LAYOUT_TCOD)
    # imports font, tells libtcod how to interpret font png

    libtcod.console_init_root(screen_width, screen_height,
                              'libtcod tutorial revised', False)
    # creates main screen (width, height, title, fullscreen T/F)

    con = libtcod.console_new(screen_width, screen_height)

    key = libtcod.Key()
    # captures keyboard input
    mouse = libtcod.Mouse()
    # captures mouse input

    while not libtcod.console_is_window_closed():
        # keeps game running as long as window is open

        libtcod.sys_check_for_event(libtcod.EVENT_KEY_PRESS, key, mouse)
        # checks for mouse or keyboard input

        libtcod.console_set_default_foreground(con, libtcod.white)
        libtcod.console_put_char(con, player_x, player_y, '@',
                                 libtcod.BKGND_NONE)
        libtcod.console_blit(con, 0, 0, screen_width, screen_height, 0, 0, 0)

        libtcod.console_flush()
        # flushes everything to printout

        libtcod.console_put_char(con, player_x, player_y, ' ',
                                 libtcod.BKGND_NONE)

        action = handle_keys(key)
        move = action.get('move')
        exit = action.get('exit')
        fullscreen = action.get('fullscreen')

        if move:
            dx, dy = move
            player_x += dx
            player_y += dy

        if exit:
            return True

        if fullscreen:
            libtcod.console_set_fullscreen(not libtcod.console_is_fullscreen())
Ejemplo n.º 19
0
def main():
    #Initialise some game variables/objects and the libtcod console
    screen_width = 16
    screen_height = 16
    fps_limit = 60

    libtcod.console_set_custom_font(
        'arial10x10.png',
        libtcod.FONT_TYPE_GREYSCALE | libtcod.FONT_LAYOUT_TCOD)
    libtcod.console_init_root(screen_width, screen_height, 'Snake', False)
    libtcod.sys_set_fps(fps_limit)

    con = libtcod.console_new(screen_width, screen_height)
    key = libtcod.Key()
    mouse = libtcod.Mouse()
    apple = Apple('A', libtcod.Color(200, 20, 20), screen_width, screen_height)
    snake = Snake(int(screen_width / 2), int(screen_height / 2), 'S',
                  libtcod.Color(20, 200, 20), 1, fps_limit, apple,
                  screen_width, screen_height)

    #Main game loop
    while not libtcod.console_is_window_closed():
        #Updates game entities if snake is not dead
        if snake.alive == True:
            snake.update()
            entities = snake.entities.copy()
            entities.append(apple.apple)

        #Handles rendering
        render_all(con, entities, screen_width, screen_height)
        libtcod.console_flush()
        clear_all(con, entities)

        #Handles keyboard input
        libtcod.sys_check_for_event(libtcod.EVENT_KEY_PRESS, key, mouse)
        input = handle_keys(key)
        move = input.get('move')
        restart = input.get('restart')
        exit = input.get('exit')
        fullscreen = input.get('fullscreen')

        if move:
            snake.set_next_dir(move)

        if restart:
            snake = Snake(int(screen_width / 2), int(screen_height / 2), 'S',
                          libtcod.Color(20, 200, 20), 1, fps_limit, apple,
                          screen_width, screen_height)

        if exit:
            return True

        if fullscreen:
            libtcod.console_set_fullscreen(not libtcod.console_is_fullscreen())
Ejemplo n.º 20
0
def get_fighters_under_mouse():
    mouse = libtcod.Mouse()
    # return a string with the names of all objects under the mouse
    (x, y) = (mouse.cx, mouse.cy)
    # create a list with the names of all objects at the mouse's coordinates and in FOV
    fighters = [
        obj for obj in GameState.current_level.get_all_objects()
        if obj.x == x and obj.y == y and Engine.Fov.is_visible(obj)
    ]

    return fighters
Ejemplo n.º 21
0
def init_ui():
    global console
    tcod.console_set_custom_font(
        'data/terminal10x16_gs_tc.png',
        tcod.FONT_TYPE_GRAYSCALE | tcod.FONT_LAYOUT_TCOD)
    tcod.console_init_root(SCREEN_WIDTH, SCREEN_HEIGHT,
                           'libtcod tutorial revisited', False)
    console = tcod.console_new(SCREEN_WIDTH, SCREEN_HEIGHT)
    popup = tcod.console_new(SCREEN_WIDTH, SCREEN_HEIGHT)
    message_log = MessageLog(MAX_MAP_WIDTH, SCREEN_HEIGHT - MAX_MAP_HEIGHT - 1)
    return message_log, tcod.Key(), tcod.Mouse()
Ejemplo n.º 22
0
def get_names_under_mouse():
    mouse = libtcod.Mouse()
    # return a string with the names of all objects under the mouse
    (x, y) = (mouse.cx, mouse.cy)
    # create a list with the names of all objects at the mouse's coordinates and in FOV
    names = [
        obj.name for obj in GameState.current_level.get_all_objects()
        if obj.x == x and obj.y == y and Engine.Fov.is_visible(obj=obj)
    ]
    names = ', '.join(names)  # join the names, separated by commas
    return names.capitalize()
Ejemplo n.º 23
0
def play_game():
    global key, mouse, player_turn

    mouse = libtcod.Mouse()
    key = libtcod.Key()

    start_time = libtcod.sys_elapsed_seconds()
    while not libtcod.console_is_window_closed():

        libtcod.sys_check_for_event(libtcod.EVENT_KEY_PRESS | libtcod.EVENT_MOUSE, key, mouse)

        delta_time = libtcod.sys_get_last_frame_length()
        #render the screen
        if not local:

            ##Clear the characters from screen.
            for object_ in R.world_obj:
                object_.clear(cam_x, cam_y)

            for city in cities:
                for merchant in city.trade_house.caravans_out:
                    merchant.clear(cam_x, cam_y)

            #handles the keys and exit if needed.
            player_action = handle_keys()
            if player_action == "exit":
                save_game()
                break
            if not pause:  #and not player_turn:
                advance_time()
                #player_turn = True

            handle_mouse()
            render_all()

        else:

            #            for object_ in R.locale_obj:
            #                object_.clear(cam_x,cam_y)
            #
            #            you.clear(cam_x, cam_y)

            #handles the keys and exit if needed.
            player_action = handle_keys()
            if player_action == "exit":
                save_game()
                break

            handle_mouse()
            render_local()

        if R.msg_redraw == True:
            update_msg_bar()
Ejemplo n.º 24
0
 def choose_spell(self):
     self.list_spells()
     key = lcod.Key()
     mouse = lcod.Mouse()
     lcod.sys_check_for_event(lcod.EVENT_KEY_PRESS, key, mouse)
     key_char = chr(key)
     if key_char in ['1', '2', '3', '4', '5', '6', '7', '8', '9']:
         key = int(key_char)
         chosen_spell = self.spells[1 - key]
     else:
         chosen_spell = self.spells[0]
     return chosen_spell
Ejemplo n.º 25
0
def main():

    libtcod.console_set_custom_font('arial10x10.png', libtcod.FONT_TYPE_GREYSCALE | libtcod.FONT_LAYOUT_TCOD)

    libtcod.console_init_root(screen_width, screen_height, 'libtcod tutorial revised', False)
    con = libtcod.console_new(screen_width, screen_height)
    dialog_prompt = DialogPrompt(dialog_pos_x, dialog_pos_y, "npc_dialog", dialog_width, dialog_height, con)

    game_map = GameMap(map_width, map_height)
    game_map.switch_map(0)

    fov_recomputer = True


    game_entities = []
    dialog_entities = []
    player = GameObject(3, 3, '@', libtcod.white, "Hero", True)
    npc = GameObject(int(screen_width / 2 - 5), int(screen_height / 2), '@', libtcod.yellow, "Bad Guy", True)
    game_entities.append(player)
    game_entities.append(npc)
    key= libtcod.Key()
    mouse = libtcod.Mouse()
    libtcod.console_set_window_title(game_title+ " - " + game_map.map_name)
    while not libtcod.console_is_window_closed():
        libtcod.sys_check_for_event(libtcod.EVENT_KEY_PRESS, key, mouse)
        draw_all(con, game_entities, game_map, screen_width, screen_height)
        libtcod.console_flush()
        clear_all(con, game_entities)
        if key.c == ord('a'):
            dialog_prompt.npc_dialog('main')
        action = handle_keys(key)

        move = action.get('move')
        exit = action.get('exit')

        if move:
            dx, dy = move

            if not game_map.is_blocked(player.x + dx, player.y + dy) and not game_map.is_transport(player.x + dx, player.y + dy):
                game_map.unblock(player.x, player.y)
                player.move(dx,dy)
            elif game_map.is_transport(player.x + dx, player.y + dy):
                transport = game_map.spaces[player.x + dx][player.y + dy].transport
                game_map.switch_map(transport.new_map_index)
                libtcod.console_set_window_title( game_title + " - " + game_map.map_name)
                game_map.unblock(player.x, player.y)
                player.move(dx , dy )
                player.move(transport.dx, transport.dy)


        if key.vk == libtcod.KEY_ESCAPE:
            return True
        game_map.update_blocked(game_entities)
Ejemplo n.º 26
0
def main():
    screen_width = 80
    screen_height = 50

    key = libtcod.Key()
    mouse = libtcod.Mouse()
    
    libtcod.console_set_custom_font('arial10x10.png', libtcod.FONT_TYPE_GREYSCALE | libtcod.FONT_LAYOUT_TCOD)
    libtcod.console_init_root(screen_width, screen_height, 'Oh, Sheep!', False)

    con = libtcod.console_new(screen_width, screen_height)
    panel = libtcod.console_new(screen_width, panel_height)
Ejemplo n.º 27
0
def play_game():
    #Start up the main game loop so the game can begin playing
    global key, mouse, game_state, examineText

    player_action = None

    mouse = libtcod.Mouse()
    key = libtcod.Key()

    while not libtcod.console_is_window_closed():
        libtcod.sys_check_for_event(
            libtcod.EVENT_KEY_PRESS | libtcod.EVENT_MOUSE, key, mouse)

        #Render the map, and all objects
        render_all()

        libtcod.console_flush()

        check_level_up()

        # Stop character trails by placing a space where the object is. If they don't move, their icon will
        # overwrite this
        for object in objects:
            object.clear(con)

        #Decide what to do. If the escape key is pressed, handle_keys returns true, and we exit the game, otherwise,
        #we process the key press accordingly
        player_action = handle_keys()
        if player_action == 'exit':
            save_game()
            break

        player_alive = player.check_if_dead()
        if not player_alive:
            game_state = 'dead'

        #Let the monsters take their turn
        if game_state == 'playing' and player_action != 'didnt-take-turn' and player_action != 'examining':
            for object in objects:
                if object.ai:
                    messages = object.ai.take_turn(map, fov_map, player,
                                                   objects)
                    if len(messages) > 0:
                        for success, line, color in messages:
                            message(line, color)
        elif player_action == 'examining':
            #The player is examining an item. We need to clear any other menus (such as the examine menu) so the
            #examine details screen can show
            render_all()
            libtcod.console_flush()
            #Show the examine details screen
            msgbox(examineText, CHARACTER_SCREEN_WIDTH)
Ejemplo n.º 28
0
def main():
    screen_width = 80  #set screen width and height as integers
    screen_height = 50

    player = Entity(int(screen_width / 2), int(screen_height / 2), '@',
                    libtcod.white)
    npc = Entity(int(screen_width / 2 - 5), int(screen_height / 2), '@',
                 libtcod.yellow)
    entities = [npc, player]

    libtcod.console_set_custom_font('arial10x10.png',
                                    libtcod.FONT_TYPE_GREYSCALE
                                    | libtcod.FONT_LAYOUT_TCOD)  #set a font

    libtcod.console_init_root(screen_width, screen_height, 'py rogue',
                              False)  #actually generate the window

    con = libtcod.console_new(screen_width, screen_height)

    key = libtcod.Key()  #holds keyboard and mouse input in variables
    mouse = libtcod.Mouse()

    while not libtcod.console_is_window_closed(
    ):  #a loop that keeps the game running esentially
        libtcod.sys_check_for_event(
            libtcod.EVENT_KEY_PRESS, key,
            mouse)  #updates key and mouse with user inputs

        libtcod.console_set_default_foreground(con, libtcod.white)
        libtcod.console_put_char(con, player_x, player_y, '@',
                                 libtcod.BKGND_NONE)
        libtcod.console_blit(con, 0, 0, screen_width, screen_height, 0, 0, 0)
        libtcod.console_flush()  #updates the screen constantly

        libtcod.console_put_char(con, player_x, player_y, ' ',
                                 libtcod.BKGND_NONE)

        action = handle_keys(key)

        move = action.get('move')
        exit = action.get('exit')
        fullscreen = action.get('fullscreen')

        if move:
            dx, dy = move
            player.move(dx, dy)

        if exit:
            return True

        if fullscreen:
            libtcod.console_set_fullscreen(not libtcod.console_is_fullscreen())
Ejemplo n.º 29
0
def main():
    screen_width = 80
    screen_height = 50

    map_width = 80
    map_height = 45

    colors = {
        "dark_wall": libtcod.Color(0, 0, 100),
        "dark_ground": libtcod.Color(50, 50, 150)
    }

    player = Entity(screen_width // 2, screen_height // 2, '@', libtcod.white)
    npc = Entity(screen_width // 2 - 5, screen_height // 2, '@', libtcod.red)
    entities = [npc, player]

    libtcod.console_set_custom_font("arial10x10.png", libtcod.FONT_TYPE_GREYSCALE | libtcod.FONT_LAYOUT_TCOD)

    libtcod.console_init_root(screen_width, screen_height, "libtcod tutorial revisited", False)

    con = libtcod.console_new(screen_width, screen_height)

    game_map = GameMap(map_width, map_height)

    key = libtcod.Key()
    mouse = libtcod.Mouse()

    while not libtcod.console_is_window_closed():
        libtcod.sys_check_for_event(libtcod.EVENT_KEY_PRESS, key, mouse)

        render_all(con, entities, game_map, screen_width, screen_height, colors)

        libtcod.console_flush()

        clear_all(con, entities)

        action = handle_keys(key)

        move = action.get('move')
        playerquit = action.get('exit')
        fullscreen = action.get('fullscreen')

        if move:
            dx, dy = move
            if not game_map.is_blocked(player.x + dx, player.y + dy):
                player.move(dx, dy)

        if playerquit:
            return True

        if fullscreen:
            libtcod.console_set_fullscreen(not libtcod.console_is_fullscreen())
Ejemplo n.º 30
0
def check_for_key_events():
    """ Check for all key events. """

    # Set mouse and keys.
    mouse = roguelib.Mouse()
    key = roguelib.Key()

    # Check for events.
    roguelib.sys_check_for_event(
        roguelib.EVENT_KEY_PRESS | roguelib.EVENT_MOUSE, key, mouse)

    # Return events.
    return mouse, key