<html>
<head>
<title>Pixel Flyer!</title>
</head>
<script>
if (window.parent.location != location) {
alert("No parenting for you...\n"+window.parent.location+"\n"+location);
location.replace('missing.php');
}
</script>
<body bgcolor="black" text="white">
<div id="thebody" name="thebody" bgcolor="black" style="position: absolute; top: 0; left: 0" width="300" height="150">
<span id="theworm" name="theworm" style="position: absolute; top: 80; left: 0"><img src="images/flyingright.gif"></span>
<span id="thetime" name="thetime" style="position: absolute; top: 155; left: 330">0</span>
<form method='POST' action='pixelscore.php' name='tosend'>
<input type='hidden' name='time' value='0'>
</form>
<script>
//Things used here that wont work in IE:
// -The Set/Get Object Top/Left
// -The decleration for the keypress
// -The way keypresses are checked
//
var n = 0
var nextpixel = 150
var stillgoing = true
var time = 0
function GetObjectLeft(objectname) {
//in NS, these are string variables, like "80px" (the px is pixels)
// we must chop off the px, subtract 10, then add the px back
var obj = document.getElementById(objectname).style;
var answer = 0;
if (obj.left.indexOf("p") != -1){
answer = Number(obj.left.substring(0,obj.left.length-2));
} else {
answer = Number(obj.left); //this is never the case but what the heck
}
return answer;
}
function SetObjectLeft(objectname, newvalue) {
//in NS, these are string variables, like "80px" (the px is pixels)
// we must chop off the px, subtract 10, then add the px back
var obj = document.getElementById(objectname).style;
var answer = 0;
if (obj.left.indexOf("p") != -1){
obj.left = String(newvalue)+"px";
} else {
obj.left = Number(newvalue); //this is never the case but what the heck
}
}
function GetObjectTop(objectname) {
//in NS, these are string variables, like "80px" (the px is pixels)
// we must chop off the px, subtract 10, then add the px back
var obj = document.getElementById(objectname).style;
var answer = 0;
if (obj.top.indexOf("px") != -1){
answer = Number(obj.top.substring(0,obj.top.length-2));
} else {
answer = Number(obj.top); //this is never the case but what the heck
}
return answer;
}
function SetObjectTop(objectname, newvalue) {
//in NS, these are string variables, like "80px" (the px is pixels)
// we must chop off the px, subtract 10, then add the px back
var obj = document.getElementById(objectname).style;
var answer = 0;
if (obj.top.indexOf("px") != -1){
obj.top = String(newvalue)+"px";
} else {
obj.top = Number(newvalue); //this is never the case but what the heck
}
}
function keystuff(e) {
var keyChar = String.fromCharCode(e.which);
var wormname = 'theworm';
var wormtop = GetObjectTop(wormname);
var wormleft = GetObjectLeft(wormname);
if (keyChar == 'w') {
if (wormtop > 0) {
wormtop -= 10;
}
}
if (keyChar == 's') {
if (wormtop < 150) {
wormtop += 10;
}
}
if (keyChar == 'd') {
if (wormleft < 300) {
wormleft += 10;
}
}
if (keyChar == 'a') {
if (wormleft > 0) {
wormleft -= 10
}
}
if (keyChar == 'p') {
alert("Paused. Click OK to continue.")
}
SetObjectTop(wormname, wormtop);
SetObjectLeft(wormname, wormleft);
}
function pixel() {
if (stillgoing) {
var topnum = 80
topnum = Math.round((Math.random()*150)-5.5)
document.getElementById('thebody').innerHTML = document.getElementById('thebody').innerHTML+"<span id='pixel"+n+"' style='position: absolute; top:"+topnum+"; left: 332'>.</span>"
setTimeout("movepixel(\"pixel"+n+"\")", 200)
n++
if (n < 45) {
setTimeout("pixel()", nextpixel)
}
}
}
function timer() {
if (stillgoing) {
time++
document.getElementById('thetime').innerHTML = time
setTimeout("timer()", 1000)
}
}
function movepixel(thepixel) {
if (stillgoing) {
var zeWorm = document.getElementById('theworm').style;
var zePixel = document.getElementById(thepixel).style;
var newtop = Math.round((Math.random()*150)-5.5) //new top for next pixel
var leftvar = Number(zePixel.left.substring(0,zePixel.left.length-2))
var topvar = Number(zePixel.top.substring(0,zePixel.top.length-2))
var wormleft = Number(zeWorm.left.substring(0,zeWorm.left.length-2))
var wormtop = Number(zeWorm.top.substring(0,zeWorm.top.length-2))
if (topvar+12 > wormtop && topvar +12 < wormtop+21 && leftvar > wormleft + 17 && leftvar < wormleft +3
{
alert("You Lose")
stillgoing = false
document.tosend.time.value=time
document.tosend.submit()
}
/*
setTimeout("if (document.getElementById('"+thepixel+"').style.Left > -1) { "+
"document.getElementById('"+thepixel+"').style.Left -= 10"+
"} else {"+
"document.getElementById('"+thepixel+"').style.Left = 332;"+
"document.getElementById('"+thepixel+"').style.Top = "+newtop+" "+
"}", 0)
*/
if (GetObjectLeft(thepixel) > -1) {
SetObjectLeft(thepixel, GetObjectLeft(thepixel) - 10);
} else {
SetObjectLeft(thepixel, 332);
SetObjectTop(thepixel, newtop);
}
setTimeout("movepixel(\""+thepixel+"\")", 200)
}
}
document.captureEvents(1024); //keypress
document.onkeypress = keystuff;
pixel();
timer();
</script>
</div>
</body>
</html>
Your Comments: