Home > Game Development > From Day 1 to Now…

From Day 1 to Now…

Well, I suppose I will start by explaining how I started my current game, what I wanted to do with it, and then work my way up to it’s current state.

After spending a lot of time reading my C++ and game programming books, browsing online tutorials and forums, and checking out source code for various games, I had plenty of ideas of what I wanted in my game. That wasn’t the problem, I’ve played my fair share of adventure games and RPG’s, I knew what I liked and what I didn’t like. The problem was finding the C++ code to do it, and making it all work together. So my first attempt, before I knew any OOP (Object Oriented Programming), was to just have a bunch of global variables for all the characters in the game, and have the player run through a bunch of if-else statements.

There was no combat, no numbers, just one-swing combat. The computer would calculate some random values for the two characters attack, compare them, and whichever was higher, there would be an output along the lines of “The troll slashed you across the face! You die!,” then the program would exit. So, that was stupid, and I knew it, but it suppressed my cravings for a real game for the time being, so I abandoned that “game” and went back to the books.

Once I got into OOP, I tried again. Starting from scratch, I made up some quick menu’s to allow the user to enter how many randomly generated enemies they would like to create. This ended up taking a while, and several visits to instructor and teaching-assistant for my C++ course. So once I worked out all the bugs, I effectively used a vector to dynamically store all the enemies. Now I wanted to fight them. So I added a character creation process, which was composed of generating a random enemy, showing the stats to the user, and asking if they liked them or not. If they did, they would get to name their new character, and then it would be stored in the same vector with the enemies. If they didn’t like it, it would be deleted, and a new random enemy would be generated and displayed to the user. This process would repeat until the user had found something they liked.

Now, I was able to use what I had previously worked on in my first game, but instead of using random numbers for the if-else statements to decide who would win, I used the 2 characters stats. Keep in mind, there was no “multiple rounds,” where one character would strike the other, and their health would decrease, then it was the other character’s turn. No, it was still just comparing the 2 characters’ Attack, and whichever was higher, they would win. That was it. The cool thing though, was that I was able to run through the vector of enemies and have the player fight each one. Well, that was enough to suppress my cravings for a real, playable game, so I abandoned it and went back to the books.

Since I had combat and character creation covered, I wanted a way for the user to be able to move about. All the user could do in my previous game was generate their character and some enemies to fight, and then select the menu option to “FIGHT!” The first idea that came to my head, was to create a class called Room, and each Room would have a description, then I would make a whole bunch of these Rooms, store them in a vector (I was into vector’s at the moment), and start the user off in the first Room of the vector. They wouldn’t really be in any Room, rather, the first Room’s description was read, and then the user would have to enter in something, and their input would go through an if-else sequence to determine whether or not they’re allowed to go to the next Room. If they entered in the password, then the iterator, that was initially set to point to the first Room in the vector, would be incremented, then pointing to the second Room. Then, as with the first Room, the description would be read (through the iterator), and the process would start over.

This was only an idea though, I had never put it in code. I didn’t really like the idea…well, I knew I could do better. So, I continued to read my books and browse the internet, and I happened to find several fairly well written articles on Linked-Lists. I remembered that I had previously seen these articles, but at the time I wasn’t ready to try and understand what was going on. Well, I was ready now, so I carefully read through them, understood them for the most part, enough to start using them. I know had my method for walking through Rooms, I liked it, and it was going to be a challenge.

Starting from scratch once again, I came up with some Linked-List implementations, particularly Double Linked-Lists, to represented the Rooms that the player could walk through. Although this method was going to work, I knew that I wasn’t going to be utilizing the real features of Linked-Lists that they are intended for, which is random insertion and deletion. I wasn’t going to be having Rooms randomly created and inserted and deleted in my chain of Rooms, I was just going to explicitly create each and every room, and chain them together as a double linked-list.

So I came up with my Room class that I would comprise my double linked-list of. All these Rooms had a description(a string), an exit(a string), and a pointer named Next to another Room, and a pointer named Previous to another Room. This is how a double linked-list works: each object, in my case Rooms, had a pointer to another object of the same type, in my case Rooms. This way, each Room knew what the next and previous Rooms were, since it had a pointer to them. For my game, this would allow the user to start in the first Room, the head, and then when they entered in the exit for the room, the Room that their current Room’s Next pointer pointed to would be set to the user’s position. Once this happened, the description of their new Room would be read, and the user could now enter in something to allow them to go to the Next Room, or go to the Previous Room (hence the need for double linked-list. A single linked-list only allows to move forward, or next). This process would be repeated until the user got to the end of the chain of Rooms, or the tail, where the loop that was processing all the Rooms would end and the user would go back to the menus.

Now that I had my movement covered, I wanted to incorporate combat. I knew how to do it, and it was fairly simple to add, with no problems. I would create a Monster class, and add to my Room class another pointer, this time pointing to a Monster. Now, when the user was in a Room, they could fight a Monster, since they had access to it via the pointer-to-a-Monster that every Room had. So, when the Rooms were created and chained together in the double linked-list, I just added the creation of a Monster, and set the appropriate pointer to point to this new Monster. Now, each Room had a description, an exit, a pointer to the Next Room, a pointer to the Previous Room, and a pointer to a Monster.

Now that I had correctly set up the necessary ends to meet that would allow for combat to take place, I needed to come up with a much better combat process then what I had used previously. Although I came up with something new, it was still nothing amazing. Each character in the game had the basic attributes, Health, Speed, Attack, and Defense. The process of combat was actually a member function within the character class that made up all the character’s in the game, and it went like this:

  1. Generate a random number and modify it by each of the characters Speed attribute, then compare the two numbers.
  2. Whichever character had a higher random number(modified by their Speed) was marked as the Attacker, and the other was the Defender.
  3. Then, the Attacker would strike the Defender, and the Defender’s Health would be decremented by an amount equal to the Attacker’s Attack attribute.
  4. Check to see if the Defender is still alive, if they are, then the Defender will strike the Attacker, and the Attacker’s Health would be decremented by an amount equal to the Defender’s Attack attribute.
  5. If the check failed, and the Defender was not alive, then the Attacker would be returned from the function.
  6. Check to see if the Attacker is still alive, if they are, go back to step 1.
  7. If the check failed, and the Attacker was not alive, then the Defender would be returned from the function.

So whoever won the fight would be returned from the function, where their name would then be announced as the winner.

To sum everything up, at it’s current state, the user would be allowed to create their character, then they would start their journey. The first rooms description would be read (there were no monsters at the head of the linked-list), and the Rooms exit would be read, they would be prompted for input, if their input matched the Rooms exit(just a string), then they would be moved to the Next Room. Once they entered the next Room, since there would be a monster in it(the Monster pointer in that Room was pointing to a Monster), they would enter combat with that Monster. Entering combat doesn’t really mean anything cool, just that the loop that I described above would be run until one of the characters had no Health left, and the winner’s name would be announced. Because the combat loop is so simple, it executed in milliseconds, so as soon as the player entered combat, it was over, and the winner was announced on the screen… not very exciting, but it was a start. Regardless of whether the player won or not, they were still able to continue playing.

Once combat was over, the Room’s description would be read, as well as the Room’s exit, and since they came from a Room, the previous Room’s exit was read as well. This meant that the user was given 2 exits, one that led to the Next Room, and one that led to the Previous Room, so they were able to go back if they wanted. This process would continue until the user got to the end of the linked-lists, where they would go back to the menu, or if they entered in “quit” when they were prompted for input.

Well, that’s it, everything up to now. From now on, my posts will describe the features that I’ve added.

Categories: Game Development Tags: ,
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: