Javascript‎ > ‎

Test Ship

var myShip = null, thrusterA = null, thrusterB = null, gyro = null, cannon = null;
var warpDrive = null, laser = null, repairBlock = null;

shipYard.addEventListener('shipAdded', function(event){
    if(event.detail.shipName == "Test"){
        userInterface.setShip(event.detail.ship);
        camera.followBody(event.detail.ship);
   
        myShip = event.detail.ship;
        thrusterA = myShip.getPartAt(1, 2);
        thrusterB = myShip.getPartAt(3, 2);
        gyro = myShip.getPartAt(2, 2);
        cannon = myShip.getPartAt(0, 1);
        warpDrive = myShip.getPartAt(4, 2);
        laser = myShip.getPartAt(1, 0);
        repairBlock = myShip.getPartAt(2, 0);
        
    }
}, false);

shipYard.createShipByInt("Test", [
	[0,	14,	29,	4,	0],
	[20, 13, 13, 1,	16],
	[12, 6,	10,	6,	11]
]);

shipYard.createShipByInt("Target", [
    [1, 1, 1],
    [1, 0, 1],
    [1, 1, 1]
    ]);

document.addEventListener('keyup', onKeyUp);
document.addEventListener('keydown', onKeyDown);

function onKeyUp(event){
    if(myShip === null) return;
    
    if(event.keyCode == 38){
		thrusterA.toggle();
		thrusterB.toggle();
	}
	
	//W pressed
	if(event.keyCode == 87){
	    if(laser !== null){
	       // repairBlock.fire();//.toggle();
	        warpDrive.requestJump(200, 0);
	       // laser.toggle();
	    }
	}
	
	//Left Arrow
	if(event.keyCode == 37){
		gyro.deactivateAnticlockwise();
	}
	
	//F key
	if(event.keyCode == 70){
	    if(cannon !== null){
	        cannon.fire();
	    }
	}
				
	//Right Arrow
	if(event.keyCode == 39){
		gyro.deactivateClockwise();
	}
}

function onKeyDown(event){
	//Left arrow
	if(event.keyCode == 37){
		gyro.activateAnticlockwise();
		gyro.deactivateClockwise();
	}
				
	if(event.keyCode == 39){
		gyro.activateClockwise();
		gyro.deactivateAnticlockwise();
	}
}