fmt fixes
[xreader.git] / xreaderifs.d
blob6964c42a3c8927b6c45159ac454a42f5df4129dd
1 /* Written by Ketmar // Invisible Vector <ketmar@ketmar.no-ip.org>
2 * Understanding is not required. Only obedience.
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 module xreaderifs;
19 import arsd.simpledisplay;
20 import arsd.image;
22 import iv.nanovg;
24 import xreadercfg;
27 // ////////////////////////////////////////////////////////////////////////// //
28 struct Interference {
29 int y, ey, speed;
32 __gshared Interference[] ifs;
35 // ////////////////////////////////////////////////////////////////////////// //
36 bool processIfs () {
37 bool res = false;
38 foreach (ref l; ifs) {
39 if (l.speed == 0) continue;
40 res = true;
41 l.y += l.speed;
42 if (l.speed < 0) {
43 if (l.y < l.ey) l.speed = 0;
44 } else {
45 if (l.y > l.ey) l.speed = 0;
48 return res;
52 void drawIfs (NVGContext vg) {
53 if (vg is null) return;
54 foreach (ref l; ifs) {
55 if (l.speed == 0) continue;
56 vg.beginPath();
57 vg.fillColor(nvgRGB(0, 40, 0));
58 vg.rect(0, l.y-1, GWidth, 3);
59 vg.fill();
64 bool addIf () {
65 import std.random : uniform;
66 if (interAllowed) {
67 int idx = 0;
68 while (idx < ifs.length && ifs[idx].speed != 0) ++idx;
69 if (idx >= ifs.length) {
70 if (ifs.length > 10) return false;
71 ifs ~= Interference();
73 if (uniform!"[]"(0, 1) == 0) {
74 // up
75 ifs[idx].y = GHeight/2+uniform!"[]"(50, GHeight/2-100);
76 int ty = ifs[idx].y-40;
77 if (ty < 0) return false;
78 ifs[idx].ey = uniform!"[]"(0, ty);
79 ifs[idx].speed = -uniform!"[]"(1, 25);
80 } else {
81 // down
82 ifs[idx].y = GHeight/2-uniform!"[]"(50, GHeight/2-100);
83 int ty = ifs[idx].y+40;
84 if (ty >= GHeight) return false;
85 ifs[idx].ey = uniform!"[]"(ty, GHeight);
86 ifs[idx].speed = uniform!"[]"(1, 25);
88 return true;
90 return false;