$app->add_event_handler( \&quit_event ); $app->add_move_handler ( \&calculate_laser ); $app->add_show_handler ( \&render_laser ); sub quit_event { my $event = shift; my $controller = shift; $controller->stop if $event->type == SDL_QUIT; } sub calculate_laser { # The step is the difference in Time calculated for the next jump my ( $step, $app, $t ) = @_; $laser += $velocity * $step; $phaser += $velocity * $step; $velocity = -$velocity if $laser > $app->w; $velocity = -$velocity if $laser < -20; } sub render_laser { my ($delta, $app) = @_; #draw bg $app->draw_rect( [0, 0, $app->w, $app->h ], 0); $app->draw_rect([$phaser, $app->h/4, 20, 4], [100, 100, 255, 255]); $app->draw_rect( [ $laser, $app->h / 2, 20, 4 ], [255, 8, 8, 255] ); $app->update(); }