Codebase list pangzero / a44d542c-5bc1-45bd-b9e0-417e00ad44e2/main lib / Games / PangZero.pm
a44d542c-5bc1-45bd-b9e0-417e00ad44e2/main

Tree @a44d542c-5bc1-45bd-b9e0-417e00ad44e2/main (Download .tar.gz)

PangZero.pm @a44d542c-5bc1-45bd-b9e0-417e00ad44e2/mainraw · history · blame

  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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
package Games::PangZero;

$Cheat   = 0;
$VERSION = '1.4.1';
$DataDir = '';  # Set it to a path to avoid autodetection (e.g. /opt/pangzero/data)

=comment

##########################################################################
#
# PANG ZERO
# Copyright (C) 2006 by UPi <upi at sourceforge.net>
#
##########################################################################

This program is free software; you can redistribute it and//or modify
it under the terms of the GNU General Public License version 2, as
published by the Free Software Foundation.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.


##########################################################################
# TODO:
##########################################################################
* P4 Bonus probability is balldesc based.
* P3 Tour mode..?
* P5 Graphics and help for machine gun and power wire
* P5 Demo of beating the game at 'normal' difficulty
* P4 Even more forgiving collision detection (?)
* P4 Smooth numbers in the scoreboard
* P3 RotoZoomer smooth parameter to eliminate warning..
* P3 Set DataDir with command line parameter.
* P2 Roll your own game
* P4 Reorg menu: MenuItem->Update(), MenuItem->Left(), MenuItem->Right(), ...

Next release:
* Sound effect for matrix effect...
* Handle possible HST corruption if game exits while merging scores


##########################################################################
# QUICK GUIDE FOR WOULD-BE DEVELOPERS
##########################################################################

'
This file contains the entire source code of Pang Zero. I know that this is
an odd design, but it works for me. You can split the file easily if you
want to.

The parts of the file are organized like this:

1. INITIALIZATION OF GLOBAL OBJECTS (configuration, balls, levels, etc)
2. HIGH SCORE TABLE
3. GAME OBJECT PACKAGES
4. UTILITY PACKAGES AND METHODS
5. GAMEBASE AND DESCENDENT PACKAGES (includes the menu)
6. "MAIN" PROGRAM LOOP
'
=cut

use SDL ':init';
use SDL::Surface;
use SDL::Palette;
use SDL::PixelFormat;
use SDL::Video;
use SDL::Event;
use SDL::Events;
use SDL::Color;
use SDL::Config;
use SDL::Cursor;
use SDL::GFX::Rotozoom;
use SDL::Joystick;
use SDL::Mouse;
use SDL::Image;
use SDLx::SFont;

use Carp;

# SDL objects

use vars qw (
  $App $VERSION $RotoZoomer $Background $ScoreFont $MenuFont $GlossyFont
  %BallSurfaces
  $BorderSurface $WhiteBorderSurface $RedBorderSurface $BonusSurface $LevelIndicatorSurface $LevelIndicatorSurface2
  $WhiteHarpoonSurface
  %Sounds $Mixer
);

# Pang Zero variables and objects

use vars qw (
  $DataDir $ScreenHeight $ScreenWidth $PhysicalScreenWidth $PhysicalScreenHeight $ScreenMargin
  $SoundEnabled $MusicEnabled $FullScreen $ShowWebsite
  $DeathBallsEnabled $EarthquakeBallsEnabled $WaterBallsEnabled $SeekerBallsEnabled $Slippery
  @DifficultyLevels $DifficultyLevelIndex $DifficultyLevel
  @WeaponDurations $WeaponDuration $WeaponDurationIndex
  @GameObjects %GameEvents $GameSpeed $GamePause $Game
  @Players @GuyImageFiles @GuyColors $NumGuys
  @BallDesc %BallDesc @ChallengeLevels @PanicLevels
  $UnicodeMode $LastUnicodeKey %Keys %Events %MenuEvents );


use Games::PangZero::Globals;
use Games::PangZero::GameObject;
use Games::PangZero::Ball;
use Games::PangZero::BonusDrop;
use Games::PangZero::GameBase;
use Games::PangZero::PlayableGameBase;
use Games::PangZero::ChallengeGame;
use Games::PangZero::Config;
use Games::PangZero::DeadGuy;
use Games::PangZero::DeathBall;
use Games::PangZero::PanicGame;
use Games::PangZero::DemoGame;
use Games::PangZero::PlaybackGame;
use Games::PangZero::DemoPlaybackGame;
use Games::PangZero::RecordGame;
use Games::PangZero::DemoRecordGame;
use Games::PangZero::EarthquakeBall;
use Games::PangZero::FpsIndicator;
use Games::PangZero::FragileBall;
use Games::PangZero::GamePause;
use Games::PangZero::GameTimer;
use Games::PangZero::Graphics;
use Games::PangZero::Guy;
use Games::PangZero::Harpoon;
use Games::PangZero::HalfCutter;
use Games::PangZero::Hexa;
use Games::PangZero::Highscore;
use Games::PangZero::Joystick;
use Games::PangZero::MachineGun;
use Games::PangZero::Meltdown;
use Games::PangZero::Menu;
use Games::PangZero::MenuItem;
use Games::PangZero::Music;
use Games::PangZero::Palette;
use Games::PangZero::Pop;
use Games::PangZero::PowerWire;
use Games::PangZero::SeekerBall;
use Games::PangZero::SlowEffect;
use Games::PangZero::SuperBall;
use Games::PangZero::TutorialGame;
use Games::PangZero::UpsideDownBall;
use Games::PangZero::WaterBall;
use Games::PangZero::XmasBall;

sub SaveScreenshot {
  my $i = 0;
  my $filename;
  do { $filename = sprintf("screenshot%03d.bmp", $i); ++$i } while (-f $filename);
  SDL::Video::save_BMP($App, $filename);
}

sub Pause {
  my $pausedSurface = SDL::Image::load("$DataDir/paused.png");
  my $event         = SDL::Event->new();

  SDL::Video::blit_surface($pausedSurface, SDL::Rect->new(0, 0, $pausedSurface->w, $pausedSurface->h),
                           $App, SDL::Rect->new(($PhysicalScreenWidth - $pausedSurface->w) / 2, $PhysicalScreenHeight / 2 - 100, 0, 0));
  $App->sync();
  $Keys   = ();
  $Events = ();
  while (1) { # Paused, wait for keypress
    SDL::Events::pump_events();
    SDL::Events::wait_event($event);
    last if $event->type() == SDL_KEYDOWN and $event->key_sym == SDLK_p;
    if ($event->type() == SDL_KEYDOWN and $event->key_sym == SDLK_ESCAPE) {
      $Game->{abortgame} = 1;
      last;
    }
    $Game->Exit() if $event->type() == SDL_QUIT;
  }
  SDL::Video::blit_surface($Background, SDL::Rect->new(0, 0, $App->w, $App->h), $App, SDL::Rect->new(0, 0, $App->w, $App->h));
  Games::PangZero::GameTimer::ResetTimer();
}

sub HandleEvents {
  my ($readBothJoystickAxes) = @_;
  my ($event, $type);

  $event = SDL::Event->new;
  while (1) {
    SDL::Events::pump_events();
    last unless SDL::Events::poll_event($event);
    $type = $event->type();

    if ($type == SDL_QUIT) {
      $Game->Exit();
    }
    elsif ($type == SDL_KEYDOWN) {
      my $keypressed = $event->key_sym;
      if ($keypressed == SDLK_ESCAPE) {
        $Game->{abortgame} = 1;
      } elsif ($keypressed == SDLK_F1) {
        SaveScreenshot();
      } elsif ($keypressed == SDLK_p and not $UnicodeMode) {
        Pause();
      } else {
        $Keys{$keypressed}   = 1;
        $Events{$keypressed} = 1;
        $MenuEvents{UP}      = 1 if $keypressed == SDLK_UP();
        $MenuEvents{DOWN}    = 1 if $keypressed == SDLK_DOWN();
        $MenuEvents{LEFT}    = 1 if $keypressed == SDLK_LEFT();
        $MenuEvents{RIGHT}   = 1 if $keypressed == SDLK_RIGHT();
        $MenuEvents{BUTTON}  = 1 if $keypressed == SDLK_RETURN();
        $MenuEvents{BACKSP}  = 1 if $keypressed == SDLK_BACKSPACE;
        $LastUnicodeKey      = $event->key_unicode() if $UnicodeMode;
      }
    }
    elsif ($type == SDL_KEYUP) {
      my $keypressed     = $event->key_sym;
      $Keys{$keypressed} = 0;
    }
  }

  Games::PangZero::Joystick::ReadJoystick($readBothJoystickAxes);
}

sub DoMenu {
  my $oldScreenHeight = $ScreenHeight;
  my $oldScreenWidth  = $ScreenWidth;
  $ScreenWidth        = $PhysicalScreenWidth - $ScreenMargin * 2;
  $ScreenWidth        = int($ScreenWidth / 32) * 32;
  $Game               = Games::PangZero::Menu->new();
  my $retval          = $Game->Run();
  Games::PangZero::Config::SaveConfig();

  $ScreenWidth        = $oldScreenWidth;
  $ScreenHeight       = $oldScreenHeight;

  return $retval;
}

sub DoDemo {
  my $messages = $Game->{messages} = {
    1 => "Use harpoons to pop the balloons",
    160 => "Pop them, and they split in two",
    300 => "Pop them again and again",
    530 => "Popping the smallest ballons makes them disappear",
    630 => "The green Super Ball gives you a lot of free time",
    720 => "Use this time wisely!",
    1150 => "Making a lot of small balls is dangerous! Observe...",
    1600 => "Don't let the balloons touch you!",
    1708 => "Dying gives you some free time.",
    1900 => "So does shooting the flashing balloons.",
    2370 => "The yellow Super Ball destroys every balloon",
    2650 => "And now... THE SPECIAL BALL DEMO!",
    2950 => "The Bouncy Ball bounces twice as high as normal balls.",
    3620 => "See?",
    4222 => "The Hexa Ball is weightless and travels in a straight line.",
    4500 => "So does its offspring.",
    5210 => "The blue Water Ball splits every time it bounces.",
    5900 => "This can cause a tide of small balls!",
    6630 => "The Earthquake Ball will really shake you up.",
    7100 => "Its offspring is not as dangerous, but still annoying.",
    7800 => "Behold, the Death Ball. It cannot be killed!!!",
    8120 => "No, really, it can't! In fact, shooting it makes it multiply.",
    8220 => "If you avoid it for 20 secs, Deathballs will get bored and go away.",
    8320 => "Also, the yellow Super Ball will destroy the Deathballs for you.",
    8800 => "Shooting it too much will lead to the Deathball Meltdown.",
    9550 => "Last but not least: here's the Seeker Ball!",
    9900 => "This ball will stalk you forever.",
    10100 => "Whew! This concludes the Special Ball Demo. Have fun playing!",
  };
  my $record = 0 x 23 . 1 x 18 . 0 x 19 . 2 x 7 . 0 x 31 . 4 x 1 . 0 x 44 . 2 x 43 . 0 x 7 . 4 x 1 . 0 x 22 . 1 x 10 . 0 x 17 . 2 x 38 . 0 x 16 . 2 x 22 . 0 x 42 . 4 x 1 . 0 x 54 . 1 x 43 . 0 x 2 . 4 x 1 . 0 x 28 . 1 x 27 . 0 x 8 . 4 x 1 . 0 x 98 . 2 x 19 . 0 x 11 . 4 x 1 . 0 x 27 . 1 x 24 . 5 x 1 . 1 x 1 . 0 x 17 . 1 x 9 . 0 x 2 . 4 x 1 . 0 x 51 . 2 x 19 . 0 x 14 . 4 x 1 . 0 x 48 . 1 x 14 . 0 x 2 . 4 x 1 . 0 x 51 . 1 x 8 . 0 x 25 . 4 x 1 . 0 x 49 . 2 x 25 . 0 x 3 . 4 x 1 . 0 x 53 . 1 x 12 . 0 x 9 . 4 x 1 . 0 x 101 . 1 x 9 . 0 x 4 . 4 x 1 . 0 x 68 . 1 x 7 . 5 x 1 . 0 x 75 . 2 x 14 . 0 x 2 . 4 x 1 . 0 x 64 . 2 x 38 . 0 x 3 . 4 x 1 . 0 x 13 . 2 x 13 . 0 x 25 . 2 x 25 . 0 x 5 . 4 x 1 . 0 x 54 . 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 1 x 1 . 5 x 1 . 1 x 2 . 0 x 3 . 1 x 1 . 5 x 1 . 1 x 6 . 5 x 1 . 1 x 7 . 5 x 1 . 1 x 6 . 5 x 1 . 1 x 6 . 5 x 1 . 1 x 7 . 0 x 12 . 2 x 7 . 0 x 2 . 4 x 1 . 2 x 2 . 0 x 4 . 4 x 1 . 0 x 135 . 8 x 1 . 0 x 252 . 1 x 57 . 0 x 199 . 2 x 37 . 0 x 3 . 1 x 1 . 5 x 1 . 1 x 29 . 0 x 21 . 1 x 30 . 0 x 37 . 4 x 1 . 0 x 77 . 1 x 17 . 0 x 4 . 2 x 126 . 3 x 1 . 1 x 52 . 5 x 1 . 1 x 64 . 0 x 39 . 8 x 1 . 0 x 140;
  my $rand = [2199.02,1.12,0.11,1.24,0.11,1.21,0.33,0.19,0.16,0.12,0.07,0.28,0.68];

  Games::PangZero::Config::SaveConfig();
  $Game = Games::PangZero::DemoPlaybackGame->new( 1, 3, $record, $rand, $messages );
  $Game->Run();
  Games::PangZero::Config::LoadConfig();
  $Game->RestoreGameSettings();
}

sub DoRecordDemo {
  my ($numguys, $difficulty) = ($NumGuys, $DifficultyLevelIndex);

  $NumGuys = 1;
  Games::PangZero::Config::SetDifficultyLevel(3);
  $Game = Games::PangZero::DemoRecordGame->new();
  $Game->Run();
  print "\n\$record = '", $Game->{record}, "';\n";
  print "\$rand = [", join( ', ', @{$Game->{rand}} ), "];\n\n";
  $NumGuys = $numguys;
  Games::PangZero::Config::SetDifficultyLevel($difficulty);
}


##########################################################################
# MAIN PROGRAM STARTS HERE
##########################################################################

sub Initialize {

  eval { SDL::init(SDL_INIT_AUDIO | SDL_INIT_VIDEO | SDL_INIT_JOYSTICK) };
  die "Unable to initialize SDL: $@" if $@;

  Games::PangZero::Config::FindDataDir();
  Games::PangZero::Config::LoadConfig();
  print "Data directory is at '$DataDir'\n";
  my $sdlFlags;
  if (Games::PangZero::Config::IsMicrosoftWindows()) {
    $sdlFlags = SDL_ANYFORMAT;
  } else {
    if ($Games::PangZero::FullScreen) {
      $sdlFlags = SDL_HWSURFACE | SDL_HWACCEL | SDL_DOUBLEBUF | SDL_ANYFORMAT | SDL_FULLSCREEN;
    } else {
      $sdlFlags = SDL_HWSURFACE | SDL_HWACCEL | SDL_DOUBLEBUF | SDL_ANYFORMAT;
    }
  }

  ($PhysicalScreenWidth, $PhysicalScreenHeight) = Games::PangZero::Graphics::FindVideoMode();

  my $icon = SDL::Video::load_BMP("$DataDir/icon.bmp");
  SDL::Video::set_color_key($icon, SDL_SRCCOLORKEY, SDL::Color->new(0, 255, 0));
  SDL::Video::wm_set_icon($icon);
  $App = SDL::Video::set_video_mode($PhysicalScreenWidth,
                                    $PhysicalScreenHeight,
                                    32, $sdlFlags);
  SDL::Video::wm_set_caption("Pang Zero $VERSION", "Pang Zero $VERSION");
  SDL::Mouse::show_cursor(0);

  $Background = SDL::Surface->new( Games::PangZero::Config::IsMicrosoftWindows() ? SDL_SWSURFACE() : SDL_HWSURFACE(), $App->w, $App->h, 16);
  $Background = SDL::Video::display_format($Background);
  $ScoreFont  = SDLx::SFont->new("$DataDir/brandybun3.png");
  $MenuFont   = SDLx::SFont->new("$DataDir/font2.png");
  $GlossyFont = SDLx::SFont->new("$DataDir/glossyfont.png");

  Games::PangZero::Graphics::LoadSurfaces();
  Games::PangZero::Music::LoadSounds();
  Games::PangZero::Joystick::InitJoystick();
}

sub MainLoop {
  my $menuResult = DoMenu();
  if ($menuResult eq 'demo') {
    DoDemo();
  }

  #$Game = Games::PangZero::DemoRecordGame->new();
  $Game                         = ($menuResult eq 'challenge')
                                ? Games::PangZero::ChallengeGame->new()
                                : Games::PangZero::PanicGame->new();
  @Games::PangZero::Highscore::UnsavedHighScores = ();
  $Game->Run();

  bless $Game, 'Games::PangZero::Menu';
  $Games::PangZero::MenuFont->use();
  Games::PangZero::Highscore::MergeUnsavedHighScores($menuResult eq 'challenge' ? 'Cha' : 'Pan');

  return;

  my ($filename, $i) = ('', 1);
  do { $filename     = sprintf("record%03d.txt", $i); ++$i } while (-f $filename);
  open RECORD, ">$filename";
  print RECORD "NumGuys = $NumGuys;\nDifficultyLevelIndex = $DifficultyLevelIndex;\nrecord = '$Game->{record}';\n",
    "DeathBallsEnabled = $DeathBallsEnabled;\nEarthquakeBallsEnabled = $EarthquakeBallsEnabled;\n",
    "WaterBallsEnabled = $WaterBallsEnabled;\nSeekerBallsEnabled = $SeekerBallsEnabled;\n",
    'rand = [', join(',', @{$Game->{rand}}), "];\n\n";
  close RECORD;

  $Game = Games::PangZero::DemoPlaybackGame->new($NumGuys, $DifficultyLevelIndex, $Game->{record}, $Game->{rand}, {});
  $Game->Run();
  $Game->RestoreGameSettings();
}

sub ShowErrorMessage {
  my ($message) = @_;
  print "Pang Zero $VERSION died:\n$message\n";
}

sub ShowWebPage {
  my ($url) = @_;

  return if $ENV{PANGZERO_TEST};

  if (Games::PangZero::Config::IsMicrosoftWindows()) {
    my $ws = "$DataDir/website.html";
    $ws =~ s/\//\\\\/g;
    exec 'cmd', '/c', $ws;
    exit;
  } elsif ($ENV{'DISPLAY'}) {
    my @tryCommands = (
      "which gnome-open > /dev/null 2>&1 && (gnome-open $url&)",
      "which mozilla-firefox > /dev/null 2>&1 && (mozilla-firefox $url&)",
      "which firefox > /dev/null 2>&1 && (firefox $url&)",
      "which mozilla > /dev/null 2>&1 && (mozilla $url&)",
      "which konqueror > /dev/null 2>&1 && (konqueror $url&)",
    );
    foreach (@tryCommands) {
      return if system($_) == 0;
    }
  } else {
    print "Visit $url for more info about Pang Zero $Games::PangZero::VERSION\n";
  }
}

1;