Showing posts with label collision detection. Show all posts
Showing posts with label collision detection. Show all posts

Sunday, July 27, 2008

Checkpoints, boxes, and bug fixes

I haven't had any time to work on Extinctathon during the week, but I've had a good two hours to work on it this morning. Things I've taken care of today:

  • Began implementing a basic checkpoint system. When the player crosses the checkpoint, he gets 1000 points and will respawn at the checkpoint if he later dies. This can easily be extended to level endpoints as well, which are a part of the next big goal which is transitioning from level to level.
  • Began work on boxes that pop out powerups. Right now the question mark boxes are popping out fireball powerups, and there's a few issues regarding the bounding boxes that need to be taken care of. I need to make it so that different types of items can come out of the question mark boxes and I need to be able to set this in both the design stage and in game (depending on the circumstances).
  • Fixed one of the audio bugs that was causing crashes when exiting and restarting a level. I wasn't disposing of the background music cue, so in certain circumstances this would cause a memory management issue which would crash the program.
  • And, finally, a couple of smaller bug fixes. Scores no longer pop up over enemies who suicided (i.e. fell off the screen) and the snakeocat no longer rapidly flips back and forth when the player is directly above him.
What's next:
  • I need to work some more on the way that blocks can pop out powerups, how this behaves, and how it is handled.
  • I need to fix an issue with the bounding boxes of the sprites. When the sprites are reformed (this happens to all projectiles), there is an issue that is causing the old bounding box to be retained. This causes a couple of collision problems which need to be fixed.
  • I need to make at least four solid levels. Once I have that, I think, I'll have a good five minutes of gameplay that I can use over and over to work on fixing bugs and polishing the game.
I don't have any vids at the moment, but I might post some later tonight after I've had more time to work.

Sunday, July 20, 2008

Game State Management: Progress!

Due to some stuff in the real world, I haven't had a lot of time to work on Extinctathon in the past week. Still, I had a chunk of time this morning, and I started making headway with implementing the Game State Management Sample without (completely) breaking the game. What actually happened was I started doing that, got fed up, tried to roll my own solution, realized I needed everything the GSM Sample did, but my version would be kind of crappy, so I started over using the sample.

So, yeah. Lots of back and forth. I got Extinctathon to work with the menus, pausing, stuff like that, with a few BIG issues.

  1. The collision detection is broken. It was dependent, before, on the input handling, collision, and updating to be done in a specific order. This had to be moved around to accomodate the new changes, and it no longer works in certain situations. This should show you how shitty my collision stuff is. It need to be completely reworked.
  2. Some minor stuff with the music. This should be easily fixed.
  3. There's a weird bug when you exit out of the game to the main menu and then start a new game. The program crashes and throws an error I haven't seen in C# before. I'll mess with it later.
Video later on.

UPDATE:
The collision detection has been mostly fixed. It's better, with a couple of exceptions, than it was before the game state management was implemented. The main bug that's left is that, when pressing up against a stack of blocks and falling, the player can get snagged on the corners of the blocks which prevents him from falling. I'll take a look at this over the coming days. I'm kind of tired of working on this at the moment, so I'll take care of that later.

The audio bugs remain, but I know what's causing them and they should be trivial to fix. Hopefully.

Video:
Extinctathon: Game state management and one more collision bug (720p, 9.8mb download)
Youtube

Sunday, June 29, 2008

Sort+sweep detection: FINALLY



Okay, so I'm super happy that I've gotten the sort/sweep implementation more or less working for my collision detection. It took me a good long while, but it's working now, and the performance increase is noticeable.

My previous collision detection did the following:
Make a list of everything.
Go through each item on the list.
Test it for collisions with everything.

It's very easy to do and very inefficient. The new algorithm does the following:
Make a list of everything.
Make a new list of the beginning and ending positions on the X axis of each item and sort this list by these X positions.
Go through each item on the list.
Test it for collisions with any objects whose X position is between the start and end positions of this object in the second list.

That's a poor way of putting it. Here's a much better explanation. It even has pictures.

So anyway, it turns a really simple but time consuming problem into a somewhat complicated but much faster problem. I still haven't addressed the major issue for XBox, the mid-game creation of objects, and that will be one of my next major goals. Nevertheless, on my laptop it can go up to 1024 sprites (the most I'm supported at the current time) with virtually no hits to the performance. The video posted is a good deal slower due to the screenshot software.

Also, I don't think I've posted a video since I've made a few changes to the interface. I changed the screen size to 720p, so it's a big taller and a lot longer. I've moved things around a little to account for overscan on my HDTV. Finally, I've made the lives and the score displays a good deal bigger. I think it looks pretty.

Video: Extincathon sort sweep collision detection

Sunday, June 22, 2008

Extinctathon: the long road ahead

I've spent the last week preparing my code for broadphase collision detection using a sweep and prune algorithm. I'm working on the actual sweep and prune process now, but getting it to work at a reasonable speed on the XBox seems like it's going to be an uphill battle. I'll be working on it for at least another week, and hopefully by that point I won't have decided to give up and focus solely on the PC.

I read an excellent article by John Wells on the topic of broadphase collision detection particularly geared towards optimizations for the XBox 360 (bit of a refresher: my game currently uses the most naive collision detection algorithm in the universe, checking every object with every other object, i.e. a O(n²) algorithm which absolutely breaks down on the 360 after five or six enemies are present). The two main goals are elimination of cases, i.e. testing the fewest possible number of collisions by implementing some rather simple logic, and the avoidance of garbage. The XBox 360 hates garbage. When you create heap-based objects, it spits in your face. It slows to a crawl. It writes goth poetry. It doesn't like new objects.

The first issue, the elimination of unneccessary cases, is easy enough to do. I'm still working on it, but I can finish it in a day or two. The second part, however, is far more complicated (to me) because it involves lots of C# functions (and even syntax) that I've never before seen. I need to learn how to do it, but it's rather complicated. I'll have to work on it later.

I'll post some more of the details a bit later when I have more time.

Sunday, June 15, 2008

Extinctathon: enemy types and collision bugs


Now that the level loading is about halfway where I want it to be (it's independently loading lists of Blocks and Species), I need to do some serious work on the collision detection algorithms. I'll go into more detail in future posts, but here are the basic problems.

  • I need to implement per-pixel collision detection. This is most noticeablely an issue with the Snakeocat at the end, which, by virtue of the size of its bounding box, floats in the air a good deal more than the other enemies
  • I need to do a much better job of processing collisions with enemies once they occur. The player dies in a handful of situations where he shouldn't. Right now, the player dies if he collides with the bottom 3/4 of the enemy. If the player is falling too fast, or the enemy is rising too fast, even when the player hits the enemy from above he dies. What needs to be done is to extract the player from the enemy and then determine if the player was on top, to the side, or underneath.
  • Similar fixes need to be done with regards to collisions with blocks. There is a rare bug when the player is between two blocks spaced exactly the width of the player apart that can cause some unusual behavior.
  • I need to optimize the hell out of it. I deployed to my XBox for the first time this weekend, and anything more than 6 enemies on screen KILLS the performance. We're talking 1 or 2 frames per second. My basic algorithm is as naive as it gets (literally everything is tested with everything, an O(n^2) algorithm), and I need to fix it as soon as possible. It does fine with a couple hundred enemies on my computer, but, of course, that's a lot faster (with certain kinds of operations).
  • In addition to optimizing the broad phase of the collision detection, i.e. deciding what should be tested against what, I need to do some serious optimizations on the collision detection itself. I have not yet decided how best to handle this.
  • And, finally, I need to make it so that when enemies die by falling off the screen they don't give you points.
That's it for now. I was kind of lazy today and ended up just making a new enemy (the af0rementioned Snakeocat). I'll get to work on the serious stuff tomorrow.

Wednesday, May 14, 2008

Extinctathon: Level Editor



I've been working on Extinctathon pretty regularly lately, at least 2-3 hours per day, and I've updated quite a bit. I've got multiple types of background tiles (Block objects), I've updated the collision detection (it works about 95% as well as I want it to), and the beginnings of a level editor (as seen in the video). It's all in one program; you hit up on the d-pad to toggle between editing and debug modes (as seen in the upper right hand corner). In edit mode the shoulder buttons cycle forward and back through the types of tiles (grass, mountain, cloud, block), and the cursor is moved with the left hand joystick. Tiles are placed by pressing A.

I still have quite a bit to work on, including adding blocks that can be broken, blocks that can pop out power-ups, enemies, and all sorts of other stuff. The code needs cleaning up, too, and there's a good amount of commenting that I need to do before I move forward. The next step I'll be taking, however, is adding a level loading and saving system. I'd like to then make one semi-complete level so that I can test it out and then add enemies. I'll hopefully do that this week.

Source:
Extinct.cs
Species.cs
Block.cs