/usr/share/perl5/Games/PangZero/ChallengeGame.pm is in pangzero 1.4-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 | ##########################################################################
package Games::PangZero::ChallengeGame;
##########################################################################
@ISA = qw(Games::PangZero::PlayableGameBase);
use strict;
use warnings;
sub new {
my ($class) = @_;
my $self = Games::PangZero::PlayableGameBase->new();
%{$self} = (%{$self},
'challenge' => undef,
);
bless $self, $class;
}
sub CreateLevelNumberSurface {
my ($level) = @_;
my ($surface, $w);
$Games::PangZero::GlossyFont->use();
$w = Games::PangZero::Graphics::TextWidth("Level $level");
$surface = SDL::Surface->new(SDL_SWSURFACE(), $w+6, 48, 32);
SDLx::SFont::print_text( $surface, 3, 3, "Level $level" );
$Games::PangZero::ScoreFont->use();
return $surface;
}
sub SetGameLevel {
my ($self, $level) = @_;
Games::PangZero::SlowEffect::RemoveSlowEffects();
$self->SUPER::SetGameLevel($level);
$level = $#Games::PangZero::ChallengeLevels if $level > $#Games::PangZero::ChallengeLevels;
$self->{challenge} = $Games::PangZero::ChallengeLevels[$level];
$self->SpawnChallenge();
my ($levelObject, $surface);
$levelObject = Games::PangZero::GameObject->new();
$surface = CreateLevelNumberSurface($level + 1);
$levelObject->{surface} = $surface;
$levelObject->{w} = $surface->w();
$levelObject->{h} = $surface->h();
$levelObject->{x} = ($Games::PangZero::ScreenWidth - $levelObject->{w}) / 2;
$levelObject->{y} = ($Games::PangZero::ScreenHeight - $levelObject->{h}) / 2;
$levelObject->{draw} = sub { my $self = shift; SDL::Video::blit_surface($self->{surface},
SDL::Rect->new(0, 0, $self->{surface}->w, $self->{surface}->h),
$Games::PangZero::App, $self->{rect} ); };
$levelObject->{advance} = sub { my $self = shift; $self->Delete() if ++$self->{time} > 200; };
push @Games::PangZero::GameObjects, $levelObject;
}
sub AdvanceGameObjects {
my ($self) = @_;
if ($self->{nextlevel}) {
Games::PangZero::PlaySound('level');
$self->SetGameLevel($self->{level} + 1);
delete $self->{nextlevel};
}
if ($self->{playerspawned}) {
$self->SpawnChallenge();
$self->{playerspawned} = 0;
}
$self->SUPER::AdvanceGameObjects();
}
sub SpawnChallenge {
my $self = shift;
my ($challenge, @guys, $balldesc, $ball, $hasBonus, %balls, $numBalls, $ballsSpawned, @ballKeys, $x);
@guys = $self->PopEveryBall();
foreach (@guys) {
$_->{bonusDelay} = 1;
$_->{invincible} = 1;
}
$Games::PangZero::GamePause = 0;
delete $Games::PangZero::GameEvents{magic};
$challenge = $self->{challenge};
die unless $challenge;
while ($challenge =~ /(\w+)/g) {
$balldesc = $Games::PangZero::BallDesc{$1};
warn "Unknown ball in challenge: $1" unless $balldesc;
$balls{$1}++;
$numBalls++;
}
$ballsSpawned = 0;
while ($ballsSpawned < $numBalls) {
foreach (keys %balls) {
next unless $balls{$_};
--$balls{$_};
$balldesc = $Games::PangZero::BallDesc{$_};
$x = $Games::PangZero::ScreenWidth * ($ballsSpawned * 2 + 1) / ($numBalls * 2) - $balldesc->{width} / 2;
$x = $Games::PangZero::ScreenWidth - $balldesc->{width} if $x > $Games::PangZero::ScreenWidth - $balldesc->{width};
$hasBonus = (($balldesc->{width} >= 32) and ($self->Rand(1) < $Games::PangZero::DifficultyLevel->{bonusprobability}));
$ball = &Ball::Spawn($balldesc, $x, ($ballsSpawned % 2) ? 0 : 1, $hasBonus);
if ($ball->{w} <= 32) {
$ball->{ismagic} = $ball->{hasmagic} = 0;
}
push @Games::PangZero::GameObjects, ($ball) ;
++$ballsSpawned;
}
}
}
sub OnBallPopped {
my $self = shift;
my ($i);
for ($i = $#Games::PangZero::GameObjects; $i >= 0; --$i) {
if ($Games::PangZero::GameObjects[$i]->isa('Games::PangZero::Ball')) {
return;
}
}
$self->{nextlevel} = 1;
}
1;
|