got rid of iv.vfs
[mmd.git] / mminer.d
blob0bb8a822e103a3c49cdd64b0d451261154f16470
1 module mminer is aliced;
3 import arsd.simpledisplay;
5 import engine;
6 import x11gfx;
7 import wadarc;
10 // ////////////////////////////////////////////////////////////////////////// //
11 void main (string[] args) {
12 //vfsAddPak("data/mminer.wad");
13 registerWad("data/mminer.wad");
15 for (int idx = 1; idx < args.length; ++idx) {
16 if (args[idx] == "-file") {
17 if (args.length-idx < 2) assert(0, "arg?!");
18 registerWad(args[idx+1]);
19 ++idx;
20 } else {
21 assert(0, "invalid arg");
25 loadGameData();
27 Room curRoom;
29 void loadRoom (int idx) {
30 curRoom = gameRooms[idx];
31 curRoom.initRoom();
32 blitType = BlitType.Green;
33 curRoom.willyDead = true;
35 loadRoom(0);
38 auto sdwin = x11gfxInit("Manic Miner");
39 bool doQuit;
40 X11Image roomImg;
42 sdwin.eventLoop(1000/20,
43 // timer
44 delegate () {
45 if (sdwin.closed) return;
47 if (!curRoom.willyDead && !singleStepWait) {
48 curRoom.stepGame();
49 if (curRoom.willyDead) {
50 blitType = BlitType.BlackWhite;
51 } else {
52 if (curRoom.checkExit()) {
53 if (gameRooms.length-curRoom.roomIdx > 1) {
54 loadRoom(curRoom.roomIdx+1);
55 curRoom.willyDead = true;
57 blitType = BlitType.Green;
60 singleStepWait = singleStep;
62 //clear(rgbcol(255, 127, 0));
63 clear(0);
65 roomImg = curRoom.draw(roomImg);
66 //roomImg.blit2xTV(0, 0);
67 roomImg.blitFast(0, 0);
69 //map.drawMap();
70 drawStr(10, vbufH-10, curRoom.title, rgbcol(255, 255, 0));
72 realizeVBuf();
73 x11gfxBlit();
75 // keyboard
76 delegate (KeyEvent evt) {
77 if (sdwin.closed) return;
78 switch (evt.key) {
79 case Key.Left: curRoom.keyLeft = evt.pressed; break;
80 case Key.Right: curRoom.keyRight = evt.pressed; break;
81 case Key.Up: curRoom.keyUp = evt.pressed; break;
82 case Key.Down: curRoom.keyDown = evt.pressed; break;
83 case Key.Ctrl: curRoom.keyJump = evt.pressed; break;
84 case Key.N1: debugColdet = !debugColdet; break;
85 case Key.N0:
86 if (!evt.pressed) break;
87 curRoom.cheatRemoveKeys();
88 break;
89 case Key.D:
90 if (!evt.pressed) break;
91 debugColdet = !debugColdet;
92 break;
93 case Key.S:
94 if (!evt.pressed) break;
95 singleStep = !singleStep;
96 singleStepWait = singleStep;
97 break;
98 case Key.Enter:
99 if (!evt.pressed) break;
100 singleStepWait = false;
101 break;
102 case Key.R:
103 if (!evt.pressed) break;
104 blitType = BlitType.Normal;
105 if (curRoom.willyDead) {
106 auto kst = curRoom.saveKeyState();
107 loadRoom(curRoom.roomIdx);
108 blitType = BlitType.Normal;
109 curRoom.willyDead = false;
110 curRoom.restoreKeyState(kst);
112 break;
113 case Key.Q: case Key.Escape: doQuit = true; break;
114 case Key.Minus:
115 if (!evt.pressed) break;
116 if (curRoom.roomIdx > 0) {
117 loadRoom(curRoom.roomIdx-1);
119 break;
120 case Key.Plus:
121 if (!evt.pressed) break;
122 if (gameRooms.length-curRoom.roomIdx > 1) {
123 loadRoom(curRoom.roomIdx+1);
125 break;
126 default: break;
128 if (doQuit) { sdwin.close(); return; }
130 // mouse
131 delegate (MouseEvent evt) {
132 if (sdwin.closed) return;
134 // char
135 delegate (dchar ch) {
136 if (sdwin.closed) return;
139 x11gfxDeinit();