added air indicator
[mmd.git] / mminer.d
blobedfb47127cc3ce4801e09113ed95ee94509307eb
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);
65 auto sdwin = x11gfxInit("Manic Miner");
66 bool doQuit;
67 X11Image roomImg;
68 bool inTitle = true;
70 sdwin.eventLoop(1000/20,
71 // timer
72 delegate () {
73 if (sdwin.closed) return;
75 if (!inTitle) {
76 if (!curRoom.willyDead && !singleStepWait) {
77 curRoom.stepGame();
78 if (curRoom.willyDead) {
79 blitType = BlitType.BlackWhite;
80 } else {
81 if (curRoom.checkExit()) {
82 if (gameRooms.length-curRoom.roomIdx > 1) {
83 loadRoom(curRoom.roomIdx+1);
84 curRoom.willyDead = true;
86 blitType = BlitType.Green;
89 singleStepWait = singleStep;
93 clear(0);
95 if (!inTitle) {
96 roomImg = curRoom.draw(roomImg);
97 roomImg.blitFast(0, 0);
98 } else {
99 gfxFill0.blitFast(152, 40);
100 gfxFill1.blitFast(176, 40);
101 printAt(154, 42, "Hello!", 13);
104 realizeVBuf();
105 x11gfxBlit();
107 // keyboard
108 delegate (KeyEvent evt) {
109 if (sdwin.closed) return;
110 switch (evt.key) {
111 case Key.Left: curRoom.keyLeft = evt.pressed; break;
112 case Key.Right: curRoom.keyRight = evt.pressed; break;
113 case Key.Up: curRoom.keyUp = evt.pressed; break;
114 case Key.Down: curRoom.keyDown = evt.pressed; break;
115 case Key.Ctrl: curRoom.keyJump = evt.pressed; break;
116 case Key.N1: debugColdet = !debugColdet; break;
117 case Key.N0:
118 if (!evt.pressed) break;
119 curRoom.cheatRemoveKeys();
120 break;
121 case Key.D:
122 if (!evt.pressed) break;
123 debugColdet = !debugColdet;
124 break;
125 case Key.S:
126 if (!evt.pressed) break;
127 singleStep = !singleStep;
128 singleStepWait = singleStep;
129 break;
130 case Key.Space:
131 if (!evt.pressed) break;
132 if (inTitle) {
133 inTitle = false;
134 loadRoom(0);
136 break;
137 case Key.Enter:
138 if (!evt.pressed) break;
139 if (inTitle) goto case Key.Space;
140 if (curRoom.willyDead) { restartRoom(); break; }
141 if (singleStep) { singleStepWait = false; break; }
142 break;
143 case Key.R:
144 if (!evt.pressed) break;
145 blitType = BlitType.Normal;
146 if (curRoom.willyDead) { restartRoom(); break; }
147 break;
148 case Key.Q: case Key.Escape: doQuit = true; break;
149 case Key.Minus:
150 if (!evt.pressed) break;
151 if (curRoom.roomIdx > 0) {
152 loadRoom(curRoom.roomIdx-1);
154 break;
155 case Key.Plus:
156 if (!evt.pressed) break;
157 if (gameRooms.length-curRoom.roomIdx > 1) {
158 loadRoom(curRoom.roomIdx+1);
160 break;
161 default: break;
163 if (doQuit) { sdwin.close(); return; }
165 // mouse
166 delegate (MouseEvent evt) {
167 if (sdwin.closed) return;
169 // char
170 delegate (dchar ch) {
171 if (sdwin.closed) return;
174 x11gfxDeinit();