Taking on a Zelda Clone: Part 4

Got a whole lot more done, although the code’s starting to get a bit out of hand.

Solid objects
I thought it was time to start doing solid objects and stuff, so I started by making a Tree object I could test on. Hit detection is easy but it’s always a pain trying to get things to work right. My first implementation was pretty funny, it’s in the video above.

I quickly realized I don’t want everything to be treated as an object though, it seems silly to make walls and such be objects, for example.

Poe made a couple more enemy sprites, so I implemented them and also finally got enemy animations working. It looks much nicer now!

Tile system
After the solid object tests from earlier, it seemed about time to implement a real tile system that can be used for the maps. I started a Room class and did a bunch of stuff to make it work. Then I decided to add in the collision detection functionality for it, and after an hour or so I finally got it working. My collision detection routine is not optimal at all, but attempts to do quicker versions have all met with issues. I’ll have to come back to this at some other point.

I’ve implemented the collision detection a bit like Zelda 1, where you can walk slightly “onto” tiles if you’re below them, it’s hard to explain in words. The problem I’ve come upon now is that trying to maneuver vertically between stuff (like the graves in the latest map, for example) is extremely difficult. I have to see how Zelda handled that, I’m kind of stumped.

Also, I made a sort of “obstacle course” at one point and stuck two enemies in it. I let them do their thing and waited to see how long it took until one reached the end. It was neat seeing the system I built run itself without any interaction like that.

Enemy classes
It was about time to make a good base Enemy class so we could have multiple types of enemies at once. For this test bed, I decided to make it so only eight enemies can show up on screen at once. I also added some stuff to make it so that enemies don’t appear on non-walkable tiles, otherwise they’d get stuck.

Speaking of which, I also modified the enemy walking behavior to be a little more Zelda-like; in general enemies walk in multiples of 12 now, or about half a tile’s width/height.

A crazy bug has appeared now – sometimes an enemy will do some crazy teleport-looking thing when knocked back. I think it has to do with the tile system and its collision detection, but I’m not sure. It seems to be my first serious bug.

I decided it’d be nice to have enemies drop something else now, and health items seemed to make the most sense. So I implemented the power pellet drops and the whole health system while I was at it. Enemies can now hurt you and you can die (and get an achievement for it!)

Getting the health to display is pretty simple, but I really don’t like how small of an area it has, and if I wanted to release this on XBLA or something it’d be rejected for placing important stuff outside of the “safe viewing” region of the screen.

Screen issues
That reminds me, I realized yesterday that the map (which is effectively 320×180 scaled up 4x to make 1280×720) has weird dimensions, so with 24×24 tiles there’ll always be extra blank space vertically and horizontally. I’m not sure what to do about this – I don’t want to do something other than 1280×720 if I can avoid it. I might do the scaling at 3x instead of 4x, but I’m pretty sure that’ll still cause the same issue. Bleh.

So this latest version is now almost a full-fledged game – I could just slap a title screen and an ending screen and make it a “kill all eight enemies” game or something. But this is really all just me building the engine for the game that’s to come later, so I won’t do that 😛

I gotta fix a few bugs and issues, but it’s now very clear that I need to do some major housecleaning with the code. I really wish there was a way to assign graphics data to enemy classes without having to do any interaction with outside classes – I don’t see how that’s possible, though. Stupid C# and its lack of global variables 🙁 Also, I need to figure out how to break the program code up into multiple files, but every time I try I wind up screwing things up terribly and it’s a crazy mess.

At some point I want to implement multiple rooms/screens, but I don’t really look forward to making the room connection stuff work or figuring out how to do the screen transitions.

Still, it’s really cool that in this short amount of time I already have a technically playable engine 😀


Both comments and pings are currently closed.

4 Responses to “Taking on a Zelda Clone: Part 4”

  1. Kyosuke says:

    This is great, man! Fun to watch the progress.

    • Mato says:

      Haha, I’m partly posting progress stuff inspired by how you used to post progress reports on your old projects too 🙂

  2. Murasaki says:

    Just did a quick Zelda test and walking in between two solids vertically seems to use a routine I was gonna suggest anyway. 😛

    Basically it kind of nudges you left or right into the proper space so that you can fit through unscathed.

    In terms applicable to your game I’d say the routine would be something like this:

    if moving up or down and player encounters an obstacle:
    if player x > obstacle x AND obstacle != max column:
    if [space just to the right of obstacle] is empty:
    if player x > empty space x – [some arbitrary limit]:
    player x += 1;
    else if player x < obstacle x AND obstacle != min column:
    if [space just to the left of obstacle] is empty:
    if player x < empty space x + [some arbitrary limit]:
    player x -= 1;

    I hope my pseudocode isn't totally incomprehensible. The [some arbitrary limit] bit of course denotes the "range" within which the game will scoot you on over into a comfortable fit between objects.

    Let me know if anything else is unclear!

    • Mato says:

      Heya! Thanks for the pseudocode, it’s pretty much along the lines of what I was thinking of doing, I wasn’t sure if that was the Zelda-y way of doing it though. I’ll give it a shot hopefully sometime today and post my results!

Subscribe to RSS Feed Follow me on Twitter!