src/app.js
// keep camper on edge of activity
keep camper on edge of activity
keep camper on edge of activity
function preventCamperFromPassingActivityBuffer(camper, activity, keyCode) {
        var minBuffer = 5,
            axis, adjustment;
        var insideBoundary = (((camper.boundaries.top) < (activity.boundaries.bottom + 0)) &&
            ((camper.boundaries.left) < (activity.boundaries.right + 0)) &&
            ((camper.boundaries.bottom) > (activity.boundaries.top - 0)) &&
            ((camper.boundaries.right) > (activity.boundaries.left - 0)));
        if (!insideBoundary) return;
        if (keyCode === 38) { 
            axis = "y";
            adjustment = (activity.boundaries.bottom - camper.boundaries.top + minBuffer);
        } else if (keyCode === 39) { 
            axis = "x";
            adjustment = (camper.boundaries.right - activity.boundaries.left + minBuffer) * -1;
        } else if (keyCode === 40) { 
            axis = "y";
            adjustment = (camper.boundaries.bottom - activity.boundaries.top + minBuffer) * -1;
        } else if (keyCode === 37) { 
            axis = "x";
            adjustment = (activity.boundaries.right - camper.boundaries.left + minBuffer);
        } else {
            return;
        }
        camper[axis] += adjustment;
    }
function preventCamperFromPassingActivityBuffer ( camper , activity , keyCode ) { var minBuffer = 5 , axis , adjustment ; var insideBoundary = ( ( ( camper . boundaries . top ) < ( activity . boundaries . bottom + 0 ) ) && ( ( camper . boundaries . left ) < ( activity . boundaries . right + 0 ) ) && ( ( camper . boundaries . bottom ) > ( activity . boundaries . top - 0 ) ) && ( ( camper . boundaries . right ) > ( activity . boundaries . left - 0 ) ) ) ; if ( ! insideBoundary ) return ; if ( keyCode === 38 ) { axis = "y" ; adjustment = ( activity . boundaries . bottom - camper . boundaries . top + minBuffer ) ; } else if ( keyCode === 39 ) { axis = "x" ; adjustment = ( camper . boundaries . right - activity . boundaries . left + minBuffer ) * - 1 ; } else if ( keyCode === 40 ) { axis = "y" ; adjustment = ( camper . boundaries . bottom - activity . boundaries . top + minBuffer ) * - 1 ; } else if ( keyCode === 37 ) { axis = "x" ; adjustment = ( activity . boundaries . right - camper . boundaries . left + minBuffer ) ; } else { return ; } camper [ axis ] += adjustment ; }
keep camper on edge of activity
keep camper on edge of activity
// if camper not inside activity boundaries, then they're just in buffer zone which is OK // up // right // down // left