I can’t believe it! I’ve had the worst bug I have ever dealt with in my code. Just spent roughly 24 hours (12 hours each day) trying to figure out what went wrong and of course it was something really stupid that I just kept looking over. 😐
First, I decided on a way I wanted to code the random dungeon generator. Something very simple that wouldn’t take too many cycles for the Atari to handle. I remember reading once a long time ago how Richard Garriott (Lord British, creator of the Ultima series) wrote the random dungeon generator for his first release Akalabeth on the Apple II. I decided that was the way to go because it wouldn’t take that many loops of randomly generating numbers. So basically, every floor is a set of Rooms (or corridors which are basically the same as Rooms with narrow walls). This makes up a 4×4 grid. The game will choose a location for the player to start along either the top, left, right, or bottom, edge of the map. Then it will place the exit (a ladder down to the next floor) on the opposite side of the maze.
Once I randomly generated the data I needed for the layout of the floor, I had to start connecting the rooms and corridors with doorways, in order to test out the code. This was simple enough. If the player was going far enough to right side of the screen, there must be a doorway there, so change the X and Y location of the player’s current corresponding room and then change the player’s X location to the other side of the screen. Do the same for the top and bottom of the screen, only adjusting the Y locations, and bam. Just had to adjust the number a bit so the doorways weren’t too picky and pixel perfect on how far in the player had to walk into them to enter the next room. I really want this games movement to be smooth and feel right. So far I’m very happy with the collision detections and how the player feels as he walks and animates around the rooms. Moving room to room now works.
However, after a few tests I notice “the bug”. This was brutal trying to solve, I can’t stress that enough, lol. To try to explain the bug: Basically the map layout is a 4×4 grid right? So 0 to 3 for the x values and 0 to 3 for the y values. Well, I noticed that if there ended up being a room at the 1,1 location or a room at the 1,3 location, they would have a room exit off the map, which would send the player to a room with no exits if he walked into it. Also, depending on what direction the player entered the room, this would seem to change where the exits would be placed in the room. I went through all of the code with (what I thought) was a fine toothed comb trying to see where the numbers didn’t add up. I got to the point where I thought there must be a bug in Stella. I actually thought for a second that it couldn’t be me, Stella must be doing something wrong! lol… Nope.. For 24 hours over the span of two days, I adjusted things, tested it. Adjusted something else, tested it. Pulled my hair out etc… Then it came to me when I was starring at the code that decides what rooms/corridors to choose… There wasn’t something that was written wrong in the code, there was something missing from the code completely! When designing all the corridors, I forgot when there is two exits in a corridor, there is more possible direction of exits than just up and down, or left and right….
There is also, up and left, or up and right, or down and left, or down and right. So there were 6 possibilities in a random maze for the required corridor for any given location and I only coded two of them. So when the player entered a room that didn’t exist in code, the Atari had just drawn the last room the player came from. That room would usually have a doorway that shouldn’t exist. The doorway would then lead the player off the map.
Man did it feel good to finally figure that out. I can’t begin to explain how good that felt to finally get. The code is “perfect” now and I can move on to the next bit. But to celebrate, I’m going to relax with my girlfriend and maybe we’ll try and find the easter egg in the Atari game Adventure (Something I’ve never done myself). Should be fun 🙂