Commit | Line | Data |
8fde61e3 |
1 | #!/usr/bin/env perl |
2 | |
3 | use SDL; |
4 | use SDL::App; |
5 | use SDL::Surface; |
6 | use SDL::Rect; |
7 | use SDL::Event; |
8 | |
9 | my $menu = new SDL::Surface -name => 'data/menu.png'; |
10 | |
11 | my $app = new SDL::App -w => $menu->width(), -h => $menu->height(), -resizeable => 1; |
12 | |
13 | my $hilight = new SDL::Surface -name => 'data/highlight.png'; |
14 | |
15 | my %menu = ( |
16 | 'start' => [ 115, 30, 160, 40 ], |
17 | 'help' => [ 120, 100, 120, 40 ], |
18 | 'giveup' => [ 120, 230, 120, 40 ], |
19 | 'spawnserver' => [ 115, 170, 165, 40 ], |
20 | 'credits' => [ 115, 285, 160, 40 ], |
21 | ); |
22 | |
23 | my $needblit; |
24 | sub drawMenu { |
25 | my ($a,$dx,$dy,$no,$hi,%m) = @_; |
26 | for (keys %m) { |
27 | my ($x,$y,$w,$h) = @{$m{$_}}; |
28 | next unless $dx >= $x && $dx <= $x+$w |
29 | && $dy >= $y && $dy <= $y+$h; |
30 | unless ($needblit) { |
31 | my $rect = new SDL::Rect -w => $w, -h => $h, |
32 | -x => $x, -y => $y; |
33 | $hi->blit($rect,$a,$rect); |
34 | $needblit = 1; |
35 | } |
36 | return $_; |
37 | } |
38 | $no->blit(NULL,$a,NULL) if $needblit; |
39 | $needblit = 0; |
40 | return 0; |
41 | } |
42 | |
43 | sub help { |
44 | print STDERR <<USAGE; |
45 | This should print a help message |
46 | |
47 | USAGE |
48 | |
49 | } |
50 | |
51 | sub credits { |
52 | print STDERR <<CREDITS; |
53 | David J. Goehrig |
54 | |
55 | CREDITS |
56 | |
57 | } |
58 | |
59 | sub spawnserver { |
60 | print STDERR <<SPAWN; |
61 | Spawinging new server... |
62 | |
63 | SPAWN |
64 | |
65 | } |
66 | |
67 | sub start { |
68 | print STDERR <<START; |
69 | This should start the game |
70 | |
71 | START |
72 | |
73 | } |
74 | |
75 | sub giveup { |
76 | print STDERR <<GIVEUP; |
77 | Giving up |
78 | |
79 | GIVEUP |
80 | |
81 | exit(0); |
82 | } |
83 | |
84 | my %events = ( |
85 | SDL_MOUSEMOTION() => sub { |
86 | my ($e) = @_; |
87 | drawMenu($app, |
88 | $e->motion_x(), |
89 | $e->motion_y(), |
90 | $menu, |
91 | $hilight, |
92 | %menu); |
93 | }, |
94 | SDL_MOUSEBUTTONUP() => sub { |
95 | my ($e) = @_; |
96 | my $routine = drawMenu($app, |
97 | $e->motion_x(), |
98 | $e->motion_y(), |
99 | $menu, |
100 | $hilight, |
101 | %menu); |
102 | &{$routine} if ($routine); |
103 | }, |
104 | SDL_QUIT() => sub { exit(0); }, |
105 | SDL_KEYDOWN() => sub { |
106 | my ($e) = @_; |
107 | exit(0) if ($e->key_sym() == SDLK_ESCAPE); |
108 | }, |
109 | ); |
110 | |
111 | $menu->blit(NULL,$app,NULL); |
112 | $app->sync(); |
113 | $app->loop(\%events); |
114 | |
115 | |