detect landing point and rote over points
[perl-landing-airplanes.git] / trace-path.pl
index 3fd2935..6239d13 100755 (executable)
@@ -45,6 +45,8 @@ our $app = SDL::App->new(
 
 our $app_rect  = SDL::Rect->new( -x => 0, -y => 0, -width => $w, -height => $h );
 $mask->blit( $mask->rect, $app, $app_rect );
+$app->sync;
+
 
 my @landing;
 
@@ -70,10 +72,6 @@ foreach ( 0 .. $mask->height / $mask_step ) {
 
 warn 'lading ',dump(@landing);
 
-exit;
-
-$app->sync;
-
 our $event = SDL::Event->new;
 
 our $mouse_down = 0;
@@ -84,6 +82,17 @@ our @path;
 sub reset_path { @path = () }
 
 sub curve {
+
+       my $mask_col = $mask->pixel( $path[-2], $path[-1] );
+       my $mask_hex = sprintf '%02x%02x%02x', $mask_col->r, $mask_col->g, $mask_col->b;
+       warn "mask $path[-2] $path[1] $mask_hex\n";
+
+       if ( $mask_hex eq '000000' ) { # push landing point at path end
+               foreach ( 1 .. 6 ) {
+                       push @path, $landing[$_]->[0], $landing[$_]->[1];
+               }
+       }
+
        if ( $#path < ( 4 * 2 - 1 ) ) { # less than 4 points
                warn "path too short ", dump @path;
                reset_path;
@@ -120,6 +129,7 @@ sub handle_events {
                } elsif ( $type == SDL_MOUSEBUTTONUP() ) {
                        debug 'mouse up', $event->button_x, $event->button_y;
                        $mouse_down = 0;
+       
                        curve;
                } elsif ( $type == SDL_QUIT() ) {
                        exit;
@@ -129,11 +139,12 @@ sub handle_events {
                        exit if $key =~ m/^[xq]$/;
                        if ( $key eq 's' ) { # XXX draw curve
                                curve;
-                       } elsif ( $key eq 'backspace' ) { # XXX clean screen
+                       } elsif ( $key eq 'backspace' || $key eq 'c' ) { # XXX clean screen
                                reset_path;
-                               my $rect = SDL::Rect->new( -x => 0, -y => 0, -w => $w, -h => $h );
-                               $app->fill( $rect, $black );
-                               $app->update( $rect );
+                               $app->fill( $app->rect, $black );
+#                              $app->update( $rect );
+                               $mask->blit( $mask->rect, $app, $app_rect );
+                               $app->sync;
                        } elsif ( $key eq 'd' ) { # XXX toggle debug
                                $debug = ! $debug;
                                warn "debug $debug\n";