Building on the tilemap scrolling code I described in a previous post, I’ve almost created a jump’n'run game. It features a tilemap, two backgrounds and a sprite as a movable character.
What you see in the screenshot is the sprite (strange blue thingy), the tiles (green and brown), a background that moves (clouds at the top) and normally you’d also see another, not moving, greenish background, but that got somehow lost in Desmume’s emulation. The movement of the character is actually working as is the collision detection with the tilemap. Thus it’s possible to jump and move around without falling through the floor or running through obstacles.
The collision detection is rather basic. I just compute the sprite’s coordinates as tile indices and then check if it’s impossible to move into the tiles that whould be entered due to the current movement vector.
The map is loaded using the EFS library (forum thread at gbadev) which makes it very easy to read data that is actually appended to the .nds ROM. I first used libfat (blog post on using it on the DS and in an emulator), which is as easy as EFS, but has the disadvantage of not being able to provide a self-contained ROM file.
Take care if you want to use the EFS patcher v1.0 in Linux. It’s possible to compile the normal efs.c in Linux, but the library then doesn’t work on the DS hardware. There is a “EFS Patcher Universal (with OSX binary)” download on the library’s homepage which compiles in Linux and produces a working library for the DS hardware.
To create the map I’ve used Tiled which is a generic tilemap editor written in Java. I wrote a custom map exporter so that I could easily read the map on the DS.
I don’t post the code because it’s really ugly at the moment, but hey, it’s working!
Tags: ds, jump'n'run, tilemap
