| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218 |
- <html>
- <head>
- <script language="JavaScript">
- var speed = 2;
- var scroll_speed = 2;
- var clicked = false;
- var run = false;
- var blocks = new Array('block_0', 'block_1', 'block_2', 'block_3');
- var crash = false;
- var score = 0;
- var highscore = 0;
- var acc = 1;
- var block_w = 30;
- var block_max_h = 100;
- var block_min_h = 10;
- var table_x = 200;
- var table_y = 100;
- var table_w = 460;
- var table_h = 360;
- var heli_x = table_x + table_w / 2;
- var heli_y = table_y + table_h / 2;
- var heli_w = 50;
- var heli_h = 25;
- var heli_border = 3;
- var border = 40;
- function init()
- {
- for(i = 0; i < blocks.length; i++)
- {
- document.getElementById(blocks[i]).x = table_x + (table_w / blocks.length * i);
- document.getElementById(blocks[i]).y = table_y;
- document.getElementById(blocks[i]).w = block_w;
- document.getElementById(blocks[i]).h = 0;
- document.getElementById(blocks[i]).style.backgroundColor = "#00ff00";
- }
- document.getElementById('table').style.left = table_x;
- document.getElementById('table').style.top = table_y;
- document.getElementById('table').style.width = table_w;
- document.getElementById('table').style.height = table_h;
- document.getElementById('border').style.left = table_x-border/2.;
- document.getElementById('border').style.top = table_y-border/2.;
- document.getElementById('border').style.width = table_w-border;
- document.getElementById('border').style.height = table_h-border;
- document.getElementById('border').style.borderWidth = border;
- document.getElementById('score').style.left = table_x + border;
- document.getElementById('score').style.top = table_y + border/2.;
- document.getElementById('highscore').style.left = table_x + border;
- document.getElementById('highscore').style.top = table_y + border/2. + 15;
- if(highscore < score)
- highscore = score;
- document.getElementById('highscore').innerHTML = "Highscore: " + highscore;
- score = 0;
- heli_x = table_x + table_w / 2;
- heli_y = table_y + table_h / 2;
- document.getElementById('heli').style.left = heli_x;
- document.getElementById('heli').style.top = heli_y;
- }
- function main_loop()
- {
- if(clicked)
- heli_y -= speed * acc;
- else
- heli_y += speed * acc;
- for(i = 0; i < blocks.length; i++)
- {
- if(document.getElementById(blocks[i]).x < table_x)
- {
- document.getElementById(blocks[i]).x = (table_w + table_x) - document.getElementById(blocks[i]).w;
- document.getElementById(blocks[i]).y = (Math.random() * table_h) + table_y;
- document.getElementById(blocks[i]).h = Math.random() * block_max_h;
- if(document.getElementById(blocks[i]).h < block_min_h)
- document.getElementById(blocks[i]).h = block_min_h;
- if((document.getElementById(blocks[i]).h + document.getElementById(blocks[i]).y) > (table_h + table_y))
- document.getElementById(blocks[i]).h = (table_h + table_y) - document.getElementById(blocks[i]).y;
-
-
- }
- else
- document.getElementById(blocks[i]).x -= scroll_speed;
- document.getElementById(blocks[i]).style.top = document.getElementById(blocks[i]).y;
- document.getElementById(blocks[i]).style.left = document.getElementById(blocks[i]).x;
- document.getElementById(blocks[i]).style.height = document.getElementById(blocks[i]).h;
- document.getElementById(blocks[i]).style.width = document.getElementById(blocks[i]).w;
- }
- document.getElementById('heli').style.top = heli_y;
- document.getElementById('heli').style.left = heli_x;
- if(check_collision())
- {
- run = false;
- crash = true;
- }
- else
- {
- run = true;
- score++;
- if(acc < 2)
- acc += 0.10;
- document.getElementById('score').innerHTML = "Score: "+score;
- window.setTimeout("main_loop()", 16);
- }
- }
- function check_collision()
- {
- if(heli_y < table_y || (heli_y + heli_h) >= (table_y + table_h))
- return true
- for(i = 0; i < blocks.length; i++)
- {
- if((heli_x + heli_w - heli_border) >= document.getElementById(blocks[i]).x && heli_x + heli_border <= (document.getElementById(blocks[i]).x+document.getElementById(blocks[i]).w))
- x_collision = true;
- else
- x_collision = false;
- if((heli_y + heli_h - heli_border) >= document.getElementById(blocks[i]).y && heli_y + heli_border <= (document.getElementById(blocks[i]).y+document.getElementById(blocks[i]).h))
- y_collision = true;
- else
- y_collision = false;
- if(x_collision && y_collision)
- {
- document.getElementById(blocks[i]).style.backgroundColor = "#ff0000";
- return true;
- }
- }
- return false;
- }
- function fly_up(event)
- {
- if(document.all)
- {
- if(window.event.keyCode == 27 && !run)
- {
- init();
- run = true;
- crash = false;
- main_loop();
- }
- }
- else
- {
- if(event.which == 27 && !run)
- {
- init();
- run = true;
- crash = false;
- main_loop();
- }
- }
- if(!clicked)
- {
- clicked = true;
- acc = 0;
- }
- if(!run && !crash)
- main_loop();
- }
- function fly_down()
- {
- acc = 0;
- clicked = false;
- }
- document.onmousedown = fly_up;
- document.onmouseup = fly_down;
- document.onkeydown = fly_up;
- document.onkeyup = fly_down;
- </script>
- </head>
- <body bgcolor="#ffffff" onload="init();">
- Press any key to fly up, release to drop down. <br/>
- ESC resets the game
- <div id="table" style="position: absolute; background-color: #000000;"> </div>
- <div id="heli" style="position: absolute;"><img src="heli.gif"></div>
- <div id="block_0" style="position: absolute; overflow: hidden; background-color: #00ff00;"></div>
- <div id="block_1" style="position: absolute; overflow: hidden; background-color: #00ff00;"></div>
- <div id="block_2" style="position: absolute; overflow: hidden; background-color: #00ff00;"></div>
- <div id="block_3" style="position: absolute; overflow: hidden; background-color: #00ff00;"></div>
- <div id="score" style="position: absolute; color: #000000; background-color: #0000ff;">Score: 0</div>
- <div id="highscore" style="position: absolute; color: #000000; background-color: #0000ff;">Highscore: 0</div>
- <div id="border" style="position: absolute; background-color: transparent; border-color: gray; border-style: solid;"></div>
- </body>
- </html>
|