Author Topic: Beginner's Guide to Roguelike Development  (Read 11671 times)

cstickel

  • Newcomer
  • Posts: 3
  • Karma: +0/-0
    • View Profile
Beginner's Guide to Roguelike Development
« on: June 07, 2012, 04:57:20 AM »
(This is a cross-post from r.g.r.d)

Hi all,

A few *cough* years *cough* ago I started writing a guide for new programmers to help ease into roguelike development and avoid common pitfalls (mostly avoiding bad habits). The goal was to get you started and having fun quickly, cleaning up and expanding as it went.

At the encouragement of a few really nice people, I've dusted off the guide and have rewrote it, added a few more articles and hosted it at a new home: http://www.kathekonta.com/rlguide/index.html

Please feel free to check it out and let me know what you think. If you're new to programming or game development, your opinions count double!

Happy coding!

- Craig

Krice

  • (Banned)
  • Rogueliker
  • ***
  • Posts: 2316
  • Karma: +0/-2
    • View Profile
    • Email
Re: Beginner's Guide to Roguelike Development
« Reply #1 on: June 07, 2012, 09:04:23 AM »
and avoid common pitfalls (mostly avoiding bad habits).

Using all caps variable names in C++ is a bad habit, but it wasn't the only problem. Looking at your code it's the "good" old C style that leads to source code which is difficult to maintain. I'm interested to know if you ever created any roguelike game yourself?

cstickel

  • Newcomer
  • Posts: 3
  • Karma: +0/-0
    • View Profile
Re: Beginner's Guide to Roguelike Development
« Reply #2 on: June 07, 2012, 03:03:51 PM »
Hi krice. Thanks for reading it through. I was wondering if you could point out where the all-capital variable names are? I agree that is a poor coding style and should be changed. As far as i know, i don't have any. I do have all-capital type names - a standard used in my professional life that has snuck into my RL life as well. If enough people don't like that, the I'm more than happy to change it.

As for the old-school C style: if I remember correctly, we've debated on this topic before. My approach is to get something up and running first, then switch over later to drive home the significance and power of proper design. The concern is that oop is an abstract and long-to-explain topic that beginners may not have the patience for just yet. I agree with you that proper coding technique is paramount, I just know what I was like when I first started.
« Last Edit: June 07, 2012, 03:08:52 PM by cstickel »

Krice

  • (Banned)
  • Rogueliker
  • ***
  • Posts: 2316
  • Karma: +0/-2
    • View Profile
    • Email
Re: Beginner's Guide to Roguelike Development
« Reply #3 on: June 07, 2012, 06:57:09 PM »
I'm more interested to hear what roguelike games you have created.

Hi

  • 7DRL Reviewer
  • Rogueliker
  • *
  • Posts: 154
  • Karma: +0/-0
    • View Profile
    • Email
Re: Beginner's Guide to Roguelike Development
« Reply #4 on: June 07, 2012, 08:03:28 PM »
I'm more interested to hear what roguelike games you have created.

I still think that you are making a joke whenever you do that.

tuturto

  • Rogueliker
  • ***
  • Posts: 259
  • Karma: +0/-0
    • View Profile
    • pyherc
Re: Beginner's Guide to Roguelike Development
« Reply #5 on: June 08, 2012, 05:34:35 AM »
The articles are pretty nifty and they focus on the very basics, which is good. I think it makes sense to first show simple way to create something and later tell what other options there are or where to find more information. Concepts are introduced in a good order, there is always something new to play around with after finishing reading an article. Person reading articles probably hasn't ever written a roguelike, so the game they'll create probably won't be the last one they write (if they stick to it), thus I don't think doing regular C is a problem.
Everyone you will ever meet knows something you don't.
 - Bill Nye

mariodonick

  • Rogueliker
  • ***
  • Posts: 296
  • Karma: +0/-0
    • View Profile
    • LambdaRogue .:. roguelike RPG
Re: Beginner's Guide to Roguelike Development
« Reply #6 on: June 08, 2012, 08:01:53 AM »
Quote
The concern is that oop is an abstract and long-to-explain topic that beginners may not have the patience for just yet.

I'm not sure -- it should be a good mixture and depends on what you want to program. OOP is very good for creating creatures, items, buildings etc., because you can easily describe the things and processes you see in your imagination using objects. You don't need to explain the concepts behind OOP -- you can simply use OOP, and explain the details later.

Edit: What I mean by this: Don't teach newbies programming by stating

"To program a roguelike with a dragon and a knight, we need to care about data structures, algorithms, and to choose a programming paradigm. There are several programming paradigms and their advantages and disadvantages are..."

Instead, tell them:

"Okay, we need to create the dragon and the knight. Both are some kind of object, and in our programming language objects are created by writing XYZ. Now we have created our dragon. We can now add some properties to the dragon, like sex, color, health, strength. Such things can be expressed numerical, so we simply add numbers to our object. This is done like this ... Now the same for the knight. Okay, to make them move on the screen, we need them to listen to the player's input."

So simply start programming by creating and refining objects which resemble the game world and its inhabitants, but don't talk about what OOP really is. This is useful later, but not for a total newbie who simply wants to get a hobby project started. This newbie needs successful experiences very soon, otherwise it's likely that he'll give up.


(Well ... actually in LambdaRogue I started without OOP, and only use records, and lots of global variables, but I once started a complete re-write of the game (LR 2.0) which only uses OOP. However, this project will probably never be finished, because it's more efficient to work on the 1.x branch).
« Last Edit: June 08, 2012, 08:10:44 AM by mariodonick »
https://mariodonick.itch.io/lambdarogue-the-book-of-stars
-- LR: The Book of Stars graphical roguelike RPG

kraflab

  • Rogueliker
  • ***
  • Posts: 454
  • Karma: +0/-0
    • View Profile
    • kraflab.com
Re: Beginner's Guide to Roguelike Development
« Reply #7 on: June 08, 2012, 08:55:57 AM »
I agree that I don't really think it matters whether you do oop or not.  That being said, i wouldn't use something like C (or c++) as a tutorial for programming or game design.  Actually i am kind of against game development tutorials in general, but that's another story.

Z

  • Rogueliker
  • ***
  • Posts: 905
  • Karma: +0/-0
    • View Profile
    • Z's Roguelike Stuff
Re: Beginner's Guide to Roguelike Development
« Reply #8 on: June 08, 2012, 11:43:56 AM »
Quote
Actually i am kind of against game development tutorials in general, but that's another story.

I agree there.

This tutorial teaches its readers how to create a map structure, how to display it, and how to make a @ move on it. It is also done in the simplest way possible. For example, there are two separate integers which describe the position of the player (x,y coordinates). I agree that this is simple, but if we are being serious about writing a roguelike, then it is very likely that we should actually create a "point" class. Maybe even we should create a "monster" class and let a player be a special instance of it (both my Hydra Slayer and HyperRogue don't do this, but if it is important for your design that the player is just as a special monster, then you should).

Another example: in Article II movement is done by repeating roughly the same piece of code four times. Yeah, this is the simplest way for this tutorial, but obviously this piece of code is incomplete, as later we will have to add monster movement after each our move, a check whether we have wandered into a trap, special abilities activated by special movement patterns should be activated, and so on. We will have to remember to always add these new stuff to four places. And we will repeat the same four-repetition structure whenever we add monster movement, missile weapons, and so on.

But it is much more convenient to create an array of directions: create an array of 4 vectors which correspond to the four directions, and simply write the general routine which adds the i-th vector. This makes serious roguelikes easier to write, and as an added bonus, if you later decide to make movement eight-directional or hex-based, or decide to let the player choose for themselves, then you can change this without any problem.

By writing this in the simplest way possible, you make it harder for your readers to continue development. And you don't teach the very important design principle, which is that you should never repeat yourself.

Even more important thing the tutorial teaches you is that whenever you write a roguelike, you should write the @ moving on screen. This is false! Good programmers do not do that. Jeff Lait has written eight seven day roguelikes. If you look at the newest one, Sword in In Hand, you will notice stuff that traces back to the oldest one, You Only Live Once. If you look at the source, you will notice things that are obviously irrelevant for Sword In Hand, but have been written for one of his previous 7DRLs and not removed. I have been once teaching programming to a friend, and he noticed that whenever we started a new project, I copied the sources of something else and removed almost everything.

That's how development is done. Bad artists imitate, great artists steal. You don't write basic stuff, just copy it from your older projects, or if you have no older projects from your own, learn/copy from older projects of other people.

I have created a roguelike which uses hyperbolic geometry. I think this was a good idea and want other people to create hyperbolic geometry roguelikes too. But I would not recommend people to implement hyperbolic geometry on their own, or write a tutorial which explains how to do that. Instead, I would recommend them to take HyperRogue source, learn how it was done, and modify it. They would only need to throw away the game mechanics engine and write their own, and understand vectors and matrices if they want to create new graphics, but they would not need to understand how the map structure was implemented, only use what is already done.

The same goes for generic roguelikes. Thomas Biskup has created QHack which is a simple roguelike written in C. I think a well documented and free-to-use working example is better than a tutorial. Other people would start with Angband, or with T-Engine. There are probably other good choices.

As far as I can tell, it is currently impossible to download the complete roguelike written in this tutorial. That is wrong. I think that you should comment it thoroughly, make it available for download, tell the players to download it and modify it, and provide the tutorial as a backup for those who want to understand why something has been done in a specific way.

That being said, i wouldn't use something like C (or c++) as a tutorial for programming or game design.

Do not write a roguelike in C. Write it in C++, it has many extensions, some of them will be useless for you, but there are other ones which are very useful (for example, I would not recommend a newbie to use C style strings, STL strings are OK). Don't write it in pure C++ either. Use an existing roguelike base (possibly based on C++ itself), it has extensions which will be even more useful for you.

Omnomnom

  • Rogueliker
  • ***
  • Posts: 79
  • Karma: +0/-0
    • View Profile
    • Email
Re: Beginner's Guide to Roguelike Development
« Reply #9 on: June 09, 2012, 01:07:50 PM »
This is the kind of stuff they should teach in schools. Don't bother will "hello world" applications, just get to move an @ around the screen.