Updated 2019 tutorial for using tcod 21.2.0, numpy 2.x and modern python#42
Open
Darky-Lucera wants to merge 1 commit into
Open
Updated 2019 tutorial for using tcod 21.2.0, numpy 2.x and modern python#42Darky-Lucera wants to merge 1 commit into
Darky-Lucera wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR updates the 2019 tutorial to work with tcod 21.2.0 and NumPy 2.x, bringing them in line with the current library API.
The changes are intentionally minimal and surgical: only API-level replacements, no rewriting of game logic or tutorial structure.
Changes
The 2019 series used the legacy
libtcodAPI throughout. Every call has been replaced with its modern equivalent:import tcod as libtcodimport tcodlibtcod.console_set_custom_font(...)tcod.tileset.load_tilesheet(...)libtcod.console_init_root(...)with tcod.context.new(...) as context:libtcod.console_new(w, h)tcod.console.Console(w, h, order='F')libtcod.console_flush()context.present(root_console)while not libtcod.console_is_window_closed()while True:(context manager handles cleanup)libtcod.sys_check_for_event(...)/console_check_for_keypress()for event in tcod.event.wait():key.vk == libtcod.KEY_UPevent.sym == tcod.event.KeySym.UPkey.laltevent.mod & tcod.event.Modifier.LALTlibtcod.map_new()/map_set_properties()/map_compute_fov()numpyarray +tcod.map.compute_fov()with.Ttransposelibtcod.map_is_in_fov(fov_map, x, y)fov_map[x, y](array indexing)libtcod.console_set_default_foreground+console_put_charcon.print(x, y, char, fg=color)libtcod.console_print_ex(...)console.print(x, y, text)libtcod.console_get_height_rect(...)con.get_height_rect(...)libtcod.console_print_rect_ex(...)window.print_box(...)libtcod.console_blit(win, 0, 0, w, h, 0, x, y, 1.0, 0.7)window.blit(dest=root_console, dest_x=x, dest_y=y, fg_alpha=1.0, bg_alpha=0.7)libtcod.Color(r, g, b)/ named color constants(r, g, b)libtcod.set_fullscreen(...)context.sdl_window.fullscreen = not context.sdl_window.fullscreenThe
main_menubackground image (libtcod.image_load/libtcod.image_blit_2x) has no equivalent in the modern API and was removed; the title text is now printed directly to the root console. The surrounding narrative was updated accordingly.root_consolewas threaded through the call chain (menu,inventory_menu,level_up_menu,message_box,character_screen,render_all,play_game,main) as required by the new blit API.Python minimum version updated to 3.8 (part-0).
Why these tutorials are still worth maintaining
I'd like to make a case for keeping both series alive and up to date.
These are still among the best beginner roguelike tutorials available. The structure — 14 parts, building a complete dungeon crawler from scratch, covering everything from a moving
@to saving/loading, inventory, spells, equipment and procedural generation — is genuinely hard to find elsewhere at this level of quality and completeness. The RogueBasin lineage gives them credibility, and the Python + tcod combination is still the most accessible entry point for someone who wants to write a roguelike without wrestling with C++ or a full game engine.The 2019 series and v2 serve different audiences, and both have real value:
The 2019 series is the better tutorial for a complete beginner. Part 1 is 40 lines and you have a moving
@on screen. The patterns it teaches —handle_keysreturning dicts,GameStatesenum, step-by-step render functions — are "visible" complexity: the code looks like what it does. The fact that those patterns don't scale well is actually pedagogically useful: you experience the pain of an ever-growingif/elifinengine.pyand discover why you'd want to refactor. That motivated discovery is worth more than copying a cleanAction + EventHandlerpattern without knowing what problem it solves.The v2 series is the better tutorial if you already have some OOP experience and want to end up with a codebase you can actually extend. The Action-based input, interchangeable EventHandlers as a state machine, NumPy for the map and FOV, and
pickle+lzmaserialization of the whole Engine are all genuinely good architectural decisions that hold up as the codebase grows. The type hints andfrom __future__ import annotationsalso teach habits that matter in real Python projects.In short: the 2019 series teaches you how to build a roguelike; the v2 teaches you how to build one well. Both are useful. Keeping them up to date means both remain usable entry points rather than historical artifacts that confuse beginners with deprecated API calls and
AttributeError: module 'numpy' has no attribute 'bool'.