cosmetix
[xreader.git] / xreaderifs.d
blob4b28ba5c83b532b2ae3df4cdda24d1ad43978b52
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.color;
21 import arsd.png;
22 import arsd.jpeg;
24 import iv.nanovg;
26 import xreadercfg;
29 // ////////////////////////////////////////////////////////////////////////// //
30 struct Interference {
31 int y, ey, speed;
34 __gshared Interference[] ifs;
37 // ////////////////////////////////////////////////////////////////////////// //
38 bool processIfs () {
39 bool res = false;
40 foreach (ref l; ifs) {
41 if (l.speed == 0) continue;
42 res = true;
43 l.y += l.speed;
44 if (l.speed < 0) {
45 if (l.y < l.ey) l.speed = 0;
46 } else {
47 if (l.y > l.ey) l.speed = 0;
50 return res;
54 void drawIfs (NVGContext vg) {
55 if (vg is null) return;
56 foreach (ref l; ifs) {
57 if (l.speed == 0) continue;
58 vg.beginPath();
59 vg.fillColor(nvgRGB(0, 40, 0));
60 vg.rect(0, l.y-1, GWidth, 3);
61 vg.fill();
66 bool addIf () {
67 import std.random : uniform;
68 if (interAllowed) {
69 int idx = 0;
70 while (idx < ifs.length && ifs[idx].speed != 0) ++idx;
71 if (idx >= ifs.length) {
72 if (ifs.length > 10) return false;
73 ifs ~= Interference();
75 if (uniform!"[]"(0, 1) == 0) {
76 // up
77 ifs[idx].y = GHeight/2+uniform!"[]"(50, GHeight/2-100);
78 int ty = ifs[idx].y-40;
79 if (ty < 0) return false;
80 ifs[idx].ey = uniform!"[]"(0, ty);
81 ifs[idx].speed = -uniform!"[]"(1, 25);
82 } else {
83 // down
84 ifs[idx].y = GHeight/2-uniform!"[]"(50, GHeight/2-100);
85 int ty = ifs[idx].y+40;
86 if (ty >= GHeight) return false;
87 ifs[idx].ey = uniform!"[]"(ty, GHeight);
88 ifs[idx].speed = uniform!"[]"(1, 25);
90 return true;
92 return false;