Posts tagged Maps
Working 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.
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 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.
One of the things I really wanted to accomplish this week was creating a player class to take over my bouncing box, as the code was pretty much my engine, which is a bunch of global things organized in a way that makes sense to me, and my XNA Game1 class, which housed the code for pretty much everything else – initialization, drawing, the debug view drawing, camera setup, etc… so it was a mess, a slightly organized one as I kept all the different parts separated by whitespace, but a mess nonetheless. So I set out to pull out the bouncing box – leave the platform where it is in the Game1 class, but everything involving my dynamic Farseer Fixture needed to move.
I first created an InputComponent, and wanted this component to handle player input that affects the box, which in my small project is jumping, or floating. I set out to do this, and had some code that checks if the jumping keys or buttons in the Configuration class are being pressed. I built the project for Windows just fine, but then realized that I was only compiling the Key code in the Input reader if we were on a Windows platform, but doing the check both ways. So I ripped out that stuff so that I just return false if I’m checking the keyboard on an Xbox.
Then, I somehow managed to forget about my actual InputComponent and moved on to the PhysicsComponent, which basically is used to create a polygon, throw it into the Farseer simulation, and then update the game world position on every update for my player. That worked perfectly, although the drawing order of the code screwed up my debug view and I ripped that out into the Physics part of the engine and made that a drawable component as well, which draws the debug view last. So my player class instantiates an input component and a physics component, and then uses just the physics component (for now) to update its position. It also loads its texture and draws it, which is pretty standard XNA stuff.
The next thing I have to do is make it actually use its InputComponent, and then I will move onto using Tiled and TiledLib to draw the placeholder platform like it’s loading a whole map, and then I can decide how I want the flow of the game to be using all of my new classes instead of hard-coded stuff in the main class. I also need to create a particle effect component so that I can easily attach particle effects to objects, which will instantly make things a lot cooler, although I still need to learn how to create my own effects with the Mercury editor.