Tuesday, 29 June 2010

Roguelike: room generation sourcecode

A few people (hi, /r/roguelikes!) have asked if I'd share my roguelike source code, or at least some of it. As a Flash dev I know I'd be really excited to see how other Flash devs are handling roguelike development, so I figured it's only fair to get mine out there. I'm hoping some gurus out there will tell me if I'm doing this wrong, and point me in the right direction, it's all a learning process!

OK, so anyway, the first thing I'm posting is a highly simplified version of my room generation code, that shows a random single room being built, and a character dropped on to a valid random square. I've also stuck it on an external Pastebin link rather than an embedded one, as this code has long descriptive comments on that freak out a bit when they're stuffed into a thin blog format.

Feedback would be appreciated!

http://pastebin.com/BBPpGPBz

5 comments:

  1. Hey Dan.
    Code looks the business good to see you taking some time commenting and layout etc.
    One thing I would recommend is moving code into smaller methods for instance in the line :-
    // Loop through all horizontal tiles in each vertical row
    You could shift the code that does that into its own method called create horizontal tiles. Same with some of your other code could be broken down further into smaller methods. Just being picky but does look good fella!

    ReplyDelete
  2. No problem,
    In some instances you can actually replace comments with method calls out which explain exactly what they do without the need for comments. Controversial some may say in terms of reducing comments but I find it can work well. Particularly when people don't have to go into your method to know exactly what it is doing. Smaller methods also mean you can reuse more easily and also unit test if that is a route you go down later when testing your code.

    Good luck and keep up the good stuff!

    ReplyDelete
  3. I actually only added the lengthy comments because I was posting it online; I'm usually a lot more concise, honest! Nothing annoys me more than people sharing their code and making it a chore to get your head around.

    ReplyDelete
  4. Yes I know what you mean. Makes me feel all stabby when I see that sort of thing.

    ReplyDelete
  5. Thank you for being the one person on the internet to share their level generation code for AS3! I'm starting out learning how to make a Roguelike, and am having a hell of a time with the level creation part. Looking through what you have has been extremely helpful! Did you abandon this project, or are you still working on it? I'm trying to figure out how to expand this to create multiple rooms in a binary tree format. Would you be able to help me with that?

    ReplyDelete