metanohi-misc-subsites/old-projects/x/game.htm

307 lines
5.7 KiB
HTML
Raw Permalink Normal View History

2011-08-02 19:57:57 +02:00
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3c.org/1999/xhtml" xml:lang="da">
<head>
<title>Kill Thrill</title>
<style type='text/css'>
* {
margin:0;
padding:0;
}
body {
font:12px arial;
background:#000 url('game/space.png');
background-position:0;
font:14px 'trebuchet ms';
color:#fff;
}
#box {
width:200px;
height:150px;
background-color:#000;
background-image:url('game/boxspace.png');
background-attachment:fixed;
background-repeat:repeat-y;
background-position:50% 0;
border:1px solid #fff;
position:absolute;
left:50%;
top:50%;
margin:-75px 0 0 -100px;
overflow:hidden;
}
#info {
width:195px;
height:20px;
background-color:#000;
background-image:url('game/infospace.png');
background-attachment:fixed;
background-repeat:repeat-y;
background-position:50% 0;
border:1px solid #fff;
position:absolute;
left:50%;
top:50%;
margin:-101px 0 0 -100px;
overflow:hidden;
padding-left:5px;
}
#f {
display:inline;
}
#spaceship {
width:20px;
height:15px;
background:url('game/spaceship.png');
position:absolute;
bottom:3px;
left:90px;
z-index:2;
}
#beams div {
height:8px;
width:2px;
background:#ff0000;
position:absolute;
bottom:10px;
left:99px;
}
#beamsound {
position:absolute;
height:1px;
width:1px;
visibility:hidden;
}
#monsters {
position:absolute;
top:2px;
left:6px;
z-index:3;
display:none;
}
#monsters div {
background:url('game/monster.png') no-repeat;
width:20px;
height:15px;
float:left;
margin-right:4px;
margin-bottom:2px;
}
</style>
<script type='text/javascript'>
l=""
r=""
cho=""
c=""
bgc=0
msc=2
var gtleft
var gtright
function startgame() {
shoot()
movebg()
//createmonsters()
//movemonsters()
}
function beamsound() {
document.getElementById("beamsound").Play()
}
function moveship(e) {
ship=document.getElementById("spaceship")
sl=ship.offsetLeft
if (window.event)
keycode=window.event.keyCode
else if (e)
keycode=e.which
if (keycode==37 && l!="y") {
l="y"
goleft()
}
else if (keycode==39 && r!="y") {
r="y"
goright()
}
startfire()
}
function stopship(e) {
ship=document.getElementById("spaceship")
if (window.event)
keycode=window.event.keyCode
else if (e)
keycode=e.which
if (keycode==37) {
clearTimeout(gtleft)
l=""
}
else if (keycode==39) {
clearTimeout(gtright)
r=""
}
endfire()
}
function startfire(e) {
if (window.event)
keycode=window.event.keyCode
else if (e)
keycode=e.which
if (keycode==32 && cho!="y") {
beamsound()
bl=sl+10
bsx=document.getElementById("beams")
fired=document.getElementById("f")
genridn=bsx.innerHTML
genridn=genridn.split("<div id=\"")
genridno=genridn.length-1
genridn=genridn[genridno]
genridn=genridn.split("\" style")
genridn=genridn[0]
genridn=genridn.substr(1,genridn.length-2)
genridn=genridn*1+1
agarr="<div id='a"+genridn+"a' style='left:"+bl+"px'></div>"
fired.innerHTML=fired.innerHTML*1+1
bsx.innerHTML=bsx.innerHTML+agarr
cho="y"
}
}
function endfire(e) {
if (window.event)
keycode=window.event.keyCode
else if (e)
keycode=e.which
if (keycode==32)
cho=""
}
function shoot() {
bsx=document.getElementById("beams")
ms=document.getElementById("monsters")
genridn=bsx.innerHTML
genridn=genridn.split("<div id=\"")
genridno=genridn.length-1
genridn=genridn[genridno]
genridn=genridn.split("\" style")
genridn=genridn[0]
genridn=genridn.substr(1,genridn.length-2)
genridn=genridn*1+1
for (i=0;i<genridn;i++) {
beamx=document.getElementById("a"+i+"a")
if (beamx!=null) {
bt=142-beamx.offsetTop
if (beamx.offsetTop>-8) {
/*
for (i=0;i<ms.childNodes.length;i++) {
node=ms.childNodes[i]
if (node.offsetTop>beamx.offsetTop)
beamx.style.display="none"
}
*/
beamx.style.bottom=bt+1+"px"
}
else if (beamx.offsetTop==-9) {
bsx.removeChild(beamx)
}
}
}
t=setTimeout("shoot()",15)
}
function goleft() {
clearTimeout(gtright)
r=""
if (document.getElementById("spaceship").offsetLeft!=1)
document.getElementById("spaceship").style.left=document.getElementById("spaceship").offsetLeft-1+"px"
gtleft=setTimeout("goleft()",10)
}
function goright() {
clearTimeout(gtleft)
l=""
if (document.getElementById("spaceship").offsetLeft!=177)
document.getElementById("spaceship").style.left=document.getElementById("spaceship").offsetLeft+3+"px"
gtright=setTimeout("goright()",10)
}
function movebg() {
boxfs=document.getElementById("box")
boxin=document.getElementById("info")
boxfs.style.backgroundPosition="50% "+bgc+"px"
boxin.style.backgroundPosition="50% "+bgc+"px"
document.body.style.backgroundPosition=bgc+"px "+bgc+"px"
if (bgc==300) bgc=0
bgc=bgc+1
bgt=setTimeout("movebg()",50)
}
function createmonsters() {
ms=document.getElementById("monsters")
mms=""
msnr=1
msn=msnr*8
for (mmsc=0;mmsc<msn;mmsc++) {
mms=mms+"<div></div>"
}
msns=(msn*2)+msnr
ms.style.marginTop="-"+msns+"px"
ms.innerHTML=mms
ms.style.display="block"
}
function movemonsters() {
ms=document.getElementById("monsters")
for (i=0;i<ms.childNodes.length;i++) {
node=ms.childNodes[i]
node.style.marginTop=msc+"px"
}
msc=msc+2
mst=setTimeout("movemonsters()",500)
}
document.onkeydown=moveship
document.onkeyup=stopship
window.onload=startgame
</script>
</head>
<body>
<object id='beamsound' type='audio/x-wav' data="game/beam.wav">
<param name="src" value="game/beam.wav">
<param name="autoplay" value="false">
<param name="autoStart" value="0">
</object>
<div id='info'>Laser beams fired: <div id='f'>0</div></div>
<div id='box'>
<div id='monsters'><div></div></div>
<div id='spaceship'></div>
<div id='beams'></div>
</div>
</body>
</html>