Ground in the porthole is visible or where there is a storm, there are new objects

Apr 03, 2018 16:11


Версия на русском языке

In this post, I'll write about one of the first projects, the Pixel Walker engine and one of the objects for it. This project was named "Where The Storm". This is a game in which the player has to control the bird and disassemble the obstacles before the character going to the storm.

At that time, in order to realize this idea, it was necessary to add at least 4 new objects. This is the "bird", "character", "obstacle" and the lower boundary of the earth, along which the character "ground" will character move on.

First of all, I took up the "ground", and then raised it over my head, and I stand, waiting, on a turtle with to three elephants! And so it could be and was, if I in my post " Heaven and earth of pixel walker" would not prove that the earth is round. =)

According to the idea, the "ground" had to be a certain contour, accidentally changing its height. But in the process of implementation some pitfalls have surfaced:



The first version of the relief of "ground"



Even if we omit the fact that the relief turned out to be not even, more like the teeth of a predatory animal, it's not difficult to notice that the relief is periodically repeated:



Cyclicity of the relief

The matter is that for each object the mechanism of repetition of a sequence of random numbers was realized, it was necessary for serialization and deserialization of objects. Pre-generated N values ​​that were repeated when N calls random numbers.

To solve the problem, I decided to increase the number of random values, and specifically for the "ground" to reduce the parity of calls:

random( random( random( H ) ) )

where random  is a function that returns a value from 0 to a specified parameter.

It was also taken into account that as a result of such manipulations the average value was less than 4 times.

After some attempts:



Unsuccessful attempts to generate a relief

The result is the following picture:



Relief

The relief turned out to be quite smooth, not cyclic, and at the same time nonlinear and fairly randomized.

Later, the current mechanism was also redone. Even when the task of object serialization arose, the number of stored random values ​​for each object was reduced from about 100 to only 9! At the same time, the quality of generation in this case was not affected, and in some cases gave even more optimistic results!

To reduce the number of stored random values, as a result of long calculations, the following formula was derived:

Res = ( (Pos -RV) * (Pos -RV ) XOR ( Pos - RV) XOR 1 ) MOD Max

Where

· Res - random number

· Pos - call counter

· RV - recorded random value, in order

· Max - maximum value of a random value

From that moment to the present day, the "ground" was also partially improved, instead of a simple black color, it received an impromptu texture, in the form of strokes (in the lower part it is highlighted in green for clarity):



the texture of the "ground"

For the dessert video, which shows the latest compilation of the project, with two new objects "bird" and "character", which will be discussed in the next post:

image Click to view



If you want to support my project, you can do it by link or by adding one of the WebMoney:

R163522901261

Z180352303030

X054099745452

I thank everyone, readers and those who leave their feedback!

Previous post Next post
Up