chris.software     development     reviews     feed

Expanding on the Light Class

I have been thinking a lot about how my light class should look, how it should work, and how I’m going to accomplish some of the things that I want to accomplish. I refactored my gravity light and base light class a bit already, so now every frame the physics world is queried with a Farseer AABB, which is basically a box I define in the physics world. I’m not sure I like that Farseer’s query function makes me define a delegate instead of letting me simply get a list of objects, but it forced me to learn more about how to use delegates and System.Func (just enough to use the function). So I defined a function called GravityEffect that takes a Fixture, and returns true or false according to Farseer’s requirements. It applies a force to the fixtures it receives, so basically I give Farseer the action that I want it to apply to the fixtures in the area I define and it does it. This translates to me telling Farseer to apply an anti-gravity force to everything in the area covered by light, which is surprisingly straightforward. And I can use this concept to play with Fixtures in any way I want, which is extremely powerful.

So next, I started thinking about the light that is going to null all other lights and I thought through the idea a little more - there’s two ways I imagine it working at the moment - a light that simply nulls the effects of what it touches, and a light that changes other lights to its own effect, effectively creating a “null virus” that cancels out all the lights that are linked up. To do this, I need to be able to switch out what I’m currently calling the EffectDelegate which lives in the base Light class, but I need it to be able to return to its original state, so obviously I need some system for changing it, but changing it back when the null light is no longer touching it. A stack of states perhaps? I’ll have to think about it some more.