function verificaDirezione(oggSx,oggDx,oggHi,oggLo,ost){
if(horOverDx(oggHi,oggLo,oggDx,ost)&& prevDx<=sinistro(ost)) {
$("test").innerHTML="Da sinistra";
oggSx=sinistro(ost)-larghezza(oggetto);
oggDx=sinistro(ost);
oggetto.style.left=oggSx+"px";
}
if(horOverSx(oggHi,oggLo,oggSx,ost)&& prevSx>=destro(ost)) {
$("test").innerHTML="Da destra";
oggSx=destro(ost)
oggDx=destro(ost)+larghezza(oggetto);
oggetto.style.left=oggSx+"px";
}
if(vertOverHi(oggSx,oggDx,oggLo,ost) && prevLo<=alto(ost)) {
$("test").innerHTML="Da alto";
oggHi=alto(ost)-altezza(oggetto);
oggLo=alto(ost)
oggetto.style.top=oggHi;
}
if(vertOverLo(oggSx,oggDx,oggHi,ost) && prevHi>=basso(ost)) {
$("test").innerHTML="Da basso";
oggHi=basso(ost);
oggLo=basso(ost)+altezza(oggetto);
oggetto.style.top=basso(ost);
}
}
Ecco, così l'oggetto si blocca quando viene a cozzare con l'ostacolo.La differenza rispetto al codice precedente è che il valore delle coordinate dell'oggetto bloccatosi viene immagazzinato in variabili a parte.
Le variabili vengono rigenerate all'inizio della funzione OnMouseMove.
Nessun commento:
Posta un commento