Lighting

Bullets are Flying

0

Rather big progress today, actually. I created another enemy that rolls at you, and I also created a bullet class and physics component, and added collision category support so that everything which collides with other things has well-defined properties. I also added “crouching” to the player, so that you can fire at two different heights. The bullets work flawlessly with the gravity light, which makes them angle upwards. This could be used to shoot the enemy that flies above you. I want to add artwork to the rolling enemy so that I can call it done, and I need to add the concept of health to the player. The enemies have health, but the player isn’t affected by them yet. Next steps are to limit the amount of bullets and make each key press fire only one bullet, and also to add artwork to the bullets and perhaps a little explosion animation when the bullet is destroyed. And then I want to create more lights, finally, now that everything is working pretty well. I will make a firm decision on which lights to move forward with shortly.

Integrating the Engine With Krypton

1

So 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…

LIGHTS!

3

I 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.

The Lighting System

0

I 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…

0

I’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.

An error message from Visual Studio stating that no suitable graphics card could be found.

Reach vs. HiDef

2

Today I received a new laptop – a ThinkPad Edge 14, which I was hoping to make a second primary development environment. I installed all of the necessary applications and opened up my project, which thankfully didn’t encounter any errors… until I tried to run it. I was met with an error – “Oh boy,” I thought, but just the same, “No big deal.”

An error message from Visual Studio stating that no suitable graphics card could be found.

The best news I've had all week.

But then I found out that the HiDef XNA profile I was using for my project had bigger implications than I realized. My original thought was that the HiDef profile meant “not Windows Phone compatible,” but what it actually means is a bit more – texture sizes, and most importantly, shader model – Reach uses 2.0, and HiDef uses 3.0. My lighting system was utilizing 3.0, so to get it to run on my new laptop I had to cut out the lighting code. This was painful, although it’s still extremely early in the project so I did it, and thankfully that took care of the issue.

Honestly it’s good that I found out about this now rather than later, because I do want to reach as many platforms as possible – I don’t want to limit my already limited audience by utilizing technology only present in newer graphics cards. They were nice effects, but for the lighting that I hope to accomplish I think that I can do it another way with similar results. I found out about a project called Krypton XNA, which attempts to offer a lighting solution for 2D XNA games. The creator just posted today that s/he is porting the project to XNA 4.0, so I’ll definitely have my eye on it to see if it’s something that I can use – I already asked if it will support the Reach profile or just the HiDef profile, and am awaiting an answer. In the meantime, I will try to create a player component so that I’ll be able to do some more complex testing with the physics engine, and if too much time goes by I’ll either try to port the project myself, depending on how big it is, or create my own lighting solution from scratch.

A square resting on a dark platform while emitting red light.

We have lighting!

0

A snapshot of Visual Studio's Solution Explorer displaying the NePlus project.

And I've only just started... I'd like to re-arrange the Engine a bit at some point.

Well, sort of. I have been working on integrating lighting effects into the game this week, and have expanded the engine components and arranged them, although I would like to move things around a bit. Currently, my Visual Studio solution is moderately small, although it does grow a bit every day. The engine’s organization is not something I’m completely happy with at the moment, although all of the function calls to it look how I’d like them to. The lighting effects exist now, thanks to an extremely helpful blog post on the subject and an example project showing the code needed to do this. However, the camera class doesn’t yet play nicely with the technique – I am still struggling with matrices and the associated jazz, so I am not sure what the best way to draw the shadows is – currently, they are being drawn at a stationary point, and I’m sure with a little testing I’ll be able to figure out exactly how I should draw them to line up with the rest of the things I’ve got working. Along with the lighting integration, I introduced a couple more of my first bugs – the Farseer debug view shouldn’t be affected by the lighting, so I’ll have to figure out how to exclude it. Also, I need to be able to draw my scenery and not have it obscured by darkness if I don’t want it to be. These things should hopefully be pretty easy to change, and will happen most likely within the next couple of days.

Moving forward, my plan is to fix those bugs and then start working on how to detect if an object is being touched by the lighting. From there, I can decide what happens if an object is indeed being touched by lights, and introduce the anti-gravity light! I also want to play with the lighting so that it is a little more dynamic as far as brightness, when it’s on, when it’s off, and so forth, all of which should be pretty simple. I just need to create simple interfaces to these things so that they can be easily manipulated.

One may note that I have not yet fully mentioned anything about Tiled, although the DLL is sitting in my project. Before the end of Sprint 2, which is now about two weeks from now, I hope to have integrated Tiled into the project in some simple fashion. I will be doing this most likely using TiledLib, which is an extension that was created with the intention of adding Tiled resources to the XNA Content Pipeline so that it is extremely easy to load Tiled maps into XNA projects, and also to provide a simple interface for accessing the data in Tiled resources. Tiled is a map editor that creates easy-to-read maps for projects, so basically I’ll be designing levels in Tiled and then reading the files in my code, and creating the game levels by positioning objects and creating their appropriate physics and lighting properties (and probably many other properties which I am not currently working on). I’m excited about using Tiled, because I have a feeling that it’s going to be a great editor that I’ll be able to use in every 2D game I ever work on during my own time. But I felt similarly about the engine I was going to use for my project, so we’ll see how it turns out in a few weeks.

The decision to be working with my own engine has so far been pretty good – I definitely like having full control over the major aspects of my project. The Farseer physics engine is still a blast to use now that it’s working, and so far none of the components I’ve brought in from outside sources have limited any of my abilities to do exactly what I want to do. That’s a nice kind of freedom, and now that I’ve been enjoying it it’s hard to imagine wanting to use a full-fledged game engine as opposed to pulling together separate components and gluing them together however I see fit.

A square resting on a dark platform while emitting red light.

It's nearly working. The platform that the box is sitting on should be visible, which I still need to work on. Click the image for a video.

Go to Top