From: Breno G. de Oliveira Date: Sun, 4 Oct 2009 07:56:28 +0000 (-0300) Subject: implemented collidehashall X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=ec3462385dcc65e31283f1212b1f5f7bd49df5b3;p=sdlgit%2FSDL_perl.git implemented collidehashall --- diff --git a/lib/SDL/Game/Rect.pm b/lib/SDL/Game/Rect.pm index 7d3af00..15fe1c9 100644 --- a/lib/SDL/Game/Rect.pm +++ b/lib/SDL/Game/Rect.pm @@ -684,6 +684,27 @@ sub collidehash { return (undef, undef); } +sub collidehashall { + my ($self, $rects) = (@_); + + unless (defined $rects and ref $rects eq 'HASH') { + croak "must receive an hash reference of SDL::Rect-based objects"; + } + + my %collisions = (); + 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) ) { + $collisions{$key} = $value; + } + } + return \%collisions; +} + + 42; __END__