PDA

View Full Version : Javascript code for game isn't working


chellyville
12-18-2003, 07:28 PM
can someone please help me figure out how to make the script work?? if you press START the little ball in the court does't bounce all over the place, it just moves a tiny bit. i re-coded it so it could fit nicely in my i-frame, so i think that may be part of the problem of why it isn't working. here (http://www.geocities.com/chellyville/you/game1.html)'s the link to the page were the game is on my webpage. & here (http://webdeveloper.earthweb.com/webjs/jsgame/item.php/251591)'s the link to the page were i found the game, which provided how the original script looks like & all. & below is a large chunck of teh re-coded code (as it appears in my webpage, not the original format of it). i hoep i didn't comfuse anyone & someone is willing to help me out. thanks i advance.

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

<meta name="description" content="simple javascript game,crazy balls">
<meta name="keywords" content="crazy balls">
<meta name="author" content="Stefano Molinari">


<script language="JavaScript" type="text/javascript">

var vel=15 /* ogni qanti millisec il ciclo si ripete */
var hitDist=8 /* determina il raggio entro il quale si è colpiti*/
var angL=1;
var angT=1;
var TotPalle=4 /*Numero tot di palle avversarie*/
var valAng = 500 /* ogni quanti cicli cambio vel e angolo */
var numpalle=1;
var turno=1; /*contatore per il punteggio e l`angolazione */
var xturno=1; /*contatore per ingresso di nuove palle ogni 800 xturni*/
var liv=4 /* determina di qunto velocemente si muove la palla grande*/
var cambioang=1; /* contatore per il cambio angolazione */
var stepL = new Array(1,1,1,1);/* step di ogni palla*/
var stepT = new Array(1,1,1,1);/* step di ogni palla*/
var colpito = "no"

function gioca()
{

for (i=0; i<numpalle; i++)
{
palla=document.images[i].style;

/* controllo che la palla resti nel quadrato */
if ( palla.posLeft+(stepL[i]*angL) >= 392 )
{stepL[i]=stepL[i]*(-1)}
else if ( palla.posLeft+(stepL[i]*angL) <= 404 )
{stepL[i]=stepL[i]*(-1)}
else if ( palla.posTop+(stepT[i]*angT) <= 360 )
{stepT[i]=stepT[i]*(-1)}
else if ( palla.posTop+(stepT[i]*angT) >= 292 )
{stepT[i]=stepT[i]*(-1)}
else
palla.posLeft = palla.posLeft+(stepL[i]*angL);
palla.posTop = palla.posTop+(stepT[i]*angT)
var Bigball = document.images[TotPalle].style
var xLeft= Bigball.posLeft-palla.posLeft
var xTop = Bigball.posTop-palla.posTop
if (xLeft<0){xLeft=xLeft*(-1)};
if (xTop<0){xTop=xTop*(-1)}
if ( (xTop <= hitDist) && (xLeft <= hitDist) )
{
azzera()
return true
}

} /* fine ciclo for */

if ( cambioang == valAng - 50 ) {document.images[TotPalle+6].style.zIndex=3}
if ( cambioang == 2 ) {document.images[TotPalle+6].style.zIndex=1}

if (cambioang == valAng)
{
angL=AngCasuale()
angT=AngCasuale()
cambioang=0
}

if (xturno == 600 && numpalle < TotPalle)
{
numpalle++
xturno = 1
inizializza(numpalle)/*porto la nuova palla in gioco*/
}
if (numpalle < TotPalle) {scoreform.xturno.value = 600-xturno}


if ( turno == 30000 ){return true}
scoreform.score.value = turno

turno++
xturno++
cambioang++
window.setTimeout("gioca()",vel)

}/* end funz gioca */

function AngCasuale()
{
var x= Math.random()
x = x.toString()
x = x.substr(2,1)
if(x=="0" || x== "1" || x== "2" || x== "3"){x=1}
else if ( x== "4" || x== "5" || x== "6" || x=="7" ){x=2}
else if ( x== "8" || x== "9" ){x=3}
return x
}


function azzera()
{
alert("Too bad..YOU LOST!!")

turno=0
xturno=0
cambioang=0
numpalle=1
angL=1; angT=1
palla=document.images[0].style;
palla.posLeft=325
palla.posTop=210
for ( i=1; i<TotPalle; i++ )
{
var dist = 20*i;
document.images[i].style.posLeft=200+dist;
document.images[i].style.posTop=80;
}
}


function inizializza(nPalla)
{
nPalla=nPalla-1
var x = AngCasuale()
x=x*30
document.images[nPalla].style.posLeft=325+x
document.images[nPalla].style.posTop=210
}

function moveBall(n)
{
var ball = document.images[n].style
if ( window.event.y > ball.posTop && ball.posTop <= 284 )
{ ball.posTop = ball.posTop+liv }
else if (window.event.y < ball.posTop && ball.posTop >= 300 )
{ ball.posTop = ball.posTop-liv }

if ( window.event.x > ball.posLeft && ball.posLeft <= 400 )
{ ball.posLeft = ball.posLeft+liv }
else if (window.event.x < ball.posLeft && ball.posLeft >= 280 )
{ ball.posLeft = ball.posLeft-liv }
}

function advise()
{
alert("You have to play from the internet site http://de.geocities.com/freedbase/index.html if you want to save the results.")
}
</SCRIPT>

</head>

<BODY onmousemove="moveBall(TotPalle)">

<center>

<h1>Crazy Balls V.02</h1>

</center>

<p><p>

<DIV STYLE="position: absolute; Left:190; Top:160;z-index:1">Balls Left:</DIV>
<IMG id="ball0" SRC="http://photobucket.com/albums/0603/chellyville/site/64d83e3b.jpg" STYLE="position: absolute; Top:200; Left:350; Width:9; Height:9;z-index=2;">
<IMG id="ball1" SRC="http://photobucket.com/albums/0603/chellyville/site/64d83e3b.jpg" STYLE="position: absolute; Top:180; Left:200; Width:9; Height:9;z-index=2;">
<IMG id="ball2" SRC="http://photobucket.com/albums/0603/chellyville/site/64d83e3b.jpg" STYLE="position: absolute; Top:180; Left:220; Width:9; Height:9;z-index=2;"><IMG id="ball3" SRC="http://photobucket.com/albums/0603/chellyville/site/64d83e3b.jpg" STYLE="position: absolute; Top:180; Left:240; Width:9; Height:9;z-index=2;">

<FORM name="scoreform">
<INPUT TYPE="button" VALUE="START!!" onClick="gioca()" STYLE="position: absolute; Top:200; Left:187;z-index:3; font-family:VERDANA; border:1PT DASHED dodgerblue; font-size:8PT; background:#145094; color:white;">
<INPUT TYPE="text" NAME="score" VALUE="Your Points" SIZE="10" STYLE="position: absolute; Top:220; Left:180;z-index:3; font-family:VERDANA; border:1PT DASHED dodgerblue; font-size:8PT; background:#145094; color:white;" readonly>
<INPUT TYPE="text" NAME="xturno" VALUE="New Ball Countdown" STYLE="position: absolute; Top:240; Left:120; font-family:VERDANA; border:1PT DASHED dodgerblue; font-size:8PT; background:#145094; color:white;">
</FORM>

<IMG id="BigBall" SRC="http://photobucket.com/albums/0603/chellyville/site/64d83e3b.jpg" STYLE="position: absolute; Top:250; Left:350; Width:15; Height:15;z-index=2;">

<IMG id="tavola" SRC="http://photobucket.com/albums/0603/chellyville/site/218dccda.gif" STYLE="position: absolute; Top:100; Left:260; Width:200; Height:200;z-index=1;" border=5>

<IMG id="light" SRC="http://photobucket.com/albums/0603/chellyville/site/f68fb0d8.jpg" STYLE="position: absolute; Top:160; Left:480; z-index:1" border=3>
<IMG id="table2" SRC="http://photobucket.com/albums/0603/chellyville/site/869cafbf.gif" STYLE="position: absolute; Top:160; Left:480; z-index:2" border=3>

chellyville
12-18-2003, 07:29 PM
by the way, sorry for all the typos in that last post!!

chellyville
12-18-2003, 07:34 PM
ohh, whoops..i think i posted this thread in the wrong forum. should it be moved to 'Client Side Scripting'?? sorry, i'm a newbie to this place..

leoo24
12-19-2003, 07:09 AM
hehe, don't worry i'll move it for you :)

welcome to the forum :)

chellyville
12-19-2003, 07:30 PM
thank you!! :D

chellyville
12-21-2003, 10:33 PM
won't anyone try helping me, please??