Building the Combat Prototype

Happy holidays! I’m writing this month’s post a few days earlier than normal because of the holidays. Since last month, I’ve put in the UI when you enter combat:

proto-combat-ui.png(wood frames by Rexard)

This of course needs to be polished further in the final game (checkout those awesome fonts!) but is perfectly functional for prototyping. Combat is actually playable now, but I want to implement a bit more of the game before publishing a public prototype.

While putting in the combat HUD is the most visible thing I’ve done in the past month, the majority of the month was actually spent on invisible-but-crucial infrastructural sort of work. In particular, I’ve written a lot of code for player and enemy data entities (objects to track HP, MP, XP, etc). This involved tons of reflection, to correlate parsed JSON with fields of the objects.

For example, here’s the method that takes in stat values and assigns them to player characters:

private void AssignPropertyValues(Dictionary<string, long> values) {
  foreach (KeyValuePair<string, long> kvp in values) {
    PropertyInfo prop = this.GetType().GetProperty(kvp.Key, BindingFlags.Instance | BindingFlags.Public | BindingFlags.IgnoreCase);
    prop.SetValue(this, (int)kvp.Value, null);
  }
}

Using reflection in this way gave me a lot of flexibility! Part of me worries that I won’t understand this deep voodoo code in a few months, but it all seems really powerful.

Incidentally, I’m also rather proud of the level function I devised. I’m referring to the function that calculates how much XP you need for the next level. It took a lot of trial and error to get a progression I liked (ie. almost exactly like the XP progression in Shining in the Darkness) but I think the effort paid off.

In the following function, plug in values like base 3.57, exponent 1.63, and multiplier 4.1:

public long XPforNext(int curLevel) {
  float exponent = Mathf.Pow(curLevel, (float)XPExponent) / curLevel;
  return (long)(XPMultiplier * Mathf.Pow((float)XPBase, exponent));
}

The best part is I can easily generate a different XP chart for every class simply by tweaking the input values.

Advertisements

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