X-Git-Url: http://git.rot13.org/?a=blobdiff_plain;ds=inline;f=Airplane.pm;fp=Airplane.pm;h=775599c665a416b849ba188885085d4a0fb47a7c;hb=33b71a0a0de167361a539859460c1602fbb60954;hp=0000000000000000000000000000000000000000;hpb=a11470792e661f75b664567bdebc7d4486832379;p=perl-landing-airplanes.git diff --git a/Airplane.pm b/Airplane.pm new file mode 100644 index 0000000..775599c --- /dev/null +++ b/Airplane.pm @@ -0,0 +1,47 @@ +package Airplane; + +use warnings; +use strict; + +sub new { + my ( $class, $app ) = @_; + my $self = { + app => $app, + path => [], + speed => 100, + tick => 0, + }; + bless $self, $class; + return $self; +} + +sub set_path { + my $self = shift; + $self->{path} = [ @_ ]; + $self->{path_position} = 0; + $self->{tick} = $self->{app}->ticks + $self->{speed}; +} + +our $plane = SDL::Surface->new( -name => 'artwork/airplane.png' ); + +sub draw { + my $self = shift; + return unless $self->{tick}; + if ( $self->{app}->ticks > $self->{tick} ) { + my $pos = $self->{path_position} += 2; + if ( $pos > $#{ $self->{path} } ) { + warn "end of path for $self"; + $self->{tick} = 0; + return; + } + my $to = SDL::Rect->new( + -x => $self->{path}[$pos], + -y => $self->{path}[$pos+1], + ); + $plane->blit( $plane->rect, $self->{app}, $to ); + warn $pos; + $self->{tick} = $self->{app}->ticks + $self->{speed}; + } +} + +1;