101
10-12-2002, 06:53 PM
I made this shooting game but i wish it to have the target moving about in a box (mabey a table of something) becuase other wise it moves about everywhere...like all over the text and then you keep highlighting the text when you try and hit it and so on...
Here is the code:
<html>
<head>
<title>
</title>
<style>
#b {position: absolute; cursor: hand}
</style>
<Script Language=JavaScript>
level = 750;
function Init() {
var xs = screen.availWidth/2;
var ys = screen.availHeight/2;
var x = Math.round(Math.random()*xs);
var y = Math.round(Math.random()*ys);
b.style.pixelLeft = x;
b.style.pixelTop = y;
timer = setTimeout("Init()",level);
}
var count = 0;
var right = 0;
function Right() {
alert("Nice Shot!");
right++;
}
function Count() { count++ }
function Score() {
count--;
pc = Math.round(eval(right*100 / count));
if (isNaN(pc)) { pc = 0 }
alert("Score\n\nShoots : "+ count+"\nHits : " + right +"\nPercentage(%) : "+pc+"");
}
</script>
</head>
<body onmousedown=Count() onload=Init()>
<center>
<b>Shoot The Target</b>
<select name=slc onchange="level=this.value">
<option value=2400 selected>Easy
<option value=1300>Medium
<option value=500>Hard
</select>
<b style="cursor:hand" onclick=Score()>Score</b>
</center>
<br>
<br>
<TABLE border=2 width=980 height=500>
<img src=Shoot.bmp id=b onmousedown=Right()>
</TABLE>
</body>
</html>
Here is the code:
<html>
<head>
<title>
</title>
<style>
#b {position: absolute; cursor: hand}
</style>
<Script Language=JavaScript>
level = 750;
function Init() {
var xs = screen.availWidth/2;
var ys = screen.availHeight/2;
var x = Math.round(Math.random()*xs);
var y = Math.round(Math.random()*ys);
b.style.pixelLeft = x;
b.style.pixelTop = y;
timer = setTimeout("Init()",level);
}
var count = 0;
var right = 0;
function Right() {
alert("Nice Shot!");
right++;
}
function Count() { count++ }
function Score() {
count--;
pc = Math.round(eval(right*100 / count));
if (isNaN(pc)) { pc = 0 }
alert("Score\n\nShoots : "+ count+"\nHits : " + right +"\nPercentage(%) : "+pc+"");
}
</script>
</head>
<body onmousedown=Count() onload=Init()>
<center>
<b>Shoot The Target</b>
<select name=slc onchange="level=this.value">
<option value=2400 selected>Easy
<option value=1300>Medium
<option value=500>Hard
</select>
<b style="cursor:hand" onclick=Score()>Score</b>
</center>
<br>
<br>
<TABLE border=2 width=980 height=500>
<img src=Shoot.bmp id=b onmousedown=Right()>
</TABLE>
</body>
</html>