cosmetix
[mmd.git] / mminer.d
blobfa3c4dbaed92644bc79326565b1f5ccf15a0063f
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;
51 loadRoom(0);
54 auto sdwin = x11gfxInit("Manic Miner");
55 bool doQuit;
56 X11Image roomImg;
58 sdwin.eventLoop(1000/20,
59 // timer
60 delegate () {
61 if (sdwin.closed) return;
63 if (!curRoom.willyDead && !singleStepWait) {
64 curRoom.stepGame();
65 if (curRoom.willyDead) {
66 blitType = BlitType.BlackWhite;
67 } else {
68 if (curRoom.checkExit()) {
69 if (gameRooms.length-curRoom.roomIdx > 1) {
70 loadRoom(curRoom.roomIdx+1);
71 curRoom.willyDead = true;
73 blitType = BlitType.Green;
76 singleStepWait = singleStep;
78 //clear(rgbcol(255, 127, 0));
79 clear(0);
81 roomImg = curRoom.draw(roomImg);
82 //roomImg.blit2xTV(0, 0);
83 roomImg.blitFast(0, 0);
85 //map.drawMap();
86 drawStr(10, vbufH-10, curRoom.title, rgbcol(255, 255, 0));
88 realizeVBuf();
89 x11gfxBlit();
91 // keyboard
92 delegate (KeyEvent evt) {
93 if (sdwin.closed) return;
94 switch (evt.key) {
95 case Key.Left: curRoom.keyLeft = evt.pressed; break;
96 case Key.Right: curRoom.keyRight = evt.pressed; break;
97 case Key.Up: curRoom.keyUp = evt.pressed; break;
98 case Key.Down: curRoom.keyDown = evt.pressed; break;
99 case Key.Ctrl: curRoom.keyJump = evt.pressed; break;
100 case Key.N1: debugColdet = !debugColdet; break;
101 case Key.N0:
102 if (!evt.pressed) break;
103 curRoom.cheatRemoveKeys();
104 break;
105 case Key.D:
106 if (!evt.pressed) break;
107 debugColdet = !debugColdet;
108 break;
109 case Key.S:
110 if (!evt.pressed) break;
111 singleStep = !singleStep;
112 singleStepWait = singleStep;
113 break;
114 case Key.Enter:
115 if (!evt.pressed) break;
116 singleStepWait = false;
117 break;
118 case Key.R:
119 if (!evt.pressed) break;
120 blitType = BlitType.Normal;
121 if (curRoom.willyDead) {
122 auto kst = curRoom.saveKeyState();
123 loadRoom(curRoom.roomIdx);
124 blitType = BlitType.Normal;
125 curRoom.willyDead = false;
126 curRoom.restoreKeyState(kst);
128 break;
129 case Key.Q: case Key.Escape: doQuit = true; break;
130 case Key.Minus:
131 if (!evt.pressed) break;
132 if (curRoom.roomIdx > 0) {
133 loadRoom(curRoom.roomIdx-1);
135 break;
136 case Key.Plus:
137 if (!evt.pressed) break;
138 if (gameRooms.length-curRoom.roomIdx > 1) {
139 loadRoom(curRoom.roomIdx+1);
141 break;
142 default: break;
144 if (doQuit) { sdwin.close(); return; }
146 // mouse
147 delegate (MouseEvent evt) {
148 if (sdwin.closed) return;
150 // char
151 delegate (dchar ch) {
152 if (sdwin.closed) return;
155 x11gfxDeinit();