Posts tagged Lights
A surprising amount of progress?
0Here are the things I’ve just done…
- Added a new light, the velocity light, which either increases or decreases the velocity of anything under it
- Added bullet animations and artwork and a flash animation for when they hit things
- Added a flashing light to the enemy that flashes and rolls at you
- Added an explosion animation for enemies when they get shot
- Added working 3D sound to enemy sound effects
It’s funny because none of these things were particularly challenging or time consuming, but the game seems way different now that it looks like something. Up until this point, I was playing the game with the debug view from the Farseer Physics Engine on, but now it can function as a visual element without physics debugging to show what’s happening in the physics world.
I am going to start expanding the level I have, adding some actual platforming, and I have been asked by classmates multiple times about adding a light that the player can control, so that seems like an obvious step to take. Moving platforms are something I’d like to have as well. It still isn’t that pretty, but I guess I need to get a video up of what it looks like. I know there are some friends that would love to play whatever I’ve got too, and I’ll make that happen this Thursday to get some advice on where I should go next, and of course to just get some end-user opinion.
I have some news about other projects that I’ll be posting about soon.
Gravity Light is Working Again
0I went ahead and re-worked how I was implementing light effects, and I think that now I have a much better system going. Basically Farseer lets me define a fixture that is defined as a “Sensor,” and I hook into collision events so that I can call a function every time an object enters or leaves a light. Using those, I maintain a list of fixtures that are currently under a light, and can apply whatever forces or manipulate whatever attributes I want with every fixture on the list. Next up is to get the null light working again, and then I’ll be in pretty good shape for starting to create new stuff.
UPDATE: Score! That wasn’t too bad at all. Now I’m back to the functionality I had before, but it’s more extensible and more stable than it was before.
Integrating the Engine With Krypton
1So far, integration has been going really well. I have played with my infrastructure a bit, and gotten the drawing of the lights to look pretty much exactly how I imagined them. The last thing I’m working out is creating some vertices in the shape of the cone lights I’m using to implement game effects, which is nearly complete. I found an excellent function on Stack Overflow for rotating vectors around points that works great, so I might as well post that code here (thanks to Empyrean):
public static Vector2 RotateVector2(Vector2 point, float radians, Vector2 pivot)
{
float cosRadians = (float)Math.Cos(radians);
float sinRadians = (float)Math.Sin(radians);
Vector2 translatedPoint = new Vector2();
translatedPoint.X = point.X - pivot.X;
translatedPoint.Y = point.Y - pivot.Y;
Vector2 rotatedPoint = new Vector2();
rotatedPoint.X = translatedPoint.X * cosRadians - translatedPoint.Y * sinRadians + pivot.X;
rotatedPoint.Y = translatedPoint.X * sinRadians + translatedPoint.Y * cosRadians + pivot.Y;
return rotatedPoint;
}
I basically sat down for a bit drawing out the problem and figuring out exactly what I needed to do, and then was able to find an answer from that. So once I’ve ironed this out, I’ll have my old functionality back with the lights actually implementing their effects on the player, and then I’ll be ready to keep developing new stuff! My plans are basically as follows:
- Create some art tiles that I can use to build some basic walkways
- Do something other than nothing when the player falls to his death (easy)
- Refine player jumping so that I can’t just fly around anymore, and make it feel good (moderately easy)
- Moving platforms (shouldn’t be too bad)
- Intro Sequence, if nothing more than a simple title (The most complicated part I can see in this is that I want to create a shadow hull from an image, but I think that I can use Farseer as an intermediary step and make this happen pretty fast)
- Simple platforming level to get the basics down (Building a more complex level may reveal problems in my infrastructure)
- Create an actual animated player sprite (This might take a while to refine)
So that’s some stuff. But to work I go…
The Lighting System
0I haven’t yet been able to resolve the Krypton issues I’m having, although I’m working very closely with the developers to try and resolve my problem. In the meantime I’ve been trying to think of the best way to split out the pieces of the lighting system into components that my game objects could use. The components are turning out to be fairly intuitive, so I’m glad that I made the decision to use them. For now, I’ve created simple components for lights and shadow hulls, so that each object which should cast a shadow in the game world gets a shadow component, which basically creates the shape that should be used to cast shadows in the lighting system and then adds it to Krypton’s collection of shadow hulls. The same sort of technique goes for the lights. And for the Krypton engine itself, I’m thinking the best way to handle it is to add another major class to my engine class called Lighting, which is a component like any other that is updated and drawn appropriately. Soon I will have to deal with the draw order of components in more detail, because things like the light artwork should be drawn over Krypton’s output to provide the illusion of an actual light, as opposed to just the light’s output.
All of this stuff is now in place in a very simple form, and I will be able to make it much more robust once I can figure out how to get Krypton working with my camera. This is really the crux of the project, so while I’m disappointed that I couldn’t have it in place already I feel that I’m pretty close, and I’ve also heard from others that they have successfully integrated Krypton with a camera system so I know that it is possible.
Trying to integrate Krypton…
0I’m in the middle of trying to integrate the lighting engine I’ll be using for my game. My initial effort didn’t go well, so basically I stubbed out the Lighting class and components that register with it, but I have yet to actually do anything other than make the whole screen covered in shadow. My technique when I fail at creating the component-based integration initially is to try to just hard code some objects in my engine class and get things working there, and then move the code to where it should actually be. That’s what I’ll be doing tonight or tomorrow, but the lighting testbed works perfectly, so I think it’s all on me to get things working. It looks great though, and hopefully I’ll be done integrating soon.
The Null Light
0I have a null light working now, which will provide some interesting gameplay. Basically it converts other lights to its own effect, which is nothing. I made it grey for now, which seems like something that might stick. I’ve definitely proven that it can be done (and it’s really not that complicated, although the way I did it needs to be re-worked), but like everything else it’s a really basic demo and doesn’t yet prove that the idea is interesting. When the light touches the gravity light, it changes the gravity light to a null light as well, and if there were more lights my system might break because I still haven’t had a great idea on how to do it, but the idea is to create a string of null lights if a null light “poisons the system.”
Expanding on the Light Class
0I 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.
Anti-Gravity Light Created
0Working with Tiled has been a real joy so far. My latest feat has been integrating TiledLib with the physics in my game, so that when I open up a map file I read in the artwork, collision (both with tiles and with Tiled “objects,” which I’ll go into in more detail in a bit, player spawn points, and light objects. What I’m striving for is having as much level data and configuration in Tiled maps as possible, given that the Tiled maps are XML (although they can be many different formats). In fact, I might switch to CSV, because that might represent maps more visually in text before they are loaded, which might be nice to keep in source control to watch their developments.

Here's another Tiled example, but here I'm actually defining a spawn point, a light, information about the light, and two different collision techniques - a tile overlay, and a Tiled object overlay. The tiled objects are just rectangles that you can attach data to, and I can create simpler collision geometry if I avoid creating it by tile.
The above image shows me designing a testbed for the anti-gravity light. The goal of this experiment was to create a light that enables the player to move between two platforms. When under the light, the player floats upwards. This is what it looks like loaded in-game, with the appropriate additions to the engine to take care of most of this automatically…

The red box is starting to float after taking a dangerous leap off the starting platform. Click the image for a video.
The test went really well, but I’m most excited about the fact that it’s so easy to define all of this stuff in my map files and have the engine take care of all the loading. As you can see in the image above, Farseer’s debug view is showing that the left platform is composed of many small squares, whereas the right platform is just one big rectangle. Obviously the one is more efficient that the many, but I am just going to keep the code around for both because it might be neat to utilize different techniques depending on the situation.
For my next trick, I’m planning on creating more light components, but after I refactor the code a bit, because I still have a bit left in my Game1 class that shouldn’t be there as a hack to get this example going. I would like to create the light that nulls other lights so that I’ve always got that in my arsenal. I also would like to have my dynamic lighting back, but I am waiting on Krypton XNA for the 4.0 update so that I can hopefully utilize that project to speed up development. However, I am still confident that if that never happens I’ll be able to do something from scratch without too much trouble. I am going to keep a collection of lights in my level class, so that they’re all easily and logically accessible. I need to figure out what the best way is to affect objects that are being touched by light with the appropriate effects, which as of now is a bit hacked together.
Make Games, Not Engines
0It’s true. Anyone who has ever started venturing to make a game has probably come across the classic Make Games, Not Engines article. And what it’s trying to say is that you need to accomplish your task, not create an abstract representation of what you think you’re going to need when you start the task. I’ve already fallen victim to, what at its core, is this same issue – I chose an engine that I wanted to work with without knowing exactly what I was going to need from it. The first problem I had with IceCream is that it wasn’t on the bleeding edge – I am going to be using XNA 4.0, so I need technologies that are compatible with it. I tried to get a newer version of the DLL, but with the issues in its development environment, as well as the fact that I was going to be unable to use certain techniques (this became clear quite quickly after starting) I decided that to use an XNA engine was only going to limit me in the long run.
There are plenty of technologies that I want to use. First off is the Farseer Physics Engine, which yesterday I spent about an hour or so compiling and integrating into a new XNA 4.0 project. I was lucky that the engine’s source control contained XNA 4.0 compatible stuff – I effectively created a “World” object and had a dynamic ball bouncing on a static rectangle, complete with Farseer’s debug view that shows you your objects and what is happening. I haven’t yet figured out how to enable the actual text and number debug output which shows detailed information about what is happening, but hopefully today I’ll be able to figure it out.
The Mercury Particle Engine is a project that I only became aware of yesterday, but already it shows great promise – I’ve got the required DLLs and played with the editor less than a minute after downloading it, and this is the kind of thing that is truly valuable – quick, easy, painless usage of a streamlined, effective product. I don’t blame the Farseer engine for being hard to set up, because I am using an unofficial release of it to work with XNA 4.0. Luckily, the particle engine is also XNA 4.0 compatible, and while I haven’t yet integrated it to start creating effects (which are going to be a large part of Ne+), I don’t foresee any mind-numbing issues.
Today, I hope to get the physics engine doing more of the things I want it to do, and specifically, I would like to have an anti-gravity light set up so that when I activate it, anything the light touches starts moving upwards. I am not sure yet what the best way to handle this is, because with Farseer the first thing you do is pass your world a gravity vector.
I am very happy with the progress I made yesterday – I wiped out my IceCream repository and started fresh with a classic XNA 4.0 project, compiled and integrated a “Hello Farseer” example, and am on my way to having a great physics debugging environment. I think that one of my primary goals for today should be NUnit integration into my project, so that I can start writing some unit tests. I am so new to all of this subject matter that they should be quite helpful.
One of the things that has been on my mind since I started pulling down all these projects is the matter of dependencies. I feel good about it in a way, because I am utilizing open-source software to its fullest, and hopefully my code will be of use to at least someone – I have decided absolutely that I want it to be available, based on how helpful it is for me to see the code of others. For example, when looking for a solution to 2D lighting (it is hard to immediately start thinking about how that would work), I asked a question on the Game Development StackExchange site and received an excellent answer linking me to a fantastic example of dynamic, and highly effective lighting. I downloaded the example and it compiled beautifully, and also provides a fantastic lighting effect. I’m very excited about what this is going to bring to my project, but the goal of my first “Sprint” is not to get lighting going, which is a graphical effect that is not absolutely essential to gameplay, but instead to have my light objects working, which does not require anything other than the simplest graphical presentation for me to confirm the results.
I feel very good about my choice to not use an engine – there is a huge element of freedom, as well as the knowledge that there are a million projects I can plug into my own without limitation, because I am the one creating the limitations. I also am not exactly attached to what the “engine” turns out to look like, because it’s not going to be entirely applicable to other projects, and it would only weigh down my code to strive toward that goal. XNA is not the platform that I want to create the rest of my work in, either, so it’s not that big of a deal.
So, today I will try to integrate more and see if I can get some anti-gravity action going, attempting to test out NUnit and add a project to my solution.

LIGHTS!
3I finally closed the lighting issue. It had to do with culling, which I still don’t fully understand, but one of the Krypton developers gave me the proper code to place before preparing the Krypton lighting and I finally was able to see a light through my camera class. I am so, so excited that this is taken care of. It marks a really big point of progress in the project, and I should really be able to amp up development now that I’m not running into such a horrible wall.
Seriously, I can’t state enough how happy I am. The Krypton guys are absolutely amazing for looking at my project and helping me figure this out. I couldn’t have done it by myself. This is why I love open-source projects; we can all collaborate. I only hope that I’ll be able to help someone out as much as I’ve been helped today in the future.
I’m left with a tiny bit of a mess because of all the commented code I created when trying different things, but that’s perfectly fine. I think I might make a sweep through my entire codebase for an hour or so to clean everything up, and then I’ll be able to finish the light and shadow hull components and Lighting class, and then move on with developing some more cool lights (now that I FINALLY have real lighting!!!!!!!) and create the introductory sequence to the game!
Thanks to xixonia on the Krypton project for the help. I am truly indebted.