Monday, 20 October 2014

Random Dungeon Generation:

Recently I was working on a title that had a random dungeon generation algorithm . It took some headaches and tweaking, but I finally was able to get something I was quite happy with. I'd thought i'd share the steps in case it would help anyone else doing the same:

1) Generate a 2D array that will represent unused tiles on a grid.
2) Mark a center tile and create a "main" room from this.
3) From this room, mark a north wall, south wall, east wall and west wall, as well as corner tiles and floor tiles. Mark each type of tile with a different array value.
4) Randomly select a tile that is a wall
5) Check which direction the wall faces
6) Depending how the wall faces, mark a vertical or horizontal door
7) Pick a seed tile adjacent to the newly selected wall tile, to draw a new room based on random length and width (this is probably the most tricky and confusing for calculations)
8) Depending how the wall faces, mark a new floor for the room. If the room only touches unused space, it's fine, but if it touches existing floor tiles, scrap the room and try again from step 4 (as it probably crossing in to a room it shouldn't).
9) Depending how the wall faces, mark more wall and corners for a new room. If any of the walls or corners touch floor tile, then stop the new room generation and try again from step 4(as it probably crossing in to a room it shouldn't).
10) Don't worry about wall tiles overwriting other wall tiles as it will allow rooms to share single walls.
11) If everything passes these checks, then draw the room to the array, and step up a room counter which will stop the generation loop when the max number of rooms you've specified has been reached. If it hasn't been reached, go to step 4.
12) The issue with this map is even though all rooms connect, there are no loops. This can be achieved by randomly selecting a few wall tiles and that have walls/corners on two opposite sides, and floor tiles on the other two opposite sides. This way some dungeons will have a loop or two.
13) The rest is easy, randomly mark up/down stairs, random loot locations, and random monster locations, etc

This will give you dungeons generated similar to the following:

Depending how you set your variables, you can change the layout of the dungeon by selecting number of rooms, min/max length and width of rooms, etc. In other-words, creating hallways is basically creating a room that is 1 tile wide.

To add to this, I created the above generator in C# as well as Javascript. This made it very easy to plug in to Unity. After spending about 30 minutes texturing some cubes, and adapting the code to unity, the ASCII above, was transformed in to this:

Forbidden Depths

Friday, 17 February 2012

Well the Campaign Editor is giving me issues, but they they will be ironed out soon enough. And getting Skyrim for the PS3 (Collectors Edition!!) from my Fiancee was a welcome distraction from programming :) So Now I present to you Revision 0000081, which has some nice additions! At this point the game is fully playable (aside from Rogues being incomplete) albeit small with only one dungeon and no content. But much more content is planned!

New items:
- Teleport scrolls now added! Will transport you 1-way back to town.
- Can now use items in combat! Use your healing/mana potion or teleport scroll!
- Can now be poisoned through traps or other means

Items needed:
- Rogue class not fully functional (rolling a Rogue is playable, but no special bonuses)
- Special spells for spellcasters
- More game content, tracking down bugs, bosses, more treasure, etc

Tuesday, 13 December 2011

Campaign Editor!

Because time is limited, there haven't been any recent updates. However, I wouldn't trade anything for the time i've been able to have with my Fiancee, daughters, and 3rd daughter on the way. Especially since it's Christmas time.

Instead of the tedious process of trying to finish the game, i've instead put my focus on the campaign editor. This provides a number of advantages. Having a creation tool like this will not only streamline the process of getting game content completed on my end, but will also allow others to join in to further speed up the process. Since everything is almost completely menu driven, it should be fairly intuitive for the novice. However, you'll probably need your handy graph paper for the map editor.

When it's ready for a download release, only the Spell Editor will be disabled for now, as the spell system is still under works, and there are many custom spells that are built straight in to the executable, and not part of the data save. So far, the options available will be as follows:

- View existing room settings and descriptions
- Edit existing or create new rooms and descriptions

- List existing monsters/NPCs and view their individual stats
- Edit existing or create new monsters/NPCs

- List existing items and view their individual stats
- Edit existing or create new items
- Items included are Weapons, Armor/Shields, Loot and Treasure
- Permanent items will have limited access (such as potions, chests) allowing you to change stats like price and other elements

- Edit game starting options such as the game introduction, what the hero starts with in regards to equipment, inventory, and what room
- Specify what rooms are listed as shops or trainers
- Specify what items or monsters/NPCs are in certain rooms

At this point, this should provide all the necessary parts in creating your own world that others can explore and find treasure and adventure. I would love to see what other could create from this. Although I would love to add a quest system/editor, because of the time and man power required (both of which I really don't have), this will be something that I think will be released in a future build.

For now i'm hoping to see a working campaign editor for everyone to use before the end of the year.

Thursday, 20 October 2011

Changelog for revision 00000.80

Here is the changelog for the new release of revision 00000.80

New items:
- fixed damage modifier bug when equiping or removing 2h weapons
- fixed issue where player could not read divine/arcane spell prices
- Item descriptions added. You can now look at items, weapons, armor etc,.
- Dying now costs gold. The church will ressurect you and take a "donation" of gold from you based on your character level
- Your dexterity now directly affects your chance to flee an encounter
- useable items! you can now buy red and blue vials (to restore health and mana respectively) at the apothecary. Not yet useable in combat.
- a scroll can be purchased now at the apothecary which will allow the user to transport back to town instantly
- inventory can now only hold 20 items (the items you are wearing are excluded from that count)
- new feature! there is now a weather and day/night cycle in game

Items needed:
- Useable items (healing/mana potions, teleport scroll)
- Rogue class not fully functional
- Armor,Attack and special spells for spellcasters
- Factor light weapon bonus for Rogues
- Backstab options for Rogues
- Resist traps for Rogues
- Dual Wield for Rogues
- Lots of game balancing
- More content/room descriptions

Existing Items:
- New feature added! can now attack preplaced (non-spawned) NPCs. Just beware if you try and attack the city guards...
- Spellcasting now active! Cleric and Sorcerer can learn and cast level 1 spells. Cleric starts with default chanted spell "cure light wounds"
 Sorcerer starts with default chanted spell "magic missle". Spell must be chanted out of combat. Additional spells can be taught at the Library
 (Sorcerer) or Church (Cleric). Cleric healing spell can be cast outside of combat.
- Clerics can now only equip blunt weapons, Rogues can now only equip light shields, light armor, and light weapons
 (only get bonus to light weapons). Sorcerers cannot wear armor (only robes/cloth), cannot use shields, and only use light weapons.
- Fixed a bug where if there was no treasure created for a certain level, would lock the program if attempting to generate
- Combat menu changed
- Treasure now drops according to room level, and not player level (sorry! no farming!)
- 2 handed weapons now functional!
- Cleric and Sorcerer class now fully functional except for specialty spells still need to be added
- spell system now active! (not combat ready) Clerics and Sorcerers come with one spell in their spell book. Spell must be prepared (chanted) before it can be
 cast in combat. Cleric spells can be taught at the church, while Sorcerer spells can be taught at the library (for the right amount of gold).
- fixed bug when training Fighter level 3,6,9 (would not break loop when selecting a stat to increase)
- release 75 has new savegame structure and will not work with older revisions
- combat now has four options:'attack', 'spellcast', 'use' or 'flee'
- moving to another room will now automatically show you if there are any items in it (you no longer have to type 'search')
- looking in your inventory will also show you what you have equipped (you no longer need to type 'equipped')
- fixed some small typos
- more game balancing
- fixed bug where program would not run on some 32 bit machines
- Monsters will now only attack when navigating, resting or doing nothing (pressing enter with no command)
- fixed bug where removing armor would increase armor rating instead of decrease
- balanced some purchasable items
- New Character creation system! 4 Stats (Strength, Stamina, Dexterity and Intellect)
- 4 Races (Humans + 2 STR, Elves + 2 INT, Dwarves + 2 STA, Halflings + 2 DEX)
- 4 classes (Fighter + 1 dmg, Rogue + 1 armor, Sorcerer + 2 mana, and Cleric + 1 spell power)
- Combat system completely recreated!
- Bug fixed where gold was looted, but not added in inventory
- Exits added throughout first level of crypts
- certain treasure now only appears according to character level
- chests added to game that can be looted just like corpses
- second level added to crypts (only 1 room, but has a new set of monsters that give more experience)
- new feature added: typing 'r' will execute the last typed command (NOTE: will not retype command, only execute it, good for resting!)
- Half of the room descriptions have been added in the city.
- The crypt has an entire level now scripted (room descriptions are not yet active)
- Game intro now added
- Health Points and Mana Points added to command bar
- Character stats rolling now added!
- Armor now factored in to combat!
- Loot system now active! upon dying, monster will leave a corpse. Corpse can be searched for items or gold (or nothing...). Gold will be picked up automatically, while items will fall to the ground to be picked up at leisure (and corpse will disappear)
- Items can be sold at the pawnshop
- Experience system has been added for monsters/kills
- Can now sell items at the pawnshop (for a discounted price)
- Glancing blows are now added to combat
- Rest system now recovers health AND mana points
- 10 Monsters added to crypts
- Combat system active
- City has been entirely re-created and mapped out
- Turn count system has been established (will eventually affect aging) and is affected by moving and by fighting monsters
- Added a blacksmith shop in the armory
- Can read the signs by using the "weapon prices", "armor prices" or "shield prices" command
- Player can purchase weapons, armor and shields
- Load or Save game (recognizes if there is no savegame file, or if it cannot overwrite a savegame file)
- Get and drop items in rooms
- Player gold system
- Inventory
- Slot items (Weapon, Armor, Shield)
- Can move up, down, north, south, east, west
- Commands are not case sensitive

Future Items:
- trap system
- another combat area: dungeon/sewers/caverns (for intermediate)

Friday, 30 September 2011

He'll be back... They always come back...

10 years ago, using Quick Basic 4.5, I wondered how hard it would be to cook up a quick text adventure. It was a fun little project, and became the source of hunger for something more. Unfortunately, other things in life made it take a backseat, and the code did nothing except collect dust. It returned again in the form of Python, 5 years later. Using lists and dictionaries moved the design time to about 1/10th of what it would have taken in another language. Unfortunately, life took over again and the project was lost somewhere, in the pit of despair.

A few months back, I picked up an old game called Forbidden Lands (by Computel). It's an old DOS port of a BBS MUD, and while being an RPG, is different animal than the usual roguelike, as there are no ASCII maps or characters. I've always found those distracting from the immersion (personal preference of course) of the game. I like the standard Interactive Fiction (ie Zork) style as it promotes storybook style imagination. I found the hours disappearing as I was playing this 20 year old game, 270k in size, and with no graphics.

As I continued playing the game, all I could see in my head was numbers being added to my old Python source code. Then I thought to myself: "Maybe I should create something like this?". After words of encouragement from my wonderful and understanding fiancee Stephanie, Shadows of Kalendale was born. A few blank sheets of graph paper soon became the City of Avalron, complete with a maze of crypts and full of undead monsters, waiting to eat Hero Brains (along with plenty of loot to discover, of course).

This game is more of a personal goal. However, if even one person finds a few hours of entertainment from this, I will have considered it more than a success. It's only in its Alpha stage of design right now, so i'm sure there are probably bugs galore. Stay tuned for more content, and happy dungeon delving!