Chaining Function Delegates

One of the key features of Killing Horizon, if not THE key feature, is chaining scoring methods together.  Each wave of asteroids, the player chooses a method to score out of 3 options.  The idea is to try to allow players to focus on using different weapons and styles of play.  These scoring methods are cumulative such that Wave 1 method continues into Wave 2 while Wave 2 is added into Wave 1’s score, and so on and so forth until the end of the game.

There will be a research/tech-tree as well, and this will add another dimension to choices for the player.  A player may want to do a lot of explosive bomby/missile damage and choose scoring that works with that.  They may want to choose scoring that works well with lasers (multipliers for asteroids that are hit with one laser beam shot, for example) and tech that gives longer-lasting laser beams.

So that’s part of the vision.

However, the main issue here is how to get the score methods to chain.

My main concept is to create a series of delegates named after the wave numbers they’re in.  Then, when the player chooses a scoring method it gets places into the given wave score method and is added to it…  The base method of the scoring for each wave will return a 0 and thus not add any complexity.  I would prefer not to be additive, necessarily, but I think doing anything more complex than merely adding these functions together leads to Spaghetti Code, and frankly, I could do without that headache.

Let me just say that having delegates/function pointers  is a wonderful convenience.  If I didn’t have that, I’d have to do an inevitably long tree of function choices that gets ever more messy with each new level, I’d have to say something like if function 1, else, function 2, else function 3.  then inside that i’d have to say if function 1(if function 4, 5, 6) then if function(1, 4 (if function 7, 8, 9) yada yada… then back up to function 1, 5… If you’re a programmer you probably get what I’m saying (I hope), but if you’re not this doesn’t make any sense.

With delegates it’s just function1() + function2() + function3()…

Leave a Reply

Your email address will not be published. Required fields are marked *