PyWeek Day 1

15th April 2018

Beginning a PyWeek25 entry. The theme is "Two Worlds" and I'm loving Rogue at the moment, so I decided to make a roguelike with a distinction between normal dungeons and magic dungeons. On day 1 I've made a dungeon generator and can explore it with a player. Making use of the tcod Python library.

Exploring The Normal World
Exploring The Normal World

ROGUE: THROUGH The Veil is yet another roguelike. In this twist on the classic game, you are constrained to a dungeon of your normal, everyday monsters and items. However, just beyond the veil there exists a magical world where incredible creatures roam and mystical items await discovery. During your search for the Amulet of Yendor, you will discover how to go beyond the veil, transitioning between the realms of reality and the magical. You will be able to bring magical items back to the real world to aid you in your quest, but beware, the magical world is a dangerous place.


THERE’S NO sounds and only a basic GUI with ASCII characters, so not much needed! I’m using tcod or tdl or libtcod, depending on what you call it! It’s a Python binding to a C library for building roguelikes, and it’s pretty nice to use. The only other Python library I’ve need is networkx, which let me consider my rooms as nodes and the passageways as edges between them. Considering the dungeon as a graph let me easily connect all the rooms together in different ways.

Day 1

WORKED PRETTY much flat out today to put together the frame around which the game will be built. Also set up the github repo.

The biggest part of the day has been spent of the dungeon generation. I’ve opted for a quite traditional 3x3 grid of rooms. I’m generating them by choosing a width and height at random, then placing the room within a bounded section at random. From there I’m using a depth-first search or breadth-first search to create a spanning tree of the rooms. I’m making doors to the rooms on the fly as need, so there’s only one door per side and the passages connecting the doors are distinct from the rooms. Once I’ve got a spanning tree I know all rooms are connected, but I want there to be a chance of loops in the paths and the chance to have loops through rooms too, so I choose a few other random connections and add them in too.

The tcod library I’m using makes it relatively easy to work with the map, it’ll work out if a tile can be walked on or if it’s transparent for me, but I had to add in whether it had been explored yet or not to get fog-of-war. From there I’m just calling tcod‘s drawing functions to handle all the GUI and user input.

Now I have a player who can move around and explore a dungeon, in the magic world or real world. Next I need to make some GUI additions such as the health bar, XP info, level info and message panel. Then it’s on to monsters and items.

Exploring The Magic World
Exploring The Magic World

Post Tags

All Tags

LIFE IS better when we share.