From 8dd59adfec801f631313e0f8562c64165c38fd4f Mon Sep 17 00:00:00 2001 From: Patrick Davison Date: Mon, 26 Nov 2012 22:02:42 -0800 Subject: Multipath animation support. Finally got the colors in the animation consistant and fairly logical. --- js/mapspecs.js | 120 +++++++++++++++++++++++++++++++++++---------------------- 1 file changed, 75 insertions(+), 45 deletions(-) (limited to 'js') diff --git a/js/mapspecs.js b/js/mapspecs.js index e983d63..87de7de 100644 --- a/js/mapspecs.js +++ b/js/mapspecs.js @@ -285,15 +285,21 @@ function request_path_done() { updateDsp(JO.mapid, 'dspID', disptext); mapdata[mapid].moveCount = new Object; + mapdata[mapid].usedTiles = new Array(); mapdata[mapid].restoreTiles = new Array(); mapdata[mapid].pathColor = new Object; + + mapdata[mapid].pathsPending = JO.path.length; + mapdata[mapid].isMultiPath = (JO.path.length > 1); + for(i in JO.path) { mapdata[mapid].moveCount[i] = 0; mapdata[mapid].pathColor[i] = '#ffffff'; animatePath(JO.path[i].path, mapid, JO.path[i].start, i); } - mapdata[JO.mapid].pathsPending = i; + + //Mark off challenges if(isChallenge) @@ -411,7 +417,7 @@ function doanimate(x, y, p, c, mapid, pathNumber) { handle.classOrigName = origclass; - //Animate. + //Track move count switch(c) { case 'f': case 'a': @@ -419,7 +425,8 @@ function doanimate(x, y, p, c, mapid, pathNumber) { break; count[mapid]--; mapdata[mapid].moveCount[pathNumber]--; - //break; + + //The path is moving to a new position case '1': //1 - Up case '2': //2 - Right case '3': //3 - Down @@ -427,20 +434,20 @@ function doanimate(x, y, p, c, mapid, pathNumber) { count[mapid]++; mapdata[mapid].moveCount[pathNumber]++; - //Starting; + //Notify users on score levels; switch(count[mapid]) { case mapjson[mapid].best: //flashelement(mapid+',dspCount', 4, "#FF0000"); break; case 500: case 400: - case 350: + //case 350: case 300: - case 250: + //case 250: case 200: - case 150: + //case 150: case 100: - case 50: + //case 50: if (checkSound(mapid)) { soundManager.setVolume('charm', 40); soundManager.setPan('charm', 75) @@ -451,24 +458,21 @@ function doanimate(x, y, p, c, mapid, pathNumber) { break; } + // + childdiv = document.getElementById('child_'+handle.id); if (childdiv.className.indexOf('grid_td_walls') < 0) { childdiv.setAttribute('class', 'grid_td_path'+pathNumber+'-'+c); - var origColor = rgbStringToHex(handle.style.backgroundColor); - console.log("OriginalColor", origColor); - handle.style.backgroundColor = mapdata[mapid].pathColor[pathNumber]; string = "if (document.getElementById('"+'child_'+eid+"').className == 'grid_td_path"+pathNumber+'-'+c+"')"; string += "document.getElementById('"+'child_'+eid+"').removeAttribute('class');"; setTimeout(string, 855); - //Reset our color back to the way it was. - //setTimeout("document.getElementById('"+eid+"').style.backgroundColor = '"+origColor+"';", 865); //Maintain disabled appearnce of checkpoints if (handle.pressed == true) { - setTimeout("document.getElementById('"+eid+"').style.backgroundColor = '"+origColor+"';", 865); + setTimeout("document.getElementById('"+eid+"').style.backgroundColor = '#dddddd';", 865); } else { setTimeout("document.getElementById('"+eid+"').style.backgroundColor = '';", 865); } @@ -478,43 +482,53 @@ function doanimate(x, y, p, c, mapid, pathNumber) { //Teleports case 't': case 'u': case 'm': case 'g': case 'i': case 'k': - case 'q': //Teleport out; + //case 'q': //Teleport out; //Checkpoints case 'r': - if (handle.pressed == true) - break; - case 'b': case 'c': case 'd': case 'e': + // if (handle.pressed == true) + // break; + //case 'a': case 'b': case 'c': case 'd': case 'e': //handle.setAttribute('class', 'grid_td_pressed'); //handle.classOrigName = 'grid_td_pressed'; - if (handle.pressed == true) { + //if (handle.pressed == true) { + + //var currentColor = rgbStringToHex(handle.style.backgroundColor); + //if (currentColor == '') + // break; + //var dulled = '#'+dullColor(currentColor, .6); + //console.log('bgcolor', dulled, currentColor); + //handle.style.backgroundColor = dulled; + //setTimeout("document.getElementById('"+eid+"').style.backgroundColor = '"+dulled+"';", 865); + + if (mapdata[mapid].isMultiPath == false) { handle.style.backgroundColor = '#dddddd'; setTimeout("document.getElementById('"+eid+"').style.backgroundColor = '#dddddd';", 865); - //alert("Pressed Point Solid Grayed is " + c); - break; + handle.pressed = true; + } else { + if (contains(mapdata[mapid].usedTiles, eid)) { + console.log("executed on", eid, c); + console.log("true:", contains(mapdata[mapid].usedTiles, eid)); + handle.style.backgroundColor = '#dddddd'; + setTimeout("document.getElementById('"+eid+"').style.backgroundColor = '#dddddd';", 865); + handle.pressed = true; + } else { + //mapdata[mapid].usedTiles.push(eid); + //break; + } } - - var currentColor = rgbStringToHex(handle.style.backgroundColor); - if (currentColor == '') - break; - - var dulled = '#'+dullColor(currentColor, .6); - - console.log('bgcolor', dulled, currentColor); - //handle.style.backgroundColor = '#dddddd'; - handle.style.backgroundColor = dulled; - setTimeout("document.getElementById('"+eid+"').style.backgroundColor = '"+dulled+"';", 865); + if (contains(mapdata[mapid].usedTiles, eid) == false) + mapdata[mapid].usedTiles.push(eid); - handle.pressed = true; - mapdata[mapid].restoreTiles.push("document.getElementById('"+eid+"').style.backgroundColor = '';"); - mapdata[mapid].restoreTiles.push("document.getElementById('"+eid+"').pressed = false;"); + //mapdata[mapid].restoreTiles.push("document.getElementById('"+eid+"').style.backgroundColor = '';"); + //mapdata[mapid].restoreTiles.push("document.getElementById('"+eid+"').pressed = false;"); //alert(mapdata[mapid].pathColor[pathNumber]); - break; + //break; } //Sound effects @@ -537,10 +551,9 @@ function doanimate(x, y, p, c, mapid, pathNumber) { //Speaking of the next tile - does it exist? //End of the line? if (t == '') { - mapdata[mapid].pathsPending--; //console.log('path pending', mapdata[mapid].pathsPending); - if (mapdata[mapid].pathsPending >= 0) + if (mapdata[mapid].pathsPending > 0) return; //console.log('path pending complete', mapdata[mapid].pathsPending); @@ -592,12 +605,18 @@ function doanimate(x, y, p, c, mapid, pathNumber) { count[mapid] = 0; mapdata[mapid].pathColor[pathNumber] = '#ffffff'; //Bring the color back to our checkpoints/teleports. - for(var i in mapdata[mapid].restoreTiles) { + var eid; + for(var i in mapdata[mapid].usedTiles) { //eval(mapdata[mapid].restoreTiles[i]); - setTimeout((mapdata[mapid].restoreTiles[i]), 2000); + //setTimeout((mapdata[mapid].restoreTiles[i]), 2000); + eid = mapdata[mapid].usedTiles[i]; + + setTimeout("document.getElementById('"+eid+"').style.backgroundColor = '';", 2500); + setTimeout("document.getElementById('"+eid+"').pressed = false;" , 2500); + } //Clear - mapdata[mapid].restoreTiles = new Array(); + mapdata[mapid].usedTiles = new Array(); //We're done, animatePathDone(mapid); return; @@ -640,13 +659,12 @@ function doanimate(x, y, p, c, mapid, pathNumber) { //Did we aquire a target? //Checkpoint targets: case 'a': - // rs = rs * 9; + rs = rs + 410; mapdata[mapid].pathColor[pathNumber] = '#F777FF'; break; case 'b': rs = rs + 410; mapdata[mapid].pathColor[pathNumber] = '#FFFF11'; - //handle.style.backgroundColor = "#000000"; break; case 'c': rs = rs + 410; @@ -690,8 +708,9 @@ function doanimate(x, y, p, c, mapid, pathNumber) { soundManager.play('ufoblip'); } - document.getElementById(eid).style.backgroundColor='#CCCCCC'; - document.getElementById(tpEid).style.backgroundColor='#CCCCCC'; + //document.getElementById(eid).style.backgroundColor='#CCCCCC'; + //document.getElementById(tpEid).style.backgroundColor='#CCCCCC'; + document.getElementById(tpEid).style.backgroundColor=''; flashelement(tpEid, 8, mapdata[mapid].pathColor[pathNumber]); @@ -745,6 +764,17 @@ function flashelement(eid, times, color, speed) { } +function contains(a, obj) { + var i = a.length; + while (i--) { + if (a[i] === obj) { + return true; + } + } + return false; +} + + function dullColor(colorAsHex, value) { var r = hexToR(colorAsHex); var g = hexToG(colorAsHex); -- cgit v1.2.3