From: Kartik Thakore Date: Sun, 27 Sep 2009 16:11:18 +0000 (-0400) Subject: Merge git://github.com/garu/SDL_perl into experimental X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=2e86ea4ee79f7bff486f1d57f672d86f1820d6fa;hp=46e4c5bf205cee6cef6dbc9cb11ef0078cb78001;p=sdlgit%2FSDL_perl.git Merge git://github.com/garu/SDL_perl into experimental --- diff --git a/lib/SDL/Game/Rect.pm b/lib/SDL/Game/Rect.pm index 66d7baa..63213d7 100644 --- a/lib/SDL/Game/Rect.pm +++ b/lib/SDL/Game/Rect.pm @@ -206,6 +206,78 @@ sub midbottom { return; } +############################### +## methods ## +############################### + +sub duplicate { +} + +sub copy { + my $self = shift; + return $self->new( + -top => $self->top, + -left => $self->left, + -width => $self->width, + -height => $self->height, + ); +} + +sub move { + my ($self, $x, $y) = (@_); + if (not defined $x or not defined $y) { + require Carp; + Carp::croak "must receive x and y positions as argument"; + } + return $self->new( + -top => $self->top + $y, + -left => $self->left + $x, + -width => $self->width, + -height => $self->height, + ); +} + +sub move_ip { + my ($self, $x, $y) = (@_); + if (not defined $x or not defined $y) { + require Carp; + Carp::croak "must receive x and y positions as argument"; + } + $self->x($self->x + $x); + $self->y($self->y + $y); + + return; +} + +sub inflate { + my ($self, $x, $y) = (@_); + if (not defined $x or not defined $y) { + require Carp; + Carp::croak "must receive x and y positions as argument"; + } + + return $self->new( + -left => $self->left - ($x / 2), + -top => $self->top - ($y / 2), + -width => $self->width + $x, + -height => $self->height + $y, + ); +} + +sub inflate_ip { + my ($self, $x, $y) = (@_); + if (not defined $x or not defined $y) { + require Carp; + Carp::croak "must receive x and y positions as argument"; + } + + $self->x( $self->x - ($x / 2) ); + $self->y( $self->y - ($y / 2) ); + + $self->w( $self->w + $x ); + $self->h( $self->h + $y ); +} + 42; __END__