📜 ⬆️ ⬇️

Perhaps the first game on Dart + Box2D

On Habré there are not too many articles devoted to the Dart programming language, but there are a lot of articles about unfinished or hard-to-do games, as well as how to make the second ones first. This article will be a mixture of these two topics.

This was the case: my old friend and I have been developing for several years now. The game, which will be discussed in the article, is far from the first that we tried to do, but the first with which it was possible. After almost a dozen failed attempts to make the game, we were finally able to objectively evaluate our strength and decided to make a puzzle. The game genre is simple in itself, but what we conceived was much more complicated and unlike any of the games presented in the VK and FB catalogs in this genre. In order to completely no chance to finish the game, we decided to use those technologies that had never seen before - Dart + Box2d.

Now about the impressions of the development on the darte. This is very different from developing in java / c # / php at least in that you cannot google the answer to a slightly complicated question, which at the same time makes you angry and gives you the feeling of a pioneer. Another significant difference in dampness technology in general, and tools in particular.

Dart language


At once I will say that the language was chosen because of the strict typification and the classical approach to the PLO. Probably, the language is most similar to Java, in general, the code of many methods can be simply inserted into java and they will work without problems, sometimes this trick can pass even with a whole class. Of the differences, the key, in my opinion, is the support of the procedural paradigm, which somewhat corrupts the code, sometimes allows to simplify the code for solving the problem. The next blow to security was the lack of access modifiers for classes, methods, and fields. At first, I resisted the temptation, but then such opportunities took their toll and as a result I received a very strongly connected code, which hardly anyone in this world recognizes as good, but this is hardly a language problem, but rather a lack of experience in general and its complete absence with respect to darth, especially at the very beginning of the journey.
')

Dart Editor (DE)


DE was made on the basis of Eclipse, which in itself does not make it bad, but makes it wary. After using DE, it starts to seem like a good corporation has cut out all the nice features of Eclipse at the last moment. Fortunately, there was a plugin for your beloved PhpStorm, which is also damp, but here at least in the IDE you feel in your native land.

Dart pub


It should be said that in terms of packages Google tried very hard. There is a general catalog of packages, in one click you can get the desired library.

The Dartium binary expires after 12 weeks


An absolutely incredible feature of development in this wonderful language was that Dartium (Chromium with a virtual machine for Darth) needs to be downloaded and installed again every 12 weeks, and if this is not done, then DartVM seemed to disappear, and what worked yesterday, at the moment stopped working altogether.

Box2d


Box2d for Dart - I want to say right away that I was working with this library for the first time and in the process of studying it there were a few things that surprised me a lot, but over time everything settled in my head, and it became clear that Box as a whole is just what you need and the port is surprisingly good.

Dart2JS


Dart2JS is a utility that comes with a development package on a dart, for building a dart code that only a tiny handful of people in the universe can understand, in js, which, as it turns out, is not understood by anyone except the browser. Although, in fact, this is one of the pleasant moments of development, although that would bring down the project, the first time I had to kill a decent amount of time. It should be noted that so far have not met a single bug associated with the incorrect construction of JS. code. It, by the way, turns out, as one would expect, absolutely unreadable.

Dart & JS


Of course, using dart, sometimes there is a desire or / and the need to use JS code, there is generally good tools for this, but it is impossible to use them. Now I will try to explain. This is the best library that could be used to work with JS, but for a language so closely related to JS, I think this support should have been transferred to the language level, the syntax might be somewhat similar to using asm from C

Now it looks at best something like this:

static void getUser(Function callback) { (context['Features'] as JsObject).callMethod('getUser', [new JsFunction.withThis((JsObject obj) { callback(); })]); } 


Dart & External Api


I have always been in love with the VK API, it seemed to me and still seems to be an example of a correctly implemented web service API. Among other things, VK delivers js-library for convenient access to its API. While developing other applications for social networks, I always liked to use this library, but when I had to turn to it from Dart, it turned the tale into a nightmare, so I tried to hide it in the farthest class of my project and open it less often. The thing is that, as I said, working with JS in Darth is implemented as a library and requires constant manipulation of objects so. the lion's share of the time for wrapping Dart objects in a JsObject and extracting from the other JsObject those few data I need, for which this is all started. But after much suffering, I was able to reduce the points of contact of languages ​​to a minimum, taking all the interactions with VkApi into a separate JS file, which processed them and gave them to a specially trained Darth class.

Two cubes


The development of the game took much longer than we would like, as is often the case. In any case, this is the first game that finally managed to finish. The main problem of its delivery to the masses is likely to be that it turned out to be quite complicated, not even in terms of control, but as a puzzle. For example, out of 2,000 people who now play it, having spent almost 15,000 attempts, just a dozen people have passed both chapters, although maybe this is the right percentage?

image

UPD: Link for those who want to see what happened in the end: vk.com/twocubes

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


All Articles