From: Breno G. de Oliveira Date: Sun, 4 Oct 2009 07:41:10 +0000 (-0300) Subject: implemented collidelist X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=85eb4c830c96cd2fd164fc019bee608a0bd8327e;p=sdlgit%2FSDL_perl.git implemented collidelist --- diff --git a/lib/SDL/Game/Rect.pm b/lib/SDL/Game/Rect.pm index a552f75..470fd65 100644 --- a/lib/SDL/Game/Rect.pm +++ b/lib/SDL/Game/Rect.pm @@ -488,8 +488,9 @@ sub _test_unionall { sub unionall { my ($self, $rects) = (@_); - croak "must receive an array reference of SDL::Rect-based objects" - unless defined $rects and ref $rects eq 'ARRAY'; + unless (defined $rects and ref $rects eq 'ARRAY') { + croak "must receive an array reference of SDL::Rect-based objects"; + } my ($x, $y, $w, $h) = _test_unionall($self, $rects); @@ -499,8 +500,9 @@ sub unionall { sub unionall_ip { my ($self, $rects) = (@_); - croak "must receive an array reference of SDL::Rect-based objects" - unless defined $rects and ref $rects eq 'ARRAY'; + unless (defined $rects and ref $rects eq 'ARRAY') { + croak "must receive an array reference of SDL::Rect-based objects"; + } my ($x, $y, $w, $h) = _test_unionall($self, $rects); @@ -632,6 +634,22 @@ sub colliderect { return _do_rects_intersect($self, $rect); } +sub collidelist { + my ($self, $rects) = (@_); + + unless (defined $rects and ref $rects eq 'ARRAY') { + croak "must receive an array reference of SDL::Rect-based objects"; + } + + for(my $i = 0; $i < @{$rects}; $i++) { + if ( _do_rects_intersect($self, $rects->[$i]) ) { + return $i; + } + } + return; +} + + 42; __END__