use wad files instead of json data
[mmd.git] / mminer.d
blob14f4a3f0179875c20585af6a178ce07dff9105c6
1 module mminer is aliced;
3 import arsd.simpledisplay;
5 import iv.vfs.arcs.wad;
6 import iv.vfs.io;
8 import engine;
9 import x11gfx;
12 // ////////////////////////////////////////////////////////////////////////// //
13 void main (string[] args) {
14 vfsAddPak("data/mminer.wad");
16 for (int idx = 1; idx < args.length; ++idx) {
17 if (args[idx] == "-file") {
18 if (args.length-idx < 2) assert(0, "arg?!");
19 vfsAddPak(args[idx+1]);
20 ++idx;
21 } else {
22 assert(0, "invalid arg");
26 loadGameData();
28 Room curRoom;
30 void loadRoom (int idx) {
31 curRoom = gameRooms[idx];
32 curRoom.initRoom();
33 blitType = BlitType.Green;
34 curRoom.willyDead = true;
36 loadRoom(0);
39 initVBuf();
40 auto sdwin = new SimpleWindow(vbufW*(blit2x ? 2 : 1), vbufH*(blit2x ? 2 : 1), "Manic Miner", OpenGlOptions.no, Resizablity.fixedSize);
42 bool doQuit;
43 Image vbimg = new Image(vbufW*(blit2x ? 2 : 1), vbufH*(blit2x ? 2 : 1));
45 X11Image roomImg;
47 sdwin.eventLoop(1000/20,
48 // timer
49 delegate () {
50 if (sdwin.closed) return;
52 if (!curRoom.willyDead && !singleStepWait) {
53 curRoom.stepGame();
54 if (curRoom.willyDead) {
55 blitType = BlitType.BlackWhite;
56 } else {
57 if (curRoom.checkExit()) {
58 if (gameRooms.length-curRoom.roomIdx > 1) {
59 loadRoom(curRoom.roomIdx+1);
60 curRoom.willyDead = true;
62 blitType = BlitType.Green;
65 singleStepWait = singleStep;
67 //clear(rgbcol(255, 127, 0));
68 clear(0);
70 roomImg = curRoom.draw(roomImg);
71 //roomImg.blit2xTV(0, 0);
72 roomImg.blitFast(0, 0);
74 //map.drawMap();
75 drawStr(10, vbufH-10, curRoom.title, rgbcol(255, 255, 0));
77 realizeVBuf(vbimg);
79 auto painter = sdwin.draw();
80 painter.drawImage(Point(0, 0), vbimg);
81 //map.drawMap(painter, player);
84 // keyboard
85 delegate (KeyEvent evt) {
86 switch (evt.key) {
87 case Key.Left: curRoom.keyLeft = evt.pressed; break;
88 case Key.Right: curRoom.keyRight = evt.pressed; break;
89 case Key.Up: curRoom.keyUp = evt.pressed; break;
90 case Key.Down: curRoom.keyDown = evt.pressed; break;
91 case Key.Ctrl: curRoom.keyJump = evt.pressed; break;
92 case Key.N1: debugColdet = !debugColdet; break;
93 case Key.N0:
94 if (!evt.pressed) break;
95 curRoom.cheatRemoveKeys();
96 break;
97 case Key.D:
98 if (!evt.pressed) break;
99 debugColdet = !debugColdet;
100 break;
101 case Key.S:
102 if (!evt.pressed) break;
103 singleStep = !singleStep;
104 singleStepWait = singleStep;
105 break;
106 case Key.Enter:
107 if (!evt.pressed) break;
108 singleStepWait = false;
109 break;
110 case Key.R:
111 if (!evt.pressed) break;
112 blitType = BlitType.Normal;
113 if (curRoom.willyDead) {
114 auto kst = curRoom.saveKeyState();
115 loadRoom(curRoom.roomIdx);
116 blitType = BlitType.Normal;
117 curRoom.willyDead = false;
118 curRoom.restoreKeyState(kst);
120 break;
121 case Key.Q: case Key.Escape: doQuit = true; break;
122 case Key.Minus:
123 if (!evt.pressed) break;
124 if (curRoom.roomIdx > 0) {
125 loadRoom(curRoom.roomIdx-1);
127 break;
128 case Key.Plus:
129 if (!evt.pressed) break;
130 if (gameRooms.length-curRoom.roomIdx > 1) {
131 loadRoom(curRoom.roomIdx+1);
133 break;
134 default: break;
136 if (doQuit) { sdwin.close(); return; }
138 // mouse
139 delegate (MouseEvent evt) {
141 // char
142 delegate (dchar ch) {
145 flushGui();
146 delete vbimg;
147 flushGui();