»
EnglishFrenchVietnamese

Print - Simple Flight Simulator - JavaScriptBank.com

Full version: jsB@nk » Game » Simple Flight Simulator
URL: https://www.javascriptbank.com/simple-flight-simulator.html

Simple Flight Simulator © JavaScriptBank.comA simple flight simulator. Cool.

Full version: jsB@nk » Game » Simple Flight Simulator
URL: https://www.javascriptbank.com/simple-flight-simulator.html



CSS
<STYLE>.struct {BORDER-RIGHT: 1px solid; BORDER-TOP: 1px solid; LEFT: 450px; BORDER-LEFT: 1px solid; WIDTH: 50px; BORDER-BOTTOM: 0px solid; POSITION: absolute; TOP: 0px; HEIGHT: 10px}.missile {BORDER-TOP-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px; FONT-SIZE: 15px; BORDER-BOTTOM-WIDTH: 0px; FONT-FAMILY: verdana; POSITION: absolute; TEXT-ALIGN: center; BORDER-RIGHT-WIDTH: 0px}</STYLE><!--    This script downloaded from www.JavaScriptBank.com    Come to view and download over 2000+ free javascript at www.JavaScriptBank.com-->


JavaScript
<SCRIPT>    var intSpeed = 100;    var intInterval = 0;    var intUserSpeed = 100;    var intLeft=0;    var intRight=0;    var intUp=0;    var intSink=0;    var intMissile=0;    var objMissile;    var intStructInter = 0;    function ignition()    {        generateStructure();    }    intInterval = setInterval("animate()",intSpeed);    intStructInter = setInterval("displayStructure()",2000);    function displayStructure()    {        var fltRandom;        fltRandom = Math.random();        setTimeout('generateStructure()',fltRandom*1000);    }    function animate()    {        var objStruc = document.all['struct'];        for(var i=1; i<objStruc.length;i++)        {            if(objStruc[i].style.display != 'none')            {                objStruc[i].style.top = objStruc[i].style.pixelTop + (objStruc[i].style.pixelTop/10) + 1;                objStruc[i].style.height = objStruc[i].style.pixelHeight + 1;                objStruc[i].style.width = objStruc[i].style.pixelWidth + 3;                objStruc[i].style.left=objStruc[i].style.pixelLeft - 2;                if(intUp!=0)                {                    objStruc[i].style.top = objStruc[i].style.pixelTop + 3;                }                if(intSink!=0)                {                    objStruc[i].style.top = objStruc[i].style.pixelTop - Math.abs(objStruc[i].style.pixelTop/10)+2;                }                if(intLeft!=0)                {                    objStruc[i].style.left=objStruc[i].style.pixelLeft + 6;                }                if(intRight!=0)                {                    objStruc[i].style.left=objStruc[i].style.pixelLeft - 6;                }            }            if(objStruc[i].style.pixelTop > 550)            {                objStruc[i].style.display="none";            }        }        moveMissiles();        if(intSpeed != intUserSpeed)        {            intSpeed = intUserSpeed;            clearInterval(intInterval);            intInterval = setInterval("animate()",intSpeed);            clearInterval(intStructInter);            intStructInter = setInterval("displayStructure()",intSpeed*20);        }    }    function moveMissiles()    {        var objMissile = document.all['missile'];        for(var i=1; i<objMissile.length;i++)        {            if(objMissile[i].style.display != 'none')            {                objMissile[i].style.top = objMissile[i].style.pixelTop - 8;                if(intUp!=0)                {                    objMissile[i].style.top = objMissile[i].style.pixelTop + 5;                }                if(intSink!=0)                {                    objMissile[i].style.top = objMissile[i].style.pixelTop - 3;                }                if(intLeft!=0)                {                    objMissile[i].style.left=objMissile[i].style.pixelLeft + 8;                }                if(intRight!=0)                {                    objMissile[i].style.left=objMissile[i].style.pixelLeft - 8;                }                checkHit(objMissile[i]);            }            if(objMissile[i].style.pixelTop < 0)            {                objMissile[i].style.display="none";            }        }    }    function checkHit(obj)    {        var objStruc = document.all['struct'];        var strMsg = "";        var intX=0;        var intY=0;        for(var i=1; i<objStruc.length;i++)        {            intX = Math.abs(obj.style.pixelLeft - objStruc[i].style.pixelLeft - (objStruc[i].style.pixelWidth/2) +19);            intY = Math.abs(obj.style.pixelTop - objStruc[i].style.pixelTop);            if(intX < 10 && intY < 10 && objStruc[i].style.display != "none")            {                  objStruc[i].style.backgroundColor ="orange";                  setTimeout('destroyStructure(' + i + ')',100);                  obj.style.display="none";            }        }    }    function destroyStructure(intStructId)    {        var objStruc = document.all['struct'];        objStruc[intStructId].style.display="none";    }    function generateStructure()    {        var objPlyAr = document.all['playArea'];        var obj;        var fltRandom;        var objStruc = document.all['struct'];        var intCount=0;        for(var i=1; i<objStruc.length;i++)        {            if(objStruc[i].style.display != "none")            {                intCount++;            }        }        if(intCount>10)        return;        if(objStruc.length>100)        {            document.all['playArea'].innerHTML = "";        }        fltRandom = Math.random();        obj = document.createElement('SPAN');        obj.className="struct";        obj.style.pixelHeight=10;        obj.style.pixelWidth=30;        obj.style.pixelLeft=(fltRandom*800);        obj.innerText = "O";        obj.style.textAlign="center";        obj.id="struct";        objPlyAr.appendChild(obj);    }    function perfAction(intCode)    {        //alert(intCode);        switch(intCode)        {            //"Shift"            case 16:                changeSpeed(1);                break;            //"Ctrl"            case 17:                changeSpeed(-1);                break;            case 37:                intLeft=1;                break;            case 39:                intRight=1;                break;            case 38:                intSink=1;                break;            case 40:                intUp=1;                break;            case 32:                generateMissile();                break;            case 27:                if(intInterval != 0)                {                    clearInterval(intInterval);                    clearInterval(intStructInter);                    intInterval=0;                }                else                {                    intInterval = setInterval("animate()",intSpeed);                    intStructInter = setInterval("displayStructure()",2000);                }                break;            default:                break;        }    }    function clearAction(intCode)    {        switch(intCode)        {            case 37:                intLeft=0;                break;            case 39:                intRight=0;                break;            case 38:                intSink=0;                break;            case 40:                intUp=0;                break;            default:                break;        }    }    function generateMissile()    {        var objPlyAr = document.all['playArea'];        var objGun = document.all['gun'];        var obj;        obj = document.createElement('SPAN');        obj.className="missile";        obj.style.pixelLeft=450;        obj.innerHTML = "<b><font color='gray'>-(</font><font color='red'>O</font><font color='gray'>)-</font></b>";        obj.style.textAlign="center";        obj.id="missile";        obj.style.pixelTop = objGun.style.pixelTop-5;        obj.style.pixelLeft = objGun.style.pixelLeft+5;        objPlyAr.appendChild(obj);        intMissile++;        setTimeout("destroyMissile(" + intMissile + ")",1500);    }    function destroyMissile(intMis)    {        objMissile = document.all['missile'];        objMissile[intMis].innerHTML="<b><font color='gray'>-(</font><font color='blue'>X</font><font color='gray'>)-</font></b>";        setTimeout('objMissile[' + intMis + '].style.display="none"', 300);    }    function changeSpeed(intMode)    {        var objColorInd = document.all['colInd'];        var arrColor = new Array('green','lime','yellow','orange','red');        if(intMode < 0)        {            if(intUserSpeed < 100)            {                intUserSpeed = intUserSpeed + 22.5;            }        }        else        {            if(intUserSpeed > 10)            {                intUserSpeed = intUserSpeed - 22.5;            }        }        for(var i=0; i<((122.5-intUserSpeed)/22.5);i++)        {            objColorInd[4-i].style.backgroundColor = arrColor[i];        }        while(i<5)        {            objColorInd[4-i].style.backgroundColor = 'white';            i++;        }    }</SCRIPT><!--    This script downloaded from www.JavaScriptBank.com    Come to view and download over 2000+ free javascript at www.JavaScriptBank.com-->


HTML
<BODY onkeydown=perfAction(event.keyCode) onkeyup=clearAction(event.keyCode); style="CURSOR: crosshair" onload=ignition();><INPUT id=struct style="DISPLAY: none" type=hidden> <INPUT id=missile style="DISPLAY: none" type=hidden> <DIV id=playArea style="BORDER-RIGHT: 1px solid; BORDER-TOP: 1px solid; LEFT: 10px; OVERFLOW: hidden; BORDER-LEFT: 1px solid; WIDTH: 950px; BORDER-BOTTOM: 1px solid; POSITION: absolute; TOP: 10px; HEIGHT: 550px"></DIV><SPAN id=gun style="BORDER-RIGHT: black 0px solid; BORDER-TOP: black 0px solid; FONT-SIZE: 20px; LEFT: 450px; BORDER-LEFT: black 0px solid; WIDTH: 100px; BORDER-BOTTOM: black 0px solid; FONT-FAMILY: verdana; POSITION: absolute; TOP: 230px; HEIGHT: 100px">[&nbsp;&nbsp;&nbsp;<SPAN id=aimer>x</SPAN>&nbsp;&nbsp;&nbsp;] </SPAN></BODY><!--    This script downloaded from www.JavaScriptBank.com    Come to view and download over 2000+ free javascript at www.JavaScriptBank.com-->