I'm close to releasing my app and my friend added the collision-detection code in the beginning. If this looks familiar please let me know:
function collides(a, b) {
var aTop = a.offset().top;
var aLeft = a.offset().left;
var bTop = b.offset().top;
var bLeft = b.offset().left;
return !(
((aTop + a.height()) < (bTop)) ||
(aTop > (bTop + b.height())) ||
((aLeft + a.width()) < bLeft) ||
(aLeft > (bLeft + b.width()))
);
}
//colliding stuff and responce.
function handleCollisions() {
if (collides($('#firstObs'),$('#player'))) {
$('#levelOne').stop();
$('#player').css('border', 'solid 1px red');
}
else { // if not collision
$('#player').html("<p></p>");
}
}
Is there a source on the web that he might of got this code from, to prove he did write it himself?
Aucun commentaire:
Enregistrer un commentaire