Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><a href="http://jsfiddle.net/yRyLN/1/" rel="nofollow">http://jsfiddle.net/yRyLN/1/</a></p> <p>I modified the following:</p> <p>The basic concept is that the z-index is increased by 1 for each step away from the lowest block. All you need to do now is add some collision detection. Fun stuff!</p> <pre><code>function drawlayer(level, depth) { var images = BlockID(); var top = depth; var left = sidecalc(level); var mytop = top; var myleft = left; var y; for (y=0; y&lt;level.length; ++y) { var row = level[y]; var x; for (x=0; x &lt; row.length; ++x) { var c = row.charAt(x); if(c != ' ') { console.log(mytop + "," + myleft); img_create(images[c], mytop, myleft, y + x); } mytop += 13; myleft += 27; } mytop = top + (y+1)*13; myleft = left - (y+1)*27; } } function img_create(src, top, left, zIndex) { console.log(top + "," + left); var block = new Image(); block.src = src; block.style.top = top + "px"; block.style.left = left + "px"; block.style.position = "absolute"; block.style.zIndex = zIndex; document.body.appendChild( block ); } function mainchar(){ var mainchar = new Image(); mainchar.id = "mainChar"; mainchar.src = "http://dl.dropbox.com/u/18785762/Rust/Images/Char_01.png"; mainchar.style.top = "62px"; mainchar.style.left = "0px"; mainchar.style.position = "absolute"; mainchar.style.zIndex = 0; window.addEventListener("keydown", movechar); document.body.appendChild(mainchar); } function movechar(e){ var event = event || e; var mainChar = document.getElementById("mainChar"); var top = Number(mainChar.style.top.replace("px","")); var left = Number(mainChar.style.left.replace("px","")); var stepSize = 32; var zIndex = Number(mainChar.style.zIndex); switch (event.keyCode){ case 37: case 65: //left left = left -27; top = top -13; zIndex -= 1; break; case 39: case 68: // right left = left + 27; top = top +13; zIndex += 1; break; case 38: case 87: // up left = left +27; top = top -13; zIndex -= 1; break; case 40: case 83: // down left = left -27; top = top +13; zIndex += 1; break; } mainChar.style.zIndex = zIndex; mainChar.style.top = top + "px"; mainChar.style.left = left + "px"; } </code></pre> <p><strong>EDITED:</strong> <a href="http://jsfiddle.net/yRyLN/2/" rel="nofollow">http://jsfiddle.net/yRyLN/2/</a></p> <p>Fixed a small layering issue. </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload