| 1 | package Games::PangZero::BonusDrop; | ||
| 2 | |||
| 3 | @ISA = qw(Games::PangZero::GameObject); | ||
| 4 | use strict; | ||
| 5 | use warnings; | ||
| 6 | |||
| 7 | use vars qw(@BonusDesc); | ||
| 8 | |||
| 9 | @BonusDesc = ( | ||
| 10 | { 'weaponClass' => 'MachineGun', 'bonusDelay' => 1500, 'srcRect' => SDL::Rect->new( 0, 64, 32, 32), }, | ||
| 11 | { 'weaponClass' => 'HalfCutter', 'bonusDelay' => 1000, 'srcRect' => SDL::Rect->new(32, 64, 32, 32), }, | ||
| 12 | { 'weaponClass' => 'PowerWire', 'bonusDelay' => 3000, 'srcRect' => SDL::Rect->new(32, 96, 32, 32), }, | ||
| 13 | { 'onCollectedSub' => \&OnCollectedSlowEffect, 'srcRect' => SDL::Rect->new(32, 0, 32, 32), }, | ||
| 14 | ); | ||
| 15 | |||
| 16 | |||
| 17 | sub new { | ||
| 18 | my ($class, $ball) = @_; | ||
| 19 | my ($self); | ||
| 20 | |||
| 21 | $self = Games::PangZero::GameObject->new(); | ||
| 22 | |||
| 23 | %{$self} = ( %{$self}, | ||
| 24 | 'x' => $ball->{x} + ($ball->{w} - 32) / 2, | ||
| 25 | 'y' => $ball->{y} + ($ball->{h} - 32) / 2, | ||
| 26 | 'w' => 32, | ||
| 27 | 'h' => 32, | ||
| 28 | 'speedY' => -3, | ||
| 29 | 'speedX' => 0, | ||
| 30 | 'bottomDelay' => 500, | ||
| 31 | 'desc' => $BonusDesc[int $Games::PangZero::Game->Rand(scalar @BonusDesc)], | ||
| 32 | ); | ||
| 33 | bless $self, $class; | ||
| 34 | } | ||
| 35 | |||
| 36 | sub Advance { | ||
| 37 | my $self = shift; | ||
| 38 | |||
| 39 | if ($self->{y} >= $Games::PangZero::ScreenHeight - $self->{h}) { | ||
| 40 | $self->{y} = $Games::PangZero::ScreenHeight - $self->{h}; | ||
| 41 | if (--$self->{bottomDelay} < 0) { | ||
| 42 | $self->Delete(); | ||
| 43 | } | ||
| 44 | } else { | ||
| 45 | $self->{speedY} += 0.1; | ||
| 46 | $self->{y} += $self->{speedY}; | ||
| 47 | } | ||
| 48 | |||
| 49 | $self->CheckCollisions() if $self->{speedY} >= 0; | ||
| 50 | } | ||
| 51 | |||
| 52 | sub CheckCollisions { | ||
| 53 | my $self = shift; | ||
| 54 | my ($guy, @guysTouched); | ||
| 55 | |||
| 56 | foreach $guy (@Games::PangZero::GameObjects) { | ||
| 57 | next unless ref($guy) eq 'Games::PangZero::Guy'; | ||
| 58 | next unless $self->Collisions($guy); | ||
| 59 | push @guysTouched, ($guy); | ||
| 60 | } | ||
| 61 | return unless @guysTouched; | ||
| 62 | $self->Collected($guysTouched[$Games::PangZero::Game->Rand( scalar @guysTouched )]); | ||
| 63 | } | ||
| 64 | |||
| 65 | sub SetOnCollectedSub { | ||
| 66 | my ($self, $onCollectedSub) = @_; | ||
| 67 | $self->{onCollectedSub} = $onCollectedSub; | ||
| 68 | } | ||
| 69 | |||
| 70 | sub Collected { | ||
| 71 | my ($self, $guy) = @_; | ||
| 72 | |||
| 73 | if ($self->{onCollectedSub}) { | ||
| 74 | $self->{onCollectedSub}->($self, $guy); | ||
| 75 | } elsif ($self->{desc}->{onCollectedSub}) { | ||
| 76 | $self->{desc}->{onCollectedSub}->($self, $guy); | ||
| 77 | } else { | ||
| 78 | $guy->{weapon} = $self->{desc}->{weaponClass}; | ||
| 79 | $guy->{bonusDelay} = $self->{desc}->{bonusDelay} * $Games::PangZero::WeaponDuration->{durationmultiplier}; | ||
| 80 | } | ||
| 81 | $self->Delete(); | ||
| 82 | } | ||
| 83 | |||
| 84 | sub Draw { | ||
| 85 | my $self = shift; | ||
| 86 | |||
| 87 | return if $self->{bottomDelay} < 100 and (($Games::PangZero::Game->{anim} / 4) % 2 < 1); | ||
| 88 | $self->TransferRect(); | ||
| 89 | SDL::Video::blit_surface($Games::PangZero::BonusSurface, $self->{desc}->{srcRect}, $Games::PangZero::App, $self->{rect}); | ||
| 90 | } | ||
| 91 | |||
| 92 | sub OnCollectedSlowEffect { | ||
| 93 | my ($self, $guy) = @_; | ||
| 94 | |||
| 95 | Games::PangZero::SlowEffect::RemoveSlowEffects(); | ||
| 96 | push @Games::PangZero::GameObjects, Games::PangZero::SlowEffect->new(); | ||
| 97 | } | ||
| 98 | |||
| 99 | 1; |