Thursday, January 3, 2013

Making Semi-Random Dungeons in RPG Maker Part 1

There are a lot of good articles out on the internet about generating dungeons, so I'll try to stay specific to the topic as it concerns my prototype specifically and RPG Maker. But first, a quick bit of background:
RPG Maker gives the user a lot of easy to use controls to create content and string it together. The stringing together part, crucially, is translated to Ruby code behind the scenes. RPG Maker also introduces a lot of flexibility by allowing the developer to modify and write their own Ruby files. Some things remain off limits (e.g. the functions that decrypt and extract information from resources) but most everything else from characters to scenes is open for fun.

Now then, my goals for the random dungeon are pretty simple (I think). I want a dungeon design that is:
  1. Easily reproducible
  2. Feel hand crafted
  3. At least reasonably interesting to move through
  4. Always has a path to all pre-placed events on the map
Let's tackle the first one of these requirements first. RPG Maker is very much all about using static maps for the games that you can create with it. There is a custom dungeon generator included in RPG Maker VX Ace, but it generates the maps in the editor before compiling which means we can't leverage it to our advantage here. If there was a way to access this feature via scripting it would be a different story, but from what I can tell this is not possible.

The route I've decided to go will be to write a Ruby module which takes input such as a seed number and then generates a dungeon level based on that seed. This allows us to easily reproduce the exact layout of the dungeon floor as long as we don't lose the seed and we don't change the other variables that go into the map generation algorithm.

Inspired by other "mysterious dungeon" games I've decided that under certain circumstances the dungeon layout will change. So long as the player does not rest for the night to recover their HP & MP, they can leave and then go right back into the dungeon and it will be just as they left it. As soon as they rest though, the floor layout changes when a new seed number is picked. This decision unexpectedly helped me out when I realized that I couldn't save a generated layout to the map files (due to them being encrypted), but the engine already accounts for saving some variables for me, so I can just stick the seed in there for each floor and the player can save and load their game with no worries!

The next aspect I want is for it to feel hand crafted. If I wanted to be truly random here, all I'd have to do is pick a random number from 0 to whatever the top tile id number is and shove it into a map's data table. This dungeon would be very unlikely to be playable though. Instead I've decided that it would be good to make the individual pieces of the dungeons myself and then just have my generation algorithm place them as it sees fit. Hopefully this will make the map feel more like someone took the time to craft each little bit by hand, even though I'm not about to do that.

We'll come back to the other two requirements I have next time. For now, we have enough to get something basic working, so let's get to that. I'm going to talk a bit about the "technical" bits on how to do this, so if that's not your cup of tea, feel free to skip down to the screenshots.

Looking at the RGSS3 documentation, we can see that the Game_Map object has an accessor for a table called "data." The table is actually a simple implementation of a three dimensional array, containing exactly four integers for each x,y coordinate. Initially I thought that at least one of those four integers would be for storing which event (if any) was present at that coordinate, but on further research it seems like all four integers are for layers of tiles at that coordinate (which is not unexpected given that past versions of RPG Maker allowed you to access different layers to put tiles on top of each other, but sadly that is not the case with VX Ace).

I've chosen, completely at random, to make my dungeon floors 100x100 tiles in size and all my hand crafted rooms that will be randomly placed are now 10x10 in size. Each map is assigned an id which is directly related to its filename, making it easy to randomly pick a number from 0 to N where N is the number of rooms I've made (this is stored in a variable) and then add the id of the first room (right now it's 22). At this point, it just takes a little bit of scripting know how to whip up a couple of four loops that randomly choose a room and copy the data from it to the dungeon map every 10 tiles.

Before we do that though, I decided that it would be nice to place some things that are static on each dungeon floor, for example, a starting and ending area. The reason for doing this isn't too complex: I want to be able to have something I know will always be there like landmark or a place to teleport the player to when they go down a floor or something. I can also use this to create boss battle rooms or similar events that I might want to keep unique to a floor. With this in mind, before any room is chosen to be copied over to our dungeon floor I check the upper left most tile in each 10x10 set. If that tile has a tile id of 0 (that is, it is blank) then I go ahead but if it has any other tile id, then I assume that the 10x10 set it represents is already filled and I skip it.

After that's written, the next problem is figuring out how to call it on each floor. This is actually pretty easy due to the handy Event system in RPG Maker. On the map for each dungeon floor we'll add an event whose trigger type is Autorun. This means that the event will run automatically when the map is loaded. Using the script command we'll pass the map's data table and seed value into our algorithm and generate the map each time it's loaded, then we use the "Erase Event" command to keep it from firing over and over again.

Here's what it looks like after everything I've described is wired up:

For comparison, here's what it looks like in the editor:
This is at 1/4 zoom. That's the starting area down in the right and up on the left is the end of the floor.



It still has some problems though, where room exits don't always match up. Like this:
Too bad I can't get to the next room!


My next post will address the other two dungeon generation goals and fix problems like the ones above.

Tuesday, January 1, 2013

January RPG: Randomly Generated Dungeons

It is a test of game design. I will probably fail it.
As mentioned in my previous post, my new year's resolution for 2013 is to make one RPG prototype each month of the year with RPG Maker VX Ace. Each month I'll focus on a different aspect or idea and hopefully come out of the year with a handful of prototypes and a lot more experience with game design. To further solidify my commitment, I've signed up with a website I found this morning: www.onegameamonth.com It seems like I'm not the only person crazy enough to do this! Without further adieu, my topic for this month will be rather uninspiring: randomly generated dungeons.

I should come clean: I'm already going to cheat a bit here and not have completely random dungeons. Completely random dungeons would likely end up not being playable. There's no guarantee that I'd be able to walk from point A to point B! So I need to have some method of ensuring that I have a allowable path from any two points on the map. Then there's the problem of ending up with something more like a maze than a dungeon. A random generator wouldn't care much about room aesthetics, decor, etc. Such a thing would likely end up feeling very haphazard.

So I'm shamelessly stealing how I think Dungeons of Dredmor's generator works. I'll specify a number of room layouts, then I'll specify some events that I want on each floor, and then upon entry to the map, the game will plop random rooms down on the map, ensuring that there's a allowable path between the exit, entrance and all events on the map.

At the start, I'm just going to shoot for one randomly generated floor with static events, encounters and entrance/exit points. Depending on how easily the dungeon generation slides into place, I'd like to add randomly placed treasures, events, encounters, exits and entrances. The problem here is that I both cannot find a lot of encouraging information on randomly generating a map in RPG Maker and also that I am not terribly familiar with Ruby as a programming language. These things will slow me down, but I am sure that I'll reach my goal by the month's end.

Entire games have been based around just the notion of a dungeon that changes each time you enter it, and I'm certain that if things go very well I can just spend all month making better and better dungeons. So what about everything else that goes into a game? Well, this is where RPG Maker shines because I'm not going to do a damn thing about anything else. I'll be making a simple hub area for the single player character to return to in order to upgrade equipment, heal, etc. But things like story, custom assets or a custom combat system will fall by the wayside this month. These things are not directly related to the dungeon generation I want to focus on this month so I'll just ignore them where I can and let RPG Maker's default assets sort out the rest.

I'll post more here later about how this is coming along and the things I'm trying and how horribly they blow up in my face. For now though, here's a screenshot of the hub area I've created. It's probably going to be the easiest bit of the prototype this month:
So romantic.



Well, time to get started!

Friday, December 21, 2012

2013 Is The Year of The RPG

A week or so ago, RPG Maker VX Ace debuted on Steam. I had spent a lot of time in my youth messing around with RPG Maker 95, 98 and XP. I remembered those days fondly for a moment, and then passed it by. I simply didn't have $70 to spend on it. Steam's Winter Sale started yesterday, and the program was 20% off. Even at this much more reasonable price, I couldn't afford it. That's when my roommate gifted me a copy of it over Steam.

I've been thinking about what I could do with this that would be meaningful and also forward my own development efforts. If you check the date of the previous post before this, you might be under the impression that I haven't been doing any game development lately. This is partly true. November is eaten by National Novel Writing Month every year, and after that 30 day thing, I was just too burnt out from all the rush. I have spent some time working on games though, just not enough to warrant any sort of blog post. There was some fiddling with the platforming engine, some XNA experiments, a lot of article reading, and finally I decided to make a simple JRPG in Unity which got as far as me working out the stat systems and displaying a map before November hit. I've got lots of ideas, but the startup cost for trying them out is always too much because I'm working in XNA or Unity where I have to either start from scratch or spend time understanding other people's frameworks before I can try out the thing I wanted to play with. This is no longer an issue.

With the aquisition of RPG Maker VX Ace, a tool I'm familiar with, I can create basic JRPGs very quickly. The biggest new feature to this version of the program is the scripting editor and it looks very flexible and easy to understand. So I'm going to jump in head first and start doing things: I've decided that 2013 will be the year of the RPG for me. My new years resolution is to make one JRPG prototype per month and I'll release it here on my blog at the start of each new month.

My plan is to focus on one core idea each month, and build the rest of the game around that idea. So for example, I want to dive into the scripting system, so maybe I'll do random dungeon generation for January. Everything else will be incidental, so I'll be skipping over steps I'd take in a more polished game like creating custom art assets. Or really any sort of resource. I'm a programmer and aspiring game designer, not an artist. It simply isn't feasable for me to do the art for my prototypes and RPG Maker accommodates that.

Early on in the month, I'll post what my theme is for the month and what my progress is like. I'll try to post about challenges and the process of getting an idea working and fun. Ideally, this will result in me gaining some experience as a game maker and some cool things will come out of it. I hope you'll be here with me whether I have soaring success, or miserable failure.

Saturday, September 1, 2012

Progress Update?

Oh man, Guild Wars 2 is so much fun. I'm spending pretty much all my free time playing it.

What's that? Adventures of Balzac? Programming?

They're crying over how little work has been done.
So I said I would be fixing bugs and then releasing the first level as a demo yesterday come hell or high water. It didn't happen. Between doing a ton of programming for my actual day job (web development) and Guild Wars 2's recent release, nothing has gotten done on my game. This is very frustrating for me since I'd love to get a job in the games industry, but feel like I need a portfolio to show first. Now it's September, 4 months since I started programming my game, and 1 month since I got anything meaningful done on it.

I'm feeling kind of lost on this project because...well, I'm not sure why. Maybe it was the fact that the game is pretty bland and generic in terms of gameplay and I'm not entirely sure what to change about it. Maybe it's that after spending every available free minute during July working on the game, I just burned out on it a bit. I'm not sure what's causing me to feel this way about the project, but I've got to take steps to deal with it and get back on track to shaping the game up to a point where I can feel good about posting it somewhere.

What I've decided to do about this is two fold:

  1. I will no longer hold myself to the previous "I need to have visual progress every Saturday" standard that I was keeping up during May, June and July. Progress will come on it's own time and I'll just have to deal with it. I suspect that there will be more progress when things are slower at work though, and less when, like now, we're scrambling to make sure all our ducks are in a row so that we can release our product.
  2. I'm going to sit down and be mapping out possible ideas to integrate into the engine. As it stands I have the jumping and shooting aspect more or less down pat. But there are other things to think about including level gimmicks and code structure (which still needs to be fixed up after the rush at the end of July). So I'll be carefully planning out where those go from here.
Hopefully these two strategies will lead to me getting more work done and feeling better about it in the future. If anyone has any ideas on how to deal with this kind of lethargic, wandering feeling regarding a game project or if you have a neat idea for a platforming mechanic that you'd like to see in a game, feel free to drop a comment below and tell me about it.

Saturday, August 18, 2012

Progress update 8/11/12 - 8/17/12

This week:


  1. I spent some time writing a simple blackjack game for the Petit Computer app on my 3DS. It isn't done, but it was a nice distraction.
  2. I spent some time watching panels from QuakeCon and some other talks about game development. July was all about rushing to get something done as quickly as possible, but now that it's over I want to devote some time to trying to prevent myself from mistakes.
  3. I fixed the bug that causes you to fly speeding through the floor whenever you get take damage from something when you're in the air. Though ultimately unrelated to the collision handling subroutines, I've already begun rewriting them. The next step in this process will be to determine whether my old subroutines are fine as is or if I should finish rewriting them.
No screenshots this week. Lots more time was spent playing videogames again, something I didn't really get to do in July and haven't really done since May. It's been lovely to remember how much fun games can be and how much I like to just sit down and play one sometimes. The first level is still on track for a public release at the end of the month, so I'll just focus on getting it as polished as possible for that time.

Saturday, August 11, 2012

Progress Update 8/4/2012 - 8/10/2012

This week:


  1. Worked on a prototype for a different sort of game in XNA. Probably won't keep it in XNA, and might not go much further with it. Who knows right now.
  2. Fixed a bug or two in Balzac, but not enough to warrant demo release.
  3. Waited anxiously for feedback from judges in last month's contest and recieved none.
  4. Reorganized TODO list for Balzac and thought about what needs to be done going forward.
Despite still feeling kinda burnt out from all the work I poured into the previous month and the release of new videogames that I love to play, I'm trying to get back into the swing of things and do something related to my game project each day. I thought that this past week would be more productive, but I guess I burned out last month a bit more than I was expecting. Anyways, the plan going forward is still to fix bugs and some art assets to make the demo more presentable, and then release it. My revised estimate/personal deadline for releasing the demo will be September 1st, which is a Saturday. Come what may, I'll release it that day and start asking for feedback. Maybe after I get some more feedback, I can get back into a position where I'm making visible changes each week!

Saturday, August 4, 2012

Progress update for 7/28/12 - 8/3/12

This week:

Coming back from my last vacation for the month, I crammed a lot of work into the last two days of the competition (the 30th and 31st). Below is a short list of things that got done:


  1. Created a bad, but topical, main menu screen.
  2. Created new enemies: Squid and Miniboss Squid
  3. My roommate added behavior for the BallRusher enemy and I ended up tweaking it a bit
  4. I also leveraged existing logic into getting the Squid and Miniboss Squid some AI patterns. They aren't great, but they'll do.
  5. Added more enemy placement throughout the level
  6. Wrote entirely new logic for Squid enemies, the miniboss can deal with having the old logic.
  7. Fixed some miscellaneous bugs relating to animation and enemies facing the right direction.
  8. Added some music that I got from www.freemusicarchive.org
  9. Added support for respawn points.
  10. About an hour and a half before the deadline, I started adding the boss battle for our only level.
  11. My roommate added a credits screen.
  12. I added a fireball sprite for the boss
  13. Added the music attributions to the credit screen 
  14. Slapped together the entry form for our game and submitted it with about ten minutes to spare.
  15. Submitted a patch the next morning because it turns out in my exhausted rush to get this done, I fucked up something simple with the respawn support, so you could crash the game by dying in the first 5 screens.
So the game is in a good state now, but I'm totally wiped out from the constant "go go go" of the contest, so I'm relaxing a bit for a few days and prototyping a different game before I continue work on Balzac. What will likely happen is this coming week I'll spend my time polishing and fixing bugs that I saw but didn't have time to deal with in July and then I'll release the first level as a sort of demo for the game. Hopefully that will make up for the lack of screenshots this week.