metanohi-misc-subsites/projects/gt3000/index.htm

752 lines
13 KiB
HTML

<!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">
<head>
<title>GT 3000</title>
<style type='text/css'>
* {
margin:0;
padding:0;
}
body {
background:#a7a6aa;
}
#info {
width:561px;
height:181px;
border:2px solid #000;
position:absolute;
top:50%;
left:50%;
margin-top:-200px;
margin-left:-320px;
background:#fff url(logo.png) no-repeat;
z-index:3;
padding:210px 5px 5px 70px;
font:18px arial;
color:#ff0000;
}
h1 {
font:bold 22px arial;
}
p {
background:url(tire.png) no-repeat;
padding-left:20px;
}
#lp {
position:absolute;
left:5px;
bottom:5px;
font:18px tahoma;
color:#000;
}
#lp.play {
font-size:30px;
color:#0000ff;
cursor:pointer;
}
#lp.play:hover {
color:#008dff;
}
#screen {
width:636px;
height:396px;
border:2px solid #000;
position:absolute;
top:50%;
left:50%;
margin-top:-200px;
margin-left:-320px;
background:#ffcb66;
z-index:2;
}
#screen img {
position:absolute;
height:1px;
display:none;
}
#nfa {
position:absolute;
left:5px;
top:5px;
font:14px arial;
font-style:italic;
color:#444;
}
#dcc {
position:absolute;
left:5px;
top:20px;
font:16px arial;
color:#000;
}
#nfb {
position:absolute;
left:5px;
top:50px;
font:14px arial;
font-style:italic;
color:#444;
}
#dcl {
position:absolute;
left:5px;
top:65px;
font:16px arial;
color:#000;
}
#nfc {
position:absolute;
left:5px;
top:95px;
font:14px arial;
font-style:italic;
color:#444;
}
#spd {
position:absolute;
left:5px;
top:110px;
font:16px arial;
color:#000;
}
#nfd {
position:absolute;
left:5px;
top:140px;
font:14px arial;
font-style:italic;
color:#444;
}
#tim {
position:absolute;
left:5px;
top:155px;
font:16px arial;
color:#000;
}
#nfe {
position:absolute;
left:5px;
top:185px;
font:14px arial;
font-style:italic;
color:#444;
}
#til {
position:absolute;
left:5px;
top:200px;
font:16px arial;
color:#000;
}
#msgtop {
position:absolute;
right:10px;
top:10px;
height:36px;
width:150px;
background:url(msgs.png) no-repeat;
}
#msgsbox {
position:absolute;
right:10px;
top:46px;
height:331px;
width:138px;
padding:3px 6px 6px 6px;
background:url(msgsbox.png) no-repeat;
font:12px verdana;
color:#000;
overflow:hidden;
}
.spla {
width:138px;
height:1px;
background:#000;
margin:5px 0 0 0;
}
.splb {
width:138px;
height:1px;
background:#fff;
margin:0 0 5px 0;
}
#lvlnfo {
display:none;
position:absolute;
left:271px;
top:173px;
width:90px;
height:50px;
text-align:center;
background:#000;
opacity:.75;
filter:alpha(opacity=75);
-moz-opacity:.75;
color:#fff;
font:20px tahoma;
}
#end {
width:100px;
height:8px;
}
#focus {
width:100px;
height:100px;
border:0;
position:absolute;
left:50%;
top:50%;
margin-left:-50px;
margin-top:-50px;
}
#clvl {
position:absolute;
left:330px;
top:5px;
font:bold 18px arial;
}
#nfall {
position:absolute;
top:30px;
left:275px;
font:italic 30px tahoma;
}
</style>
<script type='text/javascript'>
/*
This program is free software. It comes without any warranty, to
the extent permitted by applicable law. You can redistribute it
and/or modify it under the terms of the Do What The Fuck You Want
To Public License, Version 2, as published by Sam Hocevar. See
http://sam.zoy.org/wtfpl/COPYING for more details.
*/
cdo=0
cd=0
ccdw=false
cno=false
wi=0
tie=true
sw=true
dc=0
cdsec=-1
timmove=50
pixmove=0
naccelerate=false
ndeaccelerate=false
nbrake=false
clvl=0
mtt=false
cntt=false
speedt=false
wfs=false
fnmsg=true
gmpaused=false
rgmpaused=false
ci=0
spdcd=0
tftl=null
dcla=null
cnttrun=true
speedtrun=true
function nmsg(stxt) {
if (fnmsg) {
fnmsg=false
spl=""
}
else spl="<div class='spla'></div><div class='splb'></div>"
msgsbox.scrollTop-=1000000
msgsbox.innerHTML=stxt+spl+msgsbox.innerHTML
}
function roundd(num) {
num=""+num+""
nr=num.split(".")
nr=nr[0]
return nr
}
function bmovetrack() {
if (sw) {sw=false;setTimeout("bmovetrack()",500)}
else {
document.title="GT 3000"
/*lpelm=document.getElementById("lp")
lpelm.innerHTML="Play!"
lpelm.onclick=function(){nfoelm.style.display="none";movetrack()}
lpelm.className="play"*/
nfoelm.style.display="none"
nfa=document.createElement("div")
nfa.id="nfa"
nfa.innerHTML="Distance covered"
dcc=document.createElement("div")
dcc.id="dcc"
nfb=document.createElement("div")
nfb.id="nfb"
nfb.innerHTML="Distance left"
dcl=document.createElement("div")
dcl.id="dcl"
nfc=document.createElement("div")
nfc.id="nfc"
nfc.innerHTML="Speed"
spd=document.createElement("div")
spd.id="spd"
nfd=document.createElement("div")
nfd.id="nfd"
nfd.innerHTML="Time passed"
tim=document.createElement("div")
tim.id="tim"
nfe=document.createElement("div")
nfe.id="nfe"
nfe.innerHTML="Time left"
til=document.createElement("div")
til.id="til"
scrnelm.appendChild(nfa)
scrnelm.appendChild(dcc)
scrnelm.appendChild(nfb)
scrnelm.appendChild(dcl)
scrnelm.appendChild(nfc)
scrnelm.appendChild(spd)
scrnelm.appendChild(nfd)
scrnelm.appendChild(tim)
scrnelm.appendChild(nfe)
scrnelm.appendChild(til)
msgtop=document.createElement("div")
msgtop.id="msgtop"
msgsbox=document.createElement("div")
msgsbox.id="msgsbox"
msgsbox.innerHTML="<div id='end'></div>"
scrnelm.appendChild(msgtop)
scrnelm.appendChild(msgsbox)
lvlnfo=document.createElement("div")
lvlnfo.id="lvlnfo"
scrnelm.appendChild(lvlnfo)
currentlevel=document.createElement("div")
currentlevel.id="clvl"
currentlevel.innerHTML="LEVEL 1"
scrnelm.appendChild(currentlevel)
document.onkeydown=kda
document.onkeyup=kua
lvlselect()
}
}
function lvlselect() {
if (wfs) {
wfs=false
setTimeout("lvlselect()",1000)
}
else {
clearTimeout(mtt)
clearTimeout(cntt)
clearTimeout(speedt)
cnttrun=false
speedtrun=false
if (clvl<lvllength) {
cd=0
cdo=0
ccdw=false
cno=false
cdsec=-1
timmove=50
pixmove=0
naccelerate=false
ndeaccelerate=false
nbrake=false
dc=0
tb=true
tim.innerHTML="0 sec"
til.innerHTML=ttwan(lvl[clvl][1])
currentlevel.innerHTML="LEVEL "+(clvl+1)
for (i=0;i<smsgslength;i++) {
if (!smsgs[i][2]) smsgs[i][3]=false
}
movetrack()
lvlc=3
lvlnfo.style.display="block"
lvlstart()
}
else {
alert("Well done!\nThere's nothing more you can do now.")
}
}
}
function lvlstart() {
if (lvlc>-1) {
if (lvlc>0) lvlcc=lvlc
else lvlcc="START"
lvlnfo.innerHTML="LEVEL "+(clvl+1)+"<br />"+lvlcc
lvlc--
setTimeout("lvlstart()",1000)
}
else {
tb=false
lvlnfo.innerHTML=""
lvlnfo.style.display="none"
cnttrun=true
speedtrun=true
bncnt()
speed()
}
}
function speed() {
if (speedtrun) {
if (naccelerate && pixmove<14) {
pixmove++
rfspd=spdcd*5+300
}
else if (ndeaccelerate && pixmove>0) {
pixmove--
rfspd=1000-spdcd*10
}
else if (nbrake && pixmove>0) {
pixmove--
rfspd=200-spdcd*5
}
else rfspd=1
speedt=setTimeout("speed()",rfspd)
}
}
function bncnt() {
if (cnttrun) {
cdsec++
tim.innerHTML=ttwan(cdsec)
tftl=lvl[clvl][1]-cdsec
til.innerHTML=ttwan(tftl)
if (tftl==0) {
nmsg("You failed level "+(clvl+1)+". Restarting...")
wfs=true
lvlselect()
}
else cntt=setTimeout("bncnt()",1000)
}
}
function kda(e) {
if (window.event) kc=window.event.keyCode
else if (e) kc=e.which
else return
if (kc==38 && !naccelerate) {
naccelerate=true
ndeaccelerate=false
nbrake=false
}
else if (kc==40 && !nbrake) {
naccelerate=false
ndeaccelerate=false
nbrake=true
}
else if (kc==33) {
msgsbox.scrollTop-=10
}
else if (kc==34) {
msgsbox.scrollTop+=10
}
else if (kc==80 && !gmpaused && !tb) {
gmpaused=true
if (rgmpaused) {
rgmpaused=false
movetrack()
bncnt()
speed()
}
else {
rgmpaused=true
clearTimeout(mtt)
clearTimeout(cntt)
clearTimeout(speedt)
}
}
}
function kua(e) {
if (window.event) kc=window.event.keyCode
else if (e) kc=e.which
else return
if (((kc==38 && naccelerate) || (kc==40 && nbrake)) && !ndeaccelerate) {
naccelerate=false
ndeaccelerate=true
nbrake=false
}
else if (kc==80) gmpaused=false
}
function ttwan(ssec) {
if (ssec<60) cdsecr=ssec+" sec"
else {
rcs=roundd(ssec/60)
xtrs=ssec-rcs*60
if (xtrs==0) xtrs=""
else xtrs+=" sec"
cdsecr=rcs+" min "+xtrs
}
return cdsecr
}
function movetrack() {
focuspush.focus()
spci=0
while (spci<1) {
cdw=false
if (ccdw) {
cdw=true
}
if (cno) {
cno=false
cdo=0
}
odw=cdw
for (i=395;i>-1;i--) {
if (!cno) {
if (cdw) {
selm[i][0].style.display="block"
selm[i][1].style.display="none"
}
else {
selm[i][0].style.display="none"
selm[i][1].style.display="block"
}
if (cd==0) {
if (i==395) cdoi=cdo
else cdoi=0
cd=Math.round(i/5+cdoi)
if (cd<0) {
cno=true
if (odw) ccdw=false
else ccdw=true
}
else {
spci++
}
if (cdw) cdw=false
else cdw=true
if (i==395) cdw=ccdw
}
else cd--
}
}
cdo-=pixmove
dc+=pixmove
dcca=roundd(dc/100)
dcc.innerHTML=dcca+" m"
if (clvl>lvllength-1) clvl=lvllength-1
dcla=lvl[clvl][0]-dcca
dcl.innerHTML=dcla+" m"
spdcd=(pixmove/100000)*((1000/timmove)*3600)
spd.innerHTML=roundd(spdcd)+" km/h"
cd=0
}
for (i=0;i<smsgslength;i++) {
seval="if ("+smsgs[i][0]+" && !smsgs[i][3]) {smsgs[i][3]=true;nmsg(\""+smsgs[i][1]+"\")}"
eval(seval)
}
if (dcla==0 && tftl>0) {
if (lvllength>clvl+1) tbpm="Starting level "+(clvl+2)
else {
tbpm="You completed all "+lvllength+" levels! Quitting"
clearTimeout(mtt)
clearTimeout(cntt)
clearTimeout(speedt)
}
nmsg("You cleared level "+(clvl+1)+". "+tbpm+"...")
wfs=true
cdsec=-1
clvl++
lvlselect()
}
else mtt=setTimeout("movetrack()",timmove)
}
function imgload() {
if (selm[wi][0].width>0 && selm[wi][1].width>0) {
wi++
lpbelm.innerHTML="Loading images: "+Math.round(wi/396*100)+"%"
}
if (wi<396) setTimeout("imgload()",1)
else {
lpbelm.innerHTML="Loading images: "+Math.round(wi/396*100)+"%"
bmovetrack()
}
}
function createtrack() {
sw[ci]=ci+1
selm[ci]=new Array()
for (ii=0;ii<2;ii++) {
selm[ci][ii]=document.createElement("img")
selm[ci][ii].style.top=ci+"px"
selm[ci][ii].style.left=((636-sw[ci])/2-ci/4)+"px"
selm[ci][ii].style.width=sw[ci]+"px"
selm[ci][ii].src=ii+".png"
scrnelm.appendChild(selm[ci][ii])
lpaelm.innerHTML="Loading track: "+Math.round(scrnelm.innerHTML.length/51544*100)+"%"
}
if (ci<395) {
ci++
setTimeout("createtrack()",1)
}
}
function gameload() {
if (tie) {
tie=false
setTimeout("gameload()",1)
}
else {
selm=new Array()
sw=new Array()
focuspush.focus()
createtrack()
imgload()
}
}
function load() {
nfoelm=document.getElementById("info")
scrnelm=document.getElementById("screen")
focuspush=document.getElementById("focus")
lpelm=document.getElementById("lp")
lpaelm=document.getElementById("lpa")
lpbelm=document.getElementById("lpb")
inselm=document.getElementById("ins")
nfall=document.getElementById("nfall")
// //
// SPECIAL MESSAGES //
// //
smsgs=new Array()
//0=if...
//1=message
//2=display only once?
smsgs[0]=new Array()
smsgs[0][0]="roundd(spdcd)==10"
smsgs[0][1]="You reached the top speed!"
smsgs[0][2]=true
smsgs[1]=new Array()
smsgs[1][0]="tftl==10"
smsgs[1][1]="Only 10 seconds left. Hurry!"
smsgs[1][2]=false
smsgs[2]=new Array()
smsgs[2][0]="dcla==10"
smsgs[2][1]="Only 10 meters more. You can do it!"
smsgs[2][2]=false
smsgs[3]=new Array()
smsgs[3][0]="roundd(spdcd)>0 && nbrake"
smsgs[3][1]="You learnt how to brake!"
smsgs[3][2]=true
smsgslength=smsgs.length
for (i=0;i<smsgslength;i++) {
smsgs[i][3]=false
}
// //
// LEVELS //
// //
lvl=new Array()
//0=DISTANCE
//1=TIME
lvl[0]=new Array()
lvl[0][0]=5
lvl[0][1]=15
lvl[1]=new Array()
lvl[1][0]=11
lvl[1][1]=20
lvl[2]=new Array()
lvl[2][0]=18
lvl[2][1]=22
lvl[3]=new Array()
lvl[3][0]=30
lvl[3][1]=33
lvl[4]=new Array()
lvl[4][0]=40
lvl[4][1]=38
lvl[5]=new Array()
lvl[5][0]=50
lvl[5][1]=39
lvl[6]=new Array()
lvl[6][0]=70
lvl[6][1]=40
lvllength=lvl.length
nfall.innerHTML=lvllength+" levels!"
if (navigator.appName!="Netscape") {
inselm.innerHTML="<p>Use Firefox as your default browser.</p>\n"+inselm.innerHTML
lpaelm.innerHTML="Not loading track"
lpbelm.innerHTML="Not loading images"
return
}
else gameload()
}
window.onload=load
</script>
</head>
<body>
<textarea id='focus'></textarea>
<div id='info'>
<h1>Instructions:</h1>
<div id='ins'>
<p>Press "P" to pause the game.</p>
<p>Control the (invisible) car with the arrow keys.</p>
<p>Press "Page Up" or "Page Down" to scroll the message box.</p>
</div>
<div id='lp'>
<div id='lpa'>Loading track: 0%</div>
<div id='lpb'>Loading images: 0%</div>
</div>
<div id='nfall'></div>
</div>
<div id='screen'></div>
</body>
</html>