From: Breno G. de Oliveira Date: Sun, 4 Oct 2009 07:52:52 +0000 (-0300) Subject: implemented collidehash X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=ebfa743c77ce4d0c444fa06c68cec3aecf83cb31;p=sdlgit%2FSDL_perl.git implemented collidehash --- diff --git a/lib/SDL/Game/Rect.pm b/lib/SDL/Game/Rect.pm index dc883f8..7d3af00 100644 --- a/lib/SDL/Game/Rect.pm +++ b/lib/SDL/Game/Rect.pm @@ -665,6 +665,24 @@ sub collidelistall { return \@collisions; } +sub collidehash { + my ($self, $rects) = (@_); + + unless (defined $rects and ref $rects eq 'HASH') { + croak "must receive an hash reference of SDL::Rect-based objects"; + } + + while ( my ($key, $value) = each %{$rects} ) { + unless ($value->isa('SDL::Rect')) { + croak "hash element of key '$key' is not an SDL::Rect-based object"; + } + + if ( _do_rects_intersect($self, $value) ) { + return ($key, $value); + } + } + return (undef, undef); +} 42; __END__