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;
