📜 ⬆️ ⬇️

King's Bounty III: Advanced remake of the original game under DOS in Javascript / HTML5

Background and philosophical reflections


Like many of my colleagues in the programmer's workshop, especially those who began to try their hand at computer technologies early on, I have somewhere in the back of my mind a set of the warmest and most romantic memories of the first experiments. Once, back in 1987, my father first took me on a day off to his job, where he solemnly sat me on a chair in front of the humming Iskra-1030-11. About that time I firmly understood what I want to do in my future life.

image

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

About 10 years ago I got into the hands of the emulator BK-0010-01 - my first home computer. Then it was worth the hard work not to start programming for it. However, this time, another wave of nostalgia still led me to a very meaningless step, which can only be justified by the feeling of emotional uplift that I experienced completing my insane enterprise - making a remake / sequel to King's Bounty - the ancient progenitor of all Heroes games of Might & Magic.
')
In general, it is an open secret that the time of single programmers has passed. Single characters remained in the 90s, when, in the absence of the Internet and a large amount of specialized literature, as well as in an atmosphere of lack of computing resources, the next left-handed person cleverly found 7 caps from an undead bear in a short time. Today, the work of programmers in most cases is collective, and the success of a developer depends to a great extent not on algorithmic knowledge and technological skills, but on the ability to quickly find the necessary information and communication skills (including the ability to write readable code that meets the specified requirements).

In general, the situation when one person today writes a game from beginning to end (including plot development, game interaction logic, graphics creation, music selection, writing game dialogues, direct coding) is completely abnormal for the modern industry. The shoemaker should tackle the boots, and the oven pie - the pastry cook; 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 offset the costs that arise. The development of mobile platforms and the Web has made possible a kind of flashback - in exact accordance with the law of denial of negation - many modern successful game startups are created either by singles or by microinstructions that demonstrate amazing success thanks to unallocated 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 project OpenKB (http://sourceforge.net/projects/openkb/), which is currently abandoned, helped a great deal by reconstructing the original game logic and analyzing the data formats of the original game. The manuals written by the author of this project, as well as several other amateur manuals found on the network, have allowed us to seriously save power.

Technology


From the very beginning, a bet was made on cross-platform, and since with respect to Javascript and HTML5, such a titanic effort of developers has now been more or less achieved, in general, there was no particular alternative when choosing a development language.

Of course, there are a number of languages ​​broadcast in JS and with some advantages, but the desire to create an extra layer in a small project did not arise. In addition, due to the prevalence of JS, you can always count on the fact that any task that needs to be solved in the course of working on a project has already been decided before you by generously submitting code snippets for public viewing.

Due to the comparative simplicity of the game interface of the original game, it was decided to abandon the use of any heavyweight gaming frameworks. Of the libraries, only jQuery was used (in principle, it would have been possible to do without it - in fact only $ .inArray, $ .trim and working with browser trigger events were needed; to be honest, possible cross-browser problems were scary for events, so jQuery was still left in the project).

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

Working process


The work was conducted in fragments for almost one and a half months. From the very beginning, I gave myself a half-joking pledge to write 500 lines of code a day, and at first this figure was even able to be observed. Of course, when it came to the availability of the first conditionally-functional version, the pace slowed down significantly, because a significant part of the time began to go into the correction of errors and small refactoring of already written code. Some decisions made in haste in the first week of work did not justify themselves - in particular, I had to write a mini-library to work with dialogues, windows and other GUI components, although at first it seemed that it was possible to get by with very little blood .

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

I had already extracted the graphics from the original game once in the late 90s, when I wrote a KB version on C, including only battles (with an expanded set of magic and other entertainment). True, the old code died along with the dead screw back in 1999, but I remembered roughly what and where to get it. Add-ons were rendered with the help of Pixlr and images found on the network, taken as a basis. One of the pictures helped to strip my bride, so strictly speaking, not only I worked on the game.

Music is a selection of free-of-charge classics that fit within the network, sound effects are recordings from the original DOSBox -> Audacity game, or slightly processed free samples from http://freesound.org .

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

Result


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

I will be grateful for finding bugs, tips on the development of the project and any feedback in general.

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

Source: https://habr.com/ru/post/266805/


All Articles