package main; use strict; use warnings; use SDL; use SDLx::App; use SDL::Event; use SDL::Events; use Data::Dumper; use player; # Set up Application Options. Let SDLx::App take care of looping my $app = SDLx::App->new (w => 450, h => 300, t => "Bob Loblaw", hw_surface => 1, double_buf => 1, dt => .2, delay => 20,); #SDL::Events::enable_key_repeat(10, 10); # Instantiate game objects my $player = player->new(); $app->add_move_handler(\&move_handler); $app->add_show_handler(\&show_handler); $app->add_move_handler(\&event_handler); #$app->add_event_handler(\&event_handler); # Handle game object reaction to events sub event_handler { my $event = shift; #if ($event->type == SDL_QUIT) { exit; } $player->move_react(@_); $player->fire_react(@_); } # Handle game object movement sub move_handler { # add empty event to queue to force processing of event handlers #SDL::Events::push_event(SDL::Event->new); $player->move_bullets(@_); $player->move(@_); } # Handle game object drawing sub show_handler { $app->draw_rect([0,0,$app->w,$app->h], [0,0,0,0]); $player->draw_bullets(@_); $player->draw(@_); $app->update; } # Finally, run the app $app->run; 1;