r/roguelikedev • u/KelseyFrog • Jul 05 '22
RoguelikeDev Does The Complete Roguelike Tutorial - Week 2
Congratulations for making it to the second week of the RoguelikeDev Does the Complete Roguelike Tutorial! This week is all about setting up the map and generating a dungeon.
Part 2 - The generic Entity, the render functions, and the map
Create the player entity, tiles, and game map.
Creating a procedurally generated dungeon!
Of course, we also have FAQ Friday posts that relate to this week's material
- #3: The Game Loop (revisited)
- #4: World Architecture (revisited)
- #22: Map Generation (revisited)
- #23: Map Design (revisited)
- #53: Seeds
- #54: Map Prefabs
- #71: Movement
- #75: Procedural Generation
Feel free to work out any problems, brainstorm ideas, share progress, and as usual enjoy tangential chatting. :)
51
Upvotes
2
u/Felix9876543210 Jul 11 '22
How would you suggest I approach this event as a "medium-level" programmer?
I think one way is to read the tutorial and type or ctrl-c/ctrl-v the little code snippets into your code as you go along. The opposite approach would be to just do your own thing completely and just orient yourself on the milestones/features.
Maybe I'm a more experienced programmer than the intended audience for. I think I can understand what the code does even if I skipped every other week or two weeks. Last week I just read the tutorial first and then copied the whole code over from github, because copying it line by line was too tedious for me. But that's not the idea is it? Then there would really be no benefit over just reading.
I don't want to completely think of my own code, because I'm afraid I'd get stuck somewhere and not finish the project. I have never finished a roguelike yet.
Is there some middle ground between following the tutorial exactly and completely inventing your own architecture? If you do that, how do you do it? Would you maybe recommend that I suck up my laziness and copy the lines one by one anyway? Or another idea would be that I start my own roguelike with the very last code version of the tutorial.
9
u/HexDecimal libtcod maintainer | mastodon.gamedev.place/@HexDecimal Jul 05 '22 edited Jul 05 '22
GitHub | Screenshot (Cave generation)
I've decided to use cellular automata for level generation due to how simple it is to start with and how easy it'd be to modularize it. Unfortunately I'm too used to how Numpy standardizes multi-dimensional arrays and I really hate to reimplement basic functionality in other languages. It's taking a lot of effort to write a hole detection and filling algorithm in C++ when in Python I could just use scipy.ndimage.label and be done already.
The rest of the code is trying to do the absolute minimum. I'm trying to make slow careful progress and not burn out. I've noticed that the way I've ended up organizing my types in C++ is a lot cleaner than in my previous projects.
Edit: Playable
I now have holes filled in and the player is placed in a random free spot. I've now uploaded the Emscripten builds.
8
u/cordinc Jul 05 '22
Parts 2/3 in vanilla Javascript with ROT.js: Github & "Playable" version
Much of the restructuring I was thinking needed to be done last week was in Part2. That is nice, I should trust the tute more. I have some notes on other possible things but will leave them for now as maybe they are worked on in later parts too.
Had an issue with Rot.js that means I'm going off tute in one area. I could not change the tiles' colour. Banged my head against that for a bit before just going to ascii. On the other hand, the dungeon procgen with the library was super easy.
7
u/LukeMootoo Jul 05 '22
Continuing with native JavaScript, no libraries. Part 2 is up, still working on Part 3.
My notes along with copious comments in my code, and the live program are all at the links.
When I look back at my notes for my older attempt at the CodingCookies tutorial, I see that I spent most of my time trying to figure out what things did and how they worked. I looked up a lot of words that I didn't know and searched for functions in the library to see what they did. Apparently I spent a lot of time and frustration discovering that "Goldenrod" was a keyword for a colour as defined by the library.
Now that I'm without a library, I'm spending time figuring out how to actually implement things, but at least I have a better idea of how the things I implement are working.
I'm a bit concerned about how much technical debt I'm building up for the things that I've just kluged together without really knowing how JS works or how its features should be used. But having looked ahead a bit I'm pretty sure that I can just keep on klugeing and then can just write another game with the lessons learned. Not like this code base is going to be maintained by future generations.
On the other hand, maybe I'll have an epiphany in week 4 and go back for a big refactor.
7
u/redblobgames tutorials Jul 05 '22
I'm trying to adapt the python tutorial to make a "fortress mode" style game rather than "adventure mode" style game. I don't yet know whether that will work. I've just started Week 2.
I'm still trying to figure out how to do this, especially the UI for building things.
6
u/ErikEngineEngineer Jul 05 '22
Hey am I the only one getting a 'Cannot access the database' error on roguebasin.com? I'm following the C++ Tutorial and can't continue atm. Does anyone know how to get part 3 without rouge basin?
6
u/FratmanBootcake Jul 05 '22 edited Jul 05 '22
I've managed to cobble some sort of pseudo random dungeon generation and have reserved some space for the log when it arrives.
The algorithm starts off with filling the map with walls before doing a drunken walk. Finally, I stamp a few rooms randomly around the map.
Here's the result
There are few issues to smooth out as the random number generation isn't very good. I currently get a seed by saving the cpu's timer when the user presses start to begin the game. Then every random number is generated by xoring the timer at the time of the call with the saved value and then doing some shifting and xoring with itself. Sometimes it sort of populates just the upper half but given how I'm doing this, I can live with that for now.
The program ROM size is currently 954 bytes.
5
u/bodiddlie Jul 06 '22
I just published Part 2 of my adaptation of the libtcod tutorial for Typescript with ROT.js on my blog. Full series as it stands here.
I also have my repo on github as well. Tagged for Part 2.
Next will be doing the python version of Part 3, adapting that to TS/ROT.js, and then writing the next tutorial post. Hopefully my work week will allow some time for that.
4
u/KCEHOBYTE bedivere Jul 05 '22
I had some free time this weekend, so I ported dungeon generation code from python 3 tutorial. Live hereapp!
Algorithm is indeed very simple but works reasonably well. Oddly enjoyable to refresh the page again and again. I could have spent more time with this one but I think I'd better invest into fov and refactoring as it might be a problem.
4
u/mrdoktorprofessor Jul 05 '22
Haven't made a whole lot of progress since last week on my LED-matrix RL (took some time off in general). This project is attempting to follow the spirit of the Python TCOD guide but will deviate significantly week to week.
Screens/gifs:
Main screen (inc other demos for fun) | RL screen | Character movement + Attacking | Sprite setup
/u/HexDecimal kindly made a PR to the Flaschen-Taschen library to make drawing faster. I need to do some code reorganization to support that, as right now I'm just using the list-of-lists style of Python 2D array and it's probably not overly optimized.
Right now I have:
Xif they die.Next steps:
GitHub will follow at some point as this is intended to be an educational outreach project (right now my kids love playing with it). The repo is a mess of demos and WIPs (falling sand and snake work right now), but I'll clean it up as I go. Interestingly, this can be run in a terminal with the Flaschen-Taschen software as well, so that's probably something I should revisit so that people don't have to buy all my hardware I have.
3
u/lagdotcom Jul 05 '22
repo | live
Just managed to finish parts 2 and 3. The compiler/driver code makes me cringe to look at now; I have some heavy refactoring in my future. Also, I have a theme idea for the roguelike I'll eventually be writing. Hopefully I won't just give up on it like 2 years ago :D
I'm no longer on a plane/in a hotel but I still don't feel like filling out the readme. This is because I have a massive headache.
3
u/WorksOnMyMachiine Jul 05 '22
Couple of things in the works because im crazy as hell and love working in various languages.
Python Repo
Main project that I will expand upon past the tutorial is python project. I didnt follow the tutorial exactly but it is close. I added a rendering class that each handler inherits from to give rendering functions (i dont like global functions) so let me know what yall think. I go back and forth with having a seperate renderer for each handler, but ill keep it for now.
Secondary projects are Java/Kotlin, typescript, C++, and Rust. To give a backstory I love rust. It is one of my absolutely favorite lanugages, so I have actually been building small roguelikes in it for a while.
Typescript Repo
This one is also one of my favorites. My main job is fullstack web development (and I love typescript) so I came across this lib `wglt` which uses webGL for rendering. It is fast and I am enjoing the project. It uses `wolf-ecs` for the ECS manager instead of actors and actions
Java Repo
This repo is just for funsies. I wanted to try java so started experimenting around. 2 branches (main & zircon). Zircon uses the zircon lib to run the game, main uses libGTX and kTerminal. Im probably going to scrap kTerminal for squib-lib tho. We will see.
Rust Repo
There are 3 branches on my rust game. `Bevy`, `bracket-bevy`, and `shipyard`. This is me experimenting with different ECS libs. I love bevy, but their state management needs work for it to be really powerful. `Bracket-bevy` is utilizing the bevy plugin for bracket-lib. Still very early development so tons of bugs, but i like it. And `shipyard` is just trying shipyard. I actually will probably abandon this branch because I prefer specs/legion/bevy to shipyard, but I gave it a chance!
I have another repo in c++ but I havent programmed in c++ since college so I wont post that. I don't want the humiliation
3
u/reuben-john Jul 05 '22
I finished up the equivalent of parts 2 and 3 using Rust and bracket-lib. I also added in a graphics layer with very basic a very basic tileset.
I will most likely expand the tileset some after we add monsters and items.
The code is available at github and week 2 is available to play here.
3
u/jneda Jul 07 '22
I just finished part 3 using PICO-8: github repository - playable on itch.io.
I realized I should definitely dive a little deeper into lua classes. For the time being I'm using functions to build custom tables with added functionality, but this won't be practical when inheritance will come into play.
I'm writing code in Visual Studio Code since PICO-8's editor, although nice, has its limits, and thus I've split the code into lua files included into the PICO-8 cartridge.
I've managed to follow along the python tutorial so far, but I'm realizing by doing so I'm not leveraging PICO-8's native features for map building and display. I've been staying on the ASCII-like track by printing chars instead of using sprites, that's why.
The main consequence is as of now, and until I figure out how to implement a viewport, the dungeon map is only 16x16. :p
But heh, baby steps.
3
u/[deleted] Jul 07 '22 edited Jul 09 '22
Zig roguelike
Finished up part 0 & 1 and am nearly done working on part-2. I told myself I would catalog the narrative of translating the tutorial to work with Zig/libtcod as I go along but that's starting to take up a lot of time. As I go the narrative might get a bit rougher and I'll rewrite that later on. Going to include a link to the draft (branch) of part 2 I have so far and update later on this weekend when I finish that and part-3. edit: merged part2 and fixed the link above.
3
u/JasonSantilli Jul 09 '22
JavaScript + rot.js
Repo | In-browser playable game
Each individual part corresponding to the output of the tcod tutorial parts are set up as tags and releases in the repo.
I finished parts 6 and 7 over the last week, so that's what you'll see in the playable version above. These parts took significantly longer than the earlier ones. A lot of that time was spent refactoring as I better understand how I want to structure things, but I think most of the time has been working around the differences in JS and rot.js. For example, in part 7 printing of the message log relies quite a bit on the magic of python's textwrap function, but JS doesn't natively have that sort of functionality, so it took a while to dig through the rot.js code and tap into the text tokenize function to get those nice truncated lines of text.
There is definitely room out there for an updated roguelike tutorial in modern JS. I've been watching what /u/bodiddlie is doing over on their blog. Cool to see someone also do this with ES6 features like classes and modules. I'll be on the lookout there for patterns I can take inspiration from.
3
u/luismars Jul 12 '22 edited Jul 13 '22
What a busy 2 weeks I've had, I even forgot to post this, so here I am posting late.
I managed to make a "retro mode" with ascii, but I'll focus more on the "modern aesthetics one".
I lost more time than I want to admit trying to come up with a "non eculidean menger sponge" map thing that I had to discard. In the end I decided to make a fixed set of 11 x 11 rooms that will act as the maze, the generator is just a random walk that creates the connections between the rooms as it goes along, allowing not connected adjacent rooms.
I also improved the UI (minimap!) and the interaction with the board.
Repo. Play online.
3
u/bodiddlie Jul 13 '22
And finally got the tutorial write up for Typescript with ROT.js done for part 3. A bit late, but better than never. Here it is. This one was fun. Gonna go start on the code for part 4 now!
2
u/TechniMan Jul 05 '22
Wait, is it seriously this time of the year again?! It only feels like a few months since the last one! Oh man, I've gotta get my butt in gear if I'm gonna get anywhere this year!
Not sure if I'll do a classic Python project, maybe try C++ or JavaScript again, or perhaps just go for Unity since I'm quite familiar with it.
2
u/revokon Jul 05 '22
My Repo
So far, not a lot of speedbumps. Implementing Bresenham's line-drawing algorithm for the hallways was a fun exercise, even if it took a couple of tries to get it right.
Some places I could spice things up include different room types, and different level generation algorithms like cellular automata or the BSP algorithm that's on Roguebasin.
2
u/makraiz Jul 07 '22
Rust Python
Updated both projects through Part 3 of the tutorial. I am quickly losing interest in the Python version, but will try to keep up with it for now.
In the Rust version, I thought I would test Bevy's batch rendering by emulating a terminal screen with 8000 sprites, which seems to work okay on my everyday pc, but very, very slow on an old machine I tested it on.
2
u/Gogodinosaur Jul 07 '22 edited Jul 07 '22
Here is my C# implementation GitHub & Generation GIF
I implemented the rectangular room and hallway generation as described in the tutorial, but since the grid here is hexagonal, I figured hexagonal rooms would be fun layered on top of the traditional rectangular rooms.
The map generator determines a number of non-intersecting rectangular rooms and connects each room with the previous room (and the last to the first) with kinda weird chunky hallways. The hallways are created by drawing a straight line between the two room centers and linearly interpolating 100 points along the line. Each point is floored and ceilinged to ints, which are used to place an open tile in the hallway. This ends up not 100% guaranteeing that two rooms will be correctly connected, but I think the effect looks nice for now and can leave columns in the halls.
A number of hexagonal rooms are then placed throughout the map. The hexagonal rooms are allowed to overlap each other and the rectangular rooms. Then it creates more hallways for the hexagonal rooms. And creates one hallway between a hexagonal room and a rectangular room.
2
u/LukeMootoo Jul 11 '22
Part 3 for Week 2 is up!
This is my vanilla JS / no library effort. Instead of carving out rectangles to make a dungeon, I decided to plug rectangles into each other to make a space station.
There are a lot of placeholder and incomplete things in here, and I'll try to fix it up and improve it as weeks go on. I think the basics that are in place will be enough until I get to Part 10, and I can work on making improvements until that time gets here.
repo
my notes
demo
2
u/SupremeChlorophyll Jul 11 '22 edited Jul 11 '22
That was a fun week! I’ve been spending most of it implementing Binary Space Partition. Here are some first results, along with a bunch of debug images. It’s WIP and still riddled with bugs; I’ll add it to the repo once I’ve ironed it out a bit more. Also: still missing corridors!
The other thing I’ve been working on is cave generation with cellular automata (-inspired) blobs (images). I’m happy with it; if anyone wants to try it out, the txt file is here and can be copy-pasted into the PuzzleScript editor here . To generate new caves, alternate between ‘X’ and ‘Z’.
OK, week 3 here we go!
2
u/bodiddlie Jul 12 '22
Finally got Part3 done and adapted to TypeScript after a nightmare week of work keeping me from working on this. Some fun bugs in adapting the tunneling code that didn't show up until the final steps with multiple rooms. I was switching between horizontal and vertical on every iteration of the generator function, making some interesting (but useless) zig-zag hallways. Code is here and I hope to write up my tutorial blog post tomorrow as I hopefully have a light day at work.
2
u/goose-rails Jul 12 '22
Playdate untitled roguelike in development (P.U.T.R.I.D.)
Running a bit behind but I’m catching up this week. Got basic tiles, entities, movement and room generation set up.
Gif of Playdate in action
1
u/stevenportzer Jul 09 '22 edited Jul 10 '22
I just finished up Part 2 and will try to get Part 3 done over the weekend, so I guess I'll post something now and edit it once I have more progress.
Part 2 took a bunch of work since I'm building an ECS-like framework from scratch. It's a couple of horrible macros that generate a bunch of horrible boilerplate for a complicated hierarchy of traits that let you stuff data into and out of some generated storage types via a few layers of indirection. A big pain to get working, but it's incredibly satisfying seeing it actually work.
The framework's not really providing much in the way of features at the moment, but I'm intending to extend it with additional stuff like incremental computation. Hopefully I'll have enough time in later weeks of the tutorial to get that stuff implemented, but if not I can always continue working on the project after the end of the event.
Edit: I'm done with Part 3 now. I definitely need to do another pass to clean up the map gen code, but the results look nice at least (example image). It's a pretty similar approach to what I used for my 7DRL this year (run a cellular automata to generate cave shapes, try to place rooms in remaining empty space, then carve paths to connect everything up).
1
u/[deleted] Jul 09 '22 edited Jul 09 '22
eehhhhhhhhhhh, not very happy with it. And I can still get islands.
Amazing-gif
1
u/Cylog Jul 09 '22
Man, that was another chaotic week. So much time wasted for so many cave generating algorithms ... and of course reinvented the wheel twice in between. And that's exactly what I wanted to avoid.
First I tried several of my own ideas for procedural random room-to-room without tunnels. None of them appealed to me. Then I looked into d&d's so-called card deck generators (where each card is a single room with random encounters, events and/or loot). That didn't work out well either. Later I searched roguelikedev and tried the approach with the blobtiles ... again not satisfying. After that I tried geomorphs (an old idea from early d&d self generation maps) ... and eventually gave up exhausted and highly dissatisfied.
Today and yesterday I took a step back to keep the big picture in mind .... and just implemented the ideas directly from the tutorial ... and the fun of working with the roguelike returned.
FYI: The readme of the repo contains a screen. Still using all in one-in-all file (main.c).
Btw. in this thread there are already many nice inspiring solutions, keep up your hard work.
1
u/codyebberson Jul 10 '22
Coming in late!
WGLT + TypeScript
Github repo
Part 2 Pull Request
Part 3 Pull Request including screenshot
Playable demo
1
u/Sinfullyvannila Aug 02 '22
Solved my previous problem.
Other problem; on part 2, after writing the engine file but before coding the map, when running main through PyCharm, instead of having both entities display on the screen, only the player entity displays. When I use movement keys or use the mouse both entities flicker on and off. When I use the Debug feature, the npc renders displays initially and both entities flicker in the same manner.
1
u/pedrojalapa May 09 '23
When I type "from procgen import generate_dungeon I get the error saying: cannot find refernce 'generate_dungeon' in 'procgen.py' I been looking at the example code for like an hour now aand made sure everything is written exactly how it's supposed to be written and I can't find what I did wrong can anyone help please?
EDIT: in procgen.py it also says the following warning: expectd type 'int' got 'RectangularRoom' instead
0
u/[deleted] Jul 06 '22
[deleted] — view deleted comment
0
u/[deleted] Jul 05 '22
[deleted] — view deleted comment