Merge git://github.com/garu/SDL_perl into experimental
Kartik Thakore [Sun, 27 Sep 2009 16:11:18 +0000 (12:11 -0400)]
1  2 
lib/SDL/Game/Rect.pm

diff --combined lib/SDL/Game/Rect.pm
@@@ -13,7 -13,7 +13,7 @@@ sub new 
      my $w = shift || 0;
      my $h = shift || 0;
  
 -    my $self = \SDL::NewRect($x, $y, $w, $h);
 +    my $self = $class->SUPER::new($x, $y, $w, $h);
      unless ($$self) {
          require Carp;
          Carp::croak SDL::GetError();
@@@ -206,6 -206,78 +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__