Rewriting code: tile-player collision code

by Niels Brouwers 16. January 2012 04:19

A lot of time on the Carter Jones Adventures game is spent on rewriting pieces of code. Visually you probably wouldn't notice any difference if I would show the game before or after a rewrite but in terms of performance, memory leaks, bugs and maintenance of the code there can be a huge difference.

The Carter Jones Adventures is a full-directional sidescrolling game, this means that the player can roam around freely depending on how I layout the level and where I place the platforms. I do the laying out of the levels in my custom level-editor (there are some screenshots of that in previous posts). A level is built up out of graphics that are packed together in one or more large images, by copying tiles out of the larger image into the level, a level is constructed.

Tiles are 32x32 pixels in my game. And previously I defined a heightvalue ranging from 0 to 32 for each tile. This allowed for having a unique height value for each position. Height locations between adjacent tiles were extrapolated. This system of 32 different heights and extrapolating the heights between tiles was causing some problems: occasionally the player could jump 'between' tiles and get stuck on a platform for example.

So, today I set out to rewrite that code. The new approach would define a 'rectangle' of outer tiles that represent the player. These tiles are investigated, they can be either solid or fallthrough and the new algorithm detects where the solid tiles are (if any). Depending on the current state (e.g. walking to the right) and the measured rectangle (e.g. solid tiles under the player, fallthrough on the right,top and left) I can now determine the possible actions such as moving to the right. I can now use this algorithm everywhere in each object class, not just the player's (using exactly the same algorithm from several states is one of the basics of programming - which I did not obey: due to the explorative nature of the code I copied it over instead of generalizing). Anyway, the occasional errors are now gone, the code is much cleaner and therefore much easier to read and I will use this code in all future objects thus preventing myself of creating new errors. All in all it was a sunday morning well spent!

 

Visually representing the rectangle of tiles around the player helped a lot with developing this piece of code. The FPS and milliseconds of time spent in drawing (D) and game-loop updates (U) are always displayed since Dream Build Play 2011 happened.

Wappy dog

by Niels Brouwers 9. November 2011 06:33

So, I noticed this trailer for wappy dog from Nintendo. It's like a Sony Aibo connected with your Nintendo DS. Cool idea, mixing reality with the virtual world. Skylanders is another game doing this. I am not sure if these games are really worth playing, but it is just another way of interfacing with your players. And that's cool!

It inspired me to draw this 'Appy Dog' which is a little further in the future from now. I imagined an iphone / android app that you can use to control your pet. Just plug in the two antenna's in your pet and off you go!

On to some Carter Jones progress, I finally fixed a weird nasty bug in the level drawing. Also the level 3 (background) graphics are nearly done, I still need to do a lot of variations and waterfall animations but it's getting there! I am also investigating other platforms as well, it seems that with a little effort (I am an optimist with estimations! ) I can port CJA to other platforms like IPhone and Android. But first it has to become an XBOX Live Indie - I need focus! And time, lots of it!

Last but not least, and something completely different: the Dutch Ice Carving Championship 2011 is coming up. I am participating again, so that will take up some time as well the next couple of weeks. I will keep you updated!

New level in progress

by Niels Brouwers 17. October 2011 03:15

Hopefully you didn't notice that I upgraded this website to a newer version of blogengine, it did happen however and actually it was pretty easy. The only thing that didn't work out of the box was the twitter feed, but I fixed that.

I have started on the third level graphics for Carter Jones, I still need to do the entire level 2 graphics but I am expecting those graphics to be a little easier to draw (level 2 takes place inside ...err... something - it's supposed to be a surprise). Level 3 is a real interesting level to draw, it takes Carter through the jungle to the temple where he will find what he was hired to look for. He will also find a lot more, here's a quick concept sketch I did today which will also satisfy all the halloween enthousiasts out there:

 

Excuse me sir, where can I find the toilet? Oh, right there huh? Thanks!

Ofcourse, when trying to post this entry I stumbled upon a blogengine.net error... fixed it, but it did catch me by surprise!

The value of good Level Design and the Tools for it

by Niels Brouwers 18. September 2011 03:36

Because I am enjoying myself so much whilst making Carter Jones, I decided to expand the animation tool with a level editor. This will enable me to quickly move around stuff (the background, but also the baddies etc.) in a level. Previously I was doing all that in the game itself, with a built in level-editor (and I was placing baddies through a manually edited xml file). That was not ideal, now it is just an easy to develop windows forms application so if I need some special function (like the roll that you see on the screenshot) then I can build it really easy.

This tool will grow in functionality and will greatly reducde the time to 'design' the levels. Designing levels is probably the hardest part in a game, if you mess up the design then the player will notice immediately and reject the game because it is no fun (it is probably just annoying or boring or somewhere lacking). So by enabling the design process outside of the game I hope to increase the quality and also the quantity of the levels. Level editing was kind of a chore before, now it is actually fun!

 

Wobbly lines in autumn

by Niels Brouwers 5. September 2011 07:40

I have totally optimized the code for Carter right now, there are no garbage collecter issues anymore and the drawing of the background is now completely done by the hardware - which is nice (hardware instancing is awesome)! Now I have to get back to designing the game and drawing graphics for it! I also managed to get some work done on the out-of-game level editor. This thing will make life a lot easier for me as it is a windows forms application containing the XNA display. It is actually integrated into the animtool I presented a couple of months earlier.

I did some quick sketches in Sketchbook just to see how some things come out. You can see the result below, I was totally not happy with the linework that I got when using Sketchbook. I have been trying out a couple of settings but so far, the lines are wobbly and totally unacceptable for me. In Photoshop I have found out the right settings to get the kind of linework that I want to achieve (pretty default actually) but in Sketchbook I can't seem to get it right. Such a shame, it is one of the coolest software around (and very affordable).

Anyway I wasn't happy with the inking but after painting and resizing it (about half the size) it looks kinda OK. I guess I'll be using Photoshop until I sort out the line thing... 

This is my version of the German Mechanic. (hint:movie reference!)

Follow me on Twitter

13. February 22:07
RT @MasterBlud: Hey want to help #XBLIG? Well sign this petition! https://t.co/mUeWTMwe RT and pass it along. Be the best Indie Community!

13. February 21:25
@JasonADoucette yup, cool tools indeed. I am a big fan of their comparetool as well!

13. February 21:24
@CreatureBox yay, new book! That's good news, when can I order? :-)

13. February 21:20
@GHarrisonSounds nice! These chiptunes bring back memories from long time ago!

7. February 22:10
I nearly finished removing all artifacts for level 1 today. That means the background gfx are nearing completion! #xblig

www.twitter.com/nielsbrouwers