From 1a8d704429fef5418e3f1edbaf9618475291c593 Mon Sep 17 00:00:00 2001 From: Ketmar Dark Date: Mon, 17 Oct 2016 18:50:08 +0300 Subject: [PATCH] cosmetix --- mminer.d | 761 ++++++++++++++++++++++++++++++--------------------------------- 1 file changed, 363 insertions(+), 398 deletions(-) diff --git a/mminer.d b/mminer.d index 97d29d5..d0b8845 100644 --- a/mminer.d +++ b/mminer.d @@ -8,6 +8,110 @@ import iv.vfs.io; import x11gfx; +__gshared bool debugColdet = true; +__gshared bool singleStep = false; +__gshared bool singleStepWait = false; + + +// ////////////////////////////////////////////////////////////////////////// // +__gshared ubyte[][string] gameData; + + +// ////////////////////////////////////////////////////////////////////////// // +// image builders +VColor palcol (ubyte c) { + static VColor[256] palette; + static bool palset = false; + if (!palset) { + //palette = gameData["palmain"][]; + auto pp = gameData["palmain"]; + foreach (immutable cc; 0..256) { + ubyte r = cast(ubyte)(255*pp[cc*3+0]/63); + ubyte g = cast(ubyte)(255*pp[cc*3+1]/63); + ubyte b = cast(ubyte)(255*pp[cc*3+2]/63); + palette[cc] = rgbcol(r, g, b); + } + palset = true; + } + return palette[c]; +} + + +// ////////////////////////////////////////////////////////////////////////// // +X11Image buildImageMasked (const(ubyte)[] darr, int w, int h) { + assert(w > 0 && h > 0); + int dpos = 0; + auto img = new X11Image(w, h); + foreach (immutable y; 0..h) { + foreach (immutable x; 0..w) { + ubyte c = darr[dpos++]; + if (c) { + img.setPixel(x, y, palcol(c)); + } else { + img.setPixel(x, y, Transparent); + } + } + } + return img; +} + + +X11Image buildImageMaskedShiny (const(ubyte)[] darr, int brightness, int w, int h) { + assert(w > 0 && h > 0); + int dpos = 0; + auto img = new X11Image(w, h); + foreach (immutable y; 0..h) { + foreach (immutable x; 0..w) { + ubyte c = darr[dpos++]; + if (c) { + int b = (c&15)-brightness; + if (b < 0) b = 0; else if (b > 15) b = 15; + img.setPixel(x, y, palcol(cast(ubyte)((c&240)|b))); + } else { + img.setPixel(x, y, Transparent); + } + } + } + return img; +} + + +X11Image buildImageMaskedInk (const(ubyte)[] darr, int ink, int w, int h) { + assert(w > 0 && h > 0); + int dpos = 0; + auto img = new X11Image(w, h); + if (ink < 0) ink = 0; + ink *= 16; + foreach (immutable y; 0..h) { + foreach (immutable x; 0..w) { + ubyte c = darr[dpos++]; + if (c) { + img.setPixel(x, y, palcol(cast(ubyte)(c+ink))); + } else { + img.setPixel(x, y, Transparent); + } + } + } + return img; +} + + +// ////////////////////////////////////////////////////////////////////////// // +X11Image buildImageBrick (const(ubyte)[] darr, int ink, int paper, int skipy=0) { + assert(skipy >= 0); + enum { w = 8, h = 8 } + int dpos = 0; + auto img = new X11Image(w, h); + ink *= 16; + foreach (immutable y; 0..h) { + foreach (immutable x; 0..w) { + ubyte c = (y >= skipy ? darr[dpos++] : 0); + img.setPixel(x, y, palcol(cast(ubyte)(c ? ink+c : paper))); + } + } + return img; +} + // ////////////////////////////////////////////////////////////////////////// // // willy jump offsets @@ -72,6 +176,22 @@ struct Room { bool kLeft, kRight, kJump, kUp, kDown; } + @SRZIgnore { + X11Image finalSpr; + X11Image sunSpr; + X11Image[] brickCache; + X11Image[] convCache; + X11Image[] exitCache; + X11Image[] keyCache; + X11Image[][] monsterCache; + int[][] monsterOfsCache; + X11Image[] eugeneSpr; + X11Image[] kongSpr; + X11Image[] skylabSpr; + X11Image[] switchesSpr; + X11Image willySpr; + } + void initWilly () { // init willy willyX = willy.x; @@ -313,6 +433,19 @@ struct Room { default: } } + + buildWilly(); + buildBrickImages(); + buildConvImages(); + buildExitImages(); + buildKeysImages(); + buildMonsterImages(); + buildEugeneImages(); + buildKongImages(); + buildSkyLabImages(); + buildSwitchImages(); + finalSpr = buildImageMasked(gameData["final"], 256, 64); + sunSpr = buildImageMasked(gameData["sun"], 24, 16); } void stepCrumb () { @@ -360,9 +493,6 @@ struct Room { holeLen = 0; } else { ++holeY; - //eraseRect(136, 88, 8, 16); - //ctx.fillStyle = mainPal[curRoom.paper]; - //ctx.fillRect(136, 88+16-holeY, 8, holeY); if (holeY == 16) { map[11*32+17] = 0; map[12*32+17] = 0; @@ -443,8 +573,10 @@ struct Room { if (willyDead) return; checkSwitch(); if (isWillyInDeadly()) { willyDead = true; return; } - /*if (!DEBUG_COLDET)*/ { + if (!debugColdet) { if (checkMonsters()) { willyDead = true; return; } + } else { + if (checkMonsters()) singleStep = singleStepWait = true; } auto wasJump = false; @@ -510,55 +642,12 @@ struct Room { conveyor.frame += (conveyor.d ? -1 : 1); if (conveyor.frame < 0) conveyor.frame = 3; else if (conveyor.frame > 3) conveyor.frame = 0; - // must erase SPG, Willy and monsters here -- before coords change - /* - drawSPG(false); - eraseMonsters(); - eraseRect(willyX&248, willyY, 16, 16); - */ if (!willyJump) stepCrumb(); stepMonsters(); stepWillyActions(); - /* - if (DEBUG_COLDET) { - if (checkMonsters()) { - dbgSingleStep = true; dbgNF = false; - dbgColDetected = true; - } else dbgColDetected = false; - } - */ - stepKeys(); stepSwitch(); buildSPG(); - - /+ - if (willyDead) { - // dead %-( - gameRunning = false; - if (gameTID) clearInterval(gameTID), gameTID = null; - blockPage(); - message("you are dead!"); - setTimeout(startRoom, 1000); - return; - } - - if (checkExit()) { - // room complete! - gameRunning = false; - if (gameTID) clearInterval(gameTID), gameTID = null; - blockPage(); - message(curRoom.title+" complete!"); - curRoomNo++; - if (curRoomNo >= me.lsets[curLSet].rooms.length) { - curRoomNo = 0; - curLSet++; - if (curLSet >= me.lsets.length) curLSet = 0; - } - setTimeout(startRoom, 2000); - return; - } - +/ } // ////////////////////////////////////////////////////////////////////// // @@ -688,266 +777,270 @@ struct Room { } return false; } -} - -__gshared Room[] gameRooms; - -// ////////////////////////////////////////////////////////////////////////// // -__gshared ubyte[][string] gameData; - - -// ////////////////////////////////////////////////////////////////////////// // -// image builders -VColor palcol (ubyte c) { - static VColor[256] palette; - static bool palset = false; - if (!palset) { - //palette = gameData["palmain"][]; - auto pp = gameData["palmain"]; - foreach (immutable cc; 0..256) { - ubyte r = cast(ubyte)(255*pp[cc*3+0]/63); - ubyte g = cast(ubyte)(255*pp[cc*3+1]/63); - ubyte b = cast(ubyte)(255*pp[cc*3+2]/63); - palette[cc] = rgbcol(r, g, b); + X11Image draw (X11Image img=null) { + if (img is null) img = new X11Image(8*Room.Width, 8*Room.Height); + int pos = 0; + foreach (immutable y; 0..img.height) { + foreach (immutable x; 0..img.width) { + img.setPixel(x, y, palcol(this.paper)); + } + } + foreach (immutable y; 0..Room.Height) { + foreach (immutable x; 0..Room.Width) { + ubyte blk = this.map[pos++]; + if (blk < 1 || blk == 7) continue; + if (blk == 4) blk = 8; + brickCache[blk].blitTo(img, x*8, y*8); + } + } + if (this.roomIdx == 19) { + finalSpr.blitTo(img, 0, 0); + sunSpr.blitTo(img, 60, 32); } - palset = true; - } - return palette[c]; -} + void drawConveyor () { + auto conv = &this.conveyor; + if (conv.l < 1) return; + auto y = conv.y; + if (y <= 0) return; + convCache[conv.frame].blitTo(img, conv.x, conv.y, conv.l); + } -// ////////////////////////////////////////////////////////////////////////// // -X11Image buildImageMasked (const(ubyte)[] darr, int w, int h) { - assert(w > 0 && h > 0); - int dpos = 0; - auto img = new X11Image(w, h); - foreach (immutable y; 0..h) { - foreach (immutable x; 0..w) { - ubyte c = darr[dpos++]; - if (c) { - img.setPixel(x, y, palcol(c)); + void drawExit () { + int br; + if (this.keys.info.length != 0) { + br = 0; } else { - img.setPixel(x, y, Transparent); + br = this.frameNo&31; + if (br > 15) br = 31-br; + ++br; } + exitCache[br].blitTo(img, this.exit.x, this.exit.y); } - } - return img; -} - -X11Image buildImageMaskedShiny (const(ubyte)[] darr, int brightness, int w, int h) { - assert(w > 0 && h > 0); - int dpos = 0; - auto img = new X11Image(w, h); - foreach (immutable y; 0..h) { - foreach (immutable x; 0..w) { - ubyte c = darr[dpos++]; - if (c) { - int b = (c&15)-brightness; - if (b < 0) b = 0; else if (b > 15) b = 15; - img.setPixel(x, y, palcol(cast(ubyte)((c&240)|b))); - } else { - img.setPixel(x, y, Transparent); + void drawKeys () { + auto ff = this.frameNo%16; + if (ff >= 8) ff = 15-ff; + auto keyimg = keyCache[ff]; + foreach_reverse (const ref ki; this.keys.info) { + if (ki.x < 0 || ki.y < 0) continue; + //eraseRect(ki.x, ki.y, 8, 8); + if (!ki.s) continue; + keyimg.blitTo(img, ki.x&248, ki.y); } } - } - return img; -} + void drawMonsters () { + foreach (immutable f, const ref m; this.enemies) { + if (m.x < 0 || m.y < 0) continue; + auto slist = monsterCache[f]; + auto x = m.x; + if (m.vert) { + //for (var c = 0; c <= m.anim; c++) r.push(buildImageMaskedInk(me.data.vrobo, (m.gfx+c)*256, m.ink-1, 16, 16, false)); + slist[m.anim].blitTo(img, x, m.y); + } else { + auto sidx = ((x&m.anim)&0xfe)+m.d/*ir*/; + if (sidx < slist.length) { + slist[sidx].blitTo(img, x&248, m.y); + } else { + writeln("monster #", f, " is fucked: sidx=", sidx, "; max=", slist.length); + } + } + } + if (this.eugene.x >= 0) { + enum curLSet = 0; + eugeneSpr[curLSet*8+this.eugene.ink].blitTo(img, this.eugene.x, this.eugene.y); + } + if (this.kong.x >= 0) { + kongSpr[this.kong.frame*8+this.kong.ink].blitTo(img, this.kong.x, this.kong.y); + } + if (this.skylab.length) { + foreach (const ref sk; this.skylab) { + skylabSpr[sk.frame*8+sk.ink].blitTo(img, sk.x, sk.y); + } + } + } -X11Image buildImageMaskedInk (const(ubyte)[] darr, int ink, int w, int h) { - assert(w > 0 && h > 0); - int dpos = 0; - auto img = new X11Image(w, h); - if (ink < 0) ink = 0; - ink *= 16; - foreach (immutable y; 0..h) { - foreach (immutable x; 0..w) { - ubyte c = darr[dpos++]; - if (c) { - img.setPixel(x, y, palcol(cast(ubyte)(c+ink))); - } else { - img.setPixel(x, y, Transparent); + void drawSwitch () { + foreach (const ref ss; this.switches) { + if (ss.s == 0) continue; + switchesSpr[ss.s-1].blitTo(img, ss.x, ss.y); } } - } - return img; -} + void drawSPG () { + foreach (const ref sp; this.spg) { + auto x = sp.x*8; + auto y = sp.y*8; + if (x < 0 || y < 0) break; + //ctx.fillStyle = mainPal[noerase?6:this.paper]; + //ctx.fillRect(x, y, 8, 8); + foreach (immutable dy; 0..8) { + foreach (immutable dx; 0..8) { + img.setPixel(x+dx, y+dy, palcol(6)); + } + } + } + } -// ////////////////////////////////////////////////////////////////////////// // -X11Image buildImageBrick (const(ubyte)[] darr, int ink, int paper, int skipy=0) { - assert(skipy >= 0); - enum { w = 8, h = 8 } - int dpos = 0; - auto img = new X11Image(w, h); - ink *= 16; - foreach (immutable y; 0..h) { - foreach (immutable x; 0..w) { - ubyte c = (y >= skipy ? darr[dpos++] : 0); - img.setPixel(x, y, palcol(cast(ubyte)(c ? ink+c : paper))); + void drawWilly () { + auto willyPos = (this.willyX&15)>>1; + if (this.willyDir < 0) willyPos += 8; + if (debugColdet) { + auto wy = 0; + if (this.checkMonsters()) wy = 16; + willySpr.blitTo(willyPos*16, wy, 16, 16, img, this.willyX&248, this.willyY); + } else { + willySpr.blitTo(willyPos*16, 0, 16, 16, img, this.willyX&248, this.willyY); + } } - } - return img; -} + drawConveyor(); + drawKeys(); + drawMonsters(); + drawSwitch(); + drawWilly(); + drawExit(); + drawSPG(); -// ////////////////////////////////////////////////////////////////////////// // -X11Image finalSpr; -X11Image sunSpr; -X11Image[] brickCache; -X11Image[] convCache; -X11Image[] exitCache; -X11Image[] keyCache; -X11Image[][] monsterCache; -int[][] monsterOfsCache; -X11Image[] eugeneSpr; -X11Image[] kongSpr; -X11Image[] skylabSpr; -X11Image[] switchesSpr; -X11Image willySpr; + return img; + } -// ////////////////////////////////////////////////////////////////////////// // -void buildWilly (in ref Room curRoom) { - auto img = new X11Image(16*16, 16+16); - auto ww = gameData["willy"]; - foreach (immutable f; 0..16) { - foreach (immutable y; 0..16) { - foreach (immutable x; 0..16) { - ubyte c = ww[f*256+y*16+x]; - if (!c) { - img.setPixel(f*16+x, y, Transparent); - } else { - img.setPixel(f*16+x, y, palcol(c)); - // white - img.setPixel(f*16+x, y+16, palcol(15)); +private: + // ////////////////////////////////////////////////////////////////////////// // + void buildWilly () { + auto img = new X11Image(16*16, 16+16); + auto ww = gameData["willy"]; + foreach (immutable f; 0..16) { + foreach (immutable y; 0..16) { + foreach (immutable x; 0..16) { + ubyte c = ww[f*256+y*16+x]; + if (!c) { + img.setPixel(f*16+x, y, Transparent); + } else { + img.setPixel(f*16+x, y, palcol(c)); + // white + img.setPixel(f*16+x, y+16, palcol(15)); + } } } } + willySpr = img; } - willySpr = img; -} - -void buildBrickImages (in ref Room curRoom) { - auto buildBrickImage (in ref Room.CommonGfx brk, int skipy=0) { - return buildImageBrick(gameData["blocks"][brk.gfx*64..$], brk.ink, curRoom.paper, skipy); - } - brickCache = null; - foreach (immutable f; 0..8) { - X11Image img; - switch (f) { - //case 0: case 7: img = buildBrickImage(curRoom.wall, 16); break; - case 1: img = buildBrickImage(curRoom.platforms[0]); break; - case 2: img = buildBrickImage(curRoom.platforms[1]); break; - case 3: img = buildBrickImage(curRoom.wall); break; - //case 4: img = buildBrickImage(curRoom.crumb); break; - case 5: img = buildBrickImage(curRoom.deadlies[0]); break; - case 6: img = buildBrickImage(curRoom.deadlies[1]); break; - default: + void buildBrickImages () { + auto buildBrickImage (in ref Room.CommonGfx brk, int skipy=0) { + return buildImageBrick(gameData["blocks"][brk.gfx*64..$], brk.ink, this.paper, skipy); + } + brickCache = null; + foreach (immutable f; 0..8) { + X11Image img; + switch (f) { + //case 0: case 7: img = buildBrickImage(this.wall, 16); break; + case 1: img = buildBrickImage(this.platforms[0]); break; + case 2: img = buildBrickImage(this.platforms[1]); break; + case 3: img = buildBrickImage(this.wall); break; + //case 4: img = buildBrickImage(this.crumb); break; + case 5: img = buildBrickImage(this.deadlies[0]); break; + case 6: img = buildBrickImage(this.deadlies[1]); break; + default: + } + brickCache ~= img; } - brickCache ~= img; + foreach (immutable f; 0..9) brickCache ~= buildBrickImage(this.crumb, f); } - foreach (immutable f; 0..9) brickCache ~= buildBrickImage(curRoom.crumb, f); -} - -void buildConvImages (in ref Room curRoom) { - convCache = null; - auto conv = &curRoom.conveyor; - if (conv.y <= 0 || conv.l < 1) return; - foreach (immutable f; 0..4) { - convCache ~= buildImageBrick(gameData["conv"][conv.gfx*256+f*64..$], conv.ink, curRoom.paper); + void buildConvImages () { + convCache = null; + auto conv = &this.conveyor; + if (conv.y <= 0 || conv.l < 1) return; + foreach (immutable f; 0..4) { + convCache ~= buildImageBrick(gameData["conv"][conv.gfx*256+f*64..$], conv.ink, this.paper); + } } -} + void buildExitImages () { + exitCache = null; + exitCache ~= buildImageMasked(gameData["exits"][this.exit.gfx*256..$], 16, 16); + foreach (immutable f; 0..16) exitCache ~= buildImageMaskedShiny(gameData["exits"][this.exit.gfx*256..$], f, 16, 16); + } -void buildExitImages (in ref Room curRoom) { - exitCache = null; - exitCache ~= buildImageMasked(gameData["exits"][curRoom.exit.gfx*256..$], 16, 16); - foreach (immutable f; 0..16) exitCache ~= buildImageMaskedShiny(gameData["exits"][curRoom.exit.gfx*256..$], f, 16, 16); -} - - -void buildKeysImages (in ref Room curRoom) { - keyCache = null; - foreach (immutable f; 0..16) keyCache ~= buildImageMaskedShiny(gameData["keys"][curRoom.keys.gfx*64..$], f, 8, 8); -} - + void buildKeysImages () { + keyCache = null; + foreach (immutable f; 0..16) keyCache ~= buildImageMaskedShiny(gameData["keys"][this.keys.gfx*64..$], f, 8, 8); + } -void buildMonsterImages (in ref Room curRoom) { - monsterCache = null; - monsterOfsCache = null; - //auto l = curRoom.enemies.length; - foreach (immutable f, const ref m; curRoom.enemies) { - if (m.x < 0 || m.y < 0) { - monsterOfsCache ~= null; - monsterCache ~= null; - continue; - } - X11Image[] r; - int[] cc; - if (m.vert) { - foreach (immutable c; 0..4) { - auto n = (m.gfx+c)*256; - cc ~= n; - r ~= buildImageMaskedInk(gameData["vrobo"][n..$], m.ink-1, 16, 16); + void buildMonsterImages () { + monsterCache = null; + monsterOfsCache = null; + foreach (immutable f, const ref m; this.enemies) { + if (m.x < 0 || m.y < 0) { + monsterOfsCache ~= null; + monsterCache ~= null; + continue; } - } else { - foreach (immutable c; 0..(m.anim>>1)+1) { - auto n = (m.gfx+c)*256; - cc ~= n; - r ~= buildImageMaskedInk(gameData["hrobo"][n..$], m.ink-1, 16, 16); - n += m.flip*256; - cc ~= n; - r ~= buildImageMaskedInk(gameData["hrobo"][n..$], m.ink-1, 16, 16); + X11Image[] r; + int[] cc; + if (m.vert) { + foreach (immutable c; 0..4) { + auto n = (m.gfx+c)*256; + cc ~= n; + r ~= buildImageMaskedInk(gameData["vrobo"][n..$], m.ink-1, 16, 16); + } + } else { + foreach (immutable c; 0..(m.anim>>1)+1) { + auto n = (m.gfx+c)*256; + cc ~= n; + r ~= buildImageMaskedInk(gameData["hrobo"][n..$], m.ink-1, 16, 16); + n += m.flip*256; + cc ~= n; + r ~= buildImageMaskedInk(gameData["hrobo"][n..$], m.ink-1, 16, 16); + } } + monsterOfsCache ~= cc; + monsterCache ~= r; } - monsterOfsCache ~= cc; - monsterCache ~= r; } -} - -void buildEugeneImages (in ref Room curRoom) { - eugeneSpr = null; - for (int f = 0; f <= 256; f += 256) { - foreach (immutable c; 0..8) { - eugeneSpr ~= buildImageMaskedInk(gameData["eugene"][f..$], c, 16, 16); + void buildEugeneImages () { + eugeneSpr = null; + for (int f = 0; f <= 256; f += 256) { + foreach (immutable c; 0..8) { + eugeneSpr ~= buildImageMaskedInk(gameData["eugene"][f..$], c, 16, 16); + } } } -} - -void buildKongImages (in ref Room curRoom) { - kongSpr = null; - foreach (immutable f; 0..4) { - foreach (immutable c; 0..8) { - kongSpr ~= buildImageMaskedInk(gameData["kong"][f*256..$], c, 16, 16); + void buildKongImages () { + kongSpr = null; + foreach (immutable f; 0..4) { + foreach (immutable c; 0..8) { + kongSpr ~= buildImageMaskedInk(gameData["kong"][f*256..$], c, 16, 16); + } } } -} - -void buildSkyLabImages (in ref Room curRoom) { - skylabSpr = null; - foreach (immutable f; 0..8) { - foreach (immutable c; 0..8) { - skylabSpr ~= buildImageMaskedInk(gameData["sky"][f*256..$], c, 16, 16); + void buildSkyLabImages () { + skylabSpr = null; + foreach (immutable f; 0..8) { + foreach (immutable c; 0..8) { + skylabSpr ~= buildImageMaskedInk(gameData["sky"][f*256..$], c, 16, 16); + } } } -} - -void buildSwitchImages (in ref Room curRoom) { - switchesSpr = null; - foreach (immutable f; 0..2) { - switchesSpr ~= buildImageBrick(gameData["switches"][f*64..$], curRoom.platforms[1].ink, curRoom.paper); + void buildSwitchImages () { + switchesSpr = null; + foreach (immutable f; 0..2) { + switchesSpr ~= buildImageBrick(gameData["switches"][f*64..$], this.platforms[1].ink, this.paper); + } } } +__gshared Room[] gameRooms; + // ////////////////////////////////////////////////////////////////////////// // void blitTo (X11Image src, X11Image dst, int x, int y, int repx=1) { @@ -981,141 +1074,12 @@ void blitTo (X11Image src, int x0, int y0, int ww, int hh, X11Image dst, int x, } -X11Image drawRoom (in ref Room curRoom, X11Image img=null) { - if (img is null) img = new X11Image(8*Room.Width, 8*Room.Height); - int pos = 0; - foreach (immutable y; 0..img.height) { - foreach (immutable x; 0..img.width) { - img.setPixel(x, y, palcol(curRoom.paper)); - } - } - foreach (immutable y; 0..Room.Height) { - foreach (immutable x; 0..Room.Width) { - ubyte blk = curRoom.map[pos++]; - if (blk < 1 || blk == 7) continue; - if (blk == 4) blk = 8; - brickCache[blk].blitTo(img, x*8, y*8); - } - } - if (curRoom.roomIdx == 19) { - finalSpr.blitTo(img, 0, 0); - sunSpr.blitTo(img, 60, 32); - } - - void drawConveyor () { - auto conv = &curRoom.conveyor; - if (conv.l < 1) return; - auto y = conv.y; - if (y <= 0) return; - convCache[conv.frame].blitTo(img, conv.x, conv.y, conv.l); - } - - void drawExit () { - int br; - if (curRoom.keys.info.length != 0) { - br = 0; - } else { - br = curRoom.frameNo&31; - if (br > 15) br = 31-br; - ++br; - } - exitCache[br].blitTo(img, curRoom.exit.x, curRoom.exit.y); - } - - void drawKeys () { - auto ff = curRoom.frameNo%16; - if (ff >= 8) ff = 15-ff; - auto keyimg = keyCache[ff]; - foreach_reverse (const ref ki; curRoom.keys.info) { - if (ki.x < 0 || ki.y < 0) continue; - //eraseRect(ki.x, ki.y, 8, 8); - if (!ki.s) continue; - keyimg.blitTo(img, ki.x&248, ki.y); - } - } - - void drawMonsters () { - foreach (immutable f, const ref m; curRoom.enemies) { - if (m.x < 0 || m.y < 0) continue; - auto slist = monsterCache[f]; - auto x = m.x; - if (m.vert) { - //for (var c = 0; c <= m.anim; c++) r.push(buildImageMaskedInk(me.data.vrobo, (m.gfx+c)*256, m.ink-1, 16, 16, false)); - slist[m.anim].blitTo(img, x, m.y); - } else { - auto sidx = ((x&m.anim)&0xfe)+m.d/*ir*/; - if (sidx < slist.length) { - slist[sidx].blitTo(img, x&248, m.y); - } else { - writeln("monster #", f, " is fucked: sidx=", sidx, "; max=", slist.length); - } - } - } - if (curRoom.eugene.x >= 0) { - enum curLSet = 0; - eugeneSpr[curLSet*8+curRoom.eugene.ink].blitTo(img, curRoom.eugene.x, curRoom.eugene.y); - } - if (curRoom.kong.x >= 0) { - kongSpr[curRoom.kong.frame*8+curRoom.kong.ink].blitTo(img, curRoom.kong.x, curRoom.kong.y); - } - if (curRoom.skylab.length) { - foreach (const ref sk; curRoom.skylab) { - skylabSpr[sk.frame*8+sk.ink].blitTo(img, sk.x, sk.y); - } - } - } - - void drawSwitch () { - foreach (const ref ss; curRoom.switches) { - if (ss.s == 0) continue; - switchesSpr[ss.s-1].blitTo(img, ss.x, ss.y); - } - } - - void drawSPG () { - foreach (const ref sp; curRoom.spg) { - auto x = sp.x*8; - auto y = sp.y*8; - if (x < 0 || y < 0) break; - //ctx.fillStyle = mainPal[noerase?6:curRoom.paper]; - //ctx.fillRect(x, y, 8, 8); - foreach (immutable dy; 0..8) { - foreach (immutable dx; 0..8) { - img.setPixel(x+dx, y+dy, palcol(6)); - } - } - } - } - - void drawWilly () { - auto willyPos = (curRoom.willyX&15)>>1; - if (curRoom.willyDir < 0) willyPos += 8; - auto wy = 0; - //if (DEBUG_COLDET && dbgColDetected) wy = 16; - willySpr.blitTo(willyPos*16, wy, 16, 16, img, curRoom.willyX&248, curRoom.willyY); - } - - drawConveyor(); - drawKeys(); - drawMonsters(); - drawSwitch(); - if (curRoom.keys.info.length) drawExit(); - drawWilly(); - if (!curRoom.keys.info.length) drawExit(); - drawSPG(); - - return img; -} - - // ////////////////////////////////////////////////////////////////////////// // void main (string[] args) { gameRooms.txtunser(VFile("levelset0.js")); foreach (immutable idx, ref room; gameRooms) room.roomIdx = cast(int)idx; gameData.txtunser(VFile("data.js")); - finalSpr = buildImageMasked(gameData["final"], 256, 64); - sunSpr = buildImageMasked(gameData["sun"], 24, 16); Room curRoom; @@ -1123,16 +1087,6 @@ void main (string[] args) { void loadRoom (int idx) { curRoom = gameRooms[idx]; curRoom.initRoom(); - buildWilly(curRoom); - buildBrickImages(curRoom); - buildConvImages(curRoom); - buildExitImages(curRoom); - buildKeysImages(curRoom); - buildMonsterImages(curRoom); - buildEugeneImages(curRoom); - buildKongImages(curRoom); - buildSkyLabImages(curRoom); - buildSwitchImages(curRoom); } loadRoom(0); @@ -1150,7 +1104,7 @@ void main (string[] args) { delegate () { if (sdwin.closed) return; - if (!curRoom.willyDead) { + if (!curRoom.willyDead && !singleStepWait) { curRoom.stepGame(); if (!curRoom.willyDead && curRoom.checkExit()) { if (gameRooms.length-curRoom.roomIdx > 1) { @@ -1158,11 +1112,12 @@ void main (string[] args) { curRoom.willyDead = true; } } + singleStepWait = singleStep; } //clear(rgbcol(255, 127, 0)); clear(0); { - roomImg = drawRoom(curRoom, roomImg); + roomImg = curRoom.draw(roomImg); roomImg.blit2xTV(0, 0); } //map.drawMap(); @@ -1183,6 +1138,16 @@ void main (string[] args) { case Key.Up: curRoom.kUp = evt.pressed; break; case Key.Down: curRoom.kDown = evt.pressed; break; case Key.Ctrl: curRoom.kJump = evt.pressed; break; + case Key.N1: debugColdet = !debugColdet; break; + case Key.S: + if (!evt.pressed) break; + singleStep = !singleStep; + singleStepWait = singleStep; + break; + case Key.Enter: + if (!evt.pressed) break; + singleStepWait = false; + break; case Key.R: if (evt.pressed && curRoom.willyDead) { loadRoom(curRoom.roomIdx); -- 2.11.4.GIT