JS: 3D CANVAS WALKER REVISITED

more at: http://jensarps.de/2009/08/27/3d-canvas-walker-revisited/

by Felipe Alfaro

HTML

<div id="holder">
    <div id="sky"></div>
    <div id="floor"></div>
    <canvas id="canvas"></canvas>
    <div id="overlay"></div>
</div>
<div id="options">
    <p>Keys:
        <ul>
            <li>W - forward</li>
            <li>S - back</li>
            <li>A - strafe left</li>
            <li>D - strafe right</li>
            <li>LShift - walk modifier</li>
            <li>LCtrl - toggle crouch</li>
            <li>Space - jump</li>
            <li>M - realase / capture mouse</li>
        </ul>
    </p>
</div>

CSS

html, body {
    margin: 0;
    padding: 0;
    width: 100%;
    height: 100%;
}
body.mouseCaptured {
    cursor: none;
}
#content {
    font-family: arial;
    font-size: 10pt;
    background-color: #000;
    color: #CCC;
}
#options {
    display: none;
    font: 12px sans-serif;
    float: right;
    color: #C0C0C0 !important;
    padding-right: 20px;
}
#holder {
    position: relative;
    width: 100%;
    height: 100%;
    top: 0;
    left: 0;
    overflow: hidden;
}
#sky {
    position: absolute;
    left: 0;
    top: 0;
    height: 100%;
    width: 100%;
    background: #ccd url(http://jensarps.de/tests/canvas/sky-2.jpg);
}

#floor {
    position: absolute;
    left: 0;
    top: 320px;
    height: 300%;
    width: 100%;
    background: #989898 url(http://jensarps.de/tests/canvas/floor.png) repeat-x;
}
#canvas {
    position: absolute;
    top: 0;
    left: 0;
}
#overlay {
    position: absolute;
    top: 100%;
    left: 50%;
    margin-top: -300px;
    margin-left: -225px;
    width: 100%;
    height: 100%;
    background: url(http://jensarps.de/tests/canvas/overlay.gif) no-repeat;
}

JavaScript

/**
 * This is a slightly modified version of Benjamin Joffe's canvas 3D-Walker.
 *
 * The orgiginal can be found at:
 *
 * http://www.benjoffe.com/code/demos/canvascape/textures
 *
 * The original copyright notice is below.
 *
 * Thanks and enjoy, Jens Arps (http://jensarps.de)
 *
 *
 * Copyright (c) 2009, Benjamin Joffe
 * All rights reserved.
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 *     * Redistributions of source code must retain the above copyright
 *       notice, this list of conditions and the following disclaimer.
 *     * Redistributions in binary form must reproduce the above copyright
 *       notice, this list of conditions and the following disclaimer in the
 *       documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR AND CONTRIBUTORS BE LIABLE FOR ANY
 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

var canvas = document.getElementById("canvas").getContext("2d");
var overlay = document.getElementById("overlay");
var floor = document.getElementById("floor");
var sky = document.getElementById("sky");
//variables initiated at the bottom of the code...

var pixelWidth = 1,
    samples = window.innerWidth,
    texture = 8;

var canvasHeight = canvas.canvas.height =...