function World()
{
this.newRun = function()
{
threeworld.init ( "black" );
};
}
const size = 50;
let pos;
let moveUp = false;
let moveDown = false;
let moveLeft = false;
let moveRight = false;
let onKeyDown = function ( event ) {
switch ( event.keyCode ) {
case 38: // up
case 87: // w
moveUp = true;
break;
case 37: // left
case 65: // a
moveLeft = true; break;
case 40: // down
case 83: // s
moveDown = true;
break;
case 39: // right
case 68: // d
moveRight = true;
break;
case 32: // space
if ( canJump === true ) velocity.y += 350;
canJump = false;
break;
}
};
let onKeyUp = function ( event ) {
switch( event.keyCode ) {
case 38: // up
case 87: // w
moveUp = false;
break;
case 37: // left
case 65: // a
moveLeft = false;
break;
case 40: // down
case 83: // s
moveDown = false;
break;
case 39: // right
case 68: // d
moveRight = false;
break;
}
};
function aftersetup()
{
pos = {x:windowWidth/2, y:windowHeight/2};
document.addEventListener( 'keydown', onKeyDown, false );
document.addEventListener( 'keyup', onKeyUp, false );
}
//---- draw -------------------------------------------------------
function draw() // Optional
{
background(0);
rect(pos.x,pos.y,size,size);
}