r/roguelikedev • u/KelseyFrog • Jul 12 '22
RoguelikeDev Does The Complete Roguelike Tutorial - Week 3
So happy to see everyone's spins, takes, and embellishments. Keep it up folks!
This week is all about setting up a the FoV and spawning enemies
Display the player's field-of-view (FoV) and explore the dungeon gradually (also known as fog-of-war).
Part 5 - Placing Enemies and kicking them (harmlessly)
This chapter will focus on placing the enemies throughout the dungeon, and setting them up to be attacked.
Of course, we also have FAQ Friday posts that relate to this week's material.
- #12: Field of Vision(revisited)
- #41: Time Systems(revisited)
- #56: Mob Distribution
- #70: Map Memory
Feel free to work out any problems, brainstorm ideas, share progress and and as usual enjoy tangential chatting. :)
15
u/redblobgames tutorials Jul 12 '22
I'm attempting a "fortress mode" style game. Part 2 (entities, rendering, map) was straightforward, but I don't know what I'm doing for Part 3 (map generation). I made several false starts adapting that for a fortress mode game:
Playable version - press
Rto mark a room, move to the opposite corner, pressEnterto build itSo this week is supposed to be Field of View, which I no longer have since I got rid of the player character. Fog of War may still be useful. The big one will be "Placing Enemies and kicking them". I'm going to instead work on friendly NPCs, and instead of kicking them, they need to do their jobs (currently construction). I think it's going to be quite a busy week, as both pathfinding and job assignment are algorithm-heavy problems. If that weren't enough, I also want to switch from turn-based to real-time!
Ideally by the end of the week, when you mark a room to be built, the NPCs will scurry around and build it.
7
u/cordinc Jul 12 '22
Parts 4/5 in vanilla Javascript with ROT.js: Github & "Playable" version
Didn't have much time this week, and spent much of it becoming reacquainted with weakly-typed language problems after years in strongly-typed land. Didn't think much about what I was doing beyond getting it working.
6
u/codyebberson Jul 12 '22
WGLT + TypeScript
I'm trying to stick to the tutorial as much as possible, even though some design choices feel unnatural. For example, breaking out "Action" classes, and using the "spawn" method to create entities. On one hand it feels a little like overengineering. On the other hand, it's fun to go along for the ride with someone else's design doc :P
Unique to JavaScript, I'm a nervous about using JavaScript classes for anything that will need to be persisted. Last time I got stuck in the "Saving and Loading" step, because deserializing into JavaScript classes became a total mess. Unfortunately I'm not aware of a good JS equivalent of Python's pickle. I'm considering refactoring to just use plain old objects and TypeScript interfaces, without class methods or member methods. I'm curious if anyone else has found a good pattern for serialization/deserialization with JavaScript?
Part 4 pull request
Part 5 pull request
Playable demo
6
u/HexDecimal libtcod maintainer | mastodon.gamedev.place/@HexDecimal Jul 12 '22
GitHub | Playable
I think I spent most of the week setting up automatic deployment to Itch, whatever's is on the
mainbranch is what's playable on Itch right now, and any push tomainwill update the playable version automatically.I wanted to have less smooth caves from the cellular automata generator so instead of replacing the tiles immediately the tiles detected as needing to be changed are added to a list and then shuffled. This causes a phenomenon where the total number of walls and floors doesn't change during the cave generation, at least until the fill holes step kicks in. I'm not sure if I'll be able to refine this.
I haven't figured out exactly how I want to handle the actors yet. I want some way to identify them globally without having to use raw pointers or shared pointers. I might use something like giving actors a unique id and then using that to store them on a mapping type.
4
u/Zuburg Jul 12 '22
Python TCOD WOODLAND ROGUELIKE
Due to life getting in the way(work/family) I haven't been able to actually get much done. I'm hoping to get plenty done later in the week, but I'm just posting this to show that I'm still alive.
I'm currently up to part 3 of the tutorial, although I want to give it my own spin by making it in a forest (Please note I have little to no coding experience and this may have been a huge mistake).
So, in order to make a dungeon that is forest-y I tried giving it a Tileset, after faffing around for several hours I was forced to ask on here for help, so I finally got that sorted out, aaaand then I changed my mind and decided to go with pure ASCII (which I have yet to implement but give me time lol).
Secondly instead of dungeon rooms I need to make a more natural place to explore, so I had a look around and it seems like I need to code a cellular automata to make a "cave" system. Will this be easy enough to implement into the libtcod tutorial? Or am I setting myself up for failure? I like the challenge of changing it, but currently am a little lost on how to. I'm pretty sure that I need to:
1- fill the map with a random amount of both wall and floor
2- use the "game of life" rules to smooth out the mess that the first step would have made, and (hopefully) make the map look more like a thick forest.
Any pointers or advice would be hugely appreciated, I've looked at a cellular automata coded in python but it was in python 2 so I'm not sure at the cross compatibility of python versions.
I'm still wrapping my head around classes so I'm very much a rookie in python
4
u/mrdoktorprofessor Jul 12 '22 edited Jul 13 '22
Not a whole lot of forward progress on my end that's viewable, though I have still been working on my LED RL.
Things I've done since last week:
evdevto avoidpygamebut it's a bit finicky in terms of how things are handled. Still not in love with my current implementation but it gets the job done.numpyinstead of 2D lists. I have made a few demos separately that indeed show significant speed boosts as expected, but haven't merged it over into my mainline code.Things that pertain to the code-along:
I noted a bug last night that the bones became unwalkable so that needs to be resolvedresolved.Things I plan to do this week:
Midweek updates:
Downside here is that I cannot for the life of me figure out how to handle input in my local dev environment without plugging in a USB controller.
4
u/Southy__ Jul 13 '22
Github
This is a port of the libtcod tutorial straight into Java, I have copied the AsciiPanel code from here into my project and not using any external libraries other than that.
Week 3 complete.
FoV and Enemy Placement done.
FoV is a port from C -> Java of the algorithm found here
Also setup circleci to do my jlink builds for me.
3
u/revokon Jul 12 '22
My Repo
After looking at the different FOV implementations, I decided to go with the one from this article. It isn't perfect - if I were making a more involved game I would give the Permissive FOV algorithm a try - but it was fairly easy to implement.
3
u/[deleted] Jul 12 '22
Gitlab
Screenshot of the basic rooms and halls
Zig roguelike completed parts 2 and 3! Sticking pretty close to the tutorial learning the Zig programming language as I go. Haven't thought too much about specific game/story aspects yet -- probably will this week now tha we're adding kickable enemies.
Really liking the Zig language so far. I thought I would have more trouble with memory management but I really like that the default memory management allocators tell you when you've got a leak and give you some idea of where. Then I can go back and fill in a free or deinit that I missed. Looking forward to the next couple parts.
edit: spelling
3
u/reuben-john Jul 13 '22
Hands on rust veered off from the python tutorial and does FOV stuff later on. I'm not confident enough in either my Rust or my gamedev to skip ahead and implement it right now. That means I instead implemented monster placement and random movement.
Github and playable week 3
3
u/bodiddlie Jul 14 '22
Have part 4 of my typescript adaptation and tutorial done. Code is here and the tutorial post is here.
Part 4 was pretty short compared to part 3. Looking to start my adaptation of part 5 this evening.
3
u/LukeMootoo Jul 14 '22
I noticed that most people rendering to html canvas with either ROT.JS or WGLT are drawing the map with ` ` (space) characters and coloring with background color..
I've been having a bunch of trouble with sub-pixel anti-aliasing, and it is particularly a problem on any full-width characters like `
\u2588` or whatever.is everyone drawing with spaces to avoid that same problem?
3
u/[deleted] Jul 15 '22
Forgot to post last week, am staying mostly up to date with a C++ / SDL version of the tutorial.
I saw /u/HexDecimal's post of a cave generation, and really liked it, so I made something similar for my map. I eventually would like to have different types of rooms in a single level, kind of like how Brogue does it, so I made the cave generation go to a given size, so I can make it so that a cave system takes up the left side of the map, then have some other room types make up the right side. Example: 3x3 map of small, unconnected caves.
For this week, I got FOV working following code from RogueBasin.
For monsters, I added in gray apes. I want to go for a Conan-style, lower fantasy kind of setting, and delving into a set of caverns filled with ape-men possibly descended from some kind of long-lost, crumbled civilization to steal their treasures seems like a fun (and somewhat simple to make) setting to me.
3
u/Bubbly_Knee_2433 Jul 17 '22
The FOV tutorial went extremely smoothly for me, I didn't make a single syntax error this time!
However, I cannot for the life of me place any Ts or Os. I even cranked up the max_monsters_per_room to 5 in main.py to try to generate more monsters. I checked the code but it looked the same as the tutorial code. Is there any place where I have made a mistake?
3
u/snowball_dev Jul 17 '22
Not a whole lot of progress on my Godot Roguelike this week, most of it has been done during the first week.
Currently have a simple dungeon generation with raycasting FOV and enemy spawning.
repo FOV gif
3
u/luismars Jul 18 '22
This is my update for this week.
For the FOV I made a naive raycast, it's O(n2) but my map is just 11x11 so I think I can live with that for now. Initially I checked against the tile's square but it was blocking too much view, so I decided that checking against a squared rotated 45º would give a wider view, the only downside is that you can peek across diagonally placed blocks, but given that my maps are small, I won't consider that as a problem for now.
For the turn system I implemented a simple priority queue.
I created some properties: agility for the turn system and health for checking if something can be attacked.
I also changed some colors and sprite for the player and the enemy.
I'm trying to avoid coding an ECS, now I only have "ActionSystem" and a "PropertySystem" let's see if I regret going this way in the future.
As always:
Repo. Play Online.
2
u/Gogodinosaur Jul 13 '22
C# implementation GitHub - Field Of View Gif
It took a bit of fiddling, but I was able to implement hexagonal based field of view. I determine whether or not a tile is in view of the player by sampling linearly interpolated points between the player location and the target tile center point. The point is properly rounded in hex coordinates to find the tile at that position. If the tile is not transparent (i.e., it blocks the target tile), then the target tile is not visible. This process is repeated for (currently all tiles in the map, which isn't actually terribly slow), but should be repeated for tiles within a max distance of X from the player.
I've also changed the control scheme to use:
I think these controls feel better to me than the WEADZX layout, which appears to look more like a hexagon on the keyboard.
There are also some post-processing effects that I've tried to apply, just to try it and change the visuals. I'm applying a Panini Projection, which is fantastically named, to make the map look rounded towards the left and right sides of the screen. Not sure if I'll keep this.
2
u/stevenportzer Jul 14 '22 edited Jul 14 '22
Part 4 was way more of a struggle than I was expecting. I probably should have expected it since I was rolling my own FOV implementation based on a custom algorithm that I had starting working on before the tutorial event and had only just reach the point where it made sense to stick it in a game. Getting visibility for ground tiles wasn't too bad, but figuring out which walls should be visible turned out to be a massive pain since I hadn't really thought about that much and there's a few (literal) corner cases. It was kind of buggy and horrendously slow for a bit, but it's reasonably fast now and I think I've mostly fixed the bugs.
I also ran into an annoying issue in my custom data storage framework (created for part 2) that required me to randomly refactor a bunch of stuff until it compiled again. I blame/credit Rust for that being necessary/sufficient (it's a confusing mess of trait implementations, but once it compiled again it worked 100% correctly).
Part 5 was pretty straightforward. Not much to say about that.
Anyways, have an image and a playable version.
2
u/jneda Jul 14 '22 edited Jul 14 '22
PICO-8 implementation
Github | Playable
I looked up PICO-8's font size and switched tile dimensions from 8x8 to 4x6, roughly doubling the amount that can be displayed on screen. Implementing a camera in order to have a larger map is still on the todo list.
I plugged in the recursive shadowcasting code a kind user of this subreddit pointed me to. I understood the principle of it but not yet the full details. However it works and looks fine.
Implementing the entity factory went okay, but my action factory function is starting to get messy. I looked into OOP Lua a little, but I'm starting to feel the action design from the tutorial is a bit over-engineered for my project. I guess I'll see how it goes for now, but I might have to refactor it into something more PICO-8-ish down the road.
It's been a little challenging since I'm not experienced in OOP and I have just started using PICO-8, but it has been fun learning some Lua.
2
u/WorksOnMyMachiine Jul 14 '22
Decided to drop my Java project since I really was not enjoying it. Maybe in the future I will pic kit up again, but for now it is abandoned since I barely have time as it is outside of work.
Pretty good week in terms of my Rust Development. I Finally got fluent turn based in bevy with camera movement which was my main pain in the past with system execution order. I have a specs branch as well, but I think most rusteaceans are more interested in bevy so I will only post that branch. Custom Bevy stages are the way to go!!
WGLT was updated and I added a `blockedtile` tag to AI entities. Added a map indexing system to update all blocked locations per execution.
Python Bevy Repo WGLT
2
u/ChizaruuGCO Jul 15 '22
I started late, joining in the 2nd week, but no matter, it's been fun as it's my first attempt at creating a roguelike in Python. So I didn't strain off from the tutorial doing my own thing; instead, I decided to redo the tutorial in the Unity Engine as I continued building it in Python. It caused me also to create a spur-of-the-moment series called "Unity Roguelike Tutorial", which will follow my journey throughout the challenge.
2
u/LukeMootoo Jul 16 '22
Wheee, what a week.
Native JavaScript, no libraries. Part-4 is up, starting on 5 now.
Part 4 Repo
Part 4 Notes
Playable
Drawing my own field-of-view system was a wild ride. Different solution from what I expected (I learned what shadowcasting was, I was anticipating something with raycasting) and a bit different from the tutorial. Didn't actually get to the casting shadows part, but stopped when I had the basic ability to update dynamic lighting.
Rendering text on canvas is kicking my butt in a lot of ways, mostly having to do with anti-aliasing. None of the CSS features or canvas scaling options seem to be able to reliably force browsers not to do it, so I'm going to eventually have to convert my font to an image file if I want it to be pixel perfect.
I'm doing some stuff with alpha layers and will probably iterate on it a bit to get some gradient fall-off, I think the framework I have should let me easily add additional light sources in the future, so I'm happy with that.
I'm still totally cheating not having an actual game loop, and I'm just hooking updates up to the movement action which.. look, lets be totally honest here, I'm probably going to keep overloading that for the rest of this project and come back and write a better engine later.
I still have this really sloppy race condition at load time, where sometimes the fonts aren't finished loading before my canvas context tries to set its self up. I've been super lazy about fixing it, but I'm going to have to serialize that nonsense pretty soon here. If one of my demos does not work at first, just refresh a few times, lol. If I do fix it, I'll back-port the fix to the previous stages also.
2
u/KCEHOBYTE bedivere Jul 17 '22 edited Jul 17 '22
Well, I added a very simple version of "Ray Casting (http://www.roguebasin.com/index.php/Ray_casting)" algorithm, so with this I'll conclude that "Part 4 - Field of View (http://rogueliketutorials.com/tutorials/tcod/2019/part-4/)" is done. The implementation is indeed very basic and has some issues mentioned here (http://www.roguebasin.com/index.php/Ray-Tracing_Field-Of-View_Demo) for example but it is good enough for now. The new version is live (https://babysitterd-github-io.vercel.app/) as usual!
2
u/lagdotcom Jul 17 '22
repo - play
I promised refactoring but didn't do any. Right now my language resembles more of a layer over a TypeScript library and that makes me sad. I'll have to think of something more interesting to do soon.
2
u/SupremeChlorophyll Jul 18 '22
This week I mainly worked on connecting the dungeon's rooms together through corridors. It was tough to wrap my head around and cost a lot of time. I tried several approaches and ended up using a flood fill / pathfinding method. This is the result.
Other things done this week:
- the player can now move through the dungeon.
- added doors that can be opened.
- integrated FOV code. Video.
For next week I'll see if I can change the FOV so previously visited tiles are displayed in a muted color. I also haven't gotten to the NPCs yet!
Onwards!
0
u/[deleted] Jul 12 '22
[deleted] — view deleted comment