• About
  • Otis
Aduno Games

Building an Engine that Runs on Bad Words

July 12, 2012 10:04 pm / 2 Comments / Tom

I have a bad habit of yelling awful things at my computer when my programs don’t exactly work.  It usually results in a few hours of yelling followed by immediate deletion of all work in those hours, followed by about 15 minutes of writing a working solution.  Not exactly the best process, but it works.  Such was the case with collision detection between the player and the world.

I originally started by running a quick calculation on where the character was vs where the world existed.  This got way too complicated incredibly fast.  Running all that math all the time probably wouldn’t have been great on performance either.  So I started looking around the olde internet and stumbled upon the most basic solution: Bounding Boxes.  DUH!

Player in the process of jumping on an Enemy

How I overlooked that I’ll never know, but all 2D games run on bounding boxes. For those not in the know, bounding boxes are invisible boxes that surround the player and world to figure out what they should do when they hit each other.  XNA has a nice class for Rectangles that you can use and just check if they intersect.  Suddenly instead of calculating placements of everything all the time, I was calculating a bounding box once and running easy checks.  While it gave me a good starting point, I still had plenty of work to do.

I’ll get into my level building process in another post, but once I had that down, I had a few things to check aside from the collision.  There was also the matter of gravity and making sure that kicked in when needed.  There was a fun instance where you could walk off the edge of one platform and just stay at that height so long as you didn’t jump.  Not exactly game worthy.

The funny thing is each time I ran into a strange bug like that, the problem was the complexity of my code.  As the code was simplified, things began to work better.  What started as several hundred lines was cut down to about 80.  The simpler the better.

And what’s really nice about the engine is that it’s very modular.  If I decide to change the size of my tiles or the player, everything will automatically adapt.  Nice to have as I begin to move onto actual game design.

Once I had the player actually walking on the world, it was pretty simple to extend the Character class I had built into an Enemy.  They dropped into the world just as easily.  Using the same Bounding Box idea, I was able to run easy checks on whether the player was jumping on the enemy and killing it or if he was getting hit and had to get some HP deducted.

So now I’ve got a world and an enemy.  I was even able to install some goomba AI into the enemy so they’ll just walk forever until they hit something or fall.  Easy enough stuff, but a good stepping stone onto bigger and better things.

The first step in my game is done.  I’ve got an engine.  Time to start putting it through it’s paces and get rocking.

Posted in: Otis, programming

2 Thoughts on “Building an Engine that Runs on Bad Words”

  1. Bhizzle on August 9, 2012 at 5:26 pm said:

    you are either not working hard enough or not documenting your work well enough on your blog. either way, please work harder. Thank you,

    Reply↓
  2. Tom on August 9, 2012 at 7:54 pm said:

    Thanks for the feedback Bhizzle, I’m sadly just squashing bugs in the engine right now, not the most exciting thing to right about. Once that’s done (soon) I’ll have a new post about how my engine builds the levels!

    Reply↓

Leave a Reply Cancel reply

Post Navigation

← Previous Post
Next Post →

Recent Posts

  • The Most Recent Delay
  • Screenshot Time
  • Feature Lock is the Place to BE
  • Tools can be a Good Thing
  • I’m Really Good at Playing my own Game

Recent Comments

  • Monika on It’s not my World, I just Jump in it
  • Tom on Building an Engine that Runs on Bad Words
  • Bhizzle on Building an Engine that Runs on Bad Words

My Comics

  • 30 Extra Lives
  • The Cat Who Always Dies

Archives

  • June 2013
  • March 2013
  • December 2012
  • October 2012
  • August 2012
  • July 2012

Categories

  • Otis
  • programming
  • Uncategorized

Meta

  • Log in
  • Entries RSS
  • Comments RSS
  • WordPress.org
© Copyright 2012 - Aduno Games
Infinity Theme by DesignCoral / WordPress