Python Forum
[PyGame] [In Progress] - Rogue-Like Game Tutorial
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[PyGame] [In Progress] - Rogue-Like Game Tutorial
#1
There's a community on Reddit (https://www.reddit.com/r/roguelikedev) which is putting a roguelike game together, a piece at a time, on a weekly basis. It's not the first time they've done it, so we know it'll take 13 weeks. It sounds like fun, but I'm not interested in using the libtcod library to have a game running in the console, so I'm adapting it to work with pygame. Since all the tutorials are followed along with discussions, notes, and q&a, I'll try to keep the same pace as them, and link to their discussions. Likewise, I'll try to keep the project as close to the tutorial as possible, so you can read through it and have it work with very minimal changes.

github repository: https://github.com/nilamo/roguelike

Section 0, basic setup
Tutorial: http://rogueliketutorials.com/tutorials/tcod/part-0/
Code: https://github.com/nilamo/roguelike/tree/section-00
Notes:
  • After installing python, I recommend setting up a virtual environment (it helps to keep track of which dependencies are used for each project, which can help make distribution issues easier to solve). In this case, inside the repository, I ran python -m venv . to create a new environment in the folder I was currently in.
  • At the root of the repository, I also created a batch file which will open a new console window inside the virtual environment, so it's easier to activate. This is completely optional, but I'm lazy and did it for my benefit.
  • The virtual environment's Lib folder is not included in the repository, because it's fairly large, but also unrelated to the project. Creating the environment, and then running pip install pygame from within the environment will accomplish the same thing for you.

Section 1, basic pygame use, event loops, input handling, displaying a sprite, and moving the sprite
Tutorial: http://rogueliketutorials.com/tutorials/tcod/part-1/
Discussion: https://www.reddit.com/r/roguelikedev/co..._tutorial/
Code: https://github.com/nilamo/roguelike/tree/section-01
Notes:
  • The original tutorial is based on a console, where 1 "unit" is a character. Since we're using pixels instead of characters, I added the concept of a Block Size, which scales the units up to the appropriate pixel. This way, most of the tutorial stays the same (you still move one unit at a time, for example).
  • Furthermore, using fonts and drawing characters to screen is weird, so instead I created a transparent png for the character. Same outcome, different path.

Section 2, Entity class, render functions, and a basic map
Tutorial: http://rogueliketutorials.com/tutorials/tcod/part-2/
Discussion: https://www.reddit.com/r/roguelikedev/co..._tutorial/
Code: https://github.com/nilamo/roguelike/tree/section-02
Notes:
  • The concept of "colors" doesn't make as much sense since we're not using a terminal. Because we're using actual images, and coloring them outside of the engine (Paint.net, photoshop, the gimp, etc), naming things based on their color isn't significant. If that isn't factored out of the tutorial soon (maybe around map generation), I'll remove/rename the color variables to something that more accurately represents what they are. "block_type" perhaps.

Section 3, Map Generation
Tutorial: http://rogueliketutorials.com/tutorials/tcod/part-3/
Discussion: https://www.reddit.com/r/roguelikedev/co..._tutorial/
Code: https://github.com/nilamo/roguelike/tree/section-03


Section 4, Field of Vision
Tutorial: http://rogueliketutorials.com/tutorials/tcod/part-4/
Discussion: https://www.reddit.com/r/roguelikedev/co..._tutorial/
Code: https://github.com/nilamo/roguelike/tree/section-04
Notes:
  • The tutorial relies on libtcod to handle field of vision, and keeping the fov map updated, and thus mostly focuses on how to represent that information to the player. Since we're not using libtcod, I wrote a couple functions to do that using some trig. It's fast (well, fast enough that you won't notice it slowing anything down), but not perfect. libtcod has several different algorithms to try to give the "feeling" that you want, I just went with basic ray-casting because honestly that's good enough lol.



...this section to be expanded upon over time...
Reply
#2
You may want to think about branches for each section. So then you dont have to look at the commits and apply the changes, you also have the option of looking directly at the code of each section. I think it makes it easier for new users to identify. And you can link each branch along the way, so they dont get confused by branches if they do not know about it.
Recommended Tutorials:
Reply
#3
Good suggestion, thanks. I'll try to get that switched over tonight, and fix the links to point to the branches.
That'll give me the chance to add a Readme to each branch, to list all the differences from the main tutorial, and why those changes were made.

Edit: Alright, it's using branches now.
Reply
#4
Just added section 2. I didn't realize the reddit group was doing two sections per week, so I'll get section 3 done in the next day or two, and probably work on getting a few done ahead of time to avoid falling behind if I get busy.

In other news, I've also started taking the idea behind the project and re-implementing it in Unreal using freely available assets (like the ones that ship with the engine, lol). The idea behind doing this, is that I don't want someone to see the tutorial series and think something like "I'm not interested in terminal games" and just walk on past. I want to show that the concepts it introduces you to are key to pretty much all roguelikes, regardless of whether they're text-based, 2d, 3d, web-based, or pen and paper (like a custom game of Dungeons and Dragons).

That's actually part of the reason I'm doing this in the first place: the game I want to work on is partly a Roguelike, so following through the series gives me an extra level of motivation to actually work on it lol.
Reply
#5
Section 3 is up. All of the rendering code is unchanged, and there's nothing different from what's in the tutorial.
Reply
#6
Between the holiday (4th of July), and a wacky issue I ran into, I'll likely be delayed for a bit. A surprisingly large amount of section 4 is handled almost entirely by libtcod's c library, which obviously we don't have access to since we're not using a terminal. So I ran into a bit of a speedbump re-implementing Field of Vision, and need to debug it.

Well, I ran into several issues. The first, is that it straight up doesn't work right currently (all walls in the level are visible, but none of the floor is), which likely means I made a silly mistake late at night lol. The second issue is that it's abysmally slow (every time you take a step, there's a full second or two delay before the screen updates). I wasn't trying to do any tricks to make it fast, and was basically brute-force checking each tile to see if it's visible, so the speed thing can probably be improved.

The good news is that section 5 looks rather simple, so once I get fov working right, we'll be caught up for the week.
The bad news is that section 6 (next week) contains A* path navigation for enemy ai movement, which again uses libtcod internals. Section 7 looks like it should be fairly easy though, so I guess we'll see.

*edit* Boom, got it working, and at "you won't notice it" speeds, so that means it's time to move on.
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020