def __init__(self, root_path): self.root_path = root_path self.limit_fps = 60 self.is_done = False self.MAP_TILES_X = 80 self.MAP_TILES_Y = 50 self.SCREEN_TILES_X = self.MAP_TILES_X self.SCREEN_TILES_Y = self.MAP_TILES_Y self.entities = [] self.player = None self.map = Map(self.MAP_TILES_X, self.MAP_TILES_Y, self) self.map.debug_show_colors = True self.input_mode = InputMode.GAME self.panel_height = 7 self.bar_width = 20 self.panel_y = self.SCREEN_TILES_Y - self.panel_height self.fov_recompute = True self.update_sim = True self.visible_tiles = [] # todo: move to map self.use_fog_of_war = False self.torch_radius = 10 self.draw_hp = False self.init() path = os.path.join(self.root_path, 'fonts', 'arial12x12.png') tdl.set_font(path, greyscale=True, altLayout=True) self.root_console = tdl.init(self.SCREEN_TILES_X, self.SCREEN_TILES_Y, title='tcod demo', fullscreen=False) self.con = tdl.Console(self.SCREEN_TILES_X, self.SCREEN_TILES_Y) self.con_console = tdl.Console(self.SCREEN_TILES_X, self.panel_height) tdl.setFPS(self.limit_fps) logger.debug("FPS: {}".format(self.limit_fps))
def __init__(self): tdl.set_font('arial10x10.png', greyscale=True, altLayout=True) self.console = tdl.init(self.SCREEN_WIDTH, self.SCREEN_HEIGHT, title="zz", fullscreen=False) tdl.setFPS(self.LIMIT_FPS) self.objects = [] self.player = Player() self.objects.append(self.player)
def _setup(self): self.SCREEN_WIDTH = 80 self.SCREEN_HEIGHT = 50 self.LIMIT_FPS = 20 tdl.set_font('arial10x10.png', greyscale=True, altLayout=True) self.root = tdl.init(self.SCREEN_WIDTH, self.SCREEN_HEIGHT, title='AsciiRPG', fullscreen=False) tdl.setFPS(self.LIMIT_FPS) # Create an offscreen console self.console = tdl.Console(self.SCREEN_WIDTH, self.SCREEN_HEIGHT) # Map self.map = Map() self.map.create(self.SCREEN_HEIGHT, self.SCREEN_WIDTH) try: player_y = 1 player_x = 1 while self.map.tiles[player_y][player_x].blocked: player_y = randint(0, self.map.WIDTH - 1) player_x = randint(0, self.map.HEIGHT - 1) except: print("out of range") # Spawn player, first specify Y (which of the top tiles to start at), then X (which of the horizontal tiles to start at) self.player = Player(player_y, player_x, (255,255,255)) #self.cat = Cat(self.SCREEN_WIDTH + 4, self.SCREEN_HEIGHT, (255,255,255)) self.entities = [self.player]
def re_init_font(self): # allows reloading of font path = random_font_path(PATH_APP_ROOT) logger.debug("font: ", path) tdl.set_font(path, greyscale=True, altLayout=True) self.root_console = tdl.init(self.SCREEN_TILES_X, self.SCREEN_TILES_Y, title='tcod demo', fullscreen=False) self.con = tdl.Console(self.SCREEN_TILES_X, self.SCREEN_TILES_Y) tdl.setFPS(LIMIT_FPS)
def main(): global root_view # setup to start the TDL and small consoles font = os.path.join(assets_dir, "arial10x10.png") tdl.set_font(font, greyscale=True, altLayout=True) tdl.setFPS(LIMIT_FPS) root_view = tdl.init(width=SCREEN_WIDTH, height=SCREEN_HEIGHT, title="Roguelike", fullscreen=False) main_menu()
def Main(): horzDirection = 1 globalCounter = 0 delay = 20 Score = 0 Hardness = 0 SCREEN_WIDTH = 80 SCREEN_HEIGHT = 50 LIMIT_FPS = 20 tdl.set_font('arial10x10.png', greyscale=True, altLayout=True) console = tdl.init(SCREEN_WIDTH, SCREEN_HEIGHT, title="Space Invaders", fullscreen=False) tdl.setFPS(LIMIT_FPS) while not tdl.event.is_window_closed(): screen.Update() globalCounter+=1 if globalCounter >= delay - Hardness: globalCounter=0 horzDirection *= NeedToChangeDir() for en in enemies: en.TryToMove(Vector(horzDirection, 0)) PrintScreen(console) tdl.flush() print("Score: " + str(Score)) if not screen.Objects.__contains__(player): break for en in enemies: if not screen.Objects.__contains__(en): enemies.remove(en) Score+=100 tmp = Score/1000 if Hardness<19: Hardness = int(tmp) if Hardness>18: Hardness = 18 if len(enemies) == 0: InitEnemies() print("Game Over! Your Score is {0}".format(Score))
def __init__(self, screenWidth, screenHeight, fps): self.screenWidth = screenWidth self.screenHeight = screenHeight #set up window through tdl tdl.set_font('arial10x10.png', greyscale=True, altLayout=True) self.root = tdl.init(screenWidth, screenHeight, title="Roguelike", fullscreen=False) self.console = tdl.Console(screenWidth, screenHeight) tdl.setFPS(fps) self.objects = []
def __init__(self): tdl.set_font('arial10x10.png', greyscale=True, altLayout=True) self.root = tdl.init(SCREEN_WIDTH, SCREEN_HEIGHT, title="Roguelike", fullscreen=False) tdl.setFPS(LIMIT_FPS) self.con = tdl.Console(MAP_WIDTH, MAP_HEIGHT) self.panel = tdl.Console(SCREEN_WIDTH, PANEL_HEIGHT) self.panel2 = tdl.Console(PANEL_2_WIDTH, PANEL_2_HEIGHT) self.visible_tiles = [] self.fov_recompute = True self.bg_img = image_load('menu_background.png') self.game_msgs = []
def initialize(): global root, con, objects, map # Set up console tdl.set_font(FONT, greyscale=False, altLayout=False) tdl.setFPS(LIMIT_FPS) # Root Console root = tdl.init(SCREEN_WIDTH, SCREEN_HEIGHT, title="Arroguella", fullscreen=False) # Game Console con = tdl.Console(SCREEN_WIDTH, SCREEN_HEIGHT) con.clear(fg=(0, 0, 0), bg=(0, 0, 0)) # Set up map map = m.Map(width=SCREEN_WIDTH, height=SCREEN_HEIGHT) # # Optional: Print room labels # for k, r in map.rooms.items(): # objects[k] = obj.GameObject(*r.center(), k, color=(20, 20, 20)) # Set up initial objects player = p.Player(*map.player_start) objects['player'] = player
player.move(1, 0) elif user_input.key == 'ESCAPE': return True #Exit game elif user_input.key == 'ENTER': print(player.x, player.y) ############################################### # Main ############################################### tdl.set_font('celtic_garamond_10x10_gs_tc.png', greyscale=False, altLayout=True) #Console variable root = tdl.init(SCREEN_WIDTH, SCREEN_HEIGHT, title="Dungey Crawley", fullscreen=False) con = tdl.Console(SCREEN_WIDTH, SCREEN_HEIGHT) tdl.setFPS(LIMIT_FPS) #Realtime (comment for turn-based) make_map() #Testing roomGen roomGenerator(cur_map) #Generate Objects while cur_map[playerx][playery].blocked_sight: playerx = random.randint(5, MAX_MAP_WIDTH - 5) playery = random.randint(5, MAX_MAP_HEIGHT - 5) #player = GameObject(playerx, playery, '@', (255,255,255)) npc1 = GameObject(random.randint(5, MAX_MAP_WIDTH - 5), random.randint(5, MAX_MAP_HEIGHT - 5), 'X', (0,255,255))
def save_game(): """ open a new empty shelve (possibly overwriting an old one) to write the game data """ with shelve.open('savegame', 'n') as savefile: savefile['my_map'] = my_map savefile['objects'] = objects # index of player in objects list, instead of player's own ref savefile['player_index'] = objects.index(player) savefile['inventory'] = inventory savefile['game_msgs'] = game_msgs savefile['game_state'] = game_state savefile.close() ################################## # GUI initialization & Main Loop # ################################## tdl.set_font('dundalk12x12_gs_tc.png', greyscale=True, altLayout=True) root = tdl.init(SCREEN_WIDTH, SCREEN_HEIGHT, title="Roguelike", fullscreen=False) tdl.setFPS(LIMIT_FPS) con = tdl.Console(MAP_WIDTH, MAP_HEIGHT) panel = tdl.Console(SCREEN_WIDTH, PANEL_HEIGHT) main_menu()
""" import sys sys.path.insert(0, '../') import tdl WIDTH, HEIGHT = 80, 60 console = tdl.init(WIDTH, HEIGHT) # the scrolling text window textWindow = tdl.Window(console, 0, 0, WIDTH, -2) # slow down the program so that the user can more clearly see the motion events tdl.setFPS(24) while 1: event = tdl.event.wait() print(event) if event.type == 'QUIT': raise SystemExit() elif event.type == 'MOUSEMOTION': # clear and print to the bottom of the console console.draw_rect(0, HEIGHT - 1, None, None, ' ') console.draw_str(0, HEIGHT - 1, 'MOUSEMOTION event - pos=%i,%i cell=%i,%i motion=%i,%i cellmotion=%i,%i' % (event.pos + event.cell + event.motion + event.cellmotion)) continue # prevent scrolling textWindow.scroll(0, -1) if event.type == 'KEYDOWN' or event.type == 'KEYUP': textWindow.draw_str(0, HEIGHT-3, '%s event - char=%s key=%s alt=%i control=%i shift=%i' % (event.type.ljust(7), repr(event.char), repr(event.key), event.alt, event.control, event.shift))
# movement keys if user_input.key == 'UP': playery -= 1 elif user_input.key == 'DOWN': playery += 1 elif user_input.key == 'LEFT': playerx -= 1 elif user_input.key == 'RIGHT': playerx += 1 tdl.set_font('dejavu10x10_gs_tc.png', greyscale=True, altLayout=True) console = tdl.init(SCREEN_WIDTH, SCREEN_HEIGHT, title="Roguelike", fullscreen=False) tdl.setFPS(LIMIT_FPS) # for real-time game, ignore if turn-based playerx = SCREEN_WIDTH // 2 playery = SCREEN_HEIGHT // 2 while not tdl.event.is_window_closed(): console.draw_char(playerx, playery, '@', bg=None, fg=(255, 255, 255)) tdl.flush() console.draw_char(playerx, playery, ' ', bg=None) # handle keys and exit game if needed exit_game = handle_keys() if exit_game: break
elif user_input.key == "RIGHT": player_move_or_attack(1, 0) else: return "didnt-take-turn" tdl.set_font("arial10x10.png", greyscale=True, altLayout=True) #Uses a font I downlaoded from some website con = tdl.Console(SCREEN_WIDTH, SCREEN_HEIGHT) #uses earlier variables to set sceren size root = tdl.init( SCREEN_WIDTH, SCREEN_HEIGHT, title="BOGTWO", fullscreen=False ) #this is a hidden background console, I think to do some behid the scenes calculations tdl.setFPS(LIMIT_FPS) #I guess FPS limit matters? player = GameObject(SCREEN_WIDTH // 2, SCREEN_HEIGHT // 2, "@", "Player", colors.white, blocks=True) #Creates player represetned as an @ symbol objects = [player] #these are all the objects in the game. make_map() fov_recompute = True game_state = "playing" player_action = None
""" import sys sys.path.insert(0, '../') import tdl WIDTH, HEIGHT = 80, 60 console = tdl.init(WIDTH, HEIGHT) # the scrolling text window textWindow = tdl.Window(console, 0, 0, WIDTH, -2) # slow down the program so that the user can more clearly see the motion events tdl.setFPS(24) while 1: event = tdl.event.wait() print(event) if event.type == 'QUIT': raise SystemExit() elif event.type == 'MOUSEMOTION': # clear and print to the bottom of the console console.drawRect(0, HEIGHT - 1, None, None, ' ') console.drawStr(0, HEIGHT - 1, 'MOUSEMOTION event - pos=%i,%i cell=%i,%i motion=%i,%i cellmotion=%i,%i' % (event.pos + event.cell + event.motion + event.cellmotion)) continue # prevent scrolling textWindow.scroll(0, -1) if event.type == 'KEYDOWN' or event.type == 'KEYUP': textWindow.drawStr(0, HEIGHT-3, '%s event - char=%s key=%s alt=%i control=%i shift=%i' % (event.type.ljust(7), repr(event.char), repr(event.key), event.alt, event.control, event.shift))
def main_loop(): ''' begin main game loop ''' # limit the game's FPS tdl.setFPS(settings.LIMIT_FPS) # set the gamestate to the player's turn gv.gamestate = GameStates.PLAYERS_TURN turnnumber = 0 while not tdl.event.is_window_closed(): turnnumber += 1 if gv.stairs_down.descended: #msgbox('You descend further downwards {}'.format(settings.DUNGEONNAME), colors.dark_red) gen_game(newgame=False) render_all() tdl.flush() for obj in gv.gameobjects: obj.clear(gv.con) #gv.player.is_active = True # Player is considered active by default print('main loop waiting on input in turn {0}!'.format(turnnumber)) player_action = handle_keys(tdl.event.key_wait()) #print('Gamestate: {}.format(gv.gamestate)) # if the action is recognized, proceed if not player_action == None: if 'exit' in player_action: # if the player action is exit, prompt if he wants to quit the game if gv.gamestate == GameStates.PLAYERS_TURN: choice = menu( 'Save & Quit the {}?'.format(settings.DUNGEONNAME), ['Yes', 'No'], 24) if choice == 0: save_game() break elif gv.gamestate == GameStates.PLAYER_DEAD: choice = menu('Quit the {}?'.format(settings.DUNGEONNAME), ['Yes', 'No'], 24) if choice == 0: break # Esc cancels inventory interaction or cursor mode elif 'cancel' in player_action and gv.gamestate in [ GameStates.INVENTORY_ACTIVE, GameStates.CURSOR_ACTIVE ]: gv.gamestate = GameStates.PLAYERS_TURN elif 'fullscreen' in player_action: tdl.set_fullscreen(not tdl.get_fullscreen()) elif 'manual' in player_action: display_manual() else: if gv.gamestate in [ GameStates.PLAYERS_TURN, GameStates.CURSOR_ACTIVE, GameStates.INVENTORY_ACTIVE ]: print( 'Gamestate: {}, should be PLAYER_ACTIVE or CURSOR_ACTIVE' .format(gv.gamestate)) process_input(player_action) # If player has done an active turn if gv.gamestate == GameStates.ENEMY_TURN: #AI takes turn, if player is not considered inactive and is roughly in FOV for obj in gv.actors: if (obj.distance_to(gv.player) <= settings.TORCH_RADIUS + 2) and obj is not gv.player: obj.ai.take_turn() if gv.gamestate is not GameStates.PLAYER_DEAD: gv.gamestate = GameStates.PLAYERS_TURN
MSG_X = BAR_WIDTH + 2 MSG_WIDTH = SCREEN_WIDTH - BAR_WIDTH - 2 MSG_HEIGHT = PANEL_HEIGHT - 1 INVENTORY_WIDTH = 50 LIMIT_FPS = 20 playerX = SCREEN_WIDTH/2 playerY = SCREEN_HEIGHT/2 MOUSE_COORD = {'x':0, 'y':0} console = tdl.init(SCREEN_WIDTH, SCREEN_HEIGHT, title = "Roguelike") panel = tdl.Console(SCREEN_WIDTH, PANEL_HEIGHT) con = tdl.Console(MAP_WIDTH, MAP_HEIGHT) tdl.setFPS(LIMIT_FPS) ROOM_MAX_SIZE = 10 ROOM_MIN_SIZE = 6 MAX_ROOMS = 30 MAX_ROOM_ITEMS = 2 fov_recompute = False FOV_ALGO = 0 #default FOV algorithm FOV_LIGHT_WALLS = True TORCH_RADIUS = 10 HEAL_AMOUNT = 4 color_dark_wall = [0, 0, 100] color_light_wall = [130, 110, 50]
def start(): game_title = f'TSHRD v0.1' # set up parser parser = argparse.ArgumentParser(description=game_title) # handle seed parser.add_argument('-s', '--seed', help='Set the seed for the game') # default character quick start parser.add_argument('-q', '--quick', help='Quick start with default character', action='store_true', default=False) parsed_args = parser.parse_args() # set seed if provided if parsed_args.seed: try: seed = int(parsed_args.seed) random.seed(seed) except ValueError as e: print(f'Invalid seed argument: {sys.argv[1]}') quick_skip = parsed_args.quick active_game = None active_state = GameState.GAME_RESTART font_path = os.path.join(os.path.dirname(__file__), 'arial10x10.png') tdl.set_font(font_path, greyscale=True, altLayout=True) root_console = tdl.init(80, 50, title=game_title, fullscreen=False) tdl.setFPS(20) state_handlers = { GameState.ROOM: state_in_room.state, GameState.MOVE_NORTH: state_move.state, GameState.MOVE_WEST: state_move.state, GameState.MOVE_EAST: state_move.state, GameState.MOVE_SOUTH: state_move.state, GameState.ENCOUNTER_MONSTER: state_encounter_monster.state, GameState.ENCOUNTER_TRAP: state_encounter_trap.state, GameState.ENCOUNTER_SHRINE: state_encounter_shrine.state, GameState.ENCOUNTER_TREASURE: state_encounter_treasure.state, GameState.GAME_OVER: state_game_over.state, GameState.MAP: state_map.state, GameState.NEXT_LEVEL: state_next_level.state, GameState.INVENTORY: state_inventory.state, GameState.CHARACTER_SHEET: state_character.state, GameState.CHARACTER_CREATION: state_character_create.state } while not tdl.event.is_window_closed() and active_state != GameState.CLOSE: if active_state == GameState.GAME_RESTART: # create a new game active_game = GameData() if quick_skip: # create default character active_game.the_player = create_player() active_state = GameState.ROOM else: active_state = GameState.CHARACTER_CREATION continue active_game.state = active_state try: state_update = state_handlers[active_state](active_game, root_console) if state_update: active_state = state_update except WindowClosedException: # game over break