Super Dodgeball


Hello everyone!

It’s about time for me to post my nds game on the blog and that’s what I’ll be doing in this post. I haven’t blogged yet, so this is my first entry, but I have been working on my nds game behind the scenes for quite some time.
I started studying and learning C about 4 months ago and understanding the nds took quite some time and a lot of effort. Therefore I couldn’t make a game on time for the first date and decided to give it a shot at the rebound.
I had tough time programming this little masterpiece. The main cause of this was the incorrect use of pointers. I would get the weirdest errors and crashes at runtime.
I must admit that I’m still no pointer guru, but I learned to use them a little.

Now about my game: It’s called Super Dodgeball.
As you may or may not know, dodgeball is the name of a sport. In dutch it is known as “trefbal”, but that would be quite silly to use as a name for my game, since the goal of the game is to, in fact, dodge balls :p.
You can move the ship by using the left or right buttons on the d-pad, or if you’re a lefty you can use the Y and A buttons to move. You can use the stylus to destroy the blue balls. You’re game over when you’ll get hit by a ball.
The scoring system works like this:
– You gain a point every 60 frames (1 second) you survive.
– You gain a point for every blue ball destroyed.

Probably the most problematic part of programming the game was learning how to use sprites. I found a grand total of  3 useful tutorials on the internet which explained them…. a little. They are far from complete guides, so it took a lot of effort, mostly trial and error, getting my sprites to do what I wanted them to do. I used all 3 of those tutorials to make my own sprite code, and I must say I’m happy how it turned out.
I first had to understand how the OAM (Object Attribute Memory) worked. Basically, the OAM is 1024 bytes big, each sprite will take up 8 bytes, so you can use 128 sprites at the same time. In conclusion: the OAM contains 128 SpriteEntry’s.
Then I had to learn how SpriteEntry’s work:
SpriteEntry’s contain 4 attributes, or better said 4 16-bit entry’s, because saying attribute could cause some confusion, since each ‘attribute’ is a 16-bits big, but contains more than one setting. Settings are for example what the sprite’s x and y locations are, how big it is, what sprite from the sprite memory to use, etc. I created my own struct named Sprite, which contains the x and y position of the sprite, its speed, and a pointer to the SpriteEntry.
It actually contains only 1 useful entry, which is the pointer to the SpriteEntry. The rest of the entries are also kept at object level (player and ball objects).

Another challenging part was programming the collision detection. I wanted to make a simple and a detailed version: The simple version would just check if the sprites boxes collide. And the detailed version would check on pixel basis only if the simple version would return true. I wanted to do this, because always using the detailed version would cause a huge and unnecessary amount of strain on de CPU.
I have the simple version working, but de detailed one is still on the to do list, so for now that one always returns true.
And to make it less stressful I altered the simple version a bit, to reduce the hit box on the balls and the spaceship. Schematically it now works something like this:

sprite hitbox example

So as you can see, you can touch a little edge of the ball without crashing, and your ‘wings’ can’t crash you either. At this time, this is the best solution for collision detection.
Note: There is a bug that sometimes (very rarely!!) causes collision detection to fail and you can fly straight through a ball. I haven’t been able to successfully reproduce the bug on demand, so I don’t know when or what’s going on. Feel free to look into my code and see if you can fix this. You can post back here if you have an answer ;)

As for the sound: Some or all of it may sound very familiar to you. Here’s what I used:

–          Fox Movie sound (intro)

–          Mortal Kombat sound (main game them sound)

–          Arnie’s legendary words: “I’ll be back” (game over)

–          Some popping sound (destroying a ball)

You can download the source here and the .nds file here. Or download them together in one package here.
*files are hosted on rapidshare and can only be downloaded 10 times. If you can’t download it, contact me, and I’ll try to find another solution, but for now, this will have to do.

I hope you enjoy the game!

Maarten Koot


Game final version


UPDATE: Project files can now also be found here:^_files.rar

This is the final version of the first nds game I made. Rules are simple because there are no rules. You can come up with them yourself. I hope you’ll enjoy the game.

Anti-aliased line Alpha



here you can see my “game” (which isn’t really a game) from my project. As you can see images are missing but I didn’t had time to do this. Therefor a little preview of a line with and without anti-aliasing. The algoritm I used for anti-aliasing is Xiaolin Wu’s line algorithm. For the “normal” line I used the Bresenham line’s algorithm. Source code can be found here. I hope you can see the difference 😉