Showing posts with label XNA. Show all posts
Showing posts with label XNA. Show all posts

Saturday, July 28, 2012

Progress update for 7/21/12 - 7/27/12

This week:


  1. I made the camera's transition independent of the player's transition between rooms. This lets me move the player three tiles to the left and then the camera can move 5 tiles left and 3 tiles down, for example. Support for this functionality was also added into the editor.
  2. I fixed some dialog box values in the Alan Moore level and then finalized the level's geometry!
  3. My roommate fixed up our main menu since the save/load functionality won't be done in time for the end of the month and the competition deadline.
  4. Added two new enemies to the game for the Alan Moore level. They also get hand drawn sprite sheets from me, ensuring that they look terrible.
  5. Added a new AI "Walk" behavior for the above mentioned enemies.
That's about all for this week I'm afraid. July has been really busy for me this year, making this month less than awesome for a game-in-a-month competition. On the other hand, that's how competitions go I suppose. Otakon is cutting my week short this time, which means I'll really be cramming the last two days of the month to add as much polish as possible before it has to be put up online for download.

Saturday, July 7, 2012

Progress update for 6/30/12 - 7/6/12

This week:

  1. The roommate and I are participating in a gamejam this month and are using the Mega Man engine we've been working on for this purpose. Starting on the first, we're going to be making The Adventures of Balzac and Dickens.
  2. I've worked out a few problems in the level editor after my roommate and I began prototyping levels.
  3. Added platform collisions to the engine. Now you can have tiles that you can move horizontally through, and jump up from underneath, but you can stand on top of them.
  4. Added layers to the engine and the editor. Now you can have stuff in the foreground AND the background! So high tech!
  5. Changed how transitions worked a little bit in order to have more complex level designs down the line. Rooms now draw on demand instead of constantly being drawn. This lets us do neat tricks like the Lost Woods in Zelda 1.
  6. Switched from using alpha blend everywhere to color key for transparency. Especially in the editor.
That's pretty much it. I spent a lot of time working on level design and reading up on some stuff. Additionally, I was spending a lot of time preparing for my honeymoon, which starts tomorrow. So I'm afraid that next week's update will be sparse as well and only contain whatever my roommate works on. In the meantime, here's some screenshots:
There's Balzac and some glorious layers
His glorious jump animation. His shirt even flaps in the wind when jumping.
Pay no attention to the level geometry oversight in the picture.
His idle animation is pretty great too.

Saturday, June 30, 2012

Progress update for 6/23/2012 - 6/29/2012

This week:



  1. My roommate continued working on AI and got stuck on a weird .NET reference error bug. After he gave up, I took a look at it and came up with a work around. Still no idea on what was up with that bug though. For a more detailed explaination, please look here.
  2. Found a link to an article about marketing indie games that might be useful down the line.
  3. I finished room transitions to a polished shine.
  4. I rewrote the entire control system. Controls are now based on Actions (strings) and I can easily check for button presses, new presses, continuous presses, releases, etc of any button or key associated with a string quickly. The game actually controls a bit better now, though I still want to tweak how bullets are fired and how the shooting animation is played.
  5. With level transitions working properly, I went ahead and created the rest of the Cutman level's rooms in the level editor. There were some bugs to work out, but now everything works fine with transitions and running around and such. There's no enemies placed after the first room yet, but that's a minor point and will be adjusted later. Running through the level repeatedly though has shown me that there's still work to be done on the player class. There are situations where, when close to a platform corner, the player will switch to a running frame for just a moment or where the jumping variables aren't quite right and the player can't reach certain areas. These bugs will be worked out later and are just noted for now.
  6. My roommate added Beak enemies (Blasters in Japanese), though they aren't quite perfect yet, they're close.
  7. I changed Mega Man's injured logic to first push you back and then give you back control after a bit with a short period of invincibility. Before this you wouldn't get control back until invincibility wore off, which let Bladers really tear you up.
  8. Spikes kill you now. Sorry.
  9. Fixed a bug where the game would think you were on the ground when you were actually jumping past a corner.
  10. Fixed a slew of ladder related bugs. Ladders suck.
  11. Roommate added more behaviors to the enemy AI after I added an extra generic parameter for all enemies in the engine and the level editor.
  12. Added in all spawns of Beaks (Blasters), Octopus Batteries (Suzys), and Bladers (Bunby Helis).
  13. Tidied up some sprites and added death particle spritesheets
  14. Roommate added Flea enemies. Their AI does little more than jump constantly right now.
Here's a video!
Here's some screenshots:

A room further in the level


This is a bad situation to be in!

Made it to the end!

Saturday, June 16, 2012

Progress update for 6/9/2012 - 6/15/2012

This week:



  1. Moved the project to some proper source control system called Assembla. It's free up to 1GB and has a nice visual studio plug in.
  2. Got my roommate working on this with me now. He added code for doing things like playing sounds when things die and also started on writing some basic AI for the enemies.
  3. I started working on ladders thinking that it would be a quick little thing that would take a few hours. I was wrong. So, so wrong.
  4. Ladders wasn't actually so bad in retrospect, but it feels like it took a long time just because I didn't devote so much time to programming each day this week.
  5. Jumping the gun a bit here, but I was idly listening to this episode of Extra Credits and it got me thinking about my engine and why I played and enjoyed the original Mega Man games. Even better, it got me thinking about what I want to get out of this engine and what I want players to get out of this engine. This is something I'll post more about and think about more later after I've finished Cutman's stage, but it's good to be putting it on the back burner now.
  6. Roommate implemented pausing and pausing when the game window is not in focus.
  7. Not directly related to development, but maybe Mega Man L should get made; it's more than Capcom is doing now.
After last week's additions, I decided I wanted to take it slower this week so I'm not going to push myself to have anything finished. This decision is also in part because the wife leaves for a week or so starting on Saturday so I'll have PLENTY of free time to be coding this game. I intend to make a lot of progress then because of the sheer amount of free time I'll have.

Late edit: Forgot to take screenshots for Screenshot Saturday! Here:
My roommate added some basic AI code.

I added ladders.

Saturday, June 9, 2012

Progress update for 6/2/2012 - 6/8/2012

This week:



  1. Worked hard to get the level editor to a level where it can edit levels properly (Picture below)! I still need to add support for transitions in levels and enemies and any other scripted event stuff, but plopping down tiles, saving, loading, changing tilesets and a few other nice features are all implemented and working. There's still a lot to do before it's complete, but I'm at a point where I can create some levels in my map editor for use in my game. Now then, I just need to get my game loading these levels...
  2. I've given a lot of thought to the content pipeline in XNA and how or whether I should be using it. I've already got an XML schama that works with my level editor, but it seems like if I want to use the content pipeline I'll need to rewrite my schema to be XNA serializable. Here's a good tutorial about how to serialize XML for XNA. If I bypass the content pipeline, then I can make my life a bit easier even and just save levels as binary blobs, but I lose the ability to run my engine on the Xbox 360. In the end, I decided on using the content pipeline because I don't lose anything by conforming to it and I don't want to close doors I might want to use later (Xbox 360 compatibility).
  3. Powered through getting levels to load through the content pipeline in game. I also converted the current level assets I've created by hand from the editor format to the XNA format. It was tedious, but informative. The whole thing turned out to be slightly simpler than expected in some places, so that was a nice surprise. I conferred with my roommate and we isolated the render resolution and the window resolution so now everything looks much more properly to scale like the original Mega Man game. Below you'll find an image of the game running the first bit of Cutman's level in game.
  4. Found another good article about the component design pattern. It's pretty obvious that this pattern is better for larger games, but I guess I'm  not sure where the line between "small" and "large" lies. It seems like the sort of thing that requires experience to determine.
  5. Levels now properly export to a format that can be put directly into the Xna project, compiled and read into the engine. Before I had converted the files from the editor by hand and boy did I not want to do that more than the once. 
  6. I'm still fiddling with collision detection, but that should be fixed for a while in a little bit here. I eventually ended up defining hit boxes by hand for the player character since doing it automatically turned out to be quite a bit of trouble. Everything works a little better because of it though, so it was worth it.
  7. Enemy spawns now work properly in the game and can be set in the level editor. Currently the options are limited to exactly one specific case (BunbyHeli, spawn on sight, infinite spawn) and the enemies don't have any AI, but they deal damage just fine when you run into them and they're plenty killable. Overall, I'm happy with them. I included a youtube video I recorded of everything up to this point using fraps. I would've made a gif, but I don't have a good program to do so. If you know of one that's free, let me know in the comments. Thanks.
It's been a busy week, but I really wanted to push myself to get to this point. Looking back at last week's progress report, it feels like forever ago. I'm much happier with the state that the game is in now, but I really haven't spent much time unwinding from work, so I think I'm going to take it a bit easier next week.
Here is my level editor with a carefully reconstructed first bit of Cutman's level from Mega Man 1
So chic!

Saturday, June 2, 2012

Progress update for 5/26/2012 - 6/1/2012

This week:


  1. Fixed my timestep. This was the end result of debugging some physics problems. I also got to change all my constants afterwards to prevent my player from flying off the screen at every opportunity. Something else I learned about while talking to my roommate about this problem was sweep tests. This sounds like a good idea and as soon as I decide that I have need for it, I'll be implementing it in my own stuff.
  2. Read about Tiled and considered using it in place of my own map editor that I've been working on. Tiled has a lot of nice features for map editing that would help me create maps much much much faster than my own map editor will when I'm done with it (because there's no way I'm going to put in more work than I need to into it). I looked into what I would need to do in order to get Tiled to save in my map format that I've been developing. Here is a link I found about writing a plugin to get Tiled to save in your format. I decided ultimately that although Tiled is a great looking program, I would have to include it in my plans from the beginning next time to use it effectively. This time, I think I'll be better off working on this myself.
  3. Added a life bar for the player. It's position is a bit close to the screen edge, but that can be fixed later.
  4. Worked on the map editor more. Much more. Also thought about how best to integrate my level files from the map editor into the game program.

Didn't get to work as much as I wanted to this week on my project. This weekend I'm either going to work on making a visible change in the level architecture or implementing some enemy AI via finite state automata. Below is a picture of my only visible change this week, the health bar:

Saturday, May 26, 2012

Progress update for 5/19/2012 - 5/25/2012

This week:



  1. Started the week by rewriting the Player class and the Enemy class. Most actor logic is stored in the AnimatedSprite class. I'll give an overview of how I've structured things soon.
  2. Found this link on /r/gamedev:  http://higherorderfun.com/blog/2012/05/20/the-guide-to-implementing-2d-platformers/ I find it very helpful, especially since I've already figured out some of that stuff for myself.
  3. Found another link on /r/gamedev:  http://www.wildbunny.co.uk/blog/2011/12/11/how-to-make-a-2d-platform-game-part-1/ It's a 3 part series about implementing 2D platformers. With all these new resources and a three day weekend coming up, I feel like I could really get a lot done in a relatively short amount of time.
  4. After thoroughly reading the two articles above, I've noted that the design decisions I had made and were leaning towards are already recommended in those articles. This gave me a confidence boost that I was on the right track. It's also now my fall back position for not being sure about how to do something.
  5. The rewrite I started last week is done now. Hurray!
  6. I've added a basic camera to the game. It works. I'm so excited by these little things. Next up will be working on finalizing the level editor and, by extension, the level, room and tileset classes.
  7. Made good progress on the level editor. Focusing on getting the New Level, Open Level and Save Level functions perfect before I go on to include any sort of actual editing. Should be done with these by the end of the week, I suspect.
This week's screenshot:
A working camera!

Thursday, May 24, 2012

Why I'm not using Software Design Patterns

So, this post has undergone some changes. At first I was just going to describe some design patterns and talk about what situations they're useful in so that I would have a reliable reference. The problem is that there are plenty of these already. After that, I was content to talk about how different design patterns applied to video games, mine in specific (which would be more focused on progress in my project and less time spent writing on this blog which does not directly affect my project's progress). As I tried to implement some into my code, I quickly became frustrated. I was talking about implementing components into my code base when my roommate basically said "The Component design pattern is good for two cases in game design and you have neither."

I had been so caught up in trying to program in the "right" and "proper" way, that I had again forgotten to just Do The Simplest Thing That Could Possibly Work. This is a lesson that I've learned the hard way several times, and will probably learn again before I finally ingrain it into my brain. Before I go and discuss anything further, I should clearly state that I am not an expert and am still learning. What follows is my personal viewpoint and I will probably look upon it with scorn in six months or so when I know better.

There are often, in programming, multiple ways to accomplish complex tasks. The problem I'm trying to solve (the problem of making a game) has a large number of solutions; too many for me to research or know. When I started this post I was looking for some optimal pattern to use that would make for a more stable program and make my life easier in the long run. This design pattern is out there somewhere, I'm sure. I also know that there's no way in hell I'm using it.

I started out looking to implement the component pattern, which you can read about here as well as many other places on the web. It has a lot of advantages to a big game (often in 3D) or games with a very data driven engine. That isn't me. My game is 2D, has a fixed number of entities, and isn't built for DLC (I'm not even 100% sure on how to implement DLC on a technical level). My game will probably have a title screen, one level and that's it because I need to start small. It's important to note that I could implement the component pattern and do just fine with it, but it's awkward to me. Whether that awkwardness comes from a lack of experience using it or it just being the wrong fit for me personally, I can't say. Planning on how to split everything out into different components was taking up way too much of my time though; time that could've been spent implementing the simplest thing that could possibly work.

Despite my bold and eye catching title, I am fond of using the Object-Pool pattern (sometimes I've seen it as Resource Pool) where I can to minimize my memory footprint. I really like this pattern as it has a few benefits and not much in the way of drawbacks. It helps me guard against memory leaks and keep my memory footprint small, as well as being really easy to implement.

So if I'm not using popular software design patterns, what am I doing? Well, mostly I'm fumbling along on my own. I'm sure it'll end with me learning which patterns to use when the hard way, but it seems like at least some of that isn't the kind of thing I can learn without making the mistakes myself. Based on my past experience with making games, I tend to succeed in my goals when I just jump in and write horrible messy code. Then after a bit I stand back and reflect on the structure of my program and what I want to accomplish with it. Next, I rewrite my code to more accurately reflect what I want to be accomplishing. Finally, I end up with something approaching a viable program that is like the game I wanted in the first place. I'll wrap this post up here though and show an example of this process in a later post.

If you read something here that's totally wrong, or even a little wrong, please let me know in the comments so I can have the chance to learn something! Thanks for reading.

P.S. After reading this article, my hopes have been bolstered significantly. You'll notice that there's no mention of components anywhere. Also, you can't see it here, but the design pattern that I've been pursuing has been similar to that of their Mega Man example already.

Saturday, May 19, 2012

Progress update for 5/12/2012 - 5/18/2012

This week:

  1. Spent 8 hours on Sunday tweaking and thinking about architecture changes. During this session, I got an enemy spawning at a set location and dying from player bullets. I also squished some bugs, most of which were caused by silly typos in for loops. Also spent a small chunk of time wading through the enemy and player classes. Eventually I decided I would be better off rewriting them to use a single Actor class and then a component design pattern.
  2. Began redesigning the Player and Enemy classes into a more cohesive base class. Took breaks from this to design a rough outline for how the Camera and Room and Level classes need to work. Also thought about how to store all the Level and Room information. Decided to use XML files for metadata.
  3. Began work on the graphical level editor. So far this has involved some basic form functionality and then finalizing my design for level structure. I'll write a post about this in the near future once I get the basic functionality of the editor working.

Since there's nothing visually different about the actual game this week, there's no screenshots. Sorry.

Friday, May 11, 2012

The Move to XNA

The Old Code

Let's get something straight right from the get go: I am not a great programmer.
I'd like to think I'm a pretty okay programmer, but I may not even be that. Please bear that in mind as we take a quick tour of my initial code for my Mega Man clone.

Let's start by listing the files and what's inside of them:
GameEngine.cs - Contains the main game loop and references to the Graphics and Physics management classes as well as a List of all the game objects that are in memory.
GameObject.cs - Contains basic logic for tiles in the game. Is it an object that can be moved through by the player? Is it affected by gravity? Where is it located? What's it's movement speed? Direction? Acceleration? All these questions are (or were intended to be) answered here.
AnimatedGameObject.cs - Not everything in our game will have static poses; some things need animation! This inherits GameObject and really only adds functionality for animations.
Player.cs - Inherits from AnimatedGameObject. Most of the code in this class deals with responses to user input, e.g. when the Jump button is pressed and we are on the ground, do a jump.
Bullets.cs - Handles bullet creation and pooling. Also contains basic logic for bullets.
GameControls.cs - This is a static class which contains a list of properties for different actions like move left and jump.
Physics.cs - This class contains my physics methods, such as they were. There are really only two: ApplyGravity(GameObject) changes the given object's acceleration given what direction gravity is affecting it (my thinking being that doing this here would let me have gravity from multiple directions later) and MovePhysicsObject(GameObject) which then applies the object's acceleration vector to their x,y position.
Graphics.cs - This class was supposed to handle all graphics calls that my other classes made as well as initializing the game window. The idea was that by funneling all the graphics calls through this class, if I ever needed to move the code to another platform then I would only have to re-write classes that touch the platform's APIs, like graphics.
GameWindow.cs - The final class in my list mostly just handled receiving user input and updating the GameControls class as needed. This is arguably not the place for this logic, but I never got far enough on this version of the code for it to be a problem.
So that's what the code structure looks like. The player and the level that I was testing in, seen below, were generated each time the program started just before entering the game loop (bad). I began the project thinking about how to implement the game in a clean and easy to read way, but ended up with a mess (double bad). It was nothing that couldn't be cleaned up in an hour or so of refactoring, but that's an hour of time not spent putting in something new. Reading user input was handled in the GameWindow class instead of the actual Control class (triple bad) and the code in the Physics class was barely functional (so bad).

It's hacky, poorly designed, and really only had one thing going for it: it worked. All the problems I listed above would have to be fixed before I felt good about releasing it, and the longer I left them unfixed the harder it would be to fix them, but there's something to be said for something that works properly. Mega Man was animated, he ran back and forth and when you pressed the right buttons he would jump and shoot. Had I continued with this code, the next step would be to fix my design problems, work out any bugs and generally get my program into shape. Ironically this is exactly what I was doing when I decided to abandon this.

Why I moved to XNA

My first experience with XNA was several years ago shortly after graduating college. I hacked together some tile generation system with some basic MS Paint sprites. Figuring out everything was pretty terrible since the documentation was spotty in places and my own knowledge wasn't enough to fill in the gaps. I gave up. More recently I was looking at different engines and frameworks for making games. I tried my hand at Unity, but I never felt like I was using it properly and since all the online resources about how to use Unity were either aimed at people who a) couldn't use a mouse or b) had several years of game design experience already, I was out of luck. I did bumble my way around it for a while, but eventually got frustrated with my lack of meaningful progress. I also tried my hand at GameMaker, which seemed promising at first. It was simple to get into and get going, but I quickly became frustrated by the lack of control over the actual code and my own lack of understanding of how the system worked. I had gone through a few other engines at this point and was, I suppose, just frustrated by spending all my time navigating GUIs and not doing any actual typing. So I started writing the code I outlined above.

My roommate had been using XNA for quite a while and had a book on XNA 4.0 handy. I flipped through it and was pleased with how easy things looked now. Things I wanted were already set up for me, only a minimum of coding for them was involved. I could target the Xbox 360 as well as my initial target of Windows (I'm not planning on putting a Mega Man clone on Windows Phone), there are contests I could enter, there are a ton of tutorials for XNA stuff now (no such luck for my windows form code), and there's even a platformer starter kit that shipped with XNA 3.1 to provide me examples. I could go on, but that's a pretty decent set of reasons right there.

I took the plunge and within two to three hours with my old code and the platformer starter kit as a reference, I had gotten back to my previous level of functionality and then some. One of the things I took from the starter kit was the Level class which, with a minimum of modification, will allow me to have a basic tool to generate levels from easily editable text files. Most of the code is still in there and the class will need to be majorly overhauled for my purposes, but what's there is a good start.

There are a few things about the starter kit that make me scratch my head. For example, take a look at this code from the Player.cs class of the starter kit:
// Calculate bounds within texture size.            
int width = (int)(idleAnimation.FrameWidth * 0.4); //12.8
int left = (idleAnimation.FrameWidth - width) / 2; //9.6
int height = (int)(idleAnimation.FrameWidth * 0.8);//25.6
int top = idleAnimation.FrameHeight - height;      //6.4
localBounds = new Rectangle(left, top, width, height);
This code is in Player.LoadContent(), which gets called once at initialization of the class. The selection I've pasted here calculates the localBounds object which gets used in a few places doing some very useful things like checking for collisions. The numbers in the comments at the end of each line represents what the calculation comes out to with my 32x32 px Mega Man sprite. I have no idea what the magic numbers above are for and the comments near the code block provide no insight on the matter either. There's a couple places around the starter kit where things like this happen, and it's more than a little infuriating. I assume that they made the starter kits so that people new to XNA could learn from them (which would explain why all the functions are otherwise immaculately commented), so it's unfortunate that there's no explaination for this. Perhaps there is and there's something I'm missing, in which case I'll edit the explaination into this post later. It certainly makes it more difficult to calculate numbers than it should be though. I thought I could pass the player's Position variable for where the player bullets spawn, and imagine my surprise when the bullets fired from his feet!

Overall the starter kit gives me a good idea of some things I need to look at to get a respectable platformer going as well as examples of how to do some basic things in XNA as well as how the XNA devs thought the flow of the program should work. I recommend checking it out if you are unsure of where to start. You can download a version of the starter kit updated for XNA 4.0 here and read more about what Microsoft has to say about their kit here.

Screenshots

To wrap up, here's a screenshot of the old windows forms code, showcasing a particularly unfortunate problem with my detection of whether the player was standing on a solid surface:

Here's some screenshots of the new XNA code that I'll be optimizing and adding to the rest of today and tomorrow:
As you can see I am checking for solid surfaces under me better now.

Although apparently shots are coming out of Mega Man's head. Oh well, at least they're shooting, that's good enough for now.

Jumping and shooting works too! Look!