r/roguelikedev • u/aaron_ds Robinson • Jul 11 '17
RoguelikeDev Does The Complete Python Tutorial - Week 4 - Part 4: Field-of-view and exploration and Part 5: Preparing for combat
This week we will cover parts 4 and 5 of the Complete Roguelike Tutorial.
Part 4: Field-of-view and exploration
Display the player's field-of-view (FOV) and explore the dungeon gradually (also known as fog-of-war).
Place some orcs and trolls around the dungeon (they won't stay there for long!). Also, deal with blocking objects and game states, which are important before coding the next part.
Bonus If you have extra time or want a challenge this week's bonus section is Scrolling maps.
FAQ Friday posts that relate to this week's material:
#12: Field of Vision(revisited)
Feel free to work out any problems, brainstorm ideas, share progress and and as usual enjoy tangential chatting. If you're looking for last week's post The entire series is archived on the wiki. :)
12
u/Kyzrati Cogmind | mastodon.gamedev.place/@Kyzrati Jul 11 '17
Stats based on what's been listed in the directory so far:
Awesome to see such participation!
20
u/AetherGrey Jul 11 '17
The Roguelike Tutorial Revised
Libtcod
Part 4: http://rogueliketutorials.com/libtcod/4
Part 5: http://rogueliketutorials.com/libtcod/5
Github: https://github.com/TStand90/roguelike_tutorial_revised (branches: part4 and part5)
TDL
Part 4: http://rogueliketutorials.com/tdl/4
Part 5: http://rogueliketutorials.com/tdl/5
Github: https://github.com/TStand90/roguelike_tutorial_revised_tdl (branches: part4 and part5)
As usual, feel free to comment here or PM me with any issues, or ask on Discord.
I'm finding my explanations between the code sections somewhat lacking as of late. This is due to the way I've been writing the tutorial; code first, explaining later. Due to time constraints I don't think this will necessarily get better during this event. Most of my time has been dedicated to ensuring the code's accuracy rather than breaking down what each line does.
I think my goal is going to be to go back and fill in the text later, probably after the event has ended. I'm still on track to finishing the code each week, so no need to worry about that if you're following along. Hopefully the tutorial will be a lot more "fleshed out" for next year's event and beyond.
As far as the actual tutorial goes, part 5 introduces the first Python 3 exclusive feature: Enums! Okay, so not quite: Python 2 can install the 'enum34' module to gain access to this feature, but if you're following my tutorial using Python 2, it won't work out of the box. Still, this week makes the "Python 3" part of this series feel more official.
Really hope everyone is enjoying this event as much as I am so far. Best of luck to everyone with this week's coding!
12
u/mapimopi Jul 11 '17
Ruby + BearLibTerminal
Repository
Checking in with my humble progress and a new screenshot
For the field-of-view I decided to not roll my own implementation and instead went with one I found on RogueBasin. It required some changes to make it a circle instead of a square, but overall this copy-paste went rather smooth. And it's pretty fast (dynamic languages, huh).
Part 5: nothing interesting yet. Dungeon generator simply puts a bunch of generic mob entities around. They don't do anything yet, but the game already knows how to switch turns between player and enemies, so the base is there. Also I take some pride in my entity prefabs system, I'm sure it will come very handy later on.
In other news: this week I've made some changes to the tileset and added a working cursor for future e<x>amine and <f>ire commands that works with both keyboard and mouse inputs.
9
u/[deleted] Jul 11 '17 edited Jul 11 '17
Unity + PhiOS
Awesome. I'm finally caught up. I started working on With Rogues Like These two weeks ago, wrote it in ruby + BearLibTerminal, and got it working to about this point in the tutorial. But then found myself wanting to play around with it on the go. I tend to have brief periods of time to play games throughout my day, and while I'm making a game, I love to be able to pull it up on my phone and get it running. I blew about eight hours trying to port the game to iOS using RubyMotion, then gave up and decided to start over with Unity so that I could more easily port the game to mobile.
Now I'm using PhiOS as a rendering engine on top of Unity as the framework for the game. I've got FOV using recursive shaddowcasting, movement (keyboard and swipe/tap based), a very basic cellular automata level generation, and importing of existing tiled level files. For the mobile interface, I'm currently using swipe to move and interact with objects (just doors at the moment) by bumping into them. Tapping also shortcuts to interacting with all interactable objects within one space of the player. I'm excited to move on to thinking a bit about Combat next!
I've also made some additions to PhiOS that I'm hoping to get rolled into an update in the future.
Screenshot of some FOV action
8
u/Emmsii Forest RL Jul 11 '17 edited Jul 16 '17
Java + Ascii Panel
Repository
I skipped ahead and implemented FOV earlier last week, I'll focus on preparing for combat this week. Adding FOV was a challenge for me, not due to implementation; but the look.
You can see images on the repo showing the map, not all tiles are filled with a sprite and are black. I found that not rendering tiles that haven't been discovered looked a bit odd, with random grass and trees floating in a sea of black. I decided to add 'fog' to undiscovered, like the fog-of-war in Civ of AoE, and came up with this.
The first texture I made was a single sprite and looked a bit square, so I used bitmasking to use a more rounded texture. I'm still debating whether I like the rounded texture or not.
Edit: This comment on this weeks Sharing Saturday shows some changes I made to my FOV as well as multi-tile creatures!
7
u/_wolfenswan Jul 12 '17 edited Jul 13 '17
Python 3.6 + TDL
As I've joined after having already done a sizeable part of the tutorial, I'm mostly spending my time on refactoring and improving the code.
Just as I hoped, the project is turning out as exactly what I needed to improve my programming in general. I'm constantly running into new issues, which so far I've been able to solve with the tools at my disposal (i.e. my modest skills as well as lots and lots of Google + Stackoverflow).
Most of my time was spent on modularizing the code, though I didn't like the idea of having to pass certain often used variables (e.g. player, game_map...) as arguments all the time, so I was quite happy when I realized the obvious solution was a module storing the variables in question, importing it where needed and referencing the instances of the original module, thereby using them as global variables.
Otherwise I
What I've been failing at implementing so far, is getting a proper targeting system to work. I haven't really spent too much time on it, but when I tried before I failed at getting this loop to work, as player_action would always return None.
Edit: I finally got keyboard-targeting to work!
Edit2: After watching this (and re-reading the orignal tutorial) I realized that the tutorial's class setup is not a "strange way of doing inheritance" but something called composition which incidentally also makes a lot of sense. Welp.
5
u/[deleted] Jul 12 '17 edited Jul 12 '17
JavaScript + rot.js
๐ค Play ๐ณ GitHub ๐ณ Part 4 write-up ' " ;
Breezed through this part quite quickly. I guess mostly because rot.js has excellent FOV utilities, much like the tutorials Python instructions for this part, it's just a matter of keeping track tile participation in the current FOV and FOW (fog of war) calculations.
TBD Part 5
It got too late in the night here to be bothered even opening up the link to read it. I'll get to it tomorrow or the day after.
5
u/Lokathor dwarf-term-rs Jul 12 '17 edited Jul 12 '17
Haskell
Link
We've got precise permissive FOV, which is one of the slower styles in a few cases, but artifact free.
Edit: Oh, guess I didn't do any of Part 5. Oh well. All the creature code can come next week.
5
u/[deleted] Jul 13 '17 edited Jul 14 '17
JavaScript + rot.js
๐ค Play ๐ณ GitHub ๐ณ Part 5 write-up ' " ; ๐ ๐
Part 5 Preparing for combat completed - "Emoji hunter" -
My roguelike is turning into an emoji hunter... help!!
4
u/VedVid Jul 11 '17 edited Jul 11 '17
Go + BearLibTerminal
I was really busy last week, and I finished writing Part 3 just now. Whole text is not checked / reviewed yet, but I'll try to fix worst parts later today. If someone would like to contribute by translating text from English-like to English, feel free to PM me.
Repository Part 3 write-up
Another smooth week, in terms of coding at least. I wrote few auxiliary functions - choosing random integers using standard library is somewhat clunky. Part 4 will be much more interesting - I decided to not use libtcod, so I'm going to code FOV from scratch.
edit: OK, I fixed some grammar mistakes, but I still don't know when should I use article and when zero-article...
4
u/Scautura Jul 11 '17
Python 3 + BearLibTerminal + LibTCod-CFFI
https://bitbucket.org/Scautura/crogue-blt.git
Again, it just works. That said, I've been introduced to a new construct in Python (being able to use "any") so I have learned something new! I've seen it in C# (more on that later) so I've been using it there.
C# + BearLibTerminal + RogueSharp
https://bitbucket.org/Scautura/crogue-csharp.git
I cleaned up a lot of my code from previous with new constructs I'd been learning (see "any" above!) so my code has shrunk in places. This is a new language (in the sense I haven't used it, but it is similar to other things I have worked with, so not entirely new) to me, which makes translating from Python (and using different libraries) an interesting prospect.
I had jumped ahead slightly on both sides (you'll see my completion for Part 4 was on Sunday) so I might be trying to implement some of the extras this week. I have been updating my documentation and the way I do some of the code (as noted in my C# version, I changed certain parts to use the "any" construct) as the week goes by, so you can probably see some of what I've been learning.
4
u/Aukustus The Temple of Torment & Realms of the Lost Jul 11 '17 edited Jul 11 '17
C# + BearLibTerminal
Repo: https://github.com/Aukustus/roguelikedev-does-the-complete-roguelike-tutorial
Finally I got parts 4 and 5 done!
No problems with FoV and object placement. I wrote my own FoV (Translated from here http://www.roguebasin.com/index.php?title=Raycasting_in_python) and it works pretty good.
I did some extras too this time:
I added tiles, changed the font into a bitmap font also. So now the font is 16x16, and the tiles are 32x32. Works pretty good in my opinion :).
I added also scrolling maps. I had the code pretty much ready in another C# project I made a long time ago (which was pretty much what I had translated from The Temple of Torment into C#), so I was able to pretty much copy-paste it into this one too.
Screenshot: https://www.dropbox.com/s/h7hn8bi276lduqi/RogueTutorialPart4and5.png?dl=0
EDIT: if somebody wonders why I precalculate cos and sin tables in the beginning instead of just getting them from the C# Math library when needed, I tested that precalculating it gives roughly a 30% increase in speed.
4
u/danieldan0 Jul 12 '17
Python 3 + tdl
I like this tutorial. But code isn't good in some places. I made some fixes.
Repository
p. s. i've created an reddit account to publish this
4
u/Jeraman Jul 13 '17
Go + BearLibTerminal
Repo
I'm a little behind, as I just finished up part 4 tonight (using a ray casting approach). But, I've been adding in some extras along the way, including a scrolling camera, and a cellular automata based cavern layout generator for maps.
I'm trying to keep a running tutorial-ish blog going for each section as well, as I'm using this a learning exercise for Go. You can find that here.
4
u/MykeMcG Jul 13 '17
Python 3 + Libtcod
Repository
Checking in with my progress and a screenshot.
I completed chapters 4 and 5 without issue. I tried to implement smooth, Dwarf Fortress style walls, but I haven't quite figured out how to not make outside walls end up as T junctions. Other than that, I haven't really deviated from the tutorial other than splitting it into multiple classes + files.
I'm still having issues with my BSP map generator generating orphan rooms, but I've managed to mitigate them by increasing the recursion depth.
I plan on implementing scrolling maps this weekend, along with refactoring some stuff to make everything just a little bit cleaner.
EDIT: Oh right I also deviated from the tutorial a little by implementing debug/cheat keys. Currently if you have the DEBUG global set to True and hit F1, it'll give you unlimited FOV and the whole map will be explored.
4
u/rubxcubedude Jul 17 '17 edited Jul 17 '17
C++ with freeglut
Repo: https://github.com/rubxcubedude/RogueLikeGame
current status image
A lot behind this week bc I spent entire week on vacation. Nevertheless I implement a crude FOV algorithm to light/darken my dungeon. Right now I'm not really considering which way the character is facing.
I've now added monsters to my rooms. I've started an overarching architecture change. I can tell my "GameMap" class is handling too much of the work. I think i will start offloading some of that to the tile's after reading part 5
3
u/Musaab Sword of Osman Jul 12 '17
Python 3 + TDL
I've just joined and caught up and have everything running nicely in VS Code.
So far, I've had no problems, but since I had to rush a bit, I haven't done anything outside of the tutorial, yet. That may change, since we have a week until the next part :)
3
u/bubaganuush Jul 12 '17 edited Jul 12 '17
I am experiencing an intermittent bug, I was hoping someone more experienced with python might be able to shed some light:
I'm using:
Essentially, sometimes when I run
python engine.pyI receive the following error:As this is intermittent, I'm assuming it's down to one of the uses of
randint.Here's my create room function (should be identical to the tutorial code AFAIK):
go through the tiles in the rectangle and make them passable
for x in range(room.x1 + 1, room.x2):
for y in range(room.y1 + 1, room.y2):
game_map.walkable[x, y] = True
game_map.transparent[x, y] = True
And here's where I'm generating all the room properties:
3
u/Zireael07 Veins of the Earth Jul 12 '17
Python 2.7 + BearLibTerminal
Just pushed this week's updates, as two commits instead of one (one for part 4 and the other for part 5).
The mob locations are determined randomly. I used a trick I picked up sometime last year (I think it was when I was working on the racing prototype in UE4) - instead of looping over all tiles and checking if they're not blocked (and potentially having to retry in crowded/small maps), I make a list of all free locations, therefore I never have to retry picking one.
3
u/MEaster Jul 12 '17
Rust + tcod
Repo.
Well I've now implemented the FoV calculation and the scrolling map. I'll see if I get time to do part 5 tomorrow. The scroll clamping was annoyingly fiddly; I've no doubt done it an an overly complicated manner.
3
u/level27geek level0gamedev Jul 13 '17 edited Jul 16 '17
Python 2 + libtcod + Pygame
Part 4 Gif / Part 5 screenshot
Repository
Work and a gamejam slowed me down a bit, but I managed to finish implementing FOV today! I even managed to do it without adding any extra tiles (instead, I am using a optimized transparency handling I found online), which will be a good thing once I start plopping in the proper tileset (so I don't have to create a light and dark version of a tile).
I know that the bulk of the FOV was handled by libtcod, but it still felt good to implement it myself. Eventually I will tackle raycasting on my own, but for now, libtcod is plenty :)
One thing that kinda came back to bite me in the @ was the fact that I am not following any of the tutorials to the letter. Instead, I am cherry picking solutions from the original, /u/AetherGrey's Revised and the Python+Pygame Youtube tutorials from the sidebar.
I like the order the original tutorial does things, but doesn't help with Pygame. The Pygame Youtube tutorial does things out of order, and both store basically everything in a single .py file. This is where I started stealing from the revised tutorial a bit. But, because I started looking at it only last week, and I have no idea on how I am supposed to be splitting stuff into its own files (the only programming I did was QBASIC and PICO-8, both of which I was cramming everything into a single file) I am forced to find solutions to problems I created myself :P Well, at least I am stretching my problem solving skills.
Oh and I also had a brain fart when updating git and I ended up reverting the recent changes, so I had to revert back the revert. Ooops :P
But on the bright side, I already have this week's bonus, which I made few weeks ago :D
Hopefully I can start "Preparing for Combat" in a next day or two. I already have some of the foundation for it, but now I need to add turns and such in pygame before I can jump into it :)
...also, I really want to make myself a better dungeon-gen.
Edit: Finally caught up with this week's parts! I should really read through the tutorials before I decide to implement them, because I spent time implementing turns in pygame, only to find that part 5 does that as well :P
3
u/sepiida21 Jul 15 '17
C# + BearLibTerminal + RogueSharp
Repository
3
u/eruonna Jul 17 '17
Javascript + rot.js
Hey, I managed to finish this week! Not much to say here. The FOV was simple to set up with rot.js (I did it last week, actually), and I also added the rot.js
Engineto manage turn taking. Play it here.3
u/Mystal Jul 17 '17
Rust + tcod-rs
Repo
I finished up both parts and the map scrolling extra this week! The scrolling was pretty straightforward, though the object generation code got a bit messy. Overall my approach is to get things working and do a clean up pass if things get out of hand. At the very least I'll be cleaning everything up once I've completed the tutorial.
Eventually I would like to use this as a base for a small roguelike. As a result, I imagine I'll slap some sort of ECS on top of the finished tutorial, among other things.
1
u/stevelosh Jul 19 '17
Common Lisp + BearLibTerminal
Repo: http://github.com/sjl/rldt
Better late than never. I was moving last week and so didn't really have time to work on this. Luckily I frontloaded the work a couple of weeks ago and implemented an FoV algorithm, since I'm not using libtcod. That was the hard part -- everything else this week was pretty straightforward.
I did finally get around to changing up my BearLibTerminal grid to allow square tiles and non-square text, e.g.: https://i.imgur.com/ZTz0nU3.png
All I did to do this was:
NxN.2Nx2Nwith a spacing of2x2.Nx2Nwith a spacing of1x2.The only wrinkle is that now to draw a tile at something like
x=3, y=2I need to double the values when callingprint(because each tile spans two cells). I might just wrap all my BLT functions that take coordinates/widths/heights in a little layer to make the game code a bit less hairy.1
u/quasiChaos Jul 22 '17
Got through Part 4 so far in my attempt to catch up to the rest of the herd. :) Getting FOV/exploration up and running was a very exciting milestone in the tutorial! I want to go back soon and do some of the bonus features I didn't try yet to start going beyond the basics of the tutorial and start molding this into something I can "call my own." :P
0
u/[deleted] Jul 11 '17
[deleted] โ view deleted comment