shitty title
[mmd.git] / mminer.d
blob3aa7e8b3054b0b489aaef460d082219faba1e3c3
1 /* coded 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 mminer;
19 import arsd.simpledisplay;
21 import engine;
22 import x11gfx;
23 import wadarc;
26 // ////////////////////////////////////////////////////////////////////////// //
27 void main (string[] args) {
28 //vfsAddPak("data/mminer.wad");
29 registerWad("data/mminer.wad");
31 for (int idx = 1; idx < args.length; ++idx) {
32 if (args[idx] == "-file") {
33 if (args.length-idx < 2) assert(0, "arg?!");
34 registerWad(args[idx+1]);
35 ++idx;
36 } else {
37 assert(0, "invalid arg");
41 loadGameData();
43 Room curRoom;
45 void loadRoom (int idx) {
46 curRoom = gameRooms[idx];
47 curRoom.initRoom();
48 blitType = BlitType.Green;
49 curRoom.willyDead = true;
52 void restartRoom () {
53 auto kst = curRoom.saveKeyState();
54 loadRoom(curRoom.roomIdx);
55 blitType = BlitType.Normal;
56 curRoom.willyDead = false;
57 curRoom.restoreKeyState(kst);
59 //loadRoom(0);
61 auto gfxFill0 = buildImageMasked(gameData["fill"][], 16, 24);
62 auto gfxFill1 = buildImageMasked(gameData["fill"][384..$], 72, 24);
63 auto gfxAir = buildImageMasked(gameData["air"], 256, 8);
64 auto gfxSun = buildImageMasked(gameData["sun"], 24, 16);
65 auto gfxFinal = buildImageMasked(gameData["final"], 256, 64);
67 auto sdwin = x11gfxInit("Manic Miner");
68 bool doQuit;
69 X11Image roomImg;
70 bool inTitle = true;
72 sdwin.eventLoop(1000/20,
73 // timer
74 delegate () {
75 if (sdwin.closed) return;
77 if (!inTitle) {
78 if (!curRoom.willyDead && !singleStepWait) {
79 curRoom.stepGame();
80 if (curRoom.willyDead) {
81 blitType = BlitType.BlackWhite;
82 } else {
83 if (curRoom.checkExit()) {
84 if (gameRooms.length-curRoom.roomIdx > 1) {
85 loadRoom(curRoom.roomIdx+1);
86 curRoom.willyDead = true;
88 blitType = BlitType.Green;
91 singleStepWait = singleStep;
95 if (!inTitle) {
96 clear(0);
97 roomImg = curRoom.draw(roomImg);
98 roomImg.blitFast(0, 0);
99 } else {
100 clear(palcol(240));
102 static struct Sun {
103 int y;
104 ubyte m, h;
106 static Sun sun;
107 sun.m = 1;
108 sun.y = 32;
109 sun.h = 16;
111 void drawSun () {
112 for (int y = sun.h-1; y >= 0; --y) {
113 for (int x = 23; x >= 0; --x) {
114 ubyte data = gameData["sun"][(y*24)+x];
115 if (data) setPixel8(60+x, sun.y+y, data);
119 gfxFinal.blitFast(0, 0);
120 //sunSpr.blitTo(img, 60, 32);
121 drawSun();
122 gfxFill0.blitFast(152, 40);
123 gfxFill1.blitFast(176, 40);
124 //printAt(154, 42, "Hello!", 13);
126 static int TITLEwf = 2;
127 static int TITLEwp = 0;
129 if (++TITLEwp == 16) {
130 TITLEwp = 0;
131 TITLEwf = (TITLEwf+2)&7;
133 drawWilly4(TITLEwf+4);
134 // levelset: 122
137 realizeVBuf();
138 x11gfxBlit();
140 // keyboard
141 delegate (KeyEvent evt) {
142 if (sdwin.closed) return;
143 switch (evt.key) {
144 case Key.Left: curRoom.keyLeft = evt.pressed; break;
145 case Key.Right: curRoom.keyRight = evt.pressed; break;
146 case Key.Up: curRoom.keyUp = evt.pressed; break;
147 case Key.Down: curRoom.keyDown = evt.pressed; break;
148 case Key.Ctrl: curRoom.keyJump = evt.pressed; break;
149 case Key.N1: debugColdet = !debugColdet; break;
150 case Key.N0:
151 if (!evt.pressed) break;
152 curRoom.cheatRemoveKeys();
153 break;
154 case Key.D:
155 if (!evt.pressed) break;
156 debugColdet = !debugColdet;
157 break;
158 case Key.S:
159 if (!evt.pressed) break;
160 singleStep = !singleStep;
161 singleStepWait = singleStep;
162 break;
163 case Key.Space:
164 if (!evt.pressed) break;
165 if (inTitle) {
166 inTitle = false;
167 loadRoom(0);
169 break;
170 case Key.Enter:
171 if (!evt.pressed) break;
172 if (inTitle) goto case Key.Space;
173 if (curRoom.willyDead) { restartRoom(); break; }
174 if (singleStep) { singleStepWait = false; break; }
175 break;
176 case Key.R:
177 if (!evt.pressed) break;
178 blitType = BlitType.Normal;
179 if (curRoom.willyDead) { restartRoom(); break; }
180 break;
181 case Key.Q: case Key.Escape: doQuit = true; break;
182 case Key.Minus:
183 if (!evt.pressed) break;
184 if (curRoom.roomIdx > 0) {
185 loadRoom(curRoom.roomIdx-1);
187 break;
188 case Key.Plus:
189 if (!evt.pressed) break;
190 if (gameRooms.length-curRoom.roomIdx > 1) {
191 loadRoom(curRoom.roomIdx+1);
193 break;
194 default: break;
196 if (doQuit) { sdwin.close(); return; }
198 // mouse
199 delegate (MouseEvent evt) {
200 if (sdwin.closed) return;
202 // char
203 delegate (dchar ch) {
204 if (sdwin.closed) return;
207 x11gfxDeinit();