Sunday, December 2, 2012

Damageable Component

My final task for Alpha was to build a component that would keep tabs on the health of the character attached to it. This was vital to the Alpha build because it allowed the player and enemies to be defeated by  depleting their health.

Again, this is going to be a component, so it can be attached to either player or enemy. Overall, this was a  fairly easy class to create. When creating the component, the input will dictate how much health the character  has. As for functions, I made the following methods: one that subtracts from health; one that adds to health;  and one that checks if the character has run out of health. If the character has run out of health, it will delete  that character, and check if it was a player. If it is the player, then it's game over.

A simple, clean class, but necessary for our alpha build. Since I worked on the projectile class, this was  extremely easy to test with enemy projectiles. Fortunately, it works as expected.

Animation-to-Sound Handler

Since our Alpha was drawing close, I was asked to start adding sounds into the game.  In addition to that, I was asked to build a system that played sounds based on the current player's animations. This would be  useful for playing sounds in exact accordance to what animation is playing, and provide programmers one simple location to edit/replace animation sounds.

First, I designed this to be a component, so that it could be added to any character with a reasonable amount  of animations (be it player, enemy, or otherwise). This component, the AnimationSoundManager, had access to that character's avatar, and this avatar held information about what animation was currently playing. Thus, my class looks for when a new animation is played, and checks if there is an associated sound file for it. If so, it plays the sound, and waits for a new animation to activate. I give thanks to Blake who suggested a  system for storing the previous animation to compare with the current one to see if a new animation had triggered.

However, I ran into a little problem.  I had no way to shut off looping sounds from my AudioController class.   Thus, I restructured that class as well to include a way to delete clips from the previous animation.  I also programmed a function that cleaned up clips that had completed. Previously, they still existed even after they finished, but now they are properly removed.  This should prove much more efficient down the road. Additionally, I programmed a simple mute functionality that would either un-mute or mute all current clips when called (i.e. it reversed the current mute setting).

Another problem arose when I realized that the Windows version of our game doesn't switch animations  (because we only use a cube for our character on Windows). This proved an obstacle in seeing if the AnimationSoundManager was actually doing its job. To overcome this, I had to manually program changes  in the Cube's current animation (though this change was strictly to notify me when to play a sound). I decided  to keep these changes in, so that anyone playing on the Windows version would be able to hear animation  sounds.

In the end, this worked out well. We now have various sounds in our game to give it a little more life. Even though most of these sounds are placeholder, they add to the experience nonetheless.



Re-factored Projectile System

Our game went through a bit of a redesign in the last couple of weeks. This change altered how enemies and players were created and controlled. Thus, since my projectile system is based on the interactions between the two, I had to redesign the projectile manager a bit.

First, our new system is designed around adding components to a base character class.  Therefore, what defines a player or an enemy is what components are attached.  Therefore, I made my ProjectileManager class a component to be attached to either a player or enemy.  Porting my code into this format wasn't too difficult.

The next step was for the ProjectileManager to spawn arrow projectiles for enemy guards to fire. Unfortunately, the way objects were drawn was altered in the redesign, so I had some trouble porting my code.  However, one of our team members, Ron, had made a handy little class that handled the drawing of a model with our new system.

After all that, the logic still worked like a charm, and adding the new component to characters is rather easy now.  Thus, I'm glad with how this worked out, and am excited to expand upon my ProjectileManager to handle different types of projectiles.

Monday, November 26, 2012

Addon System for Characters

As alpha approached, we needed a system that allowed the programmers to add various objects to the Avatar models. For example, the team wanted me to add a placeholder helmet for the guard characters. This was simply to show we had the capability to do this before the alpha stage was completed, but I decided to go ahead and create the first iteration of the system beyond just adding a hat.

To start, I had to configure the Character Factory class to include this addon system for the guard characters. This was relatively simple to do, and our robust system for adding components seems to be paying off.

My first goal, after that, was to simply create a class that put a box on top of the guards, so I used our dummy avatar class as a template (which is just a big box anyway). From there, I expanded the code to be much more adaptive. When calling the AddModel ability from within Addon component, one has to supply it with the model's location in content, and a Vector3 which is an offset to where the model will be in relation to the character's center.

At this point, the box would now appear wherever I wanted it to be, but I soon realized that my code needed to accommodate multiple objects being attached to a character within the same addon class. I heavily tweaked the containers that held the model's information to be compatible with multiple objects. The Dictionary class proved most useful in keeping tabs on information that was associated to each model (transforms, positions, etc). From there, I simply needed to tweak the Draw method to iterate through every model and draw them.

The final challenge was translating the Vector3 position to be relative the character's position and orientation. Without that, the attached object would quickly become detached once the character started moving. Thus, created a function that takes in the position, and translates each coordinate properly according to the character's orientation.

In the end, I'm quite satisfied with how this worked out. We can now freely add any models, like weapons/armor/clothing, to the characters through my Addons component. Here's a little picture showing a couple of addons being attached (do note, I did this on the Windows version which means I didn't have use of the Avatar models). I attached the little box to all the guards, and added a little shuriken for kicks.


From my testing, both objects move completely in sync with the character, so I'd say this is good progress!

Saturday, November 24, 2012

Ledge Swapping Mechanic

I was briefly assigned to work on a control mechanic for the game. I worked on allowing the Avatar the ability to jump to another ledge. This would apply when the Avatar is already hanging on a ledge, but needs to move around to the other side without climbing up.

Going into this, I had little information on the actual avatar movement mechanics, but I figured it would be a good exercise to learn more about it. Fortunately, there was already a movement controller (a movement controller is a class that governs how an object moves given a certain state) that was similar to what I needed to accomplish. This was in the climbing movement controller which governed the movement when the Avatar needed to climb up from a ledge. This was similar for two reasons. First, it used ray casting to see if the ledge connected to a valid platform. Second, it handled the movement of the Avatar automatically (most other movement controllers take in the player's input).

With this in mind, I set out to program the ledge swapping ability. To start, I had to figure out which way I needed to ray cast. To set the direction, I needed to get which side of the ledge the player was on. If he was the right side, I needed to set the ray's position forward and to the right of the player's position; I then needed to ray cast to the left to see if a ledge existed on the other side. If the player was on the left side, I simply needed to set the ray's position left and forward instead, and then send the ray right. This handled the logic I needed to determine if the player could swap to the other ledge in the first place.

The second task was the actual movement which was a tad trickier than I anticipated. I asked Blake to help me understand his climbing movement code. With a good bit of help from him, we were able to get the player to snap over to the other ledge by using the position given by the previous ray cast (which determined if he could grab the other ledge in the first place). We did run into a little tiff about the player not latching on to the ledge, but that was fixed by re-oriented the player's facing so it faced the wall properly (it's hard to tell if the player is facing the wall when the player is just a box on the windows version).

After all that work, the ledge swap mechanic works very well, and the player can swap to another ledge, given that such a ledge exists, at the press of a button. In addition, I learned a more about ray casting which is quite useful in 3D programming.