From 5a7f55657d15207bc25bc0e707faff73e188d03c Mon Sep 17 00:00:00 2001 From: Ketmar Dark Date: Sun, 20 Dec 2015 04:21:21 +0200 Subject: [PATCH] locased names --- index.html | 4 +- miner.js | 496 ++++++++++++++++++++++++++++++------------------------------- 2 files changed, 250 insertions(+), 250 deletions(-) diff --git a/index.html b/index.html index f798acc..421a047 100644 --- a/index.html +++ b/index.html @@ -44,7 +44,7 @@ no, it's not another stupid Tetris or Invaders or Paratrooper. nobody wants to p |__________________________________________________________|
impressed? can't believe it's true? don't wait, just go and play it NOW!
- +
guide Willy through 40 (yes, 40!) lethal caverns, send me one million bucks %-) and prepare to meet Willy in "Jet Set Willy: a Night at the Opera!"


@@ -102,6 +102,6 @@ there are neither gifs nor external images in the game.


have fun and happy hacking,
-Ketmar // Avalon Group
+Ketmar // Invisible Vector diff --git a/miner.js b/miner.js index b4fa454..5b8ba17 100644 --- a/miner.js +++ b/miner.js @@ -25,24 +25,24 @@ function ManicMiner () { ". . . . . . . ."; - function UnpackRoom (roomS) { + function unpackRoom (roomS) { var room = {}, pos = 0; - function GetNum () { + function getNum () { var n = roomS.charCodeAt(pos++)-48, len; var len = n>>4; n = n&0x0f; while (len--) n = n*10+roomS.charCodeAt(pos++)-48; return n; } - function GetIP (arr) { - arr.ink = GetNum(); - arr.paper = GetNum(); + function getIP (arr) { + arr.ink = getNum(); + arr.paper = getNum(); } - function GetGIP (arr) { - arr.gfx = GetNum(); - GetIP(arr); + function getGIP (arr) { + arr.gfx = getNum(); + getIP(arr); } // map @@ -53,66 +53,66 @@ function ManicMiner () { while (cnt--) { room.map.push(bt); f++; } } // params and Willy start - room.air = GetNum(); - room.willy = { x:GetNum(), y:GetNum(), sd:GetNum() }; - room.exit = { gfx:GetNum(), x:GetNum(), y:GetNum() }; - room.border = GetNum(); - GetIP(room); + room.air = getNum(); + room.willy = { x:getNum(), y:getNum(), sd:getNum() }; + room.exit = { gfx:getNum(), x:getNum(), y:getNum() }; + room.border = getNum(); + getIP(room); // platforms - var cnt = GetNum(); + var cnt = getNum(); room.platforms = []; while (cnt--) { - var t = {}; GetGIP(t); + var t = {}; getGIP(t); room.platforms.push(t); } - room.wall = {}; GetGIP(room.wall); - room.crumb = {}; GetGIP(room.crumb); + room.wall = {}; getGIP(room.wall); + room.crumb = {}; getGIP(room.crumb); // deadlies - var cnt = GetNum(); + var cnt = getNum(); room.deadlies = []; while (cnt--) { - var t = {}; GetGIP(t); + var t = {}; getGIP(t); room.deadlies.push(t); } // conveyor - room.conveyor = { x:GetNum(), y:GetNum(), d:GetNum(), l:GetNum() }; - GetGIP(room.conveyor); + room.conveyor = { x:getNum(), y:getNum(), d:getNum(), l:getNum() }; + getGIP(room.conveyor); // keys - cnt = GetNum(); + cnt = getNum(); //LogPrint("keys: "+cnt); - room.keys = { gfx: GetNum(), info:[] }; + room.keys = { gfx: getNum(), info:[] }; for (var f = 0; f < 5; f++) { var t = {}; - if (f < cnt) t = { x:GetNum(), y:GetNum(), s: GetNum() }; + if (f < cnt) t = { x:getNum(), y:getNum(), s: getNum() }; else t = { x:-1, y:-1, s:0 }; room.keys.info.push(t); } // switches - cnt = GetNum(); + cnt = getNum(); room.switches = []; for (var f = 0; f < 2; f++) { var sw; - if (f < cnt) sw = { x: GetNum(), y:GetNum(), s:GetNum() }; + if (f < cnt) sw = { x: getNum(), y:getNum(), s:getNum() }; else sw = { x: 0, y: 0, s: 0 }; room.switches.push(sw); } // enemies - cnt = GetNum(); + cnt = getNum(); room.enemies = []; for (var f = 0; f < 8; f++) { var e; if (f < cnt) { e = {}; e.vert = roomS.charCodeAt(pos++)=="V"; - GetGIP(e); - e.x = GetNum(); - e.y = GetNum(); - e.min = GetNum(); - e.max = GetNum(); - e.d = GetNum(); - e.s = GetNum(); - e.flip = GetNum(); - e.anim = GetNum(); + getGIP(e); + e.x = getNum(); + e.y = getNum(); + e.min = getNum(); + e.max = getNum(); + e.d = getNum(); + e.s = getNum(); + e.flip = getNum(); + e.anim = getNum(); } else { e = { vert: true, gfx: 0, ink: 1, paper: 0, x: -1, y: -1, min: 2, max: 81, d: 0, s: 111, flip: 0, anim: 0 }; } @@ -130,7 +130,7 @@ function ManicMiner () { * * modified by Ketmar // Avalon Group */ - function LZWUnpack (str) { + function lzwUnpack (str) { var dict = {}; var data = (str+"").split(""); var currChar = data[0]; @@ -156,20 +156,20 @@ function ManicMiner () { var me = this, canvas, ctx, mainX, mainY, mainPal; this.lsets = []; - this.SetData = function (data) { + this.setData = function (data) { this.data = data; var k; for (k in data) { var v = data[k]; - if (typeof(v) == "string") data[k] = LZWUnpack(v); + if (typeof(v) == "string") data[k] = lzwUnpack(v); } }; - this.AddLevelSet = function (lset) { + this.addLevelSet = function (lset) { if (lset.packed) { delete lset.packed; var r = lset.rooms; lset.rooms = []; - for (var f = 0; f < r.length; f++) lset.rooms.push(UnpackRoom(r[f])); + for (var f = 0; f < r.length; f++) lset.rooms.push(unpackRoom(r[f])); } this.lsets.push(lset); }; @@ -196,7 +196,7 @@ function ManicMiner () { var dbgNF, dbgSingleStep; -function RemoveMessage (force) { +function removeMessage (force) { var msg = document.getElementById("k8PageMesssage"); if (!msg) return; if (msg.k8ClickToRemove && !force) return; @@ -210,7 +210,7 @@ function RemoveMessage (force) { } -function Message (msgs, clickToRemove) { +function message (msgs, clickToRemove) { while (!msgs) msgs = rndMessages[Math.ceil(Math.random()*rndMessages.length)]; var msg = document.getElementById("k8PageMesssage"); if (!msg) { @@ -260,7 +260,7 @@ function Message (msgs, clickToRemove) { msg.style.left = wx+"px"; msg.style.top = wy+"px"; if (clickToRemove) { - msg.onclick = function () { RemoveMessage(true); }; + msg.onclick = function () { removeMessage(true); }; msg.k8ClickToRemove = true; } else { msg.onclick = function () {}; @@ -277,7 +277,7 @@ function Message (msgs, clickToRemove) { } -function BlockPage () { +function blockPage () { var i = document.getElementById("k8PageBlocker"); if (i) return; var db = document.body; @@ -289,8 +289,8 @@ function BlockPage () { } -function UnblockPage () { - RemoveMessage(false); +function unblockPage () { + removeMessage(false); var i = document.getElementById("k8PageBlocker"); if (!i) return; i.style.display = "none"; @@ -302,16 +302,16 @@ function UnblockPage () { ///////////////////////////////////////////////////////////////////////// // image builders -function ConvertPalette () { - function ToHC (n) { return (n>15?"":"0")+(n.toString(16)); } +function convertPalette () { + function toHC (n) { return (n>15?"":"0")+(n.toString(16)); } mainPal = []; var pd = me.data.palmain; //opera.postError(pd.length); - for (var f = 0; f < 256; f++) mainPal[f] = "#"+ToHC(pd[f*3+0]*4)+ToHC(pd[f*3+1]*4)+ToHC(pd[f*3+2]*4); + for (var f = 0; f < 256; f++) mainPal[f] = "#"+toHC(pd[f*3+0]*4)+toHC(pd[f*3+1]*4)+toHC(pd[f*3+2]*4); } -function BuildImageMasked (darr, dpos, w, h) { +function buildImageMasked (darr, dpos, w, h) { var cc = document.createElement("canvas"); cc.setAttribute("width", w); cc.setAttribute("height", h); @@ -333,7 +333,7 @@ function BuildImageMasked (darr, dpos, w, h) { } -function BuildImageMaskedShiny (darr, dpos, brightness, w, h) { +function buildImageMaskedShiny (darr, dpos, brightness, w, h) { var cc = document.createElement("canvas"); cc.setAttribute("width", w); cc.setAttribute("height", h); @@ -357,7 +357,7 @@ function BuildImageMaskedShiny (darr, dpos, brightness, w, h) { } -function BuildImageMaskedInk (darr, dpos, ink, w, h) { +function buildImageMaskedInk (darr, dpos, ink, w, h) { ink = (ink||0); if (ink < 0) ink = 0; ink *= 16; var cc = document.createElement("canvas"); cc.setAttribute("width", w); @@ -380,7 +380,7 @@ function BuildImageMaskedInk (darr, dpos, ink, w, h) { } -function BuildImageBrk (darr, dpos, ink, paper, skip, w, h, rep, masked) { +function buildImageBrk (darr, dpos, ink, paper, skip, w, h, rep, masked) { skip = skip||0; ink *= 16; w = w||8; h = h||8; rep = rep||1; var cc = document.createElement("canvas"); cc.setAttribute("width", w*rep); @@ -403,7 +403,7 @@ function BuildImageBrk (darr, dpos, ink, paper, skip, w, h, rep, masked) { } -function BuildWilly () { +function buildWilly () { var cc = document.createElement("canvas"); cc.setAttribute("width", 16*16); cc.setAttribute("height", 16+16); @@ -432,51 +432,51 @@ function BuildWilly () { ///////////////////////////////////////////////////////////////////////// // image cachers -function CacheBrickImages () { - function BuildBrickImage (brk, skip) { - return BuildImageBrk(me.data.blocks, brk.gfx*64, brk.ink, curRoom.paper, skip||0); +function cacheBrickImages () { + function buildBrickImage (brk, skip) { + return buildImageBrk(me.data.blocks, brk.gfx*64, brk.ink, curRoom.paper, skip||0); } brickCache = []; for (var f = 0; f <= 7; f++) { var r; switch (f) { - //case 0: case 7: r = BuildBrickImage(curRoom.wall, 16); break; - case 1: r = BuildBrickImage(curRoom.platforms[0]); break; - case 2: r = BuildBrickImage(curRoom.platforms[1]); break; - case 3: r = BuildBrickImage(curRoom.wall); break; - //case 4: r = BuildBrickImage(curRoom.crumb); break; - case 5: r = BuildBrickImage(curRoom.deadlies[0]); break; - case 6: r = BuildBrickImage(curRoom.deadlies[1]); break; + //case 0: case 7: r = buildBrickImage(curRoom.wall, 16); break; + case 1: r = buildBrickImage(curRoom.platforms[0]); break; + case 2: r = buildBrickImage(curRoom.platforms[1]); break; + case 3: r = buildBrickImage(curRoom.wall); break; + //case 4: r = buildBrickImage(curRoom.crumb); break; + case 5: r = buildBrickImage(curRoom.deadlies[0]); break; + case 6: r = buildBrickImage(curRoom.deadlies[1]); break; } brickCache.push(r); } - for (var f = 0; f <= 8; f++) brickCache.push(BuildBrickImage(curRoom.crumb, f)); + for (var f = 0; f <= 8; f++) brickCache.push(buildBrickImage(curRoom.crumb, f)); } -function CacheConvImages () { +function cacheConvImages () { convCache = []; //monsterCache = []; if (conv.y <= 0 || conv.l < 1) return; for (var f = 0; f <= 3; f++) { - convCache.push(BuildImageBrk(me.data.conv, conv.gfx*256+f*64, conv.ink, curRoom.paper, 0, 8, 8, conv.l)); + convCache.push(buildImageBrk(me.data.conv, conv.gfx*256+f*64, conv.ink, curRoom.paper, 0, 8, 8, conv.l)); } } -function CacheExit () { +function cacheExit () { exitCache = []; - exitCache.push(BuildImageMasked(me.data.exits, curRoom.exit.gfx*256, 16, 16)); - for (var f = 0; f <= 15; f++) exitCache.push(BuildImageMaskedShiny(me.data.exits, curRoom.exit.gfx*256, f, 16, 16)); + exitCache.push(buildImageMasked(me.data.exits, curRoom.exit.gfx*256, 16, 16)); + for (var f = 0; f <= 15; f++) exitCache.push(buildImageMaskedShiny(me.data.exits, curRoom.exit.gfx*256, f, 16, 16)); } -function CacheKeys () { +function cacheKeys () { keyCache = []; - for (var f = 0; f <= 15; f++) keyCache.push(BuildImageMaskedShiny(me.data.keys, curRoom.keys.gfx*64, f, 8, 8)); + for (var f = 0; f <= 15; f++) keyCache.push(buildImageMaskedShiny(me.data.keys, curRoom.keys.gfx*64, f, 8, 8)); } -function CacheMonsters () { +function cacheMonsters () { monsterCache = []; monsterOfsCache = []; var l = curMonsters.length; for (var f = 0; f < l; f++) { @@ -487,16 +487,16 @@ function CacheMonsters () { for (var c = 0; c <= 3; c++) { var n = (m.gfx+c)*256; cc.push(n); - r.push(BuildImageMaskedInk(me.data.vrobo, n, m.ink-1, 16, 16)); + r.push(buildImageMaskedInk(me.data.vrobo, n, m.ink-1, 16, 16)); } } else { for (var c = 0; c <= m.anim>>1; c++) { var n = (m.gfx+c)*256; cc.push(n); - r.push(BuildImageMaskedInk(me.data.hrobo, n, m.ink-1, 16, 16)); + r.push(buildImageMaskedInk(me.data.hrobo, n, m.ink-1, 16, 16)); n += m.flip*256; cc.push(n); - r.push(BuildImageMaskedInk(me.data.hrobo, n, m.ink-1, 16, 16)); + r.push(buildImageMaskedInk(me.data.hrobo, n, m.ink-1, 16, 16)); } } monsterOfsCache.push(cc); @@ -505,36 +505,36 @@ function CacheMonsters () { } -function CacheEugene () { +function cacheEugene () { eugeneSpr = []; for (var f = 0; f <= 256; f += 256) for (var c = 0; c <= 7; c++) - eugeneSpr.push(BuildImageMaskedInk(me.data.eugene, f, c, 16, 16)); + eugeneSpr.push(buildImageMaskedInk(me.data.eugene, f, c, 16, 16)); } -function CacheKong () { +function cacheKong () { kongSpr = []; for (var f = 0; f <= 3; f++) { for (var c = 0; c <= 7; c++) { - kongSpr.push(BuildImageMaskedInk(me.data.kong, f*256, c, 16, 16)); + kongSpr.push(buildImageMaskedInk(me.data.kong, f*256, c, 16, 16)); } } } -function CacheSkyLab () { +function cacheSkyLab () { skylabSpr = []; for (var f = 0; f <= 7; f++) for (var c = 0; c <= 7; c++) - skylabSpr.push(BuildImageMaskedInk(me.data.sky, f*256, c, 16, 16)); + skylabSpr.push(buildImageMaskedInk(me.data.sky, f*256, c, 16, 16)); } -function CacheSwitch () { +function cacheSwitch () { switchesSpr = []; for (var f = 0; f < 2; f++) { - switchesSpr.push(BuildImageBrk(me.data.switches, f*64, curRoom.platforms[1].ink, curRoom.paper, 0)); + switchesSpr.push(buildImageBrk(me.data.switches, f*64, curRoom.platforms[1].ink, curRoom.paper, 0)); } } @@ -542,7 +542,7 @@ function CacheSwitch () { ///////////////////////////////////////////////////////////////////////// // painters -function EraseRect (x0, y0, w, h) { +function eraseRect (x0, y0, w, h) { ctx.fillStyle = mainPal[curRoom.paper]; ctx.fillRect(x0, y0, w, h); var xe = x0+w, ye = y0+h; @@ -559,7 +559,7 @@ function EraseRect (x0, y0, w, h) { } -function DrawRoom () { +function drawRoom () { var pos = 0; ctx.fillStyle = mainPal[curRoom.paper]; ctx.fillRect(0, 0, 32*8, 16*8); @@ -578,7 +578,7 @@ function DrawRoom () { } -function DrawConveyor () { +function drawConveyor () { if (conv.l < 1) return; var y = conv.y; if (y <= 0) return; @@ -586,7 +586,7 @@ function DrawConveyor () { } -function DrawExit () { +function drawExit () { if (keysLeft) br = 0; else { br = frameNo&31; @@ -597,7 +597,7 @@ function DrawExit () { } -function DrawKeys () { +function drawKeys () { //if (!keysLeft) return; var ff = frameNo%16; if (ff >= 8) ff = 15-ff; @@ -605,30 +605,30 @@ function DrawKeys () { for (var f = curKeys.length-1; f >= 0; f--) { var ki = curKeys[f]; if (ki.x < 0 || ki.y < 0) continue; - EraseRect(ki.x, ki.y, 8, 8); + eraseRect(ki.x, ki.y, 8, 8); if (!ki.s) continue; ctx.drawImage(img, 0, 0, 8, 8, ki.x&248, ki.y, 8, 8); } } -function EraseMonsters () { +function eraseMonsters () { var l = curMonsters.length; for (var f = 0; f < l; f++) { var m = curMonsters[f]; //if (m.x < 0 || m.y < 0) continue; // we can't kill monsters now var x = m.x; if (!m.vert) x = x&248; - EraseRect(x, m.y, 16, 16); + eraseRect(x, m.y, 16, 16); } - if (eugene) EraseRect(eugene.x, eugene.y, 16, 16); - if (kong) EraseRect(kong.x, kong.y, 16, 16); + if (eugene) eraseRect(eugene.x, eugene.y, 16, 16); + if (kong) eraseRect(kong.x, kong.y, 16, 16); if (skylab) { - for (var f = 2; f >= 0; f--) EraseRect(skylab[f].x, skylab[f].y, 16, 16); + for (var f = 2; f >= 0; f--) eraseRect(skylab[f].x, skylab[f].y, 16, 16); } } -function DrawMonsters () { +function drawMonsters () { //return; var l = curMonsters.length; for (var f = 0; f < l; f++) { @@ -637,7 +637,7 @@ function DrawMonsters () { var slist = monsterCache[f]; var 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)); + //for (var c = 0; c <= m.anim; c++) r.push(buildImageMaskedInk(me.data.vrobo, (m.gfx+c)*256, m.ink-1, 16, 16, false)); ctx.drawImage(slist[m.anim], 0, 0, 16, 16, x, m.y, 16, 16); } else ctx.drawImage(slist[((x&m.anim)&0xfe)+m.dir], 0, 0, 16, 16, x&248, m.y, 16, 16); //} else ctx.drawImage(slist[frameNo&m.anim], 0, 0, 16, 16, x&248, m.y, 16, 16); @@ -657,7 +657,7 @@ function DrawMonsters () { } -function DrawSwitch () { +function drawSwitch () { var l = switches.length; for (var f = 0; f < l; f++) { var ss = switches[f]; @@ -666,7 +666,7 @@ function DrawSwitch () { } -function DrawSPG (noerase) { +function drawSPG (noerase) { if (!spg) return; for (var f = 0; f < spg.length; f++) { var x = spg[f].x*8, y = spg[f].y*8; @@ -678,7 +678,7 @@ function DrawSPG (noerase) { -function DrawWilly () { +function drawWilly () { var willyPos = (willyX&15)>>1; if (willyDir < 0) willyPos += 8; var wy = 0; @@ -691,7 +691,7 @@ function DrawWilly () { // checkers // x & y: in pixels -function GetBlockAt (x, y, simplify) { +function getBlockAt (x, y, simplify) { x = x>>3, y = y>>3; if (x < 0 || y < 0 || x > 31 || y > 15) return 0; // empty var b = curMap[y*32+x]; @@ -705,35 +705,35 @@ function GetBlockAt (x, y, simplify) { } -function IsWillyFalling () { +function isWillyFalling () { if (willyY&7) return true; for (var dx = 0; dx <= 8; dx += 8) { - var b = GetBlockAt(willyX+dx, willyY+16, true); + var b = getBlockAt(willyX+dx, willyY+16, true); if (b > 0 && b != 5) return false; } return true; } -function IsWillyInDeadly () { +function isWillyInDeadly () { for (var dx = 0; dx <= 8; dx += 8) { for (var dy = 0; dy <= 16; dy += 8) { - if (GetBlockAt(willyX+dx, willyY+dy, true) == 5) return true; + if (getBlockAt(willyX+dx, willyY+dy, true) == 5) return true; } } return false; } -function IsWillyOnConv () { +function isWillyOnConv () { if (willyY&7) return false; - var b0 = GetBlockAt(willyX, willyY+16); - var b1 = GetBlockAt(willyX+8, willyY+16); + var b0 = getBlockAt(willyX, willyY+16); + var b1 = getBlockAt(willyX+8, willyY+16); return b0 == 7 || b1 == 7; } -function CheckExit () { +function checkExit () { if (keysLeft) return false; var x = curRoom.exit.x, y = curRoom.exit.y; return (willyX >= x-2 && willyX+10 <= x+18 && willyY >= y-5 && willyY+16 <= y+22); @@ -743,9 +743,9 @@ function CheckExit () { // pixel-perfect collision detector // fully stolen from Andy's sources %-) var mpcGrid = new Array(256); -function PixelCheckMonster (rx, ry, darr, dpos) { +function pixelCheckMonster (rx, ry, darr, dpos) { var x, y, w; - + // rx -= willyX&248; ry -= willyY; if (rx < -15 || rx > 15 || ry < -15 || ry > 15) return false; @@ -767,36 +767,36 @@ function PixelCheckMonster (rx, ry, darr, dpos) { } -function CheckMonsters () { +function checkMonsters () { var l = curMonsters.length; for (var f = 0; f < l; f++) { var m = curMonsters[f], cc = monsterOfsCache[f]; //if (m.x < 0 || m.y < 0) continue; // we can't kill monsters now if (m.vert) { - if (PixelCheckMonster(m.x, m.y, me.data.vrobo, cc[m.anim])) return true; + if (pixelCheckMonster(m.x, m.y, me.data.vrobo, cc[m.anim])) return true; } else { - if (PixelCheckMonster(m.x&248, m.y, me.data.hrobo, cc[((m.x&m.anim)&0xfe)+m.dir])) return true; + if (pixelCheckMonster(m.x&248, m.y, me.data.hrobo, cc[((m.x&m.anim)&0xfe)+m.dir])) return true; } } // Eugene? if (eugene) { - if (PixelCheckMonster(eugene.x, eugene.y, me.data.eugene, 256*curLSet)) return true; + if (pixelCheckMonster(eugene.x, eugene.y, me.data.eugene, 256*curLSet)) return true; } // Kong? if (kong) { - if (PixelCheckMonster(kong.x, kong.y, me.data.kong, 256*kong.frame)) return true; + if (pixelCheckMonster(kong.x, kong.y, me.data.kong, 256*kong.frame)) return true; } // SkyLab? if (skylab) { for (var f = 2; f >= 0; f--) { var sk = skylab[f]; - if (PixelCheckMonster(sk.x, sk.y, me.data.sky, 256*sk.frame)) return true; + if (pixelCheckMonster(sk.x, sk.y, me.data.sky, 256*sk.frame)) return true; } } } -function CheckSwitch () { +function checkSwitch () { var l = switches.length; for (var f = 0; f < l; f++) { var ss = switches[f]; @@ -807,7 +807,7 @@ function CheckSwitch () { } -function CheckSPG () { +function checkSPG () { if (!spg) return; for (var f = 0; f < spg.length; f++) { var x = spg[f].x*8, y = spg[f].y*8; @@ -822,7 +822,7 @@ function CheckSPG () { ///////////////////////////////////////////////////////////////////////// // doers -function SPGCheckMonster (x, y) { +function spgCheckMonster (x, y) { x *= 8; y *= 8; for (var f = 0; f < curMonsters.length; f++) { var cm = curMonsters[f]; @@ -833,13 +833,13 @@ function SPGCheckMonster (x, y) { } -function BuildSPG () { +function buildSPG () { var x = 23, y = 0, done = false; var dir = 0, idx = 0; if (!spg) spg = []; - function AddXY (x, y) { + function addXY (x, y) { idx++; while (spg.length < idx) spg.push({x:-1, y:-1}); spg[idx-1].x = x; spg[idx-1].y = y; @@ -847,19 +847,19 @@ function BuildSPG () { do { var blockhit = curMap[y*32+x]; - var robohit = SPGCheckMonster(x, y); + var robohit = spgCheckMonster(x, y); if (blockhit && robohit) { - AddXY(-1, -1); + addXY(-1, -1); done = true; } else if (!blockhit && robohit) { if (idx && spg[idx-1].x == x && spg[idx-1].y == y) { spg[idx-1].x = spg[idx-1].y = -1; done = true; - } else AddXY(x, y); + } else addXY(x, y); dir ^= 1; } else if (!blockhit && !robohit) { - AddXY(x, y); + addXY(x, y); } else if (blockhit && !robohit) { if (idx && spg[idx-1].x == x && spg[idx-1].y == y) { spg[idx-1].x = spg[idx-1].y = -1; @@ -871,23 +871,23 @@ function BuildSPG () { if (!blockhit) { if (!dir) { y++; - blockhit = curMap[y*32+x]; - if (y == 15 || blockhit) done = true; + blockhit = curMap[y*32+x]; + if (y == 15 || blockhit) done = true; } else { x--; - blockhit = curMap[y*32+x]; - if (x == 0 || blockhit) done = true; + blockhit = curMap[y*32+x]; + if (x == 0 || blockhit) done = true; } } else { if (!dir) { x--; if (!x) done = true; } else { y++; if (++y == 15) done = true; } } } while (!done); - AddXY(-1, -1); + addXY(-1, -1); } -function DoKeys () { +function doKeys () { if (!keysLeft) return; for (var f = curKeys.length-1; f >= 0; f--) { var ki = curKeys[f]; @@ -901,22 +901,22 @@ function DoKeys () { } -function DoCrumb () { +function doCrumb () { if (willyY&7) return false; for (var f = 0; f <= 8; f += 8) { var x = willyX+f, y = willyY+16; - var b = GetBlockAt(x, y); + var b = getBlockAt(x, y); if (b == 4) b = 8; if (b < 8) continue; x >>= 3; y >>= 3; if (++b > 15) b = 0; curMap[y*32+x] = b; - EraseRect(x*8, y*8, 8, 8); + eraseRect(x*8, y*8, 8, 8); } } -function DoMonsters () { +function doMonsters () { var l = curMonsters.length; for (var f = 0; f < l; f++) { var m = curMonsters[f]; @@ -972,7 +972,7 @@ function DoMonsters () { case 1: // just started curMap[2*32+15] = 0; curMap[2*32+16] = 0; - EraseRect(16, 120, 16, 8); + eraseRect(16, 120, 16, 8); kong.falling = 2; break; case 2: @@ -1017,7 +1017,7 @@ function DoMonsters () { } -function DoSwitch () { +function doSwitch () { // hole? if (holeLen && switches.length && switches[0].state) { if (holeLen < 0) { @@ -1025,7 +1025,7 @@ function DoSwitch () { holeLen = 0; } else { holeY++; - EraseRect(136, 88, 8, 16); + eraseRect(136, 88, 8, 16); ctx.fillStyle = mainPal[curRoom.paper]; ctx.fillRect(136, 88+16-holeY, 8, holeY); if (holeY == 16) { @@ -1040,12 +1040,12 @@ function DoSwitch () { } -function DoWillyLeft () { +function doWillyLeft () { if (willyDir > 0) { willyDir = -1; return true; } var xx = willyX-2; - var b0 = GetBlockAt(xx, willyY); - var b1 = GetBlockAt(xx, willyY+8); - var b2 = willyY&7?GetBlockAt(xx, willyY+16):b1; + var b0 = getBlockAt(xx, willyY); + var b1 = getBlockAt(xx, willyY+8); + var b2 = willyY&7?getBlockAt(xx, willyY+16):b1; if (b0 == 3 || b1 == 3 || b2 == 3) return false; willyX -= 2; if (willyX < 0) willyX += 240; @@ -1054,13 +1054,13 @@ function DoWillyLeft () { } -function DoWillyRight () { +function doWillyRight () { if (willyDir < 0) { willyDir = 1; return true; } if (willyX > 245) return false; var xx = willyX+10; - var b0 = GetBlockAt(xx, willyY); - var b1 = GetBlockAt(xx, willyY+8); - var b2 = willyY&7?GetBlockAt(xx, willyY+16):b1; + var b0 = getBlockAt(xx, willyY); + var b1 = getBlockAt(xx, willyY+8); + var b2 = willyY&7?getBlockAt(xx, willyY+16):b1; if (b0 == 3 || b1 == 3 || b2 == 3) return false; willyX += 2; if (willyX > 240) willyX -= 240; @@ -1069,16 +1069,16 @@ function DoWillyRight () { } -function DoWillyJump () { +function doWillyJump () { if (!willyJump) return; willyY += willyJ[willyJump]; var x = willyX, mv = false; - if (willyJumpDir < 0) mv = DoWillyLeft(); else if (willyJumpDir > 0) mv = DoWillyRight(); + if (willyJumpDir < 0) mv = doWillyLeft(); else if (willyJumpDir > 0) mv = doWillyRight(); if (willyJump < 9) { willyFall = 0; // up - var b0 = GetBlockAt(x, willyY); - var b1 = GetBlockAt(x+8, willyY); + var b0 = getBlockAt(x, willyY); + var b1 = getBlockAt(x+8, willyY); if (b0 == 3 || b1 == 3) { // headboom! (apstenu %-) willyX = x; willyY -= willyJ[willyJump]; @@ -1089,8 +1089,8 @@ function DoWillyJump () { // down if (willyJump > 12) willyFall += willyJ[willyJump]; if ((willyY&7) == 0) { - var b0 = GetBlockAt(willyX, willyY+16); - var b1 = GetBlockAt(willyX+8, willyY+16); + var b0 = getBlockAt(willyX, willyY+16); + var b1 = getBlockAt(willyX+8, willyY+16); if (b0 || b1) { if (b0 == 3 || b1 == 3) willyX = x; willyFall = 0; // can't fall too deep while jumping @@ -1105,23 +1105,23 @@ function DoWillyJump () { } -function DoWillyActions () { +function doWillyActions () { if (willyDead) return; - CheckSwitch(); - if (IsWillyInDeadly()) { willyDead = true; return; } + checkSwitch(); + if (isWillyInDeadly()) { willyDead = true; return; } if (!DEBUG_COLDET) { - if (CheckMonsters()) { willyDead = true; return; } + if (checkMonsters()) { willyDead = true; return; } } var wasJump = false; if (willyJump) { willyLastMoveDir = 0; - DoWillyJump(); + doWillyJump(); if (willyJump) return; wasJump = true; } - var falling = IsWillyFalling(); + var falling = isWillyFalling(); if (!kDown && falling) { willyConv = willyStall = willyLastMoveDir = 0; willyFall += 4; @@ -1137,9 +1137,9 @@ function DoWillyActions () { if (willyDead) return; var dx = kLeft?-1:kRight?1:0; - if (IsWillyOnConv()) { + if (isWillyOnConv()) { var cdir = conv.d?1:-1; - // dx==cdir,!dx,lastmove==cdir + //dx==cdir,!dx,lastmove==cdir if (willyLastMoveDir == cdir || dx == cdir || !dx) willyConv = cdir, willyStall = 0; // was moving in conv. dir or standing if (!willyConv) { // Willy just steps on the conveyor, and Willy walking to the opposite side @@ -1161,32 +1161,32 @@ function DoWillyActions () { willyConv = willyStall = willyLastMoveDir = 0; willyJumpDir = dx; willyJump = 1; - DoWillyJump(); + doWillyJump(); return; } if (kDown) willyY -= 8; willyLastMoveDir = 0; - if (dx < 0) DoWillyLeft(); else if (dx > 0) DoWillyRight(); + if (dx < 0) doWillyLeft(); else if (dx > 0) doWillyRight(); } ///////////////////////////////////////////////////////////////////////// // game ticking -function GameDraw () { - DrawSPG(true); - DrawConveyor(); - DrawKeys(); - DrawMonsters(); - DrawSwitch(); - if (keysLeft) DrawExit(); - DrawWilly(); - if (!keysLeft) DrawExit(); +function frameDraw () { + drawSPG(true); + drawConveyor(); + drawKeys(); + drawMonsters(); + drawSwitch(); + if (keysLeft) drawExit(); + drawWilly(); + if (!keysLeft) drawExit(); } -var StartRoom; -function GameStep () { +var startRoom; // forward declaration +function gameStep () { gameRunning = true; if (dbgSingleStep && !dbgNF) return dbgNF = false; @@ -1195,47 +1195,47 @@ function GameStep () { if (conv.frame < 0) conv.frame = 3; else if (conv.frame > 3) conv.frame = 0; // must erase SPG, Willy and monsters here -- before coords change - DrawSPG(false); - EraseMonsters(); - EraseRect(willyX&248, willyY, 16, 16); - if (!willyJump) DoCrumb(); - DoMonsters(); - DoWillyActions(); + drawSPG(false); + eraseMonsters(); + eraseRect(willyX&248, willyY, 16, 16); + if (!willyJump) doCrumb(); + doMonsters(); + doWillyActions(); if (DEBUG_COLDET) { - if (CheckMonsters()) { + if (checkMonsters()) { dbgSingleStep = true; dbgNF = false; dbgColDetected = true; } else dbgColDetected = false; } - DoKeys(); - DoSwitch(); - if (spg) BuildSPG(); - GameDraw(); + doKeys(); + doSwitch(); + if (spg) buildSPG(); + frameDraw(); if (willyDead) { // dead %-( gameRunning = false; if (gameTID) clearInterval(gameTID), gameTID = null; - BlockPage(); - Message("you are dead!"); - setTimeout(StartRoom, 1000); + blockPage(); + message("you are dead!"); + setTimeout(startRoom, 1000); return; } - if (CheckExit()) { + if (checkExit()) { // room complete! gameRunning = false; if (gameTID) clearInterval(gameTID), gameTID = null; - BlockPage(); - Message(curRoom.title+" complete!"); + 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); + setTimeout(startRoom, 2000); return; } } @@ -1244,7 +1244,7 @@ function GameStep () { ///////////////////////////////////////////////////////////////////////// // game initializers -function InitRoom () { +function initRoom () { gameRunning = false; frameNo = 0; // copy map @@ -1277,19 +1277,19 @@ function InitRoom () { } // Eugene? if (curRoomNo == 4) { - CacheEugene(); + cacheEugene(); eugene = { x:120, y:1, dir:0, min:1, max:87, ink:6 }; } else eugene = eugeneSpr = false; // Kong? if (curRoomNo == 7 || curRoomNo == 11) { - CacheKong(); + cacheKong(); kong = { x:120, y:0, max:104, frame:0, ink:2, m:0 }; holeLen = 2*8; holeY = 0; } else kong = kongSpr = holeLen = holeY = false; // SkyLab? if (curRoomNo == 13) { curMonsters = []; - CacheSkyLab(); + cacheSkyLab(); skylab = [ {p:0, s:4, ink:6, max:72, m:0, frame:0}, {p:2, s:3, ink:5, max:56, m:0, frame:0}, @@ -1303,7 +1303,7 @@ function InitRoom () { } else skylab = skylabSpr = false; // solar power generator spg = false; - if (curRoomNo == 18) BuildSPG(); + if (curRoomNo == 18) buildSPG(); // switches switches = []; for (var f = 0; f < curRoom.switches.length; f++) { @@ -1313,12 +1313,12 @@ function InitRoom () { } //opera.postError(switches.length); // caching - CacheBrickImages(); - CacheConvImages(); - CacheExit(); - CacheKeys(); - CacheMonsters(); - CacheSwitch(); + cacheBrickImages(); + cacheConvImages(); + cacheExit(); + cacheKeys(); + cacheMonsters(); + cacheSwitch(); // init willy willyX = curRoom.willy.x; willyY = curRoom.willy.y; willyDir = curRoom.willy.sd>0?-1:1; @@ -1331,19 +1331,19 @@ function InitRoom () { } -StartRoom = function () { +startRoom = function () { gameRunning = false; - BlockPage(); - Message("loading"); + blockPage(); + message("loading"); setTimeout(function () { - InitRoom(); - DrawRoom(); - GameDraw(); - Message("entering "+curRoom.title); + initRoom(); + drawRoom(); + frameDraw(); + message("entering "+curRoom.title); setTimeout(function () { - RemoveMessage(); - UnblockPage(); - gameTID = setInterval(GameStep, 50); + removeMessage(); + unblockPage(); + gameTID = setInterval(gameStep, 50); }, 2000); }, 1); } @@ -1352,18 +1352,18 @@ StartRoom = function () { ///////////////////////////////////////////////////////////////////////// // controls, etc -function KbdTogglePause () { +function kbdTogglePause () { if (!gameRunning) return; if (gameTID) clearInterval(gameTID), gameTID = null; - else gameTID = setInterval(GameStep, 50); + else gameTID = setInterval(gameStep, 50); - if (!gameTID) BlockPage(), Message("paused"); else RemoveMessage(), UnblockPage();; + if (!gameTID) { blockPage(); message("paused"); } else { removeMessage(); unblockPage(); } //kLeft = kRight = kJump = false; } kbdActions = [ - { key: ("P").charCodeAt(0), action: KbdTogglePause }, + { key: ("P").charCodeAt(0), action: kbdTogglePause }, { key: ("K").charCodeAt(0), action: function () { keysLeft = 0; } }, { key: ("N").charCodeAt(0), action: function () { keysLeft = 0; willyX = curRoom.exit.x; willyY = curRoom.exit.y; } }, { key: ("R").charCodeAt(0), action: function () { willyDead = true; } }, @@ -1380,7 +1380,7 @@ kbdActions = [ ]; -function KbdFindKey (evt) { +function kbdFindKey (evt) { for (var f = kbdActions.length-1; f >= 0; f--) { var k = kbdActions[f]; if (k.key != evt.keyCode) continue; @@ -1393,9 +1393,9 @@ function KbdFindKey (evt) { } -function OnKeyDown (evt) { +function onKeyDown (evt) { if (evt.ctrlKey) kJump = true; - var k = KbdFindKey(evt); + var k = kbdFindKey(evt); if (!k) return true; evt.preventDefault(); k.down = true; @@ -1403,9 +1403,10 @@ function OnKeyDown (evt) { return false; } -function OnKeyUp (evt) { + +function onKeyUp (evt) { if (evt.ctrlKey) kJump = false; - var k = KbdFindKey(evt); + var k = kbdFindKey(evt); if (!k) return true; evt.preventDefault(); k.down = false; @@ -1414,7 +1415,7 @@ function OnKeyUp (evt) { } -function OnKeyPress (evt) { +function onKeyPress (evt) { //opera.postError("kp: "+evt.keyCode); if (!gameTID) return true; evt.preventDefault(); @@ -1422,35 +1423,34 @@ function OnKeyPress (evt) { } -function HookKeys () { +function hookKeys () { for (var f in kbdActions) kbdActions[f].down = false; - - document.addEventListener("keydown", OnKeyDown, false); - document.addEventListener("keyup", OnKeyUp, false); - document.addEventListener("keypress", OnKeyPress, false); + document.addEventListener("keydown", onKeyDown, false); + document.addEventListener("keyup", onKeyUp, false); + document.addEventListener("keypress", onKeyPress, false); } /* prepare images */ -function LoadData () { - BlockPage(); - Message("initializing"); -setTimeout(function () { - ConvertPalette(); - BuildWilly(); - finalSpr = BuildImageMasked(me.data.final, 0, 256, 64); - sunSpr = BuildImageMasked(me.data.sun, 0, 24, 16); - HookKeys(); - gameTID = false; - score = 0; - curLSet = 0; - curRoomNo = 0; - setTimeout(StartRoom, 10); -}, 10); +function loadData () { + blockPage(); + message("initializing"); + setTimeout(function () { + convertPalette(); + buildWilly(); + finalSpr = buildImageMasked(me.data.final, 0, 256, 64); + sunSpr = buildImageMasked(me.data.sun, 0, 24, 16); + hookKeys(); + gameTID = false; + score = 0; + curLSet = 0; + curRoomNo = 0; + setTimeout(startRoom, 10); + }, 10); } -function InitCanvas () { +function initCanvas () { canvas = document.createElement("canvas"); canvas.setAttribute("width", 512); canvas.setAttribute("height", 256); @@ -1483,10 +1483,10 @@ function InitCanvas () { } -this.Run = function () { +this.run = function () { gameRunning = false; - InitCanvas(); - LoadData(); + initCanvas(); + loadData(); }; -- 2.11.4.GIT