And here is my first attempt to get out into the open spaces of Habrahabr.
Recently my game Evasion was released. Simple arcade game in which you need to dodge obstacles. The game itself is easy to develop, but each simplicity has its own pitfalls. I want to talk about a couple of them in this article.
The red ball moves to the point of contact of the finger.
')
Level editor
Levels in Evasion are represented as a matrix of sprites that fall at a certain speed. When the bottom row falls below the permissible coordinates, it moves to the very top. The result is a kind of conveyor belt. At the time of moving the obstacles change, respectively, and the image on the sprites. Each type of obstacle has its own id. The level information is stored in a two-dimensional array.
In this way, the obstacles change:
public static bool Next_M(int Series) // { if (Set < 0) Set = 0; if (Set < mLvl) // { // xR - for (int i = 0; i < xR; i++) { M_Load(Series, i, Level[i, Set]); // , Level } Set++; } else // { for (int i = 0; i < xR; i++) { M_Load(Series, i, 0); } if (Finish) { Finish = false; return true; } } return false; }
At first, in order to create levels, you had to enter a string expression and convert it into an integer value.
Base[0] = "040900080205080202000204050000001500060001001515141314140706000705110704040004020406";
But he quickly realized that things were not being done this way. The work process was slow, dreary, and error correction was punished by an in-depth search for a needle in a haystack. The result was the decision to create a quick and easy level editor.
The central tape is lowered by slides.
The editor has simplified the development several times. You can quickly build a level and test it there. And if in your game there is an opportunity to make life easier by creating a level editor, do not be lazy to spend your time on it, it's worth it. In addition, it can be presented as an additional option in the game (if your editor is convenient for ordinary mortals to use).
Although the editor in Evasion is present, it is only for reference. Although you can save levels, the ability to share with friends and so on. But that's another story ...
Endless mode
Not having a lot of knowledge in mathematics, random level generation has become an incomprehensible task for me. The only solution was to create small blocks with a length of 3 - 5 sprites and their repetition. Boring and tedious implementation, but there was no other choice. Until one day, while sitting in a BFU on a pair of mathematics, one single word did not occur to me: sets!
All obstacles can be divided into sets:
- All kinds of obstacles
- All obstacles from above (Subset of the first array)
- All obstacles below
- Left
- On right
Those species that have several obstacles fall into several arrays at once. Randomly find out where the entrance, where the output and the distance between them. Everything happens within a single row. Depending on the distance, we learn where and in what place to exclude the appearance of an impassable place.
public static void Next_M(int S) { int Di = Math.Abs(In - Ou); // if (Di == 0) // { List<int> Cut = Draw(0, 1); // 0 - , 1 - M_Load(S, In, Cut[StaticVolue.Rnd(0, Cut.Count)]); } else { List<int> Cut = new List<int>(); if (In > Ou) { Cut = Draw(0, 2); M_Load(S, In, Cut[StaticVolue.Rnd(0, Cut.Count)]); for (int C = In - 1; C >= Ou; C
static List<int> Draw(int A) { List<int> CellSet = new List<int>(); bool ice; for (int y = 0; y < AllCell.Length; y++) { ice = true; for (int i = 0; i < 9; i++) { if (AllCell[y] == EnterCell[A, i]) // , A { ice = false; } } if (ice) CellSet.Add(AllCell[y]); } return CellSet; }
This is the implementation of the random level. If you have ideas on how this could be done better, write in the comments.
Musical accompaniment
I wanted to say a few words about the music in the game.
What if you are a student and you don’t have enough money for good music, but you don’t like free options? There are two ways out: either to write yourself or have good friends, preferably with your group. It so happened that I do not know how to write music independently, but I was lucky with my friends.
The music for my game was kindly provided by our local Kaliningrad group “Houston, we've got problems!” For those who love post-rock, I recommend to get acquainted with their work.
That's all. Good luck to everyone in the projects.