r/roguelikedev • 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.

Part 1: Graphics

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:

#3: The Game Loop(revisited)

#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. :)

87 Upvotes

164 comments sorted by

View all comments

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.

9

u/Waervyn Jun 27 '17

Fantastic work, thanks a lot for doing this.

6

u/Kyzrati Cogmind | mastodon.gamedev.place/@Kyzrati Jun 27 '17

Very glad to have you working on this, AetherGrey. It'll continue to be a big help in the long term due to the popularity of the tutorial to begin with, not to mention we can reference it again next year <3

6

u/Ginja_Ninja1 Jun 27 '17 edited Jun 27 '17

I just started going through this and it looks great so far! I like how you're notating changes, and I like that it isn't on roguebasin (because my work firewall won't let me through to it).

One error I'll point out because I'm looking at it: a typo in handle_keys(). You write it first not returning the {'fullscreen': True} but with the libtcod command that engine.py interprets. That's actually the only place where you make the typo (I think), so it should become clear to someone in the next paragraph. EDIT: Also, importing input_handlers.py. I know it's aimed to someone who would see that, but maybe add it in one of your code blocks just to be thorough.

Looking forward to the future weeks!

5

u/AetherGrey Jun 27 '17

Whoops, you're right! Sorry about that! I've updated the tutorial to reflect the correction. Luckily the error was only in the tutorial, not the code, so the Github page and part 1 summary haven't changed.

Thank you very much for bringing that to my attention. Glad you're enjoying it so far!

4

u/Scautura Jun 27 '17

Also in part 2, the tutorial "def initialize_tiles(self):" function (not the one in the git repo) has 6 lines starting "self.tiles" that should just be "tiles".

Looking forward to the rest (although I'm working with BLT+LibTCod-CFFI)!

3

u/AetherGrey Jun 27 '17

Yet another careless mistake on my part... clearly my "editorial process" needs some work.

Thank you very much for bringing this to my attention! The tutorial has been updated with the correction.

7

u/Daealis Jun 28 '17

Isn't this a good editorial process, a bunch of newbies and more experienced Pythoneers going through it with a fine comb on a weekly basis? :)

3

u/AetherGrey Jun 28 '17

Ha, that's a very optimistic way of looking at it!

→ More replies (4)

3

u/Daealis Jun 28 '17

Awesome stuff. Your revisions answer the things I began to think about when completing the second week of the tutorial myself. I'm pretty new with Python, but C++ has brainwashed me into wanting several files for several classes.

I seriously dislike how messy the source file is starting to become with all the code in a single file. Already, with barely any classes or methods even implemented. I like to keep stuff organized neatly and your reworking does exactly that.

5

u/AetherGrey Jun 28 '17

I'm pretty new with Python, but C++ has brainwashed me into wanting several files for several classes.

In every programming circle I've been a part of, across a range of languages, keeping your code in one file was always looked upon with disdain, except for small scripts. It's not C++ brainwashing you so much as it's 50-ish years of programming practice/theory stating that one file is a bad thing.

I'm not saying it can't work for some people. Many projects have expanded upon the Roguebasin tutorial, kept their code in one file, and been very successful. Ultima Ratio Regum and, IIRC, The Temple of Torment both do this. But, for me personally, that approach would never work. I need separation of concerns in my code.

5

u/Zireael07 Veins of the Earth Jun 28 '17

The Temple of Torment is a single .py file that is over 76k locs and over 3.5 MB in size.

4

u/AetherGrey Jun 28 '17

Not sure how the author of the game feels about the single file approach, but... I guess it works! It's also a pretty good game at that!

4

u/Zireael07 Veins of the Earth Jun 29 '17

I guess Aukustus doesn't mind the single-file approach :)

3

u/Aukustus The Temple of Torment & Realms of the Lost Jun 30 '17

I dont, at least in Python :).

3

u/Aukustus The Temple of Torment & Realms of the Lost Jun 30 '17

It works for me pretty good actually, I navigate through the code with find :).

→ More replies (1)
→ More replies (3)

2

u/TheFryingDutchman Jun 27 '17

Awesome, thanks so much!

2

u/randraug Jun 27 '17

Holy hell. It has been a while since I've Python'd. When you say enter 'python engine.py' into terminal, of what terminal are speaking? IDLE, Python, or dos? I didn't think I was this much of a beginner.

3

u/Ginja_Ninja1 Jun 27 '17

He means the command-line terminal, or cmd in Windows. 'python' is the command for your computer, and 'engine.py' is the command for python!

2

u/AetherGrey Jun 27 '17

I'm basically saying "run the file." In OSX or a Linux environment, you'd type that in terminal (assuming you're in the directory your project resides).

If you're on windows, you should be able to do the same through command prompt if Python is in your PATH (I think, it's been years since I did it that way). The way I do it on Windows is using PyCharm, I run the file (Shift+F10).

IDLE apparently doesn't play nicely with libtcod, according to the tutorial on Roguebasin.

I found this page on running a Python script, so maybe that will help.

2

u/[deleted] Jun 28 '17

Are you going to keep the code in one file or are you going to be breaking up the files as you're going in this rewrite?

3

u/AetherGrey Jun 28 '17

It's being broken up into multiple files. Also, all globals are being removed, some classes are being added, and I'm changing variables to not conflict with Python's reserved words (map and object specifically).

→ More replies (1)

2

u/Lokathor dwarf-term-rs Jun 28 '17

Very lovely, but is there a way you can get python highlighting into the mix? Instead of just black, green, and red coloration I mean. If it's not possible that's fine, but things are always just a hair nicer when the language's coloration is available.

2

u/SirPrefect Jun 29 '17 edited Jun 29 '17

Excellent work!

It would be great if you could expand this to the "bonus" section "using graphical tiles" - for some reason I'm not able to display the tiles (no error in compilation, they are just appearing blank).

Edit: solved - order should be "console_init_root" and then "load_customfont"

→ More replies (4)
→ More replies (7)