#!/Perl/bin/perl package Game; use base qw(Class::Accessor); Game->mk_accessors(qw(app)); use strict; use warnings; use Data::Dumper qw/Dumper/; use SDL; use SDL::App qw/SDL_GetKeyName/; use SDL::Rect; use Perl6::Say; =head1 METHODS =head2 new() Ctor. =cut sub new { my $class = shift; my $self = bless({}, $class); $self->init(); return $self; } # /new =head2 init() init the app, load everything we will use. check if everything that could be nedded is present. Set the initial game mode. =cut sub init { my $self = shift; my $app = new SDL::App ( -title => 'Application Title', -width => 640, -height => 480, -depth => 32 ); $self->app($app); } # /init =head2 run() Runs the game. =cut sub run { my $self = shift; my $app = $self->app(); my %actions = ( SDL_QUIT() => sub { exit(0); }, SDL_KEYDOWN() => sub { $self->keydown(@_); }, SDL_MOUSEBUTTONDOWN() => sub { $self->mousebuttondown(@_); }, ); $app->loop(\%actions); } #/run =head2 mousebuttondown() In welchem Game-Modus bin ich, was soll ich in diesem Modus tun? -> Dispatcher für die einzelnen Modi. =cut sub mousebuttondown { my $self = shift; my $event = shift; say "mousebutton"; say '<' . $event->button_x() . ',' . $event->button_x() . '>'; } # /mousebuttondown =head2 keydown() =cut sub keydown { my $self = shift; my $event = shift; say "Ereignis"; print Dumper $event->key_sym(); print Dumper $event->key_name(); #printf("Die Taste '%s' wurde gedrückt!\n", SDL_GetKeyName(ereignis.key.keysym.sym)); }; 1; # /Game my $game = Game->new(); $game->run();