Posts tagged XNA
I’m currently working on creating the first enemy for Ne+, and with it I will be bringing my first actual animation into the project. I am creating the sprite sheet, and then will proceed to play the animation in XNA and then create an EnemyComponent which will try and attack the player. This means I will also need to have the player fire projectiles or something similar to fight enemies, and I hope to have both of these things done by Tuesday for my sprint presentation. I have a good idea of how it’s all going to work; I’ll have a collision category in Farseer that represents bullets, and then if the player bullets hit enemies the enemies will implement some action or death animation. I have a good idea of a death animation to use for my first enemy as well; Paint.NET has a bunch of cool effects that have values to manipulate, and often manipulating them in sequence offers some string of images that look like good animations to me, especially for projects on time constraints. I also have particle effects to play with, which I might use for when bullets hit platforms or something. The bullets could also emit a particle effect en route; I’m still thinking about it, however, all of this is polish-type stuff as opposed to actual new features like the basic things I want done by Tuesday.
It turns out that way back in my main Game class that I hardly ever touch I wasn’t clearing the graphics device in its Draw function. So there were some moments in the loading screen when the game is being loaded or destroyed in which nothing was drawing, giving me the horrible purple screen that is now dead and buried. I wanted to ignore it, but I just couldn’t; I had to fix it. I used Beyond Compare 3 to look at all the changes that I had made from the Game State Management sample and noticed that it was clearing the graphics device while I wasn’t. Seriously, Beyond Compare 3 is one of my favorite applications. Just earlier I used it to sync an MP3 folder to my phone, I use it to mirror my folder of important stuff to another hard drive for keeping a backup, and it is absolutely fantastic for comparing code. I’m sure there are more uses I haven’t discovered yet.
Well, I am. I spent a tragically short winter break completing the last of my work for an internship, which when considering some much needed personal time as well left me with little progress on my project throughout the break; however, given that I will have a very large amount of time to dedicate to it due to my lack of a job through this next term, I should be able to do about twice as much in the next three months as I did in the previous three. My determination has been somewhat strengthened as well, and as stated I have implemented what looks to me like a great infrastructure to work with. My last bit of big progress was abandoning XNA’s component system and using my own, which I did to have absolute control over what was happening, and also to allow me to step through my code and see what needs to happen where. A game is a beautiful system; many say that object-oriented programming doesn’t always lend itself to games, and from my very limited experience, I think I can at least see why someone would say such a thing. I’ve done my best so far in creating a manageable system, but still there remain some components that I think break some rules and work well enough now, but might not later. I see this, but I also have learned from the first third of this project that one cannot spend time re-coding systems in the most ideal way, for there is always a more ideal way. I will make things re-usable as possible only for myself in this current project; I didn’t create the engine class library to use over and over (although as always it would be nice if that were possible), but to keep my code organized and manageable.
Moving forward, I have some so-called “New Year’s Resolutions”:
- Make at least some substantial progress or implement a new feature for Ne+ every two days starting 01/04/2011
- Maintain this blog even more than it has been so far, and use it not only for review, but also brainstorming purposes
- Write at least one tutorial a month if at all possible for those who may be using the same technologies as myself
- Stop re-writing things that work fine (this has been a big issue for me, but no more)
- Stop wasting time on the perfect design, because I’m just really not the person who’s going to come up with it (my audience doesn’t care if the code is amazing or just pretty okay)
- Work out (health and productivity aren’t unrelated)
I think that, if I take care of these issues immediately, things will be looking pretty good. As broad strokes I want to make throughout this term, I have laid out a few major goals:
- Start defining content for the game and have some rough levels available
- Design more content
- Introduce effects and other cinematic touches into the game presentation
- Implement or integrate a config file system
- Introduce audio into the game and manipulate it dynamically according to gameplay (I don’t know yet how carried away I want this aspect to be, but as a first step get audio working)
- Polish the player class and define what moving the character is going to feel like with the physics engine
- Integrate lighting (if I need to drop XNA Reach profile support, fine. The project’s completion is more important to me at this point than eliminating some of my audience. I hate that I even have to make this decision, but I don’t think I have time to write my own lighting from scratch)
- Define more lights! I will probably write entries for the lights to describe why I think they’re important, and my big ideas on how I want them to be used.
- Think of ways to make anything that’s boring more interesting. After playing Dirt 2, I have really noticed the need for a highly polished game. Obviously no one sets out to make a game that isn’t polished, but Dirt 2 shows that polish can really take a game to the next level.
There are other things I want to get done too, but these are the important things. I am really going to go nuts this term, no more procrastinating or other work getting in the way. I am also taking image and video editing classes that will take some time, but I will do everything I can to be defining Ne+ content with the work assigned in those classes. This is the most important time for the project as I see it, and now that I have the resources to dedicate to it I am determined to make a great amount of progress.
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.
I have been spending the last week (on and off, as I had to make a drive over to Corvallis for the MECOP Fall Event), trying to integrate Tiled and TiledLib with my project. I learned a lot about the fantastic functionality of Tiled and how to actually go about using the program, which of course is going to become one of my main development environments when I need to start creating content for Ne+ (and really, I’d want to use Tiled for any 2D game moving forward), but I got hung up pretty badly once I started trying to load a map with XNA’s Content Pipeline and the TiledLib extension. I was getting an error about indexing past the end of an array in TiledLib’s map loading functions, so immediately I wondered what the deal was as I had tried out the demo and it worked perfectly.
So, I started taking a closer look at the demo – I was truly doing the absolute bare minimum in my project – declaring a map variable and then attempting to load the map file that I added to the content project, fully aware that the file was referencing a tile PNG with my one tile in it, but TiledLib was supposed to handle loading that for me. Eventually I just replaced the demo’s map with mine and saw my map load no problem in that project, but not in my own.
I debugged for a while, and saw that indeed, my project was not loading the PNG referenced in the map correctly. I pulled out garbage values where it was supposed to read the filename. Then I thought that maybe the file was getting processed incorrectly in my project, and then I remembered that there are settings for the importer and processor for every content item in your content project.
Sure enough, the importer and processor were blank. I set them to the TMX (map file extension) importer and processor, and bam, immediately the map appeared in the scene I’ve been testing. I still need to make my engine load up physics for the maps I load, and I think that with Tiled’s awesome ability to attach “properties” to tiles I’ll be able to decide whether or not the tiles are just for show, or should be “Collideable,” or anything else I can think of. I can also use Tiled to define player spawn points that don’t actually display on the screen, and other areas of interest. It’s a really cool program that provides nothing more than exactly what I’d want from it, and I can’t wait to start utilizing it more heavily.
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.
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.”
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.
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 few things have been reconsidered based on some additional research. I have found out about Conkerjo in more detail, who is involved with a few projects that I am considering incorporating heavily into my project. The first big technology is IceCream, a 2D game engine for the XNA platform. This is a big deal – I originally tried Torque’s game engine and although it was a pleasure to use, I wanted something a little more “open.” This open-source engine is exactly what I was looking for, and although it’s not “feature-complete” yet the code is available which will be invaluable as I start to learn more about it. It has a visual designer called Milkshake, which comes along with the package and looks very promising.
After settling on IceCream as the game engine I will most likely use (there must be a bit of testing before I commit), I looked at some of Conkerjo’s other work and found an A.I. library called BRAINS. I haven’t looked into the specifics of this library, but I think that, if I can’t use it directly, it will be very helpful in working toward my own A.I. solution.
A new direction
The next thing I must express is that the idea I have for my project has drastically changed. I started thinking a little more realistically than I have thus far and come to the conclusion that I can’t accomplish everything I want to on my first attempt at a game. I simultaneously spontaneously developed an entire set of ideas for a game that is simpler in construct, but still accomplishes many of the things I want to with this project in general – cinematic presentation, dynamic audio, stimulating gameplay, and most of all, should be entirely possible to complete (with polish) having the better part of a year to work on it. I still need to create a design document and maintain my Engineering Notebook, but the direction of the project has changed and my previous idea will be saved for a time in which I have more experience.
I want to make a game for many reasons – school, myself, everyone else… if I had to assign an ultimate purpose to it I’d say it’s for everyone to enjoy. It’s going to be open. If it’s good, people might pay for it. If it’s not, maybe I will. Regardless, it’s clear to me that I need to learn as much as I can throughout the rest of the project to avoid wasting time.
In a few weeks I’ll be moving to a quiet town in Eastern Oregon where I can focus on this project for a year. The main things that I want to accomplish in my first independent game are…
- A simple artificial intelligence construct for non-playable characters (and potentially to help govern audio/visual effects)
- A level management system enabling the player to easily recurse through different stages instantly as a gameplay dynamic
- An intriguing and enjoyable space-opera plot
- A simple, attractive 2D graphical style with some 3D effects running at 1080p
- Windows 7 and XBox 360 support using Microsoft’s XNA, the Farseer Physics Engine, and potentially other helpful technologies
- An open-source codebase
That’s a nice, tough list of bullets to fulfill for an initial project. That’s why I intend to start small, developing numerous prototypes proving different pieces of my concept until I can build on and integrate them into the final product.
Where to start? The piece of this project that I’ve assigned the most risk to is the artificial intelligence. My initial plan is to create a prototype in which I can view my AI constructs interacting with objects and environments based on a set of needs. I also would like the player of the prototype to be able to interact with the AI entities. Ideally, this prototype could be a small standalone experiment of its own, rather than participating in the project purely as a stepping stone.
During development, I will be explaining the more interesting aspects of what I am currently working on. In the near future I will be covering my initial contact with XNA and simple genetic algorithms. I will be posting screenshots of my work and code examples as warranted for discussion.