Leser: 2
2 Einträge, 1 Seite |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#!/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();
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
sub mousebuttondown {
my $self = shift;
my $event = shift;
my $app = $self->app();
say "mousebutton";
say '<' . $event->button_x() . ',' . $event->button_x() . '>';
my $r_width = 10;
my $r_height = 10;
my $rect = SDL::Rect->new(
-height => $r_height,
-width => $r_width,
-x => $event->button_x() - $r_width/2,
-y => $event->button_y() - $r_height/2,
);
my $color = SDL::Color->new(
-r => 0x00,
-g => 0x00,
-b => 0xff,
);
$app->fill( $rect, $color );
$app->update( $rect );
} # /mousebuttondown
2 Einträge, 1 Seite |