r/roguelikedev • u/KelseyFrog • Jul 18 '22
RoguelikeDev Does The Complete Roguelike Tutorial - Week 4
Tutorial squad, this week we wrap up combat and start working on the user interface.
Part 6 - Doing (and taking) some damage
The last part of this tutorial set us up for combat, so now it’s time to actually implement it.
Part 7 - Creating the Interface
Our game is looking more and more playable by the chapter, but before we move forward with the gameplay, we ought to take a moment to focus on how the project looks.
Of course, we also have FAQ Friday posts that relate to this week's material.
- #16: UI Design(revisited)
- #17: UI Implementation(revisited)
- #18: Input Handling(revisited)
- #19: Permadeath(revisited)
- #30: Message Logs(revisited)
- #32: Combat Algorithms(revisited)
- #83: Main UI Layout
Feel free to work out any problems, brainstorm ideas, share progress and and as usual enjoy tangential chatting. :)
11
u/redblobgames tutorials Jul 19 '22
I'm attempting a "fortress mode" style game. Last week, Part 4's topic was Field of View, and I decided to skip it. It's a "god's eye" game so you can see everything for now. Part 5's topic was Enemies, and I changed that to allies. To make allies work, I needed to change from turn-based to real-time, add pathfinding, add NPCs, add a job system, and give them something to do.
It turns out that was way too much for me.
I got stuck. Many times (see notes). After getting nowhere for several days, to the point where I was pondering giving up on this project, I decided to step back a bit and figure out something much simpler to work on.
I made a bunch of chickens run around randomly. Watch them run!
Working on something much much much simpler got me un-stuck. Whew.
This week, Part 6's topic is Combat, and I don't have combat, so a job system seems like a suitable topic to work on. Part 7's topic is Interface, but I've been working on that throughout so I'll focus on the job system.
Trying to handle pathfinding and the job system and NPCs and switching from turn-based to real-time was too much. But I got some NPCs and switched to real-time last week. I'll work on the job system this week. And I'll postpone pathfinding until next week (as part of Part 9, Targeting). For now they'll just walk through walls.
Also trying to reduce the scope, I'm going to make the rooms build instantaneously. This makes me sad, because having rooms built tile by tile was something I was looking forward to. And it's a good source of jobs for the NPCs. But it makes the job system and pathfinding more complicated, and I need those two systems to be simpler if I'm going to finish. I'll work on room building next week (as part of Part 8, Inventory).
Another observation: I prematurely tried to organize my code. I think it's like premature optimization and premature generalization that it's what I tend to do, but it backfired. As this is not a type of game I've worked on before, I don't know what organization makes most sense, and I should've just left it all one big file with globals until I figured out how it naturally cleaves into modules. Tutorials often make it seem like it's obvious how to structure code, so it's something to be done up front. But it's not obvious to me until after I've written some of the code, so I need to write some and then go back and refactor.
9
u/HexDecimal libtcod maintainer | mastodon.gamedev.place/@HexDecimal Jul 19 '22
GitHub | Playable
I thought I could do this without needing to make forward declarations but I must have forgotten I was writing C/C++. The abstract action class needs actors declared for its abstract function and actors need a pointer to their action for AI purposes. Right now it seems the cleanest way to handle those is to have separate forward declaration headers for the relevant types.
The C++ tutorial uses libtcod's constant named colors, and switching these out with colors from Paletton has always been an improvement whenever I've done so. The previous colors for the HP bar were called dark red but they're simply not dark enough.
So far I've almost kept ahead but internally I'm still in the middle of AI. If this was complete enough then I could've added things like auto-explore or attack-nearest-enemy commands. I also haven't added trolls yet. It's hard to strictly follow the tutorial when making refactors to it, and it will be some work to get it on par with the new Python tutorial feature-wise.
I was having some trouble debugging errors until I noticed that the "All exceptions" breakpoint in VSCode was not enabled. It's very hard to debug exceptions without that!
7
u/mrdoktorprofessor Jul 19 '22 edited Jul 22 '22
microRL // edgeRL // RaspberryPI-RL (name TBD)
Updates from me -
To do next-ish -
#for walls and.for floors is fun, but probably gets a bit tired after a while.Open questions -
Right now I have HP bars underneath each entity that supports HP and that gets the job done, however next I'm thinking of adding text and that most likely is going to involve spriting out each letter of the alphabet (right now I'm saving each sprite as an 8x8 2D array that is parsed and dumped to my
pixelsarray. Gets the job done but means I need to come up with sprites for everything.2. How to handle user input in a testing environment?
I have a controller hooked up to a Raspberry Pi (recognized by
python-evdev) that outputs to a 64x64 LED panel using the Flaschen-Taschen software. What this means is that I have a Python script running my game, output going to a separate location (in prod - the LED panel / in testing - the Flaschen-Taschen software running in terminal mode in a separate window). I've toyed withevdevpermissions but can't get the laptop keyboard to be recognized, no matter what permissions my user account has. I'd rather not plug my controller into my computer for testing (or a USB keyboard at that) forevdevto work, but it's starting to seem more and more like I need to figure this one out for those who don't have my HW setup and want to try it out (plus - the whole testing while away from my desk thing).Update - figured out how to handle this.
tkinterto the rescue! GUI popup3. Figure out a good way to support multiple users.
This is eventually going to be in a public space for students to play with, and it would be neat for them to scan a QR code and auto-login or something like that. This is a looooong-term stretch goal, but on my mind at least.
5
u/codyebberson Jul 19 '22
WGLT + TypeScript
Last week, I was getting nervous about serialization, and that boiled over this week. The change from "Entity" to "Entity + Actor" started making things difficult, because there isn't a good equivalent of Python's
copy.deepcopy(self)in pure JS/TS.I started down the path of using plain old JS objects for everything, hoping I could leverage TypeScript interfaces to keep the objects organized. But it ended up requiring lots of manual dispatch (i.e.,
switch (entity.entityType)andswitch (action.actionType)), which felt gross and unnecessary.Instead, I updated WGLT with some new serialization features that turned out well, based on suggestions from u/redblobgames last week (thanks!) . In WGLT 0.3.5 there are new serialize and deserialize utilities that preserve ES6 classes and handle nested references and graph cycles. It uses TypeScript decorators, so it's just a matter of adding
@serializablebefore the class. This solved the immediate need for adeepcopy, and will be extremely helpful in the upcoming weeks.Aside from that, everything else was pretty straightforward, just following the spec.
Part 6 pull request
Part 7 pull request
Playable demo
5
u/bodiddlie Jul 21 '22
Part 6 of my TypeScript adaptation of the tutorial is done and written up. This was definitely a longer one and that was without having to do the refactor that is at the top of the python version of Part 6. Writing the prose for the tutorial took me the better part of today. There's definitely some room to clean some things up I think. Debating whether to boy scout it and clean them as I go, or maybe do an epilogue post after the full set of tutorials. Hmmmmm
Anyway the tutorial is here and the code is on my github here.
Now to start on part 7!
4
u/Corncycle Jul 19 '22
I haven't tried to take Python particularly seriously before now, and I'm just wondering if someone can shed some light on a particular line of code from the refactoring. In the refactored actions.py file, the constructor is given as
What is
super().__init__()doing here? I understand what super does for subclasses, but as far as I can tell Action is not a subclass of anything (besides maybe a general "object" class), so I can't imagine this line doing anything. I commented outsuper().__init__()and the project appears to run exactly the same. Does anyone have any insight why this was put in, and if it's doing anything?3
u/Cylog Jul 19 '22 edited Jul 19 '22
It is not easy to follow the tutorial when developing in a procedural programming language. In the end, I cloned the tcod_tutorial_v2 repository completely locally and only checked out the respective branch so that I could work directly one-to-one from it.
I also discarded any of my own ideas from the beginning (colors, symbols, etc.) and now stick very closely to the tutorial's implementation, keeping only the custom font.
The only real difference is the pure use of C (Rev. 11) and - as from the beginning - SDL2 and stb.
The self-developed algorithms like FOV and Pathfinding are kept very rudimentary and simple and are both understood to be imperfect ... I am far more concerned with the KISS principle than with providing a complete engine.
Repo
Screen
What's still missing in part 7 is the history viewer ... I'll try to finish that today.
Next target is the splitting of the code (still one-in-all file aka main.c).
Edit: I will provide a release-package (only for windows) on github and repo ... when I have identified how this works.
3
u/[deleted] Jul 19 '22
Slowly scooting along learning Zig and trying to mostly faithfully translate the tutorial. Taking a bit to learn how to translate the idioms into Zig from Python. Code definitely needs a good refactoring before I get going on part 6, starting to get a bit messy.
repo
3
u/JasonSantilli Jul 21 '22
Repo | Playable
JS w/ ROT.js
Finished up part 9, in the middle of part 10 now. I'm not really sure how I'll get saving to work, but I've got to dive into that now.
I've stopped spending a lot of time on refactoring. There are areas now where I'm duplicating code, and where I didn't realize I would need certain data so the data ends up getting passed along in weird ways, like in some of the part 9 scrolls with callback functions. But I think the plan will be to power through for now and keep the lessons learned in mind for later. Hard to anticipate every architectural need before you understand the full scope of the project.
The good news is, I think I'm in an ok spot to get through the remaining chapters if I can get through saving. I'll be excited to see how other's code turns out too!
3
u/cordinc Jul 21 '22 edited Jul 21 '22
Parts 6/7 in vanilla Javascript with ROT.js: [Github](https://github.com/jarrahtech/RoguelikeTutorial2022) & ["Playable" version](https://jarrahtech.github.io/RoguelikeTutorial2022/)
This week's lessons took me much longer than the previous weeks! Some notes:
3
u/caliskor Jul 21 '22
GitHub
The first two weeks went great, I had so many ideas, but then I slowly realized that I've overscoped the project.
At first I planned to make a post-apocalyptic roguelike in which the player travels through deserts and ruins of the World Before. I had a rudimentary roadmap with a list of things I want to implement, such as hunger and thirst, hunting and gathering, searching ruins for things to sell, random encounters, and more. The development went well, until it stopped completely due to the increased amount of work in my company.
More than week went by without anything done in the game, and when I finally found some time to get back to the development, I looked at my to-do list and came to realization I will never make it within the time frame of this event.
In the end I scrapped the additional stuff, and went with the basics (dungeon generation, fov, random enemy placement etc.). At the moment of writing this post I've completed half of Part 5 (without the attacks). I'm quite confident I can get things up to speed this week, and have Part 7 done until Sunday.
Why the backtracking? I would rather have a completed project that I can build upon than a barely working stub with a great potential, but zero gameplay.
3
u/luismars Jul 22 '22
I had part of the interface already in place, so I just needed to add a health bar for this update. I also recolored everything again because I wasn't happy on the contrast.
For now the combat is just deals a fixed amount of damage. I may need to extract the attributes of different enemies to a file so it's easier to mantain in the future.
I think I have some performance issues but I don't know exactly how to solve them, I think the refresh rate of Blazor is not good or maybe I'm not calling the refresh function the right way. For now I just added a tiny clock to the player to know when the enemies are moving.
Repo. Play online.
3
u/snowball_dev Jul 22 '22
Repo | Screenshot
Finally got some motivation to work on my basic Godot 4 RL again, so I implemented very basic enemies and an even more basic UI.
Not quite satisified with code quality and usage of idomatic Godot, but I had a lot of issues using the latest alpha build that took me some time to fix.
3
u/jneda Jul 23 '22
I've been struggling to push along this week.
I'm starting to think trying to follow the Python 2020 tutorial and porting it to PICO-8 maybe was too ambitious. I only know some Python, have little experience in OOP, and have only started to learn Lua for this project, thus I sometimes find it difficult to adapt the tutorial code.
I've managed to implement a camera view, allowing bigger levels, and astar, while also trying to improve my use of the grid data structure, but I've been having trouble refactoring the action system and implementing components.
I've hacked my way along so far, but doing so accrued some technical debt I find difficult to solve now, and I'm very tempted to start anew almost from scratch, probably following the 2019 tutorial.
In the interim, I'll be going for a bicycle ride!
3
u/stevenportzer Jul 24 '22
Screenshot | Playable
Basically done with parts 6 and 7. There's no way to examine enemies, but not the end of the world if I don't end up implementing that.
For part 6 I had to do some more work on my custom framework to support action handling. I'm abusing Rust's type system to encode whether an action succeeded or not in the return value such that an error statically guarantees that the game state wasn't mutated. I can also invoke an action with an immutable reference to the game state to get any errors and check if the action would succeed without actually doing it. I expect that this'll be less error prone than trying manage action errors without static enforcement, but the ergonomics aren't quite where I'd want them.
I also wanted to make the enemies a bit smarter so they'd move out of the way of other enemies under more circumstances, but gave up before getting that working. It should be totally doable, but it was taking a while to figure out exactly how I wanted it to work and I didn't want to spend a lot of time on it.
I don't think I did anything particularly interesting for part 7. If I have more time later I might try to clean up the custom message formatting language I wrote for my previously project and use it here.
2
u/Southy__ Jul 20 '22
GitHub | Release
Pretty much as the tutorial for combat and basic UI, some slight differences because of the way libtcod can render secondary panels.
I am not going to be adding mouse support so I created a 'look' mode instead that lets you move a cursor around the screen to see what is in your FoV.
2
u/[deleted] Jul 20 '22
Still working through in C++ / SDL. Current pic.
This one was a rough week, but did get everything done to follow along with the tutorial. The first issue I hit was with killing and deleting enemies. I have been working through an Entity-Component System based off of this video from the Caves of Qud developers. An enemy would receive a MeleeAttack event, and then check if they had no health left, and if so, they would die and be deleted from the list of actors. Then the event would keep firing on an actor that no longer existed, and the program would error out. After a few hours of failed attempts (I have never loved Git more) I ended up adding another event queue that would hold world actions and clear itself out after every actor's turn, so if something dies, it happens there.
After that, I knew how I wanted to do enemy turns, and I knew it would take some effort, so I added in blood spatter on melee attacks rather than do that. Hits in this dont do too much damage usually, so my current system is that if an actor has a BloodComponent, when they receive a MeleeAttack event, for every point of damage done they paint a random tile around them red. Its not perfect, but it works.
I eventually moved on to basic AI. Actors have a BrainComponent, which for monsters will return an action that they will perform, as described here. At the moment, they do not use any pathfinding, and just try to walk towards whatever direction you're in if their tile is lit.
My GUI is a direct clone from SIL, because I like how it looks there and I wanted something simple.
At the moment, I am looking at redoing some of my dungeon generation when I have time, or possibly reducing the line of sight distance. Right now, if the tunnel is clear then most of the enemies can see you and start moving to attack you, which is pretty hard to fight through. This might get solved when armor and weapons are added, but it doesn't seem as fun.
2
u/Bubbly_Knee_2433 Jul 24 '22
Part 6 went very nicely, but I've hit an error on Part 7, right after the first time modifying engine.py and main.py to bring in the message log: File "D:\pytutorial\YART\engine.py", line 50, in render self.message_log.render(console=console, x=21, y=45, width=40, height=5) TypeError: MessageLog.render() got an unexpected keyword argument 'console' What could the terminal mean by that? I am pretty sure that I have followed the tutorial closely, and I have the latest version of tcod and python installed. Help would be much appreciated, thanks!
2
u/KCEHOBYTE bedivere Jul 24 '22
I didn't have much time for the project this week, nevertheless, first version of combat is here (https://babysitterd-github-io.vercel.app/)! There are a bunch of pretty embarrassing bugs e.g. monsters can make a pack on even hide behind you but I'll take care of them next week. There are indeed some monsters, they block your way, you can fight and kill those, they are going to chase you down until they can't see you anymore and of course, if you die GAME OVER ☠️ Added a hud window with a battle log that helps to keep track of what's happening
1
u/SupremeChlorophyll Jul 25 '22 edited Jul 25 '22
(gifs & image)
There wasn’t much time to work on this project this week. Here’s what happened:
- UI - wise I decided to go with a randomized skill tree. I made a simple menu screen - PuzzleScript has one action-command (hitting X) - this drops you into the menu. The menu is hard-coded into the line table to the left of where the level procgen happens. Control is handed from the player sprite to the menu cursor upon pressing X, and the camera just follows / flips over. There’s not much in there yet, but the bare-bones system is in place now.
- I wrote some code for a pop-up. PuzzleScript has a built-in ‘message’ function which cuts to a text screen - I wanted something a bit more integrated into the actual level, that also allows for more customization.
Hey - I already got one week further into the tutorial than last year! This is shaping up into… something!
(Edit for clarity)
1
u/reuben-john Jul 27 '22
I'm stilling running through Hands on Rust. I finished up the code for this early but then ran into an issue getting my WASM release working. I figured out I was missed embedding and linking the resource to make it work on the web.
Code is at github and you can play this week's game here.
0
u/[deleted] Jul 18 '22
[deleted] — view deleted comment