I moved to a new URL! Check it out!

posts dated from: january 2014

Dev Log: Areas of Effect

Dev Log: Areas of Effect
My most recent development in my game's crazy system is implementing an area of effect. Right now areas of effect can keep track of any Entities that enter them with a "Combatant" component. I'm using the Combatant component to keep track of anything in the scene that can either deal or receive damage in some way. Here's an area of effect that increases the player's "TimeRate" stat:

Image


When the TimeRate stat is modified the player's weapons will fire faster, and anything else that depends on that stat is also changed. I think the way I have it set up right now any sort of regeneration status will be effected by the TimeRate, so if I had a health regeneration modifier then it would be applied faster than normal.

The way I have things set up right now is that all entities in the scene that are combatants have some sort of core stats table. These stats determine all kinds of things for each of those entities, and things like areas of effect can just apply modifiers to those stats and hopefully the entities will react accordingly. This is all totally new stuff to me and I'm learning a lot as I go, but progress is kinda slow as the more I learn about this stuff the more I know about what I could be doing better -- so I end up scrapping stuff and writing it better as I realize it.

Not quite as fast as a game jam scenario, but I don't want to code myself into a corner when it comes to making a system like this!

Dev Log: More Data Driving

Dev Log: More Data Driving
How far is too far when it comes to making data driven code? Right now I'm wrestling with this question. I have a bunch of stuff defined in my xml which is all well and good for some parts of this game, but then I came to think of spells and abilities and how to make them data driven... but I think to truly do that would require some sort of scripting!

I was looking into Lua or using some form of Python for scripting in my game, but ultimately I've decided to hold off on that sort of thing. It sounds really fun, especially when I start to consider the modding possibilities of a game that uses a lot of scripting and data driven stuff... but it feels like a large burden to take on very early on in a project (even though getting Lua set up in C# is incredibly easy!)

As I slowly pick away at these systems everything is becoming a little bit more clear with each day of work. I'm still learning the ins and outs of C# and the power of reflection. One thing I started looking into today is custom attributes. It seems like a powerful way to combine data driven and engine driven stuff into one. I think by using custom attributes I could define a lot of data right in a class itself, and I would be mostly doing this in instances where I wouldn't want this kind of data exposed to the end user.

For example right now I have my stat class set up with a Dictionary where the enum StatType is the key, and a float is the value. This is all fine, but it means that in the constructor of my stat manager class I have to define all of those stats by doing Add(StatType, value) a bunch of times. An alternative way to do this might be to define the stats as just floats in the class itself, and apply custom attributes to each one like [Stat] or [CoreStat] or [DerivedStat]. I'm going to spend a little time experimenting with this stuff and we'll see how it turns out!

Doodle Post

Image

Dev Log: Fun with Stats

Dev Log: Fun with Stats
I haven't made much progress on my system to set up triggers and actions for Enchantments, but I did make some progress on my player stats system. I coded up a pretty generic Stat class that allows StatMods to be applied. Check it out!
class Stat {

public float BaseValue;
public string Name;

public bool Capped;
public float Cap;

public List<StatMod> StatMods { get; private set; }

bool needsUpdate = false;
float cachedValue;

public Stat(string name, float basevalue = 0) {
Name = name;
BaseValue = basevalue;
Cap = BaseValue * 2;
StatMods = new List<StatMod>();
cachedValue = basevalue;
}

public Stat(float basevalue) : this("", basevalue) { }

public StatMod AddMod(StatMod mod) {
StatMods.Add(mod);
needsUpdate = true;
return mod;
}

public StatMod RemoveMod(StatMod mod) {
StatMods.Remove(mod);
needsUpdate = true;
return mod;
}

public void ClearMods() {
StatMods.Clear();
cachedValue = BaseValue;
}

public float FinalValue {
get {
if (needsUpdate) {
float v = BaseValue;
var m = 1;
foreach (var s in StatMods) {
v += s.Add;
}
foreach (var s in StatMods) {
v += BaseValue * s.Multiply;
}
cachedValue = v;
needsUpdate = false;
}
if (Capped && cachedValue > Cap) return Cap;
return cachedValue;
}
}

public static implicit operator float(Stat stat) {
return stat.FinalValue;
}


}

class StatMod {
public float Multiply = 1;
public float Add;

public StatMod(float add = 0, float multiply = 0) {
Multiply = multiply;
Add = add;
}
}
I'll probably add this into the Utility folder of Otter at some point. Basically you can make a stat, like new Stat(10), then apply modifiers and get the final modified value back. You can also treat it as a float and it will spit out the modified value as well.

Multiply might not work the way you think at first though. Setting Multiply to 1 in a StatMod actually means to Add 100% of the stat to itself. For example, a stat of 100 with a multiplier mod of 1 will calculate as 200. It's as if the mod is saying "BaseStat +100%" when you set it to 1. So 0.5f would be interpreted as +50%, -0.5f would be -50%, and so on.

Modifiers will always be applied with addition, then multiplication. For example if a stat had a base value of 100, and then you apply a modifier with Add set to 50, and then another modifier with Multiply set to 1, then the final result will be 300. It applies the +50, and then the +100%. It doesn't matter which order they're applied in.

Now I'll get back to work on my dumb trigger and action system that I have no idea how to implement right now, yahoo!

Dev Log: Going Data Driven

Dev Log: Going Data Driven
I've been making a lot of progress on tackling this system I want to implement for my next game. Since yesterday I decided to scrap a bunch of code in favor of going for a data driven approach. Lars gave me the final push I needed to go for this method of content.

My initial design of the code structure was going to be object or class driven for specific content. For example I had a namespace and a folder set up for "Weapon" and inside Weapon there was a "Base" class for any sort of Weapon. Then I made a few classes that extended the Base class inside the Weapon namespace which then changed values and added their own code to various functions.

This seemed like a good idea at the time. Using classes and extending base classes for specific functionality is something I do a lot in my games. It makes sense for a lot of things, I think. Like enemies. The enemies in All the King's Men for example are specific classes that extend a base Enemy class to implement their own specific functionality.

As I began to think about all the possibilities for gear, weapons, enchantments, and whatever else in my game, I was pretty grossed out by the thought of having a billion classes in my project for each single one. After thinking it over I ripped out all my old code for content and started on replacing it with one class for each different thing, and having a factory that instantiates objects using data from various data xml files.

I'm more excited about this method since so far it feels cleaner. The code to parse everything out of the xml for each object is pretty ugly, but editing content should be pretty easy with this structure in place. I can also use the xml files as a good guide on what to do next. Right now my work flow is to just start writing the xml data for whatever I can think I would want to customize for each thing, and then I start implementing each thing I've written. Working "backwards" like this can be a big help when working in a system where I have no idea where to begin.

Dev Log: RPGish Systems

Dev Log: RPGish Systems
I'm spending this week at the lovely Indie House in Vancouver, Canada! Since I was coming up to Seattle for Steam Dev Days I figured it was a good opportunity to just hop on a bus and spend some time with my best Canadian pals.

The past couple of days I've been banging my head against a wall trying to come up with some kind of RPG inspired system for the game tentatively titled Gaiaden. One of my goals for the game is to have a robust system of equipment, weapons, enchantments, and all that kinda stuff for the player to experiment with. I've never really created anything like this before so all of this stuff is completely new territory for me.

I thought a good place to start would be to check out roguelikes since they are games usually all about systems of items, equipment, spells, and more. I searched around for some open source ones and managed to find Amaranth. Although the source of this game is super clean, it was pretty hard for me to follow.

I also tried looking up just some general purpose roguelike development tutorials for using items, equipment, and all that kinda stuff. I read through a couple like this one and this one but they weren't really digging deep enough to get to the part I was really curious about. I want a system in which "Enchantments" can trigger, and then have an effect on something in the game, and I couldn't find any resources to help me understand how to build such a system.

I put out a call for help on Twitter and got help from a lot of developers, and I'm constantly amazed at how awesome the game making community is. Special thanks to all of you who helped me out via Skype and Twitter! You are the very best.

After some late night chats with developers who've been through this scenario before, it seems like I have to go down the route of using a bunch of events in order to trigger any enchantments that are on the player. The idea is that equipment in the game can have enchantments which could have simple to complex conditions, and effects. I want to ultimately be able to generate equipment and enchantments on the fly... and it turns out this is pretty tough to figure out.

I have a basic system working now, but the way I do it right now is to loop through all the available enchantments on the player and have them call a CheckTrigger() function. That function also takes in a struct called TriggerInfo, which will eventually contain a boatload of info about the current game state. I might scrap this and go for a pure event based system, but I worry about over using events and not being able to follow the code if everything gets totally decoupled. The TriggerInfo method works great currently, but I have a feeling once I try to trigger enchantments based off of things like "the player just built an island" or "the player just took damage" it'll become a pain to register that with TriggerInfo on the update function.

So that's where I'm at now, just churning away at this system to eventually enable the player to get some cool stuff set up.