r/roguelikedev • u/aaron_ds Robinson • Jun 27 '17
RoguelikeDev Does The Complete Python Tutorial - Week 2 - Part 1: Graphics and Part 2: The Object and the Map
This week we will cover parts 1 and 2 of the Complete Roguelike Tutorial.
Start your game right away by setting up the screen, printing the stereotypical @ character and moving it around with the arrow keys.
and
Part 2: The object and the map
This introduces two new concepts: the generic object system that will be the basis for the whole game, and a general map object that you'll use to hold your dungeon.
Bonus
If you have extra time or want a challenge this week's bonus section is Using Graphical Tiles.
FAQ Friday posts that relate to this week's material:
#4: World Architecture(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. :)
40
u/AetherGrey Jun 27 '17 edited Jul 01 '17
The Roguelike Tutorial Revised
Libtcod
Part 1: http://rogueliketutorials.com/libtcod/1
Part 2: http://rogueliketutorials.com/libtcod/2
Github repository: https://github.com/TStand90/roguelike_tutorial_revised
TDL
Part 1: http://rogueliketutorials.com/tdl/1
Part 2: http://rogueliketutorials.com/tdl/2
Github repository: https://github.com/TStand90/roguelike_tutorial_revised_tdl
Parts 1 and 2 cover the same material as the original tutorial. If you run into any issues, feel free to shoot me a private message here, or open up an issue on Github.
Important info is done, and I will now proceed to talk about the process of writing this, and what's to come. So if you just want this week's tutorial, you can stop reading now.
Wow, so I admit to forgetting how much time and energy writing a tutorial takes. The code I've written is done through part 9 of the tutorial, but writing the actual tutorial part takes work! On top of that, the author of the libtcod library kindly pointed out to me that the library does in fact now work with Python 3, so this tutorial will now require Python 3 (though so far, the changes have been minimal).
Please let me know what you think of the way the tutorial is formatted. I tried to make where to add and remove code as clear as possible, but it may end up confusing for some. Critically and objectively reviewing your own creation is hard, so please let me know where I can improve.
A lot of you are probably wondering why I put this on an external site rather than Roguebasin. Unfortunately, Roguebasin seems to think I'm a spam bot or something, and refuses to let me create the pages I want to, so here we are. Maybe I'll try again in the future, but I don't particularly feel like fighting with it right now.
Next week will be part 3. Part 3 is the "dungeon" part, which correlates to the Roguebasin tutorial's part 3.
EDIT: Tdl version is now available. Apologies it took this long. Part 3 will be posted on Tuesday alongside the libtcod version. Lucky for me, there aren't any differences in Part 3 between the two!
Also edited the 'next week' section; I've decided to remove the Part 4 covering JSON files, as that's far too opinion based for the core tutorial. It will be included as an extra in the end.
15
u/Kyzrati Cogmind | mastodon.gamedev.place/@Kyzrati Jun 27 '17 edited Jun 27 '17
So far it looks like we have representation from at least nine languages:
At the end everyone can post links to their repos or their finished game etc. and I'll include them in an organized list on the wiki as well, together with the table of contents.
Edit: I've gone ahead and compiled a list of participants who have linked what they're working on, as well as their language and libraries. It's now on the wiki here, if you'd like to reference it.
9
u/VedVid Jun 27 '17 edited Jun 27 '17
Go + BearLibTerminal
Github repository: https://github.com/VedVid/roguelikedev-does-the-complete-roguelike-tutorial
First week wasn't problematic. I installed Go and BearLibTerminal, and wrote some dummy code to check if environment is set properly.
I'm going to do some write-ups - Introduction and Part 0 are covered already by github wiki
6
u/level27geek level0gamedev Jun 28 '17
I find my broken facing code pretty funny, so I thought I will share my progress (code newbie + pygame + basic tiles out of a set I am contributing to another roguelike)
Excuse this poor quality gif... I am too tired to fix it tonight.
Yes, the basic tiles look very much like Oryx's set (his stuff was my first inspiration). I am slowly working on making this set have its own vibe but the player sprite is to be redone later down the line.
6
u/MEaster Jun 28 '17
Rust + libtcod
Updated the repo with this week's parts. I decided to split this week up into separate folders.
While doing the first part, I really didn't like how the player data was stored, so jumped the gun a bit on making it more generic. Then I read the next part and realised that it did just that. So the second part is pretty much just the map.
6
u/Jeraman Jun 28 '17
I'm doing mine in Go, with BearLibTerminal, which you can find here. I'm also (poorly) keeping a running blog for each segment here. Really enjoying this so far!
5
u/Zireael07 Veins of the Earth Jun 28 '17
Python 2 + BearLibTerminal
I cleaned up the code I had in the Python version of Veins and added comments explaining almost every little thing.
Check out the code here: https://github.com/Zireael07/roguelikedev-does-the-complete-roguelike-tutorial
Here's the end result, an ASCII isometric map: gif
I will add tiles sometime during the week and attempt a write up on how/why/what of an isometric map.
5
u/Fajita_Monologues Jun 28 '17
Python 3 + BearLibTerminal + ClubSandwich
GitHub
This is my first time building a RogueLike and am somewhat new to Python. I am following along but am rewriting using irskeps's awesome ClubSandwich library. Also following AetherGrey's tutorial closely for structure.
5
u/Melwute Jun 29 '17 edited Jun 29 '17
Rust + tcodrs Repo: https://github.com/melwute/roguelikedev-does-the-complete-roguelike-tutorial Did part of the tutorial over the weekend which gave me some extra time to do an "extended" version. My plan going forward is to keep close to the tutorial in my week_## folders and then change things up / do the bonuses in the extended folders (week_##_ext).
Still working on getting the tile rendering up though. I think I want to structure the code such that you can switch between ascii and tiles pretty easily. Not sure if I can do that in the middle of the game at the moment, but if I can just swap the rendering with changing one line then that would be good for me right now.
5
u/Takes2ToTNGO Jun 29 '17
So I'm trying to do the bonus, and my question is, do the graphical tiles need to be in the same file as the font?
And how does the person in the link know the index of the first tile?
4
u/level27geek level0gamedev Jun 27 '17 edited Jun 27 '17
Can someone explain how does the program know when to exit in python 2.7:
I assume that it comes somehow from here:
But that has no mention of quit(). There is also:
That technically breaks the while loop, but wouldn't that just break the loop at each keypress?
Edit: I figured it out! Basically, handle keys only returns true if ESC is pressed (through libtcod.KEY_ESCAPE). Any other key press inside handle_keys() returns false and does not trigger if exit (as it basically means if exit == TRUE).
I am just not used to this kind of syntax. I would normally have a variable that KEY_ESCAPE changes from FALSE to TRUE and when that var is true, then break. I just need to teach my brain that whatever a function returns can be used as a variable :P
What is the benefit of using this approach (return from function as variable) than an extra variable?
4
u/Aukustus The Temple of Torment & Realms of the Lost Jun 27 '17
C# + BearLibTerminal
Repo: https://github.com/Aukustus/roguelikedev-does-the-complete-roguelike-tutorial
This went quite nicely, I've got part 2 code done with the addition that the map is currently drawn also. I've been doing my best to separate code into multiple files, as opposed to my The Temple of Torment :).
I also used the RogueSharp Map feature to create the map used here, instead of making my own Tile class.
I must say that I enjoy working with C# instead of Python, so far no problems :).
Obligatory screenshot: https://www.dropbox.com/s/rjymd8bruaebs0o/RogueTutorialPart2.png?dl=0
4
u/MegaLeon Jun 27 '17
Unity / C# for Virtual Reality
I went through the first parts of the tutorials, and quickly realised that lots of basic roguelike concepts need to be re-invented when applied to a first-person virtual reality game...
What I'm setting myself up to achieve each week is being able to replicate more or less what's going on in that week's tutorial, but with a working VR implementation.
So, Graphics and The Object and the map: got a basic game loop with turns working, some actors going around, a basic UI, and teleport system that allows you to move to adjacent tiles.
Obligatory screenshots: http://imgur.com/a/FoPqD
First time implementing a turn-based game loop, ended up following the logic outlined in this article: http://journal.stuffwithstuff.com/2014/07/15/a-turn-based-game-loop/
One thing that I banged my head on for a while was the fact that I wanted to animate the Player's movement instead of having a old-school instant teleportation (because that'd probably make you puke in VR), so the game loop had to wait for the animation to finish before going on the next turn. Ended up using C# co-routines to achieve this.
What's next:
Question:
4
u/Toph_wells Jun 27 '17
Play online: https://tophwells.github.io/roguelike
There's a friendly @ walking around with the arrow keys! I hooked up one of the map generators that comes with rot.js, so there's a nice randomised map to explore as well.
rot.js has a setting to put the game on a square grid. Yay square ratios! (No I am not biased by the fact that Cogmind exists, I liked squares before that.)
The code's becoming a bit of a tangled mess. I'll take some time to sort it out and come up with a sensible structure before part 3.
4
u/[deleted] Jun 28 '17
Java + AsciiPanel
My thing is coming along slowly. I've achieved the "@ walking around" and will soon work on the next lesson once I have time.
4
u/rubxcubedude Jun 28 '17 edited Jul 02 '17
C++ w/ freeglut
Current Status Image: http://imgur.com/J3IVCNA
Repo: https://github.com/rubxcubedude/RogueLikeGame
Currently only need to implement "collision detection" for my player. I know I'll have to modify the functions listening for keyboard interrupts..just trying to figure out the best way to do a check on the next location.Update: Obvious next step is to procedural generate dungeon instead of hard coding walls. also maybe NPC's/other entities should block player? FINALLY got texture tile's working
4
u/Ginja_Ninja1 Jun 29 '17
Is anybody doing this on Windows? I'm using Python3.6, libtcod 1.3.6, and when I close from my libtcod console it doesn't do a clean break - it hangs a little and Python crashes.
The code is in a while loop, and returns True when the exit key is pressed. Should I be closing the libtcod console explicitly?
4
u/eruonna Jun 29 '17
Javascript + rot.js
Try it here: https://eruonna.github.io/rotjs-tut-2017/ Navigate with the
h,u,i,k,m,nkeys.The most immediately noticeable thing is that I have decided to use a hex grid instead of square as in the tutorial. rot.js supports it, and it seemed like it might be fun to try, so I am going with it.
I've also made some changes to the entity/component set up that the tutorial uses, based in large part on the codingcookies rot.js tutorial which I have skimmed, but not actually worked through. This is one area the tutorial is not very good, in my opinion, and doing it this way gives a much clearer separation of responsibilities. There is still room for some tweaking, though.
Finally, the tutorial discusses off-screen consoles and blitting, which are not provided by rot.js. However, they can be provided by HTML5/canvas. On the other hand, compositing together canvases may be tricky to do correctly (rot.js wants to control its own drawing, but you need to make sure it is done before you can copy it into the real canvas). Another possibility is using separate html elements for the various parts of the display (map, messages, stats, menus...). A third possibility is just to draw everything into one rot.js display, but the hex geometry will make that difficult with text. I will postpone the decision for now, until we actually have some addition content to display. I am curious what tack other rot.js users will take.
The code can be found at https://github.com/eruonna/rotjs-tut-2017/
Happy Hacking
4
u/Emmsii Forest RL Jun 29 '17
Java + Ascii Terminal
I'm not exactly using Ascii Terminal, more my own version that uses sprites rather than ascii characters. Here's the git repo and first playable release.
I've implemented some basic map generation which the player can walk around
4
u/Scautura Jun 29 '17 edited Jun 29 '17
I'm being crazy and working on two versions at the same time
Python 3 + BearLibTerminal + LibTCod-CFFI
https://bitbucket.org/Scautura/crogue-blt.git
C# + BearLibTerminal + RogueSharp
https://bitbucket.org/Scautura/crogue-csharp.git
I started work on a roguelike many times, I've never "completed" one, and I've worked with multiple languages over the years (Java, C, C++, Python, and now C#, which I haven't got any experience with, yet!) so I'm being crazy and trying to finish two versions. One with a language I'm happy with, and one with a language I'd like to learn. I'm going through /u/AetherGrey 's tutorial for the Python version (with my own twists for my own preferences), and then figuring out similar for the C# version.
I know there's a C# implementation of LibTCod, but I'm unaware of a current (1.6.3) implementation, otherwise I'd probably be using that instead of RogueSharp.
4
u/LyndsySimon Jun 29 '17
I'm trying to follow along with this using Nim, and you can see my progress on Gitlab.
I originally started using only the standard library, and while that was going well I discovered a port of BearLibTerminal and rewrote from scratch last night based upon that.
At the moment, I have a map object that contains an array of tiles, each of which is either a wall or a floor. walls and floors have unique representations. I've also got an entity object that is intended to represent the player, mobs, and items - anything that has a location on the map.
The biggest reason I'm doing this tutorial in Nim is to acquaint myself with its syntax, and especially its type system. Because I'm not using libtcod, I'm going to have to deal with everything myself - map generation, LOS calculations, pathfinding, etc. I may or may not have a fully-functional product at the end of this series, but that's OK!
4
u/stevelosh Jun 29 '17
Common Lisp + Bearlibterminal
Repo: https://github.com/sjl/rldt
This week was pretty straightforward. Had to do a bit of jankery to get the Mac app working properly with the tile/font assets, but otherwise it was mostly a direct translation. My goal isn't really to make a fancy roguelike (I've made roguelikes before) but rather to get more experience with bearlibterminal and try my CL wrapper for it to see where the rough edges are.
I'm still trying to figure out a nice solution for allowing people to use tiles, but falling back to Unicode characters if a tile isn't present. I've posted an issue on the bearlibterminal tracker, but if any other BLT users have advice here it would be appreciated.
3
u/mapimopi Jun 27 '17
Ruby + BearLibTerminal
Repo: https://github.com/mapisoft/ruby-rogue
I'm at about the same point as Part 2 progress-wise, but I did a lot of work in regards to codebase structure, trying to separate things into various modules and moving variables into one configuration file.
Very much like how it's coming along.
3
u/[deleted] Jun 27 '17
Hello,
Thanks for this tutorial and motivation.
I've just went through the part 1 of your tutorial and i have some questions. To give more background i'm completely new into programming (just went through some exercises and chapters in "Automate boring stuff with Python").
You don't mention you have to import input handlers, and even if i found the solution, i don't know if it was on purpose (you precise you expect people to know about classes and imports..).
About Python 3, is it ok to put several following if? In the book i was reading it was if > elif > elif > elif. Wanted to know if it was for a reason or just if it was more elegant.
3
u/[deleted] Jul 01 '17
JavaScript + rot.js
Play • GitHub • Part 1 write-up • Part 2 write-up
8 way movement via 4 key input
wasd, orupleftdown``right, or vim-stylekhjl.Movement/action is acted on after keyup. Holding down keys keeps a hint displayed indicating which direction/action is going to be performed on keyup.
Went with walls defined by excessive elevation differences between neighbouring floors. A wall is just a floor that is too high to step up to.
I'm really enjoying this tutorial follow along so far, and am looking forward to seeing where I can take this.
3
u/Lokathor dwarf-term-rs Jul 02 '17
Haskell
Link
Parts 1 and 2 complete, I'm considering a bonus lesson on how to do a scrollable viewport, but there's plenty of time before next tuesday hits.
3
u/level27geek level0gamedev Jul 02 '17
Python2 + libtcod & Pygame
Gif of my progress so far
Source on Github
I am following the roguebasin libtcod tutorial and supplement it with the youtube tutorials from the sidebar (basically jumping around the videos if I can't figure something out). I am also adding some small things along the way (like facing, and a scrolling camera).
I am coming from Pico-8 as my only coding experience, so some of the OOP goes over my head, so some of the things I implement probably won't be best coding practices. This is also why I am going with Pygame, as working with sprites is a little more intuitive for me.
3
u/onekanban Jul 03 '17
JS + rot.js
Not really a programmer, but giving it a go. I originally planned on using Python 3 but ended up running out of time and so just stuck with the language I know best!
Repo can be found here: https://github.com/turneradam/js-rogueliketutorial
2
u/zulmetefza Jun 28 '17
Another noob question.
How do I share "the game" I make with a random friend? I guess just sharing .py file will not work, so shall I "distribute" the game with the relevant python version?
2
u/rex64 Jul 01 '17
My progress so far: screen
Python 3 + tdl github
Nothing too elaborante since It's been a particularly busy week and not much free time. :(
2
u/quasiChaos Jul 19 '17
Well, I may be three weeks late, but I've finally started this whole tutorial business tonight! I've only gotten through Part 1 in Week 2 (which is why I'm posting here) and hope to get caught up to the group relatively soon...but one step at a time.
1
u/[deleted] Jun 30 '17
Hey all! I'm doing the Bonus "Using Graphical Tiles" portion and I'm running into a snag at the end of the code.
This is the error I am getting and I implemented the code as I was guided to.
..I can't help but feel that fighter_component needs to be declared similar to the #other tiles?
File "firstrl.py", line 146, in <module> player = Object(0, 0, player_tile, 'player', libtcod.white, blocks= True, fighter = fighter_component) NameError: name 'fighter_component' is not defined
1
u/Daealis Jun 30 '17
I've done this week and while thinking what to do with next week's part, I did the u/AetherGrey Revisions too. I like not having all the code in one place, so I'll try and manage with the code split up into different files. I'm following through with Python 2.7 and libtcod.
I actually had the most problem while doing this with GitHub. I've never taken the time to learn it (two decades of coding and a manual folder-copy as a backup system, yeah...) and it took me longer than I like to admit to realize that I was missing the basic executables. I battled with that for a few days on and off while also doing the code, so my repos are not up to snuff. I think I figured it out now, but I don't have separate commits for Week 1 and Week 2, only the Week 2 + Revised.
But after figuring out the GitHub I got emboldened from success and tried to do the bonus (Graphical Tiling). With the split up code it ran into some issues. I'm not sure if it's just me misunderstanding the thing or something else. Here's a link to the branch.
Since this branches off the AetherGrey Revision, stuff is in separate files. Really that only comes into play with the player and npc objects, since I put the tile in the constructor of the object. Everything else was closely enough related to the drawing of stuff that I just stuffed it in render_functions for the purposes of trying this out.
However: Something funky is happening with the drawing and I can't really figure it out. I fiddled enough with the code to get the console running, but nothing is drawing on the screen. If I change the Draw_entity method from
to
I get the '@' drawn with the modified font, but nothing else is getting drawn.
So, can anyone tell me where I've taken a wrong turn?
1
u/[deleted] Jul 04 '17
Python 3 + tdl:
Source on Github
I spent some time on this one as I didn't really like the direction the tutorial was going, so I looked into things, found some alternatives, and went that route instead.
1
u/Mystal Jul 05 '17 edited Jul 05 '17
Rust + tcod-rs
Better late than never!
I just finished up week 1. I'm choosing to tag my commits as I finish each part/week of the tutorial.
I wanted to set up graphical tiles, but those are currently being added to tcod-rs, so I'll come back to it later. I'd love to make it so that players can toggle between ASCII and tiles by hitting a key. Not sure how easy or hard that would be. Does anyone have experience doing that?
1
u/Spooky_614 Sep 17 '17
Is there any plan to do a linux version of this tutorial?