engine moved to separate module
[mmd.git] / mminer.d
blobf7f2d08b037bfbdef0de3cf8d619077ca1cc8196
1 module mminer is aliced;
3 import arsd.simpledisplay;
5 import iv.vfs.io;
7 import engine;
8 import x11gfx;
11 // ////////////////////////////////////////////////////////////////////////// //
12 void main (string[] args) {
13 loadGameData();
15 Room curRoom;
17 void loadRoom (int idx) {
18 curRoom = gameRooms[idx];
19 curRoom.initRoom();
21 loadRoom(0);
24 initVBuf();
25 auto sdwin = new SimpleWindow(vbufW*(blit2x ? 2 : 1), vbufH*(blit2x ? 2 : 1), "Manic Miner", OpenGlOptions.no, Resizablity.fixedSize);
27 bool doQuit;
28 Image vbimg = new Image(vbufW*(blit2x ? 2 : 1), vbufH*(blit2x ? 2 : 1));
30 X11Image roomImg;
32 sdwin.eventLoop(1000/20,
33 // timer
34 delegate () {
35 if (sdwin.closed) return;
37 if (!curRoom.willyDead && !singleStepWait) {
38 curRoom.stepGame();
39 if (curRoom.willyDead) {
40 blitType = BlitType.BlackWhite;
41 } else {
42 if (curRoom.checkExit()) {
43 if (gameRooms.length-curRoom.roomIdx > 1) {
44 loadRoom(curRoom.roomIdx+1);
45 curRoom.willyDead = true;
47 blitType = BlitType.Green;
50 singleStepWait = singleStep;
52 //clear(rgbcol(255, 127, 0));
53 clear(0);
55 roomImg = curRoom.draw(roomImg);
56 //roomImg.blit2xTV(0, 0);
57 roomImg.blitFast(0, 0);
59 //map.drawMap();
60 drawStr(10, vbufH-10, curRoom.title, rgbcol(255, 255, 0));
62 realizeVBuf(vbimg);
64 auto painter = sdwin.draw();
65 painter.drawImage(Point(0, 0), vbimg);
66 //map.drawMap(painter, player);
69 // keyboard
70 delegate (KeyEvent evt) {
71 switch (evt.key) {
72 case Key.Left: curRoom.keyLeft = evt.pressed; break;
73 case Key.Right: curRoom.keyRight = evt.pressed; break;
74 case Key.Up: curRoom.keyUp = evt.pressed; break;
75 case Key.Down: curRoom.keyDown = evt.pressed; break;
76 case Key.Ctrl: curRoom.keyJump = evt.pressed; break;
77 case Key.N1: debugColdet = !debugColdet; break;
78 case Key.N0:
79 if (!evt.pressed) break;
80 curRoom.cheatRemoveKeys();
81 break;
82 case Key.D:
83 if (!evt.pressed) break;
84 debugColdet = !debugColdet;
85 break;
86 case Key.S:
87 if (!evt.pressed) break;
88 singleStep = !singleStep;
89 singleStepWait = singleStep;
90 break;
91 case Key.Enter:
92 if (!evt.pressed) break;
93 singleStepWait = false;
94 break;
95 case Key.R:
96 if (!evt.pressed) break;
97 blitType = BlitType.Normal;
98 if (curRoom.willyDead) {
99 loadRoom(curRoom.roomIdx);
101 break;
102 case Key.Q: case Key.Escape: doQuit = true; break;
103 case Key.Minus:
104 if (!evt.pressed) break;
105 if (curRoom.roomIdx > 0) {
106 loadRoom(curRoom.roomIdx-1);
108 break;
109 case Key.Plus:
110 if (!evt.pressed) break;
111 if (gameRooms.length-curRoom.roomIdx > 1) {
112 loadRoom(curRoom.roomIdx+1);
114 break;
115 default: break;
117 if (doQuit) { sdwin.close(); return; }
119 // mouse
120 delegate (MouseEvent evt) {
122 // char
123 delegate (dchar ch) {
126 flushGui();
127 delete vbimg;
128 flushGui();