The Enchanted Cave Ports to iOS and Android

Title Screen

The Enchanted Cave is now available for both Android and iOS!

I learned a ton from the port so I wanted to give people a look at what went into it.  A good bit is technical stuff geared more towards developers, so feel free to skim over those parts.  I won’t be offended.


I Had No Idea How to Code When I Made the Flash Game

I made The Enchanted Cave way back in 2010 and it’s been my most successful game so far.  Ironically it was also my first commercial game, and my first game coding from scratch.  For these reasons, the code in the game is AWFUL.  Basically what you’d expect for the first game of a self-taught programmer.  It worked for the most part, so if you’re lucky enough to not encounter a bug you won’t ever know, but when it comes to adding features or changing poorly written code it’s a nightmare.  Often the best choice in these situations is to just rewrite it from scratch.

I went into making the port thinking it would a quick process, like 20 hours should be plenty.  Yeah I knew my code was bad, but really I just needed to make the windows bigger and to work on touchscreen, right?  Maybe throw in a couple improvements players have asked for.  Turns out this was a huge project, and working evenings and weekends when I could bear it (since I worked 8-5 weekdays as a programmer elsewhere) the port project took about 3 months of work.  Maybe around 100 hours total?  That’s a rough guess.

FlashDevelop
First things first, I was gonna have to get the game working in FlashDevelop, since I had written the game in the Flash IDE’s code editor, and had been compiling with it’s compiler.  During the development of two other games between Flash TEC and this port, I had discovered the awesomeness of FlashDevelop and the Flex compiler, which makes coding a lot easier and compiling MUCH faster.

Well the Flash IDE doesn’t require you to declare datatypes for any of your variables so me being a newbie coder back in 2010 didn’t type anything.  FlashDevelop then gives me 2000 warnings when I try to compile because of all of the non-typed variables.  (Also declaring types lets you use the nifty auto-complete features of coding which I honestly don’t know how I lived without).  So I got to work declaring types for all of my variables and getting the game as is to at least run on my phone.  This alone took a few days to do which was actually several months before most of the actual work took place.  I must have noticed how big of a project this was going to be after looking at my crappy code and lost interest for several months.

Wow this code is really terrible
One example is that all of the windows in the game had all of the methods working from a file aptly named “WindowClass.as.”  I didn’t split any of these unique windows into their own classes and objects, as is the correct Object-Oriented Programming approach.  So this “WindowClass” had over 5000 lines of code to handle every window, whether that’s items, equipment, battle, treasure, shops, messages… everything.  I was doing some kind of funky store-every-window-in-an-array thing that was completely unnecessary and would just refer to say an equipment window as “windows[12]” instead of a much nicer “equipmentWindow.”  I basically had no idea what I was doing.  I didn’t want to deal with making changes to a terrible structure, so for the port I split up all of my windows into their own objects with their own class so that I could actually make sense of my code and make the necessary changes.  This was quite the chore.

Another example is how the floor maps are 2D arrays of ints written directly in the code editor.  I was smart enough to place them on different lines of code so that it sort of visually represented a floor, if you could image 6 as a monster and 3 as a wall.  Today I would use Tiled, a nifty little tool that gives you a visual editor to create maps and spits out a nice XML file you can then parse into whatever project you’re using it for.


Tiny Screen Touchscreen Changes

The flash version has the cozy dimensions of 550×400 pixels, with size 8 pixel fonts and as much information as you could possible need crammed onto the screen at once.  It worked ok with the precision of a mouse, but I have gotten comments on how the text is still too small, which I totally agree.  For the mobile version I was taking the screen size that appears on your pc and shrinking it down to less than half as much to display on a phone. These 8pt fonts were going to be microscopic and there was no way you could accurately tap any of the buttons with a finger.  For this reason the entire UI was completely redone from scratch.

Items
Item icons were tiny in the flash version relative to screen size, and I needed to make them larger to make them tappable on a phone.  So I bumped up their size 1.5x and then faced the problem of how many items should appear on the screen at once.  Immediately I recognized that the size window method in the flash game wasn’t going to work because I needed all the space I could, so I developed the full screen items and equipment window you see in the port.

Inventory

The different tabs to sort items was nice in the flash, but I was going to have to make them much bigger for mobile.  You really can only see about 6 items at once in your inventory but the sorting tabs and swiping function of the displayed items lets you find a particular item pretty quickly.  I also completely scrapped the whole drag-and-drop items deal that was present in the flash to a much easier and faster single/double tap to do things method.


Different Screen Sizes

A really fun thing about mobile development is you get to make sure your game looks good on each of the bazillion different sizes of phones that people have.  Oh wait this isn’t fun, it’s pretty awful.  There’s different methods to do this, and it really depends on the type of game you’re making and it’s best to know from the beginning that it’s going to be a mobile game.  To combat this, most of the things in the game are still drawn to a 550×400 area, the size of the flash game.  This sprite is then simply scaled to fit the screen as well as it can.  On it’s own this would fill up the screen fine for devices with aspect ratios of 11:8, but I’m pretty sure that’s 0% of devices out there.  Otherwise you’re gonna get empty space to the left and right (or top and bottom) of the game.

The game objects – the floors, enemies, player, etc are drawn and moved to be viewed best in this 550×400 frame, but the UI windows can be anywhere.  I was already redoing the whole UI anyway, so all of the windows and UI buttons are positioned based on your specific aspect ratio.  In the items screenshot above, this was taken on a 16:9 widescreen ratio, so there’s a good bit of space on the left and right of the items (which is a fixed width because of the visual look of the tabs and equipment windows) but you’ll notice the health bars and gold are still neatly in the corners of the whole screen.  On say a 4:3 aspect ratio, there’s hardly going to be any space at all on the left and right of the items window and the health and gold may unfortunately be hidden behind the equipment window.  Allowing the UI buttons and windows to be placed dynamically based on screen size eliminates the black bars issue.

Title Screen Ratio
But the title screen is a single image though, how’s that have no black bars?  Well what you have to do here is make the graphic with a 16:9 aspect ratio, but with all of the important stuff is still in a 4:3 area in the middle, so that you can scale the image as needed on a 1:1 ratio, and wider screens just let some extra pixels be visible on the sides.  Buttons can then be positioned based on the size of the entire screen.  Here’s what I mean:

 Aspect Ratios

The sides of the image is just more rock… nothing really to look at, but a ton better than black bars.  This is likely something nobody would ever notice, but you know they’d see the ugly black bars if they were there.


Looking Back

This was a massive project, and I’m very happy to complete it.  It’s been a request from players of the flash game for years (along with the sequel of course) and I knew I needed to deliver it so that my words mean something when I say I’ll do something.  I just had no idea it’d take this much work.  The game itself came out very nicely as a mobile game, and several improvements here like fast-finding new items and quick-selling junk in the shops make it a faster, simpler experience.  My hope is to spark enough interest in this old game of mine to get some people on board for the sequel’s kickstarter.  This part-time, work-evenings-and-weekends stuff with school and now work is absolutely draining.  If you liked the port and want the sequel from a dev with now years of experience, tell your friends about the game, and let me know your thoughts!  I love hearing from you all, and read every comment. 🙂

14 thoughts on “The Enchanted Cave Ports to iOS and Android

  1. Hi Dustin,

    Years after having finished TEC 1&2 on PC, I decided to get into it again. Hence I discovered the Android port of TEC 1 and I must say it has aged very well. The game is as good as before and the way you’ve re-thought the interface for smartphones is really clever. For 1€09, it’s a bargain. I don’t know if you plan future updates but if you do, could you just add a counter on the artifact screen to tell the player how many he found and how many there are in the game (just as you did on the medal screen) ? This would be an easy way to add replay value to collectors.

    PS: I already had the opportunity to tell it to you years ago but once again, congrats for what you’ve done on the TEC series. I’ve always been a fan of the Ancient Cave and your games are really a great tribute to it, with your personal touch and additions of course!

    1. Thanks so much! I’m glad you’ve enjoyed both games and their ports. At this time I don’t have any plans for an update but I agree that an artifact counter would be nice. Something to keep in mind for future games!

  2. Congrats on finishing your project ! I don’t own a smartphone, so I’ll have to wait for the TEC 2 kickstarter to begin.

    And thanks for sharing what you went through, it’s really inspiring for new game devs. I really like your blog entries about game development !

  3. Just thought I’d pop in.

    I noticed that you don’t keep previously equipped artifact gear when you re-enter the dungeon on the port. It’s making me start without full health as I have to re-equip the gear again. Is this intentional or just an oversight?

    Another thing I noticed is that the Escape wings are always last in the artifact screen, do you think you could change it so that it’s always in the 1st slot so you don’t have to scroll through every single artifact when you want to quit?

    Except for my string of bad luck I’m enjoying it, just have to keep on reminding myself that “YES, I can step over that empty sack, I don’t have to fight 3 more ninjas to get to the chest” (If you ever feel like making additional achievements it could be a fun “easter egg” to get a medal for stepping over an empty sack for the 1st time, “What kind of sorcery is this?”)

    1. Haha, yes stepping on a bag is quite the feat!

      The keeping artifacts equipped is an oversight, since I forgot that that was how the flash version worked. That makes sense that’d you need them equipped to have your health bonuses.

      That’s a good point about the escape wings, too. I’ll get them listed first. These should be fixed in the next update. Thanks for your help!

  4. You did a great job with this! I never would have expected it to be as big a project as it was, but I’m really happy with the improvements you’ve made. The new interface works really well for touch, and the pathfinding is very convenient.

    I do have one question though: did you adjust the difficulty in some way? I’m at floor 72, and haven’t needed to use the escape wings even once. Most enemies only deal 1 damage. This is way different from the desktop version, which took me a long time to beat. Some sort of difficulty setting would be nice, or maybe a hard mode once the game is beat the first time.

    Either way, this is one of my favorite Android games already!

    1. Yeah I redid the damage formulas along with making attack magic more useful. The formula’s a lot simpler now, but could probably use some more tweaking. It’s tough because of the random aspect of the game where you may get lucky with great equipment some runs and not so lucky others. I probably need to make equipment stats not so radically different.

      Thanks for letting me know, though. I’m going to make some adjustments and go through the game again tonight to see if it feels better. It’s also pretty difficult trying to make the game challenging for players of the original as well as not too hard for totally new players.

      1. I thought weapons were balanced pretty well, just armor has too high numbers overall. I just finished the game without ever dying or needing to use the wings. The final boss hit all 1’s while I hit 300’s. It still took 2-4 hits to kill most enemies, but they were all hitting 1’s on me.

        Personally, the thing that made EC my favorite was that it was so fun, yet so difficult. I remember wondering if I could manage to kill one more monster before having to wing out, and being nervous all the while. I died on the 90th floor once, but still had a lot of fun starting over from scratch.

        1. Just got done playing through it again with new settings. I lowered the defense on most of the items, and upped the attack on monsters, along with some other tweaks on elemental stuff. The last boss especially got a major do-over and is strong enough to be a final boss now. I’ve published it to the play store so I guess you’ll get the update in a couple of hours, but I guess you’ve beaten it already. 🙂

          Thanks for your report! I definitely agree that the difficulty was too low.

          1. Much better! I played it again (I don’t seem to get tired of this game) and felt sufficiently challenged. I ended up dying once, and was able to continue my game with my artifacts and stats as if I had used the escape wings.

  5. Im 24, have been playing this game for years so basic and fun great time waster. would love to see it on IOS would probably be willing to pay for it as well. thanks for the fun

    1. Glad you like it, the iOS version is up for review so I’m just waiting on Apple now. Hopefully it all goes well and they won’t tell me to change anything before they can accept it.

Leave a Reply

Your email address will not be published.