PangZero/SeekerBall.pm untested

filter: Statementstmt 0.0% 0 / 36 Branchbran 0.0% 0 / 10 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 7 Podpod 0.0% 0 / 5 totaltotal 0.0% 0 / 58 CC 6 SCAR 22.3
CC
6
Cov
0%
NormalAdvance
20.0
new
6.0
Draw
6.0
CRAP 9.3
1 ##########################################################################
2 package Games::PangZero::SeekerBall;
3 ##########################################################################
4  
5 @ISA = qw( Games::PangZero::Ball );
6 use strict;
7 use warnings;
8  
9 sub new {
10 my $class = shift;
11 my $self = Games::PangZero::Ball->new(@_);
12 my @guys = grep {ref $_ eq 'Games::PangZero::Guy'} @Games::PangZero::GameObjects;
13 $self->{target} = $guys[$Games::PangZero::Game->Rand(scalar @guys)];
14 $self->{deltaX} = (-$self->{w} + $self->{target}->{w}) / 2;
15 die unless $self->{target};
16  
17 bless $self, $class;
18 }
19  
20 sub NormalAdvance {
21 my $self = shift;
22
23 my $multiplier = ($self->{y} > $Games::PangZero::ScreenHeight - 120) ? 0 : 25;
24 unless( $Games::PangZero::GamePause > 0 ) {
25 if ($self->{x} + $self->{speedX} * $multiplier > $self->{target}->{x} + $self->{deltaX}) {
26 $self->{speedX} -= 0.08;
27 } else {
28 $self->{speedX} += 0.08;
29 }
30 }
31 $self->SUPER::NormalAdvance();
32 }
33  
34 sub AdjustChildren {
35 my ($self, $child1, $child2) = @_;
36
37 $self->SUPER::AdjustChildren($child1, $child2);
38 $child1->{speedX} *= 2;
39 $child1->{deltaX} -= 30;
40 $child1->{target} = $self->{target};
41 $child2->{speedX} *= 2;
42 $child2->{deltaX} += 30;
43 $child2->{target} = $self->{target};
44 }
45  
46 sub GiveMagic {
47 }
48  
49 sub Draw {
50 my $self = shift;
51
52 $self->SUPER::Draw();
53 my $guySurface = $self->{target}->{player}->{guySurface};
54 my $srcrect = ($self->{w} <= 32)
55 ? SDL::Rect->new(320, 176, 16, 16)
56 : SDL::Rect->new(320, 128, 32, 32);
57 my $dstrect = SDL::Rect->new(
58 $self->{x} + $Games::PangZero::ScreenMargin + ($self->{w} - $srcrect->w()) / 2,
59 $self->{y} + $Games::PangZero::ScreenMargin + ($self->{h} - $srcrect->h()) / 2 + 2, $srcrect->w, $srcrect->h);
60 SDL::Video::blit_surface($guySurface, $srcrect, $Games::PangZero::App, $dstrect);
61 }
62  
63 1;