Si puo' migiorare comunque....
codice:
<HTML>
<HEAD>
<TITLE></TITLE>
<SCRIPT language="JavaScript" type="text/JavaScript">
<!--
function up() {
common(-5,0);
}
function down() {
common(5,0);
}
function left() {
common(15,15);
}
function right() {
common(20,20);
}
function common(top,left) {
document.getElementById('immagine').style.position="absolute";
document.getElementById('immagine').style.top=parseInt(document.getElementById('immagine').style.top)+top;
document.getElementById('immagine').style.left=parseInt(document.getElementById('immagine').style.left)+left;
}
var tIdX;
function animateX() {
clearTimeout(tIdX);
common(0,1)
tIdX=setTimeout('animateX()', 40);
} // function animateX()
var tDrop;
var tDropFirst = true;
function dropBomb() {
clearTimeout(tDrop);
if (tDropFirst) {
document.getElementById('bomb').style.position = "absolute";
document.getElementById('bomb').style.top = parseInt(document.getElementById('immagine').style.top) + document.getElementById('immagine').height - 6;
document.getElementById('bomb').style.left = parseInt(document.getElementById('immagine').style.left) + parseInt(document.getElementById('immagine').width/2);
tDropFirst = false;
//status = document.getElementById('bomb').style.top + ' - ' + document.getElementById('bomb').style.left;
}
document.getElementById('bomb').style.top = parseInt(document.getElementById('bomb').style.top)+2;
document.getElementById('bomb').style.left = parseInt(document.getElementById('bomb').style.left)+1;
if (! scanTank()) {
tDrop=setTimeout('dropBomb()', 60);
}
}
function scanTank() {
b = document.getElementsByTagName('IMG');
n = b.length;
for (i=0;i<n;i++) {
curImg = b.item(i);
if (curImg.id.substr(0,4) == 'tank') {
posBombX = document.getElementById('bomb').offsetLeft + document.getElementById('bomb').offsetWidth;
posBombY = document.getElementById('bomb').offsetTop + document.getElementById('bomb').offsetHeight;
tankLeft = curImg.offsetLeft;
tankRight = tankLeft + curImg.offsetWidth;
tankUp = curImg.offsetTop;
tankDown = tankUp + curImg.offsetHeight;
status = "posbomb:"+posBombY+'- tank :'+tankUp+'.'+tankDown;
if (posBombX >= tankLeft && posBombX <= tankRight) {
if (posBombY >= tankUp && posBombY <= tankDown) {
document.getElementById('bomb').style.top = -1000;
curImg.src = 'image8.jpg';
return true;
} // if (posBombY >= tankUp && posBombY <= tankDown)
} // if (posBombX >= tankLeft && posBombX <= tankRight)
if (posBombY >= tankDown) {
document.getElementById('bomb').style.top = tankUp;
document.getElementById('bomb').src = "image9.jpg";
return true;
} //
} // if (curImg.id.substr(0,4) == 'tank')
} // for (i=0;i<n;i++)
return false;
} // function scanTank()
//-->
</script>
</HEAD>
<BODY>
[img]Image5.jpg[/img]
[img]Image4.jpg[/img]
[img]Image7.jpg[/img]
[img]Image7.jpg[/img]
[img]Image7.jpg[/img]
<INPUT type="button" name="up" value="UP" onmouseover="up()">
<INPUT type="button" name="down" value="DOWN" onmouseover="down()">
<INPUT type="button" name="left" value="LEFT" onClick="left()">
<INPUT type="button" name="right" value="RIGHT" onClick="right()">
<INPUT type="button" name="start" value="start" onClick="animateX();if (!tDropFirst){dropBomb()};">
<INPUT type="button" name="stop" value="stop" onClick="clearTimeout(tIdX);clearTimeout(tDrop);">
<INPUT type="button" name="drop" value="Drop bomb" onClick="dropBomb();">
</BODY>
</HTML>