Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <title>Jet Attack</title>
- <meta name="author" content="Lionel Mertens" />
- <meta name="description" content="JET ATTACK is a simple video game that utilizes web browser SVG capabillities." />
- <meta name="keywords" content="JET ATTACK!" />
- <!-- for-mobile-apps -->
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
- <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
- <!-- //for-mobile-apps -->
- <style>
- body{margin:0px;
- overflow-x:hidden;
- overflow-y:hidden;
- background-color:#000;
- }
- #battleZone {
- height:100%;
- width:100%;
- margin:0;
- overflow-x:hidden;
- }
- svg#jet {
- position:absolute;
- display:block;
- stroke:#000;
- stroke-width:0.2;
- fill:transparent;
- margin-right:-75px;
- top:0;
- right:0;
- }
- svg#rocket {
- position:absolute;
- display:block;
- margin:0 calc(50% - 20px);
- stroke:#000;
- stroke-width:0.2;
- fill:transparent;
- bottom:22px;
- }
- #flame,
- #wreckage,
- #blast {display:none;}
- #panel {
- position:absolute;
- display:inline-block;
- margin:0 calc(50% - 137px);
- width:274px;
- height:25px;
- bottom:2px;
- }
- .stats {
- position:relative;
- display:inline-block;
- width:100px;
- height:25px;
- line-height:25px;
- padding:0;
- margin:0 4px;
- background-color:#fff;
- border-radius:2px;
- text-align:left;
- text-indent:6px;
- font-family:sans-serif;
- font-size:13px;
- font-weight:normal;
- letter-spacing:1px;
- }
- #kills {
- float:left;
- }
- #rockets {
- float:right;
- }
- #btn {
- display:inline-block;
- margin:0 auto;
- width:auto;
- line-height:20px;
- text-align:center;
- background-color:#008080;
- border:1px solid #008080;
- border-radius:3px;
- padding:0 8px;
- color:#FFF;
- font-family: 'Arial', Helvetica, Sans-Serif;
- font-size:14px;
- font-weight:300;
- text-decoration:none;
- letter-spacing:2px;
- box-shadow:0px 0px 2px 2px cyan;
- }
- #btn:hover {color:cyan;}
- #btn:focus {outline:none;}
- #btn:active {
- box-shadow:0px 0px 3px 3px cyan, 0px 0px 2px 2px lime;
- color:#FFF;}
- </style>
- <script>
- rocketHeight = 72;
- buttonHeight = 20;
- jetHeight = 20;
- deductions = rocketHeight + buttonHeight + jetHeight;
- fired = 'false';
- flightWidth = screen.availWidth + 75;
- screenWidth = screen.availWidth;
- screenHeight = screen.availHeight;
- deadCenter = screenWidth / 2;
- flightDirection = -5;
- topSpacer = 100;
- bottomSpacer = 300;
- rocketSpot = 0;
- kills = 0;
- rockets = 100;
- flyBys = 0;
- flightData = new Array (
- -1,1,1,7,
- 0,1,1,0,
- 1,1,1,-7,
- -1,1,-1,-7,
- 0,1,-1,0,
- 1,1,-1,7,
- -1,-1,1,7,
- 0,-1,1,0,
- 1,-1,1,-7,
- -1,-1,1,7,
- 0,1,1,180,
- 1,1,1,187
- );
- function randomize(min, max){
- return Math.floor(Math.random() * (max - min)) + min;
- }
- function flightPlan(adjuster) {
- var randNum = 4 * (randomize(0,6));
- var i = randNum + adjuster;
- step = flightData[i];
- scaaleX = flightData[i+1];
- scaaleY = flightData[i+2];
- rotation = 'rotate('+flightData[i+3]+'deg)';
- if(step != -1){topSpacer = 10;bottomSpacer = 400;}
- else{topSpacer = 300;bottomSpacer = 100;}
- var randNum = randomize(topSpacer,(screenHeight - bottomSpacer));
- trajectory = randNum;
- }
- function postStats(ID,TEXT) {
- document.getElementById(ID).innerHTML=TEXT;
- }
- function takeOff(){
- alert('Welcome to JET ATTACK\!\nYou have 100 rockets to shoot down as many jets as you can.\nGood Luck!\nPress \'OK\' to play JET ATTACK\!');
- postStats('kills','Kills: '+kills);
- postStats('rockets','Rockets: '+rockets);
- displayId('jet','block');
- flightLength = -75;
- stopFlight = setInterval(flyLeft,0010);
- flightPlan(0);
- }
- function propelJet() {
- var r = 'matrix('+scaaleX+',0,0,'+scaaleY+','+flightLength+','+trajectory+') '+rotation;
- styleTransform('jet',r);
- flightLength = flightLength + flightDirection;
- trajectory = trajectory + step;
- }
- function flyLeft() {
- if(flightLength > -flightWidth){
- propelJet();
- }
- else {
- clearInterval(stopFlight);
- flyBys++;
- stopFlight = setInterval(flyRight,0010);
- flightDirection = 5;
- flightPlan(24);
- }
- }
- function flyRight() {
- if(flightLength < 0){
- propelJet();
- }
- else {
- clearInterval(stopFlight);
- flyBys++;
- stopFlight = setInterval(flyLeft,0010);
- flightDirection = -5;
- flightPlan(0);
- }
- }
- function fireRocket() {
- if(fired == 'true'){return;}
- else{
- rocketPath = 0;
- fired = 'true';
- displayId('flame','block');
- rockets--;
- postStats('rockets','Rockets: '+rockets);
- stopRocket = setInterval(propelRocket,0002);
- }
- }
- function crashLand() {
- if(trajectory < screenHeight){
- var rot = 'rotate('+cartWheel+'deg)';
- var c = 'matrix('+scaaleX+',0,0,'+scaaleY+','+flightLength+','+trajectory+') '+rot;
- styleTransform('jet',c);
- flightLength = flightLength + flightDirection;
- trajectory = trajectory + step;
- cartWheel = cartWheel + (flightDirection * 2);
- }
- else{clearInterval(
- stopCrash);
- resetRocket();
- flyBys++;
- stopFlight = setInterval(flyLeft,0010);
- displayId('fuselage','block');
- displayId('thruster','block');
- displayId('wreckage','none');
- flightLength = -75;
- flightDirection = -5;
- flightPlan(0);
- }
- }
- function afterMath() {
- displayId('blast','none');
- displayId('fuselage','none');
- displayId('thruster','none');
- displayId('wreckage','block');
- cartWheel = flightDirection;
- stopCrash = setInterval(crashLand,0030);
- clearInterval(stopFlight);
- step = 15;
- }
- function resetRocket(){
- if(rockets < 1){
- clearInterval(stopFlight);
- alert('Congratulations you shot down '+kills+' jets.\nIn '+flyBys+' flyBys.');
- window.location.reload(false);
- }
- rocketPath = 0;
- var m = 'matrix(1,0,0,1,'+rocketSpot+','+rocketPath+')';
- styleTransform('rocket',m);
- toggleRocket('block');
- fired = 'false';
- }
- function propelRocket(){
- var rocketY = (screenHeight - deductions) + rocketPath;
- var killZoneLeft = deadCenter + 74;
- var killZoneRight = deadCenter - 9;
- var killZoneTop = trajectory + 6;
- var killZoneBottom = trajectory - 6;
- if((-flightLength < killZoneLeft) && (-flightLength > killZoneRight) && (rocketY > killZoneBottom) && (rocketY < killZoneTop)){
- clearInterval(stopRocket);
- toggleRocket('none');
- displayId('blast','block');
- kills++;
- postStats('kills','Kills: '+kills);
- setTimeout(afterMath,0300);
- }
- if(rocketPath > -screenHeight){
- var m = 'matrix(1,0,0,1,'+rocketSpot+','+rocketPath+')';
- styleTransform('rocket',m);
- rocketPath = rocketPath - 5;
- }
- else{
- clearInterval(stopRocket);
- resetRocket();
- }
- }
- function toggleRocket(status){
- rocketParts = new Array ('rocket-body','fin','flame');
- displayId('rocket-body',status);
- displayId('fin',status);
- displayId('flame','none');
- }
- function displayId(ID,DISPLAY) {
- document.getElementById(ID).style.setProperty('display',DISPLAY);
- }
- function styleTransform(ID,TRANS){
- document.getElementById(ID).style.transform=TRANS;
- }
- function shiftRocket(shift){
- rocketSpot = rocketSpot + shift;
- deadCenter = deadCenter + shift;
- var m = 'matrix(1,0,0,1,'+rocketSpot+','+rocketPath+')';
- styleTransform('rocket',m);
- }
- </script>
- </head>
- <body onload="takeOff()">
- <div id="battleZone">
- <svg id="jet" width="75" height="15" viewBox="0 0 50 10">
- <defs>
- <pattern id="fuselage" width="50" height="10" patternUnits="userSpaceOnUse">
- <polyline fill="lime" points="0,7 7,5.6 12,5.7 15,5.3 18.2,4 23,6 35,6 43,0 45,0 40.5,9 32,9.8 15,10 7,9.1 0,7">
- </polyline>
- </pattern>
- <pattern id="wreckage" width="50" height="10" patternUnits="userSpaceOnUse">
- <polyline fill="#555" points="0,7 7,5.6 12,5.7 15,5.3 18.2,4 23,6 35,6 43,0 45,0 40.5,9 32,9.8 35,6 15,5.3 15,10 7,9.1 0,7">
- </polyline>
- </pattern>
- <pattern id="thruster" width="50" height="10" patternUnits="userSpaceOnUse">
- <polyline stroke-width=".4" stroke="orange" fill="yellow" points="40.6,8 50,7 41.9,6">
- </polyline>
- </pattern>
- <pattern id="wing" width="50" height="10" patternUnits="userSpaceOnUse">
- <polyline stroke-width=".5" points="15,7.9 28,8.2 ">
- </polyline>
- </pattern>
- <pattern id="cockpit" width="50" height="10" patternUnits="userSpaceOnUse">
- <polyline fill="white" stroke-width=".3" points="7,5.6 11,3.5 12.5,3 14,2.8 16,3 18.2,4 15,5.3 12,5.7">
- </polyline>
- </pattern>
- <pattern id="tail" width="50" height="10" patternUnits="userSpaceOnUse">
- <polyline stroke-width=".5" points="36,7 41,6.8">
- </polyline>
- </pattern>
- </defs>
- <rect x="0" y="0" width="50" height="10" stroke-width="0" fill="url(#fuselage)" />
- <rect x="0" y="0" width="50" height="10" stroke-width="0" fill="url(#wreckage)" />
- <rect x="0" y="0" width="50" height="10" stroke-width="0" fill="url(#wing)" />
- <rect x="0" y="0" width="50" height="10" stroke-width="0" fill="url(#cockpit)" />
- <rect x="0" y="0" width="50" height="10" stroke-width="0" fill="url(#tail)" />
- <rect x="0" y="0" width="50" height="10" stroke-width="0" fill="url(#thruster)" />
- </svg>
- <svg id="rocket" width="40" height="40" viewBox="0 0 25 25">
- <defs>
- <pattern id="rocket-body" width="25" height="25" patternUnits="userSpaceOnUse">
- <polyline fill="red" points="12.5,0 13.5,2 13.5,14 15.5,17 15.5,20 13.5,20 13.5,19 12.5,18 11.5,19 11.5,20 9.5,20 9.5,17 11.5,14 11.5,2 12.5,0 ">
- </polyline>
- </pattern>
- <pattern id="fin" width="25" height="25" patternUnits="userSpaceOnUse">
- <polyline fill="red" stroke-width=".1" points="12.1,15.5 12.5,14 12.9,15.5 12.9,20 12.1,20 12.1,15.5">
- </polyline>
- </pattern>
- <pattern id="flame" width="25" height="25" patternUnits="userSpaceOnUse">
- <polyline fill="yellow" stroke="orange" stroke-width=".4" points="11.5,20 12.5,25 13.5,20">
- </polyline>
- </pattern>
- <pattern id="explosion" width="25" height="25" patternUnits="userSpaceOnUse">
- <circle cx="12.5" cy="12.5" r="6.5" fill="red" />
- </pattern>
- <pattern id="explosion2" width="25" height="25" patternUnits="userSpaceOnUse">
- <circle cx="12.5" cy="12.5" r="7.5" stroke="DarkOrange" stroke-width="2.8" fill="url(#explosion" />
- </pattern>
- </defs>
- <rect x="0" y="0" width="25" height="25" stroke-width="0" fill="url(#rocket-body)" />
- <rect x="0" y="0" width="25" height="25" stroke-width="0" fill="url(#fin)" />
- <rect x="0" y="0" width="25" height="25" stroke-width="0" fill="url(#flame)" />
- <circle id="blast" stroke="yellow" stroke-width="1" cx="12.5" cy="12.5" r="10" fill="url(#explosion2)" />
- </svg>
- <div id="panel">
- <div class="stats" id="kills"></div>
- <button id="btn" onclick="fireRocket()">Fire!</button>
- <div class="stats" id="rockets"></div>
- </div>
- </div>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment