Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
14 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,37 @@ | ||
use strict; | ||
use warnings; | ||
use Carp 'croak'; | ||
use SDL; | ||
use SDL::Events; | ||
use SDL::Video; | ||
use SDL::Surface; | ||
use SDLx::App; | ||
|
||
use lib 'lib'; | ||
use SDLx::Controller; | ||
use SDLx::Widget::Menu; | ||
|
||
croak 'Cannot init ' . SDL::get_error() if SDL::init(SDL_INIT_VIDEO) == -1; | ||
|
||
# Create our display window | ||
my $display | ||
= SDL::Video::set_video_mode( 800, 600, 32, | ||
SDL_HWSURFACE | SDL_DOUBLEBUF | SDL_HWACCEL ) | ||
or croak 'Cannot create display: ' . SDL::get_error(); | ||
my $app = SDLx::App->new( | ||
w => 800, | ||
h => 600, | ||
eoq => 1, | ||
); | ||
|
||
my $game = SDLx::Controller->new( eoq => 1 ); | ||
my $menu = SDLx::Widget::Menu->new( topleft => [ 0, 400 ], mouse => 1 ); | ||
$menu->items( | ||
'New Game' => sub { }, | ||
'Load Game' => sub { }, | ||
'Options' => sub { }, | ||
'Quit' => sub { $menu->{exit} = 1; }, #return the of this in event loop | ||
'Quit' => sub { $menu->{exit} = 1; }, | ||
); | ||
|
||
$game->add_event_handler( | ||
$app->add_event_handler( | ||
sub { | ||
$menu->event_hook( $_[0] ); | ||
$game->stop if $menu->{exit}; | ||
$app->stop if $menu->{exit}; | ||
} | ||
); | ||
|
||
$game->add_show_handler( | ||
$app->add_show_handler( | ||
sub { | ||
$menu->render($display); | ||
SDL::Video::flip($display); | ||
$app->draw_rect( undef, undef ); | ||
$menu->render($app); | ||
$app->update; | ||
} | ||
); | ||
|
||
$game->run; | ||
$app->run; |