X-Git-Url: http://git.rot13.org/?p=perl-landing-airplanes.git;a=blobdiff_plain;f=Airplane.pm;h=0078cb4041ce13bd85555ca88b9dafc5ff5d4c71;hp=775599c665a416b849ba188885085d4a0fb47a7c;hb=4361ed72f1bcfcd545354266c7b8fb3362d33a19;hpb=33b71a0a0de167361a539859460c1602fbb60954;ds=sidebyside diff --git a/Airplane.pm b/Airplane.pm index 775599c..0078cb4 100644 --- a/Airplane.pm +++ b/Airplane.pm @@ -3,6 +3,8 @@ package Airplane; use warnings; use strict; +use SDL::Tool::Graphic; + sub new { my ( $class, $app ) = @_; my $self = { @@ -22,7 +24,7 @@ sub set_path { $self->{tick} = $self->{app}->ticks + $self->{speed}; } -our $plane = SDL::Surface->new( -name => 'artwork/airplane.png' ); +my $tool = SDL::Tool::Graphic->new; sub draw { my $self = shift; @@ -34,12 +36,27 @@ sub draw { $self->{tick} = 0; return; } +# $plane->blit( $plane->rect, $self->{app}, $to ); + + my $radian = atan2( + $self->{path}[$pos+1] - $self->{path}[$pos+3], + $self->{path}[$pos] - $self->{path}[$pos+2], + ); + my $deg = $radian / 3.1459265 * 180; + + $deg = -$deg + 90; # plain nose at 90 deg. + + my $plane = SDL::Surface->new( -name => 'artwork/airplane.png' ); + my $rotated = $tool->rotoZoom( $plane, $deg, 1, 1 ); + my $to = SDL::Rect->new( - -x => $self->{path}[$pos], - -y => $self->{path}[$pos+1], + -x => $self->{path}[$pos] - $rotated->width / 2, + -y => $self->{path}[$pos+1] - $rotated->height / 2, ); - $plane->blit( $plane->rect, $self->{app}, $to ); - warn $pos; + + $rotated->blit( $rotated->rect, $self->{app}, $to ); + + warn "$pos $radian $deg ", $rotated->width, ' ', $rotated->height; $self->{tick} = $self->{app}->ticks + $self->{speed}; } }