| 1 | ########################################################################## | ||
| 2 | package Games::PangZero::Menu; | ||
| 3 | ########################################################################## | ||
| 4 | |||
| 5 | use SDL::Events; | ||
| 6 | use Games::PangZero::FpsIndicator; | ||
| 7 | use Games::PangZero::MenuItem; | ||
| 8 | |||
| 9 | @ISA = qw(Games::PangZero::GameBase); | ||
| 10 | use vars qw(@syms); | ||
| 11 | @syms = qw(UNKNOWN FIRST BACKSPACE TAB CLEAR RETURN PAUSE ESCAPE SPACE EXCLAIM QUOTEDBL HASH DOLLAR AMPERSAND QUOTE LEFTPAREN RIGHTPAREN ASTERISK PLUS COMMA MINUS PERIOD SLASH 0 1 2 3 4 5 6 7 8 9 COLON SEMICOLON LESS EQUALS GREATER QUESTION AT LEFTBRACKET BACKSLASH RIGHTBRACKET CARET UNDERSCORE BACKQUOTE a b c d e f g h i j k l m n o p q r s t u v w x y z DELETE WORLD_0 WORLD_1 WORLD_2 WORLD_3 WORLD_4 WORLD_5 WORLD_6 WORLD_7 WORLD_8 WORLD_9 WORLD_10 WORLD_11 WORLD_12 WORLD_13 WORLD_14 WORLD_15 WORLD_16 WORLD_17 WORLD_18 WORLD_19 WORLD_20 WORLD_21 WORLD_22 WORLD_23 WORLD_24 WORLD_25 WORLD_26 WORLD_27 WORLD_28 WORLD_29 WORLD_30 WORLD_31 WORLD_32 WORLD_33 WORLD_34 WORLD_35 WORLD_36 WORLD_37 WORLD_38 WORLD_39 WORLD_40 WORLD_41 WORLD_42 WORLD_43 WORLD_44 WORLD_45 WORLD_46 WORLD_47 WORLD_48 WORLD_49 WORLD_50 WORLD_51 WORLD_52 WORLD_53 WORLD_54 WORLD_55 WORLD_56 WORLD_57 WORLD_58 WORLD_59 WORLD_60 WORLD_61 WORLD_62 WORLD_63 WORLD_64 WORLD_65 WORLD_66 WORLD_67 WORLD_68 WORLD_69 WORLD_70 WORLD_71 WORLD_72 WORLD_73 WORLD_74 WORLD_75 WORLD_76 WORLD_77 WORLD_78 WORLD_79 WORLD_80 WORLD_81 WORLD_82 WORLD_83 WORLD_84 WORLD_85 WORLD_86 WORLD_87 WORLD_88 WORLD_89 WORLD_90 WORLD_91 WORLD_92 WORLD_93 WORLD_94 WORLD_95 KP0 KP1 KP2 KP3 KP4 KP5 KP6 KP7 KP8 KP9 KP_PERIOD KP_DIVIDE KP_MULTIPLY KP_MINUS KP_PLUS KP_ENTER KP_EQUALS UP DOWN RIGHT LEFT INSERT HOME END PAGEUP PAGEDOWN F1 F2 F3 F4 F5 F6 F7 F8 F9 F10 F11 F12 F13 F14 F15 NUMLOCK CAPSLOCK SCROLLOCK RSHIFT LSHIFT RCTRL LCTRL RALT LALT RMETA LMETA LSUPER RSUPER MODE COMPOSE HELP PRINT SYSREQ BREAK MENU POWER EURO UNDO LAST ); | ||
| 12 | |||
| 13 | sub Exit { | ||
| 14 | my $self = shift; | ||
| 15 | |||
| 16 | Games::PangZero::Config::SaveConfig(); | ||
| 17 | $self->SUPER::Exit(); | ||
| 18 | } | ||
| 19 | |||
| 20 | sub SetGameSpeed { | ||
| 21 | $Games::PangZero::GameSpeed = 1.0; | ||
| 22 | } | ||
| 23 | |||
| 24 | sub ShowTooltip { | ||
| 25 | my $self = shift; | ||
| 26 | my (@lines, $y, $yinc, $rect); | ||
| 27 | |||
| 28 | @lines = @_; | ||
| 29 | @lines = ("Pang Zero $Games::PangZero::VERSION (C) 2006 by UPi (upi\@sourceforge.net)", | ||
| 30 | "Use cursor keys to navigate menu, Enter to select", | ||
| 31 | "P pauses the game, Esc quits") unless scalar @lines; | ||
| 32 | |||
| 33 | $Games::PangZero::ScoreFont->use(); | ||
| 34 | ($y, $yinc) = ($Games::PangZero::ScreenHeight + 35, 20); | ||
| 35 | $rect = SDL::Rect->new(0, $y, $Games::PangZero::PhysicalScreenWidth, $Games::PangZero::PhysicalScreenHeight - $y ); | ||
| 36 | SDL::Video::fill_rect( $Games::PangZero::Background, $rect, SDL::Color->new(0,0,0) ); | ||
| 37 | foreach (@lines) { | ||
| 38 | SDLx::SFont::print_text( $Games::PangZero::Background, 10, $y, $_ ) if $y + $yinc < $Games::PangZero::PhysicalScreenHeight; | ||
| 39 | |||
| 40 | $y += $yinc; | ||
| 41 | } | ||
| 42 | $rect = SDL::Rect->new( 0, $Games::PangZero::ScreenHeight + 35, $Games::PangZero::PhysicalScreenWidth, $Games::PangZero::PhysicalScreenWidth - $y ); | ||
| 43 | SDL::Video::blit_surface($Games::PangZero::Background, $rect, $Games::PangZero::App, $rect); | ||
| 44 | $Games::PangZero::MenuFont->use(); | ||
| 45 | } | ||
| 46 | |||
| 47 | sub MenuAdvance { | ||
| 48 | my $self = shift; | ||
| 49 | |||
| 50 | my $advance = $self->CalculateAdvances(); | ||
| 51 | %Games::PangZero::Events = %Games::PangZero::MenuEvents = (); | ||
| 52 | %Games::PangZero::GameEvents = (); | ||
| 53 | Games::PangZero::HandleEvents('readbothaxes'); | ||
| 54 | while ($advance--) { | ||
| 55 | $self->AdvanceGameObjects(); | ||
| 56 | } | ||
| 57 | while (ref($Games::PangZero::GameObjects[$#Games::PangZero::GameObjects]) ne 'Games::PangZero::MenuItem') { | ||
| 58 | unshift @Games::PangZero::GameObjects, (pop @Games::PangZero::GameObjects); | ||
| 59 | } | ||
| 60 | $self->DrawGame(); | ||
| 61 | } | ||
| 62 | |||
| 63 | sub SetCurrentItemIndex { | ||
| 64 | my ($self, $index) = @_; | ||
| 65 | |||
| 66 | return if ($index < 0 or $index >= scalar @{$self->{menuItems}} or not $self->{menuItems}->[$index]->CanSelect()); | ||
| 67 | $self->{currentItemIndex} = $index; | ||
| 68 | $self->{currentItem} = $self->{menuItems}->[$index]; | ||
| 69 | $self->{currentItem}->Select(); | ||
| 70 | } | ||
| 71 | |||
| 72 | sub EnterSubMenu { | ||
| 73 | my $self = shift; | ||
| 74 | my ($recall, $menuItem); | ||
| 75 | |||
| 76 | $recall->{oldItems} = $self->{menuItems}; | ||
| 77 | $recall->{oldCurrentItemIndex} = $self->{currentItemIndex}; | ||
| 78 | foreach $menuItem (@{$self->{menuItems}}) { $menuItem->Hide(); } | ||
| 79 | $self->{menuItems} = []; | ||
| 80 | |||
| 81 | return $recall; | ||
| 82 | } | ||
| 83 | |||
| 84 | sub LeaveSubMenu { | ||
| 85 | my ($self, $recall) = @_; | ||
| 86 | my ($menuItem); | ||
| 87 | |||
| 88 | foreach $menuItem (@{$self->{menuItems}}) { $menuItem->HideAndDelete(); } | ||
| 89 | $self->{menuItems} = $recall->{oldItems}; | ||
| 90 | foreach $menuItem (@{$self->{menuItems}}) { $menuItem->Show(); } | ||
| 91 | $self->SetCurrentItemIndex($recall->{oldCurrentItemIndex}); | ||
| 92 | $self->{abortgame} = 0; | ||
| 93 | } | ||
| 94 | |||
| 95 | sub HandleUpDownKeys { | ||
| 96 | my $self = shift; | ||
| 97 | |||
| 98 | if ($Games::PangZero::MenuEvents{DOWN}) { | ||
| 99 | $self->SetCurrentItemIndex( $self->{currentItemIndex} + 1 ); | ||
| 100 | } | ||
| 101 | if ($Games::PangZero::MenuEvents{UP}) { | ||
| 102 | $self->SetCurrentItemIndex( $self->{currentItemIndex} - 1 ); | ||
| 103 | } | ||
| 104 | } | ||
| 105 | |||
| 106 | sub KeyToText { | ||
| 107 | my ($key) = @_; | ||
| 108 | eval("SDLK_$_ eq $key") and return ucfirst(lc($_)) foreach @syms; | ||
| 109 | print "No match for $key\n"; | ||
| 110 | return "???"; | ||
| 111 | } | ||
| 112 | |||
| 113 | sub KeysToText { | ||
| 114 | my $keys = shift; | ||
| 115 | my ($retval); | ||
| 116 | if ( $keys->[0] =~ /^[LRB](\d)+$/ ) { | ||
| 117 | return "Joystick $1"; | ||
| 118 | } | ||
| 119 | return join(' / ', KeyToText($keys->[0]), KeyToText($keys->[1]), KeyToText($keys->[2]) ); | ||
| 120 | } | ||
| 121 | |||
| 122 | sub RunTutorial { | ||
| 123 | my ($self, $ball) = @_; | ||
| 124 | my $recall = $self->EnterSubMenu(); | ||
| 125 | my @oldGameObjects = @Games::PangZero::GameObjects; | ||
| 126 | my %oldGuys = %Guy::Guys; | ||
| 127 | my %oldHarpoons = %Harpoon::Harpoons; | ||
| 128 | my $oldGame = $Games::PangZero::Game; | ||
| 129 | |||
| 130 | $Games::PangZero::ScoreFont->use(); | ||
| 131 | $Games::PangZero::Game = Games::PangZero::TutorialGame->new; | ||
| 132 | $Games::PangZero::Game->SetChallenge($ball); | ||
| 133 | $Games::PangZero::Game->Run(); | ||
| 134 | $Games::PangZero::MenuFont->use(); | ||
| 135 | $self->SetGameSpeed(); | ||
| 136 | |||
| 137 | foreach (@Games::PangZero::GameObjects) { $_->Clear(); } | ||
| 138 | @Games::PangZero::GameObjects = @oldGameObjects; | ||
| 139 | %Guy::Guys = %oldGuys; | ||
| 140 | %Harpoon::Harpoons = %oldHarpoons; | ||
| 141 | $Games::PangZero::Game = $oldGame; | ||
| 142 | $self->LeaveSubMenu($recall); | ||
| 143 | } | ||
| 144 | |||
| 145 | sub RunTutorialMenu { | ||
| 146 | my $self = shift; | ||
| 147 | my ($baseX, $menuItem); | ||
| 148 | |||
| 149 | my $recall = $self->EnterSubMenu(); | ||
| 150 | $self->{title}->Hide(); | ||
| 151 | my $baseY = 50; | ||
| 152 | |||
| 153 | my @tutorials = ( | ||
| 154 | ['n2', 'Normal Ball', 'There is nothing special about this ball. Just keep shooting it.'], | ||
| 155 | ['b0', 'Bouncy Ball', 'This ball bounces higher than the normal ball.', 'Otherwise it behaves the same.'], | ||
| 156 | ['h0', 'Hexa', 'The Hexa is weightless and travels in a straight line.', 'With practice you can shoot it just as easily as the normal ball.'], | ||
| 157 | ['w1', 'Water Ball', 'The water ball pops each time it bounces.', 'This can create a tide of small balls fast.', 'Mop it up quickly.'], | ||
| 158 | ['f1', 'Fragile Ball', 'The fragile ball shatters into little bits the moment it is hit.', 'Prepare for a shower of small balls.'], | ||
| 159 | ['death', 'Death Ball', 'This ball cannot be killed with your harpoon.', 'Shooting will make it multiply. Too many death balls cause meltdown.', 'Evade it for 20 seconds to get rid of it.'], | ||
| 160 | ['seeker', 'Seeker Ball', 'The seeker ball will chase you forever.', 'You have to keep moving and shooting to evade it.'], | ||
| 161 | ['quake', 'Earthquake Ball', 'This ball is super heavy.', 'In fact the earth will quake each time it bounces.', 'Shoot it quickly, or it will send you flying.'], | ||
| 162 | ['u0', 'Upside Down Ball', 'This crazy ball bounces on the top of the screen.', 'Maybe it came from an alternate universe,', 'where gravity is negative?'], | ||
| 163 | ['super0, n1', 'Super Ball', 'The Super Ball is your friend. It will still kill you on touch.', 'The green super ball will pause the game for 8 seconds.', 'The gold super ball will kill every ball.'], | ||
| 164 | ); | ||
| 165 | |||
| 166 | push @{$self->{menuItems}}, | ||
| 167 | Games::PangZero::MenuItem->new( 50, $baseY, "Back to main menu"), | ||
| 168 | Games::PangZero::MenuItem->new( 50, $baseY += 40, "Run Demo" ); | ||
| 169 | |||
| 170 | $baseY = 110; | ||
| 171 | $baseX = 50; | ||
| 172 | foreach (@tutorials) { | ||
| 173 | my @tutItem = @{$_}; | ||
| 174 | my $challenge = shift @tutItem; | ||
| 175 | my $menuItem = Games::PangZero::MenuItem->new( $baseX, $baseY += 40, @tutItem ); | ||
| 176 | $menuItem->{challenge} = $challenge; | ||
| 177 | push @{$self->{menuItems}}, $menuItem; | ||
| 178 | if ($baseY + 140 >= $Games::PangZero::ScreenHeight) { | ||
| 179 | $baseY = 110; | ||
| 180 | $baseX = 450; | ||
| 181 | } | ||
| 182 | } | ||
| 183 | push @Games::PangZero::GameObjects, (@{$self->{menuItems}}); | ||
| 184 | $self->SetCurrentItemIndex(1); | ||
| 185 | |||
| 186 | while (1) { | ||
| 187 | $self->MenuAdvance(); | ||
| 188 | last if $self->{abortgame}; | ||
| 189 | $self->HandleUpDownKeys(); | ||
| 190 | |||
| 191 | if ($Games::PangZero::MenuEvents{LEFT} and $self->{currentItemIndex} > 1) { | ||
| 192 | $self->SetCurrentItemIndex($self->{currentItemIndex} - 5); | ||
| 193 | } | ||
| 194 | if ($Games::PangZero::MenuEvents{RIGHT} and $self->{currentItemIndex} > 1) { | ||
| 195 | $self->SetCurrentItemIndex($self->{currentItemIndex} + 5); | ||
| 196 | } | ||
| 197 | if ($Games::PangZero::MenuEvents{BUTTON}) { | ||
| 198 | if (0 == $self->{currentItemIndex}) { | ||
| 199 | last; | ||
| 200 | } elsif (1 == $self->{currentItemIndex}) { | ||
| 201 | $self->{result} = 'demo'; | ||
| 202 | last; | ||
| 203 | } else { | ||
| 204 | $self->RunTutorial($self->{currentItem}->{challenge}); | ||
| 205 | } | ||
| 206 | } | ||
| 207 | } | ||
| 208 | |||
| 209 | $self->LeaveSubMenu($recall); | ||
| 210 | $self->{title}->Show(); | ||
| 211 | } | ||
| 212 | |||
| 213 | sub RunCredits { | ||
| 214 | my ($self, $demo) = @_; | ||
| 215 | my ($i, $ball, @balls); | ||
| 216 | |||
| 217 | my $time = $self->{anim}; | ||
| 218 | my $recall = $self->EnterSubMenu(); | ||
| 219 | my @oldGameObjects = @Games::PangZero::GameObjects; | ||
| 220 | foreach my $gameObject (@Games::PangZero::GameObjects) { | ||
| 221 | $gameObject->Clear(); | ||
| 222 | } | ||
| 223 | @Games::PangZero::GameObjects = ($self->{title}); | ||
| 224 | push @Games::PangZero::GameObjects, Games::PangZero::FpsIndicator->new(); | ||
| 225 | my ($y, $yinc) = (110, 36); | ||
| 226 | push @{$self->{menuItems}}, ( | ||
| 227 | Games::PangZero::MenuItem->new( 100, $y += $yinc, "Written by: UPi <upi\@sourceforge.net>"), | ||
| 228 | Games::PangZero::MenuItem->new( 100, $y += $yinc, "Music by: SAdam" ), | ||
| 229 | Games::PangZero::MenuItem->new( 100, $y += $yinc, "Graphics by: UPi, DaniGM, EBlanca" ), | ||
| 230 | Games::PangZero::MenuItem->new( 100, $y += $yinc * 1.5, "TESTERS" ), | ||
| 231 | Games::PangZero::MenuItem->new( 100, $y += $yinc, "Ulmar, Surba, Miki, Aisha, Descant" ), | ||
| 232 | Games::PangZero::MenuItem->new( 100, $y += $yinc * 1.5, "http://apocalypse.rulez.org/pangzero" ), | ||
| 233 | ); | ||
| 234 | foreach $i (@{$self->{menuItems}}) { $i->Center(); } | ||
| 235 | |||
| 236 | for ($i = 0; $i < 20; ++$i) { | ||
| 237 | $ball = Games::PangZero::Ball::Spawn( $Games::PangZero::BallDesc{'credits1'}, 100, 1, 0 ); | ||
| 238 | $ball->{y} = $i * -5; | ||
| 239 | push @balls, ($ball); | ||
| 240 | $ball = Games::PangZero::Ball::Spawn( $Games::PangZero::BallDesc{'credits2'}, $Games::PangZero::ScreenWidth - 132, -1, 0 ); | ||
| 241 | $ball->{y} = $i * -5; | ||
| 242 | push @balls, ($ball); | ||
| 243 | } | ||
| 244 | push @Games::PangZero::GameObjects, @balls; | ||
| 245 | push @Games::PangZero::GameObjects, (@{$self->{menuItems}}); | ||
| 246 | |||
| 247 | while (1) { | ||
| 248 | $self->MenuAdvance(); | ||
| 249 | last if $self->{abortgame}; | ||
| 250 | if ($demo) { | ||
| 251 | last if %Games::PangZero::Events; | ||
| 252 | last if $self->{anim} - $time > 20 * 100; # 30s | ||
| 253 | } | ||
| 254 | } | ||
| 255 | |||
| 256 | @Games::PangZero::GameObjects = @oldGameObjects; | ||
| 257 | foreach (@balls) { $_->Delete(); } | ||
| 258 | $self->LeaveSubMenu($recall); | ||
| 259 | } | ||
| 260 | |||
| 261 | sub RunHighScore { | ||
| 262 | my ($self, $difficultyLevel, $table, $auto) = @_; | ||
| 263 | my ($time, $recall, $y, $yinc, $retval); | ||
| 264 | |||
| 265 | die unless $table =~ /^(Cha|Pan)$/; | ||
| 266 | $time = 0; | ||
| 267 | $recall = $self->EnterSubMenu(); | ||
| 268 | ($y, $yinc) = (110, 40); | ||
| 269 | $difficultyLevel = $Games::PangZero::DifficultyLevels[$difficultyLevel]; | ||
| 270 | push @{$self->{menuItems}}, ( | ||
| 271 | Games::PangZero::MenuItem->new( 320, 50, ($table eq 'Cha' ? 'Challenge Game - ' : 'Panic Game - ') . $difficultyLevel->{name} ), #. " difficulty" ), | ||
| 272 | Games::PangZero::MenuItem->new( 50, $y, "Highest Score" ), | ||
| 273 | Games::PangZero::MenuItem->new( 480, $y, "Highest Level" ), | ||
| 274 | ); | ||
| 275 | $self->{menuItems}->[0]->Center(); | ||
| 276 | $y += $yinc; | ||
| 277 | foreach (@{$difficultyLevel->{"highScoreTable$table"}}) { | ||
| 278 | push @{$self->{menuItems}}, ( Games::PangZero::MenuItem->new( 10, $y += $yinc, $_->[0] ) ); | ||
| 279 | push @{$self->{menuItems}}, ( Games::PangZero::MenuItem->new( 250, $y, $_->[1] ) ); | ||
| 280 | } | ||
| 281 | $y = 110 + $yinc; | ||
| 282 | foreach (@{$difficultyLevel->{"highLevelTable$table"}}) { | ||
| 283 | push @{$self->{menuItems}}, ( Games::PangZero::MenuItem->new( 460, $y += $yinc, $_->[0] ) ); | ||
| 284 | push @{$self->{menuItems}}, ( Games::PangZero::MenuItem->new( 700, $y, $_->[1] ) ); | ||
| 285 | } | ||
| 286 | push @Games::PangZero::GameObjects, (@{$self->{menuItems}}); | ||
| 287 | |||
| 288 | while (not $retval) { | ||
| 289 | $self->MenuAdvance(); | ||
| 290 | if ($self->{abortgame}) { | ||
| 291 | $retval = 'abortgame'; last; | ||
| 292 | } | ||
| 293 | if ($auto) { | ||
| 294 | $retval = 'next' if ++$time > 100 * 6; | ||
| 295 | $retval = 'abortgame' if %Games::PangZero::Events; | ||
| 296 | } else { | ||
| 297 | if ($Games::PangZero::MenuEvents{LEFT} or $Games::PangZero::MenuEvents{UP}) { | ||
| 298 | $retval = 'prev'; last; | ||
| 299 | } elsif ($Games::PangZero::MenuEvents{RIGHT} or $Games::PangZero::MenuEvents{DOWN}) { | ||
| 300 | $retval = 'next'; last; | ||
| 301 | } elsif ($Games::PangZero::MenuEvents{BUTTON}) { | ||
| 302 | $retval = 'abortgame'; | ||
| 303 | } | ||
| 304 | } | ||
| 305 | } | ||
| 306 | $self->LeaveSubMenu($recall); | ||
| 307 | return $retval; | ||
| 308 | } | ||
| 309 | |||
| 310 | sub RunHighScores { | ||
| 311 | my ($self, $auto) = @_; | ||
| 312 | my ($recall, $retval, $i, $table, @tables); | ||
| 313 | |||
| 314 | if ($auto) { | ||
| 315 | $self->ShowTooltip(); | ||
| 316 | } else { | ||
| 317 | $self->ShowTooltip("Use arrow keys to navigate, Esc to go back"); | ||
| 318 | } | ||
| 319 | $recall = $self->EnterSubMenu(); | ||
| 320 | $self->{title}->Hide(); | ||
| 321 | $table = 0; | ||
| 322 | @tables = ( [0, 'Pan'], [0, 'Cha'], [1, 'Pan'], [1, 'Cha'], [2, 'Pan'], [2, 'Cha'], [3, 'Pan'], [3, 'Cha'], [4, 'Pan'] ); | ||
| 323 | |||
| 324 | while (1) { | ||
| 325 | $retval = $self->RunHighScore( @{$tables[$table]}, $auto ); | ||
| 326 | if ($retval eq 'next') { | ||
| 327 | ++$table; | ||
| 328 | $table = 0 if $table == scalar @tables; | ||
| 329 | last if $table == 0 and $auto; | ||
| 330 | } elsif ($retval eq 'prev') { | ||
| 331 | --$table; | ||
| 332 | $table = $#tables if $table < 0; | ||
| 333 | } else { | ||
| 334 | last; | ||
| 335 | } | ||
| 336 | } | ||
| 337 | |||
| 338 | $self->ShowTooltip(); | ||
| 339 | $self->{title}->Show(); | ||
| 340 | $self->LeaveSubMenu($recall); | ||
| 341 | } | ||
| 342 | |||
| 343 | sub UpdateBallMixerMenu { | ||
| 344 | my $self = shift; | ||
| 345 | |||
| 346 | $self->{menuItems}->[1]->SetParameter( $Games::PangZero::DeathBallsEnabled ? 'on' : 'off' ); | ||
| 347 | $self->{menuItems}->[2]->SetParameter( $Games::PangZero::EarthquakeBallsEnabled ? 'on' : 'off' ); | ||
| 348 | $self->{menuItems}->[3]->SetParameter( $Games::PangZero::WaterBallsEnabled ? 'on' : 'off' ); | ||
| 349 | $self->{menuItems}->[4]->SetParameter( $Games::PangZero::SeekerBallsEnabled ? 'on' : 'off' ); | ||
| 350 | } | ||
| 351 | |||
| 352 | sub RunBallMixerMenu { | ||
| 353 | my $self = shift; | ||
| 354 | my ($recall); | ||
| 355 | |||
| 356 | $recall = $self->EnterSubMenu(); | ||
| 357 | my ($y, $yinc) = (110, 40); | ||
| 358 | push @{$self->{menuItems}}, ( | ||
| 359 | Games::PangZero::MenuItem->new( 100, $y += $yinc, "Back to options menu"), | ||
| 360 | Games::PangZero::MenuItem->new( 100, $y += $yinc + 20, "Death Balls: ", "Death balls multiply every time you shoot them.", "You can get rid of them by NOT shooting them for 20 seconds." ), | ||
| 361 | Games::PangZero::MenuItem->new( 100, $y += $yinc, "Earthquake Balls: ", "Earthquake balls shake the ground when they bounce.", "This sends you flying. Very dangerous." ), | ||
| 362 | Games::PangZero::MenuItem->new( 100, $y += $yinc, "Water Balls: ", "Water balls quickly dissolve, creating a flood of small balls." ), | ||
| 363 | Games::PangZero::MenuItem->new( 100, $y += $yinc, "Seeker Balls: ", "This ball picks a target, and chases him." ), | ||
| 364 | ); | ||
| 365 | $self->UpdateBallMixerMenu(); | ||
| 366 | push @Games::PangZero::GameObjects, (@{$self->{menuItems}}); | ||
| 367 | $self->SetCurrentItemIndex(0); | ||
| 368 | |||
| 369 | while (1) { | ||
| 370 | $self->MenuAdvance(); | ||
| 371 | last if $self->{abortgame}; | ||
| 372 | $self->HandleUpDownKeys(); | ||
| 373 | |||
| 374 | if ($Games::PangZero::MenuEvents{BUTTON}) { | ||
| 375 | last if $self->{currentItemIndex} == 0; # Back to main | ||
| 376 | if ($self->{currentItemIndex} == 1) { | ||
| 377 | $Games::PangZero::DeathBallsEnabled = 1 - $Games::PangZero::DeathBallsEnabled; $self->UpdateBallMixerMenu(); | ||
| 378 | } elsif ($self->{currentItemIndex} == 2) { | ||
| 379 | $Games::PangZero::EarthquakeBallsEnabled = 1 - $Games::PangZero::EarthquakeBallsEnabled; $self->UpdateBallMixerMenu(); | ||
| 380 | } elsif ($self->{currentItemIndex} == 3) { | ||
| 381 | $Games::PangZero::WaterBallsEnabled = 1 - $Games::PangZero::WaterBallsEnabled; $self->UpdateBallMixerMenu(); | ||
| 382 | } elsif ($self->{currentItemIndex} == 4) { | ||
| 383 | $Games::PangZero::SeekerBallsEnabled = 1 - $Games::PangZero::SeekerBallsEnabled; $self->UpdateBallMixerMenu(); | ||
| 384 | } | ||
| 385 | } | ||
| 386 | } | ||
| 387 | |||
| 388 | $self->LeaveSubMenu($recall); | ||
| 389 | } | ||
| 390 | |||
| 391 | sub UpdateOptionsMenu { | ||
| 392 | my $self = shift; | ||
| 393 | |||
| 394 | $self->{menuItems}->[1]->SetParameter( $Games::PangZero::Slippery ? 'on' : 'off' ); | ||
| 395 | $self->{menuItems}->[3]->SetParameter( $Games::PangZero::SoundEnabled ? 'on' : 'off'); | ||
| 396 | $self->{menuItems}->[4]->SetParameter( $Games::PangZero::MusicEnabled ? 'on' : 'off'); | ||
| 397 | $self->{menuItems}->[5]->SetText('< ' . ('Windowed', 'Fullscreen', 'Widescreen')[$Games::PangZero::FullScreen] | ||
| 398 | . ($self->{restart} ? ' (requires restart)' : '') . ' >'); | ||
| 399 | $self->{menuItems}->[6]->SetParameter( $Games::PangZero::ShowWebsite eq $Games::PangZero::VERSION ? 'no' : 'yes' ); | ||
| 400 | } | ||
| 401 | |||
| 402 | sub RunOptionsMenu { | ||
| 403 | my $self = shift; | ||
| 404 | my $recall = $self->EnterSubMenu(); | ||
| 405 | my ($y, $yinc) = (80, 38); | ||
| 406 | push @{$self->{menuItems}}, ( | ||
| 407 | Games::PangZero::MenuItem->new( 100, $y += $yinc, "Back to main menu"), | ||
| 408 | Games::PangZero::MenuItem->new( 100, $y += $yinc + 20, "Slippery floor: ", "Turning this on creates and icy floor that you slide on", "This makes the game a lot harder!" ), | ||
| 409 | Games::PangZero::MenuItem->new( 100, $y += $yinc, "Ball Mixer...", "Turn the special balls on and off.", "This can make the game easier." ), | ||
| 410 | Games::PangZero::MenuItem->new( 100, $y += $yinc, "Sound: ", "Press Enter to turn sound effects on/off." ), | ||
| 411 | Games::PangZero::MenuItem->new( 100, $y += $yinc, "Music: ", "Press Enter to turn the background music on/off." ), | ||
| 412 | Games::PangZero::MenuItem->new( 68, $y += $yinc, "Fullscreen", "Press Left/Right to set the screen mode.", "If you have a wide screen (e.g. 16:9), use the Widescreen option.", "This doesn't take effect until you quit and restart the game." ), | ||
| 413 | Games::PangZero::MenuItem->new( 100, $y += $yinc, "Show website at exit: ", "Should Pang Zero take you to our web site at exit?", "True enlightenment awaits you online!" ), | ||
| 414 | ); | ||
| 415 | $self->UpdateOptionsMenu(); | ||
| 416 | push @Games::PangZero::GameObjects, (@{$self->{menuItems}}); | ||
| 417 | $self->SetCurrentItemIndex(0); | ||
| 418 | |||
| 419 | while (1) { | ||
| 420 | $self->MenuAdvance(); | ||
| 421 | last if $self->{abortgame}; | ||
| 422 | $self->HandleUpDownKeys(); | ||
| 423 | |||
| 424 | if ($Games::PangZero::MenuEvents{LEFT} and $self->{currentItemIndex} == 5) { | ||
| 425 | if ($Games::PangZero::FullScreen > 0) { --$Games::PangZero::FullScreen; $self->{restart} = 1; } | ||
| 426 | $self->UpdateOptionsMenu(); | ||
| 427 | } | ||
| 428 | if ($Games::PangZero::MenuEvents{RIGHT} and $self->{currentItemIndex} == 5) { | ||
| 429 | if ($Games::PangZero::FullScreen < 2) { ++$Games::PangZero::FullScreen; $self->{restart} = 1; } | ||
| 430 | $self->UpdateOptionsMenu(); | ||
| 431 | } | ||
| 432 | if ($Games::PangZero::MenuEvents{BUTTON}) { | ||
| 433 | last if $self->{currentItemIndex} == 0; # Back to main | ||
| 434 | if ($self->{currentItemIndex} == 2) { | ||
| 435 | $self->RunBallMixerMenu(); | ||
| 436 | } elsif ($self->{currentItemIndex} == 1) { | ||
| 437 | $Games::PangZero::Slippery = $Games::PangZero::Slippery ? 0 : 1; $self->UpdateOptionsMenu(); | ||
| 438 | } elsif ($self->{currentItemIndex} == 3) { | ||
| 439 | $Games::PangZero::SoundEnabled = 1 - $Games::PangZero::SoundEnabled; $self->UpdateOptionsMenu(); | ||
| 440 | } elsif ($self->{currentItemIndex} == 4) { | ||
| 441 | Games::PangZero::SetMusicEnabled(1 - $Games::PangZero::MusicEnabled); $self->UpdateOptionsMenu(); | ||
| 442 | } elsif ($self->{currentItemIndex} == 6) { | ||
| 443 | $Games::PangZero::ShowWebsite = ($Games::PangZero::ShowWebsite eq $Games::PangZero::Version ? 0 : $Games::PangZero::VERSION); $self->UpdateOptionsMenu(); | ||
| 444 | } | ||
| 445 | } | ||
| 446 | } | ||
| 447 | |||
| 448 | $self->LeaveSubMenu($recall); | ||
| 449 | } | ||
| 450 | |||
| 451 | sub UpdateControlsMenu { | ||
| 452 | my $self = shift; | ||
| 453 | |||
| 454 | $self->{menuItems}->[1]->SetText("< Number of Players: $Games::PangZero::NumGuys >"); | ||
| 455 | for (my $i = 1 ; $i <= 6; ++$i) { | ||
| 456 | if ($i > $Games::PangZero::NumGuys) { | ||
| 457 | $self->{menuItems}->[$i+1]->Hide(); | ||
| 458 | $self->{keysAsText}->[$i-1]->Hide(); | ||
| 459 | } else { | ||
| 460 | $self->{menuItems}->[$i+1]->Show(); | ||
| 461 | $self->{keysAsText}->[$i-1]->Show(); | ||
| 462 | } | ||
| 463 | } | ||
| 464 | } | ||
| 465 | |||
| 466 | sub RunControlsMenu { | ||
| 467 | my $self = shift; | ||
| 468 | my ($menuItem, @keysAsText, @yPositions); | ||
| 469 | |||
| 470 | my $recall = $self->EnterSubMenu(); | ||
| 471 | $self->{title}->Hide(); | ||
| 472 | my $baseY = 50; | ||
| 473 | |||
| 474 | push @{$self->{menuItems}}, | ||
| 475 | Games::PangZero::MenuItem->new( 50, $baseY, "Back to main menu"), | ||
| 476 | Games::PangZero::MenuItem->new( 18, $baseY += 40, "<>", "Use left and right key to set the number of players here.", "The more the merrier!", "Don't forget to set their keys below." ); | ||
| 477 | for ( my $i = 1; $i <= 6; ++$i ) { | ||
| 478 | $yPositions[$i] = $baseY + 20 + $i * 40; | ||
| 479 | push @{$self->{menuItems}}, (Games::PangZero::MenuItem->new( 50, $yPositions[$i], "Player $i")); | ||
| 480 | push @keysAsText, (Games::PangZero::MenuItem->new( 220, $yPositions[$i], KeysToText($Games::PangZero::Players[$i-1]->{keys})) ); | ||
| 481 | } | ||
| 482 | push @Games::PangZero::GameObjects, (@keysAsText, @{$self->{menuItems}}); | ||
| 483 | $self->{keysAsText} = \@keysAsText; | ||
| 484 | $self->UpdateControlsMenu(); | ||
| 485 | $self->SetCurrentItemIndex(1); | ||
| 486 | |||
| 487 | while (1) { | ||
| 488 | $self->MenuAdvance(); | ||
| 489 | last if $self->{abortgame}; | ||
| 490 | $self->HandleUpDownKeys(); | ||
| 491 | if ($Games::PangZero::MenuEvents{LEFT} and $self->{currentItemIndex} == 1) { | ||
| 492 | --$Games::PangZero::NumGuys if $Games::PangZero::NumGuys > 1; | ||
| 493 | $self->UpdateControlsMenu(); | ||
| 494 | } | ||
| 495 | if ($Games::PangZero::MenuEvents{RIGHT} and $self->{currentItemIndex} == 1) { | ||
| 496 | ++$Games::PangZero::NumGuys if $Games::PangZero::NumGuys < 6; | ||
| 497 | $self->UpdateControlsMenu(); | ||
| 498 | } | ||
| 499 | if ($Games::PangZero::MenuEvents{BUTTON}) { | ||
| 500 | last if $self->{currentItemIndex} == 0; # Back to main | ||
| 501 | next if $self->{currentItemIndex} == 1; | ||
| 502 | my $player = $Games::PangZero::Players[$self->{currentItemIndex} - 2]; | ||
| 503 | my $key = 0; | ||
| 504 | my $keysAsText = $keysAsText[$self->{currentItemIndex} - 2]; | ||
| 505 | $self->{currentItem}->Hide(); | ||
| 506 | $keysAsText->Hide(); | ||
| 507 | my @prompts = ("Press 'LEFT' key or joystick button", "Press 'RIGHT' key", "Press 'FIRE' key"); | ||
| 508 | my $keyMenuItem = Games::PangZero::MenuItem->new( 100, $yPositions[$self->{currentItemIndex} - 1], $prompts[0] ); | ||
| 509 | push @Games::PangZero::GameObjects, ($keyMenuItem); | ||
| 510 | $keyMenuItem->Select; | ||
| 511 | while (1) { | ||
| 512 | $self->MenuAdvance(); | ||
| 513 | if ($self->{abortgame}) { | ||
| 514 | $self->{abortgame} = 0; | ||
| 515 | goto endOfKeyEntry; | ||
| 516 | } | ||
| 517 | if (%Games::PangZero::Events) { | ||
| 518 | my ($event) = %Games::PangZero::Events; | ||
| 519 | if ($event =~ /^B(\d+)$/) { | ||
| 520 | $player->{keys} = ["L$1", "R$1", "B$1"]; | ||
| 521 | last; | ||
| 522 | } | ||
| 523 | $player->{keys}->[$key] = $event; | ||
| 524 | ++$key; | ||
| 525 | last if $key >= 3; | ||
| 526 | $keyMenuItem->SetText($prompts[$key]); | ||
| 527 | } | ||
| 528 | } | ||
| 529 | |||
| 530 | $keyMenuItem->SetText('Select character'); | ||
| 531 | my $guy = Games::PangZero::Guy->new($player); | ||
| 532 | $guy->{x} = $keyMenuItem->{targetX} + $keyMenuItem->{w} + 10; | ||
| 533 | $guy->{y} = $keyMenuItem->{targetY} - 10; | ||
| 534 | $guy->DemoMode(); | ||
| 535 | splice @Games::PangZero::GameObjects, -2, 0, $guy; | ||
| 536 | while (1) { | ||
| 537 | $self->MenuAdvance(); | ||
| 538 | if ($self->{abortgame}) { | ||
| 539 | $self->{abortgame} = 0; | ||
| 540 | goto endOfKeyEntry; | ||
| 541 | } | ||
| 542 | if ($Games::PangZero::Events{$player->{keys}->[0]}) { | ||
| 543 | --$player->{imagefileindex}; | ||
| 544 | $player->{imagefileindex} = $#Games::PangZero::GuyImageFiles if $player->{imagefileindex} < 0; | ||
| 545 | Games::PangZero::Graphics::MakeGuySurface($player); | ||
| 546 | $guy->{surface} = $player->{guySurface}; | ||
| 547 | $guy->CalculateAnimPhases(); | ||
| 548 | } elsif ($Games::PangZero::Events{$player->{keys}->[1]}) { | ||
| 549 | ++$player->{imagefileindex}; | ||
| 550 | $player->{imagefileindex} = 0 if $player->{imagefileindex} > $#Games::PangZero::GuyImageFiles; | ||
| 551 | Games::PangZero::Graphics::MakeGuySurface($player); | ||
| 552 | $guy->{surface} = $player->{guySurface}; | ||
| 553 | $guy->CalculateAnimPhases(); | ||
| 554 | } elsif ($Games::PangZero::Events{$player->{keys}->[2]}) { | ||
| 555 | last; | ||
| 556 | } | ||
| 557 | } | ||
| 558 | |||
| 559 | $keyMenuItem->SetText('Select color'); | ||
| 560 | while (1) { | ||
| 561 | $self->MenuAdvance(); | ||
| 562 | if ($self->{abortgame}) { | ||
| 563 | $self->{abortgame} = 0; | ||
| 564 | goto endOfKeyEntry; | ||
| 565 | } | ||
| 566 | if ($Games::PangZero::Events{$player->{keys}->[0]}) { | ||
| 567 | --$player->{colorindex}; | ||
| 568 | $player->{colorindex} = $#Games::PangZero::GuyColors if $player->{colorindex} < 0; | ||
| 569 | Games::PangZero::Graphics::MakeGuySurface($player); | ||
| 570 | $guy->{surface} = $player->{guySurface}; | ||
| 571 | } elsif ($Games::PangZero::Events{$player->{keys}->[1]}) { | ||
| 572 | ++$player->{colorindex}; | ||
| 573 | $player->{colorindex} = 0 if $player->{colorindex} > $#Games::PangZero::GuyColors; | ||
| 574 | Games::PangZero::Graphics::MakeGuySurface($player); | ||
| 575 | $guy->{surface} = $player->{guySurface}; | ||
| 576 | } elsif ($Games::PangZero::Events{$player->{keys}->[2]}) { | ||
| 577 | last; | ||
| 578 | } | ||
| 579 | } | ||
| 580 | |||
| 581 | endOfKeyEntry: | ||
| 582 | $guy->Delete() if $guy; | ||
| 583 | $self->{currentItem}->Show(); | ||
| 584 | $self->{currentItem}->Select; | ||
| 585 | $keysAsText->SetText(KeysToText($player->{keys})); | ||
| 586 | $keysAsText->Show; | ||
| 587 | $keyMenuItem->HideAndDelete; | ||
| 588 | } | ||
| 589 | } | ||
| 590 | |||
| 591 | foreach my $menuItem (@keysAsText) { $menuItem->HideAndDelete(); } | ||
| 592 | $self->LeaveSubMenu($recall); | ||
| 593 | $self->{title}->Show(); | ||
| 594 | delete $self->{keysAsText}; | ||
| 595 | } | ||
| 596 | |||
| 597 | sub UpdateGameMenu { | ||
| 598 | my $self = shift; | ||
| 599 | |||
| 600 | $self->{menuItems}->[3]->SetText("< Difficulty: $Games::PangZero::DifficultyLevel->{name} >"); | ||
| 601 | $self->{menuItems}->[4]->SetText("< Weapon Duration: $Games::PangZero::WeaponDuration->{name} >"); | ||
| 602 | } | ||
| 603 | |||
| 604 | sub RunGameMenu { | ||
| 605 | my $self = shift; | ||
| 606 | my $recall = $self->EnterSubMenu(); | ||
| 607 | my ($y, $yinc) = (110, 40); | ||
| 608 | push @{$self->{menuItems}}, ( | ||
| 609 | Games::PangZero::MenuItem->new( 100, $y += $yinc, "Back to main menu", "Press Enter to return to the main menu"), | ||
| 610 | Games::PangZero::MenuItem->new( 100, $y += $yinc + 20, "Start Panic Game", "In Panic Mode, the balls continuously fall from the sky.", "Can you keep up the pace?", "This game is for advanced players." ), | ||
| 611 | Games::PangZero::MenuItem->new( 100, $y += $yinc, "Start Challenge Game", "More and more difficult levels challenge your skill.", "This game is best for beginners." ), | ||
| 612 | Games::PangZero::MenuItem->new( 68, $y += $yinc, "<>", "Press the Left and Right keys to set the game difficulty.", "The game speed and number of harpoons depend on this setting.", "The `Miki' level is for Deathball Specialists (Panic mode only)." ), | ||
| 613 | Games::PangZero::MenuItem->new( 68, $y += $yinc, "<>", "Press the Left and Right keys to set the bonus weapon duration.", "This will determine how long you can use bonus weapons." ), | ||
| 614 | ); | ||
| 615 | $self->UpdateGameMenu(); | ||
| 616 | push @Games::PangZero::GameObjects, (@{$self->{menuItems}}); | ||
| 617 | $self->SetCurrentItemIndex($Games::PangZero::LastGameMenuResult ? $Games::PangZero::LastGameMenuResult : 1); | ||
| 618 | |||
| 619 | while (1) { | ||
| 620 | $self->MenuAdvance(); | ||
| 621 | last if $self->{abortgame}; | ||
| 622 | $self->HandleUpDownKeys(); | ||
| 623 | |||
| 624 | if ($Games::PangZero::MenuEvents{LEFT} and $self->{currentItemIndex} == 3) { | ||
| 625 | Games::PangZero::Config::SetDifficultyLevel($Games::PangZero::DifficultyLevelIndex - 1); | ||
| 626 | $self->UpdateGameMenu(); | ||
| 627 | } | ||
| 628 | if ($Games::PangZero::MenuEvents{RIGHT} and $self->{currentItemIndex} == 3) { | ||
| 629 | Games::PangZero::Config::SetDifficultyLevel($Games::PangZero::DifficultyLevelIndex + 1); | ||
| 630 | $self->UpdateGameMenu(); | ||
| 631 | } | ||
| 632 | if ($Games::PangZero::MenuEvents{LEFT} and $self->{currentItemIndex} == 4) { | ||
| 633 | Games::PangZero::Config::SetWeaponDuration($Games::PangZero::WeaponDurationIndex - 1); | ||
| 634 | $self->UpdateGameMenu(); | ||
| 635 | } | ||
| 636 | if ($Games::PangZero::MenuEvents{RIGHT} and $self->{currentItemIndex} == 4) { | ||
| 637 | Games::PangZero::Config::SetWeaponDuration($Games::PangZero::WeaponDurationIndex + 1); | ||
| 638 | $self->UpdateGameMenu(); | ||
| 639 | } | ||
| 640 | if ($Games::PangZero::MenuEvents{BUTTON}) { | ||
| 641 | last if $self->{currentItemIndex} == 0; # Back to main | ||
| 642 | if ($self->{currentItemIndex} == 1) { | ||
| 643 | $self->{result} = 'panic'; | ||
| 644 | } elsif ($self->{currentItemIndex} == 2) { | ||
| 645 | if ($Games::PangZero::DifficultyLevel->{name} ne 'Miki') { | ||
| 646 | $self->{result} = 'challenge'; | ||
| 647 | } else { | ||
| 648 | $self->ShowTooltip("Miki difficulty level is for panic mode only."); | ||
| 649 | } | ||
| 650 | } | ||
| 651 | } | ||
| 652 | last if $self->{result}; | ||
| 653 | } | ||
| 654 | |||
| 655 | $Games::PangZero::LastGameMenuResult = $self->{currentItemIndex}; | ||
| 656 | $self->LeaveSubMenu($recall); | ||
| 657 | } | ||
| 658 | |||
| 659 | sub OnMenuIdle { | ||
| 660 | my $self = shift; | ||
| 661 | |||
| 662 | ++$self->{idle}; | ||
| 663 | if ($self->{idle} == 1) { $self->RunHighScores('auto'); } | ||
| 664 | elsif ($self->{idle} == 2) { $self->RunCredits('demo'); } | ||
| 665 | elsif ($self->{idle} == 3) { $self->{idle} = 0; return 'demo'; } | ||
| 666 | return ''; | ||
| 667 | } | ||
| 668 | |||
| 669 | sub Run { | ||
| 670 | my $self = shift; | ||
| 671 | my ($y, $yinc, $idle); | ||
| 672 | |||
| 673 | $self->ResetGame(); | ||
| 674 | $Games::PangZero::ScoreFont->use(); | ||
| 675 | ($y, $yinc) = ($Games::PangZero::ScreenHeight + 15, 20); | ||
| 676 | SDLx::SFont::print_text( $Games::PangZero::Background, 10, $y += $yinc, "Pang Zero $Games::PangZero::VERSION (C) 2006 by UPi (upi\@sourceforge.net)" ) if $y + $yinc * 2 < $Games::PangZero::PhysicalScreenHeight; | ||
| 677 | |||
| 678 | SDLx::SFont::print_text( $Games::PangZero::Background, 10, $y += $yinc, "Use cursor keys to navigate menu, Enter to select" ) if $y + $yinc * 2 < $Games::PangZero::PhysicalScreenHeight; | ||
| 679 | |||
| 680 | SDLx::SFont::print_text( $Games::PangZero::Background, 10, $y += $yinc, "P pauses the game, Esc quits" ) if $y + $yinc * 2 < $Games::PangZero::PhysicalScreenHeight; | ||
| 681 | |||
| 682 | SDL::Video::blit_surface($Games::PangZero::Background, SDL::Rect->new(0, 0, $Games::PangZero::App->w, $Games::PangZero::App->h), $Games::PangZero::App, SDL::Rect->new(0, 0, $Games::PangZero::App->w, $Games::PangZero::App->h)); | ||
| 683 | |||
| 684 | $Games::PangZero::MenuFont->use(); | ||
| 685 | push @Games::PangZero::GameObjects, (Games::PangZero::FpsIndicator->new()); | ||
| 686 | $self->SetGameSpeed(); | ||
| 687 | $Games::PangZero::GamePause = 0; | ||
| 688 | |||
| 689 | ($y, $yinc) = (90, 40); | ||
| 690 | |||
| 691 | $self->{menuItems} = [ | ||
| 692 | Games::PangZero::MenuItem->new( 100, $y += $yinc, "Start Game" ), | ||
| 693 | Games::PangZero::MenuItem->new( 100, $y += $yinc, "Options", "Various game settings" ), | ||
| 694 | Games::PangZero::MenuItem->new( 100, $y += $yinc, "Setup players", "Set the number of players, setup keys and joysticks" ), | ||
| 695 | Games::PangZero::MenuItem->new( 100, $y += $yinc, "Help", "How to play the game, demo of special balls" ), | ||
| 696 | Games::PangZero::MenuItem->new( 100, $y += $yinc, "Credits", "You might be wondering: Who has created Pang Zero?", "Wonder no more." ), | ||
| 697 | Games::PangZero::MenuItem->new( 100, $y += $yinc, "High Scores", "Hall of Fame." ), | ||
| 698 | Games::PangZero::MenuItem->new( 100, $y += $yinc, "Exit Game", "Press Enter to exit the game" ), | ||
| 699 | ]; | ||
| 700 | |||
| 701 | $self->{title} = Games::PangZero::MenuItem->new( 300, 60, "PANG ZERO" ); | ||
| 702 | $self->{title}->{filled} = 1; | ||
| 703 | $self->{title}->{fillcolor} = SDL::Color->new(0, 128, 255); | ||
| 704 | $self->{title}->Center(); | ||
| 705 | |||
| 706 | push @Games::PangZero::GameObjects, ( | ||
| 707 | Games::PangZero::Ball::Spawn($Games::PangZero::BallDesc[8], -1, 1), | ||
| 708 | Games::PangZero::Ball::Spawn($Games::PangZero::BallDesc[0], -1, 0), | ||
| 709 | Games::PangZero::Ball::Spawn($Games::PangZero::BallDesc{super0}, -1, 1), | ||
| 710 | Games::PangZero::Ball::Spawn($Games::PangZero::BallDesc[2], -1, 0), | ||
| 711 | Games::PangZero::Ball::Spawn($Games::PangZero::BallDesc[5], -1, 1), | ||
| 712 | $self->{title}, | ||
| 713 | @{$self->{menuItems}}, | ||
| 714 | ); | ||
| 715 | |||
| 716 | $self->SetCurrentItemIndex( 0 ); | ||
| 717 | Games::PangZero::GameTimer::ResetTimer(); | ||
| 718 | |||
| 719 | while (1) { | ||
| 720 | $self->MenuAdvance(); | ||
| 721 | $self->Exit() if $self->{abortgame}; | ||
| 722 | $self->HandleUpDownKeys(); | ||
| 723 | last if $self->{result}; | ||
| 724 | if ($Games::PangZero::MenuEvents{BUTTON}) { | ||
| 725 | if ($self->{currentItemIndex} == 0) { | ||
| 726 | $self->RunGameMenu(); | ||
| 727 | } elsif ($self->{currentItemIndex} == 1) { | ||
| 728 | $self->RunOptionsMenu(); | ||
| 729 | } elsif ($self->{currentItemIndex} == 2) { | ||
| 730 | $self->RunControlsMenu(); | ||
| 731 | } elsif ($self->{currentItemIndex} == 3) { | ||
| 732 | $self->RunTutorialMenu; | ||
| 733 | } elsif ($self->{currentItemIndex} == 4) { | ||
| 734 | $self->RunCredits(); | ||
| 735 | } elsif ($self->{currentItemIndex} == 5) { | ||
| 736 | $self->RunHighScores(); | ||
| 737 | } | ||
| 738 | $self->Exit() if $self->{currentItemIndex} == 6; | ||
| 739 | } | ||
| 740 | if (%Games::PangZero::Events) { | ||
| 741 | $idle = 0; | ||
| 742 | } else { | ||
| 743 | if (++$idle > 1000) { | ||
| 744 | $self->{result} = $self->OnMenuIdle(); | ||
| 745 | $idle = 0; | ||
| 746 | } | ||
| 747 | } | ||
| 748 | } | ||
| 749 | |||
| 750 | $Games::PangZero::ScoreFont->use(); | ||
| 751 | return $self->{result}; | ||
| 752 | } | ||
| 753 | |||
| 754 | 1; |