From: Breno G. de Oliveira Date: Sun, 4 Oct 2009 07:20:45 +0000 (-0300) Subject: implemented collidepoint X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=0064136debf6b3e5eea159887367743220a31d20;hp=b6eea8bc8d821ff717eeb1c057248000a6f02a69;p=sdlgit%2FSDL_perl.git implemented collidepoint --- diff --git a/lib/SDL/Game/Rect.pm b/lib/SDL/Game/Rect.pm index a74413f..7cffffa 100644 --- a/lib/SDL/Game/Rect.pm +++ b/lib/SDL/Game/Rect.pm @@ -590,6 +590,23 @@ sub contains { return $contained; } + +sub collidepoint { + my ($self, $x, $y) = (@_); + + unless (defined $x and defined $y) { + croak "must receive (x,y) as arguments"; + } + + my $inside = $x >= $self->x + && $x < $self->x + $self->w + && $y >= $self->y + && $y < $self->y + $self->h + ; + + return $inside; +} + 42; __END__