King's Bounty III: An Advanced Remake of the Original Javascript / HTML5 DOS Game

Published on September 14, 2015

King's Bounty III: An Advanced Remake of the Original Javascript / HTML5 DOS Game

Background and philosophical considerations


Like many of my colleagues in the programming workshop, especially those who began to try their hand at computer technology early on, I have somewhere in the back of my mind a collection of the fondest and most romantic memories of my first experiences. Once, back in 1987, my father first took me to work on a weekend, where he solemnly sat me down in a chair in front of the buzzing Iskra-1030-11. Around that time, I firmly understood what I wanted to do in my future life.

image

Nowadays, by launching DOSBox, you can easily plunge into the aroma of carefree childhood, remember that wonderful feeling of children's omnipotence, dizzying interest, exciting new knowledge and skills. Now I’m 34, under my supervision more than a hundred people work, I still write quite a lot of code - especially where complex algorithms for intelligent data processing are required. Behind - in the arsenal of student achievements - the final of the ACM Olympiad, the victory of my chess engine in ex-USSR championships, one of the algorithms on search trees called by my name, hundreds of thousands of lines of my code in prod, but nothing brings such joy and not as inspiring as returning to the carefree world of childhood.

About 10 years ago, the BK-0010-01 emulator, my first home computer, came into my hands. Then it cost a lot of work not to start programming for it. However, this time another wave of nostalgia nevertheless pushed me to a very meaningless step, which could be justified by the feeling of emotional uplift that I experienced when I completed my crazy enterprise - making the remake / sequel of King's Bounty - the ancestor of all the games of the Heroes line of Might & Magic.

In general, this is an open secret that the time of lone programmers has passed. Single heroes remained in the 90s, when in the absence of the Internet and a large volume of specialized literature, as well as in an atmosphere of lack of computing resources, another left-hander deftly cut 7 hats from the skin of an unkilled bear in a short time. Today, the work of programmers in most cases is collective, and the success of a developer to a greater extent does not depend on algorithmic knowledge and technological skills, but on the ability to quickly find the necessary information and communication skills (including the ability to write well-readable code that meets the given requirements).

In general, the situation when one person writes a game from beginning to end today (including plot development, game interaction logic, creating graphics, selecting music, writing game dialogs, direct coding) is completely abnormal for the modern industry. The shoemaker should stitch the boots, and the oven - the pie-keeper to pies, otherwise labor productivity will not be the highest. But on the other side of the scale lies a high level of motivation, which in some cases makes it possible to more than compensate for the costs involved. The development of mobile platforms and the Web has made possible a kind of flashback - in exact accordance with the law of the negation of denial - many modern successful game startups are created either by themselves or by microcommands, which demonstrate amazing successes thanks to uninhibited work.

Of course, in my case, the project is purely entertaining - there are no ideas about monetization, and in the case of such an “underground” remake, it is hardly possible at all. The task was greatly simplified by the fact that the lion's share of game graphics and logic was borrowed from the original game. In this regard, the OpenKB project (http://sourceforge.net/projects/openkb/), currently abandoned, helped a lot, the author of which did a great job of reconstructing the original game logic and analyzing data formats of the original game. Manuals written by the author of this project, as well as several other amateur manuals found on the network, have seriously saved energy.

Technology


From the very beginning, a stake was made on cross-platformness, and since with respect to Javascript and HTML5, this has been more or less achieved by the titanic efforts of developers to date, there was, in general, no particular alternative when choosing a development language.

Of course, there are a number of languages ​​translated into JS and having some advantages, but there was no desire to create an extra layer in a small project. In addition, due to the prevalence of JS, you can always rely on the fact that any problem that you need to solve during the work on a project has already been solved by someone, generously providing code snippets for everyone to see.

Due to the comparative simplicity of the game interface of the original game, it was decided to abandon the use of any heavy game frameworks. Of the libraries, only jQuery was used (in principle, one could do without it - in fact, only $ .inArray, $ .trim and work with browser event triggers were needed; to be honest, the possible cross-browser problems were just scary in relation to events, so jQuery was still left in the project).

Graphics and music were implemented using standard HTML5 mechanisms (Canvas, Audio). The standard Canvas methods are more than enough to implement sprite graphics with minimal labor. Audio provides everything you need to supply the game with sound effects. All required snippets are easily detected on stackoverflow with simple queries, so some practical programming experience in the modern development ecosystem is quite enough to understand all the technological nuances in one or two evenings.

Working process


Work was carried out in fits and starts for almost a month and a half. From the very beginning I gave myself a half-joking vow to write 500 lines of code per day, and at first I even managed to observe this indicator. Of course, when it came to the readiness of the first conditionally functional version, the pace significantly decreased, because a significant part of the time began to be spent on fixing bugs and minor refactoring of already written code. Some decisions made in haste in the first week of work did not justify themselves - in particular, as a result, I had to write a mini-library for working with dialogs, windows, and other components of the GUI, although at first it seemed that you could do very little blood in this regard .

Special attention deserves the work on the logic of conservation in the game. Here, I succumbed to one more of my weaknesses - love of data compression algorithms, so saves are packed using the built-in compression algorithm (dictionary + LZW with dynamic bit alignment). Having resorted to retrospective rationalization, I will justify this with the desire to save space on mobile devices (the unpacked save still draws more than a hundred kilobytes), as well as the desire to at least slightly diversify the life of cheaters.

I already got graphics from the original game in the late 90s when I wrote a version of KB in C that included only fights (with an extended set of magic and other entertainments). True, the old code died with the dead screw back in 1999, but I approximately remembered what and where to get it. Add-ons were refined using Pixlr and found on the network of images taken as a basis. My bride helped off one of the pictures, so strictly speaking, not only I worked on the game.

Music - a selection of suitable free classics from the net, sound effects - recordings from the original DOSBox -> Audacity game, or slightly processed free samples from http://freesound.org .

From half to 3/4 of the time it took coding - in the received project a little less than 12,000 lines (not counting jQuery) (380 kilobytes of script). The rest is the writing of game texts (they, unlike the original game, are noticeably larger, in addition, the game is bilingual), as well as testing.

Result


The mechanics of the game in basic terms repeats the mechanics of the original game - attack formulas, magic, etc. fully consistent with the original. Also taken from the original game are graphics (supplemented by a small number of new objects) and a map of the first mainland (with minimal changes). The plot is significantly expanded, the continents are not 4, but 5, while the second card has a larger size than in the original game. Added all sorts of jokes, secrets, new plot twists. We tested the entire economy on Chrome, FF, Edge, IE, the mobile version of IE.

I would be grateful for finding bugs, advice on the development of the project, and generally any feedback.

The address of the page with the game: http://genes1s.net/kb/game.html .