PangZero/Harpoon.pm untested

filter: Statementstmt 0.0% 0 / 44 Branchbran 0.0% 0 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 7 Podpod 0.0% 0 / 6 totaltotal 0.0% 0 / 61 CC 3 SCAR 13.3
CC
3
Cov
0%
Advance
6.0
Draw
6.0
Create
2.0
CRAP 3.8
1 ##########################################################################
2 package Games::PangZero::Harpoon;
3 ##########################################################################
4  
5 @ISA = qw(Games::PangZero::GameObject);
6 use vars qw(%Harpoons $HarpoonId);
7  
8 sub Create {
9 return Games::PangZero::Harpoon->new(@_);
10 }
11  
12 sub new {
13 my ($class, $guy) = @_;
14 my ($self);
15  
16 $self = Games::PangZero::GameObject->new();
17 %{$self} = ( %{$self},
18 'x' => $guy->{x} + 22,
19 'y' => $Games::PangZero::ScreenHeight - 32,
20 'w' => 18,
21 'h' => 32,
22 'speedY' => -3,
23 'speedX' => 0,
24 'guy' => $guy,
25 'surface' => $guy->{player}->{harpoonSurface},
26 'popEffect' => '',
27 'id' => ++$HarpoonId,
28 );
29 $Harpoons{$self->{id}} = $self;
30 bless $self, $class;
31 }
32  
33 sub Delete {
34 my $self = shift;
35  
36 delete $Harpoons{$self->{id}};
37 --$self->{guy}->{harpoons};
38 $self->SUPER::Delete();
39 }
40  
41 sub Advance {
42 my $self = shift;
43  
44 if ($self->{y} < 0) {
45 $self->Delete();
46 return;
47 }
48 $self->{y} += $self->{speedY};
49 $self->{h} = $Games::PangZero::ScreenHeight - $self->{y};
50 }
51  
52 sub GetAnimPhase {
53 my $self = shift;
54  
55 return (int($Games::PangZero::Game->{anim} / 4) % 3) + 1;
56 }
57  
58 sub Draw {
59 my $self = shift;
60 my ($x, $y, $h, $maxh, $dstrect, $srcrect);
61  
62 $self->TransferRect();
63 $y = $self->{y};
64 $dstrect = SDL::Rect->new( $self->{x} + $Games::PangZero::ScreenMargin, 0, $self->{w}, 0 );
65 $srcrect = SDL::Rect->new( (0, 64, 32, 96)[ $self->GetAnimPhase() ], 0, $self->{w}, 0 );
66 $maxh = 160;
67  
68 # The harpoon needs to be drawn from tile pieces.
69 # $y iterates from $self->{y} to $Games::PangZero::ScreenHeight
70 # We draw at most $maxh height tiles at a time.
71  
72 while ($y < $Games::PangZero::ScreenHeight) {
73 $h = $Games::PangZero::ScreenHeight - $y;
74 $h = $maxh if $h > $maxh;
75 $dstrect->y( $y + $Games::PangZero::ScreenMargin );
76 $dstrect->h( $h );
77 $srcrect->h( $h );
78 SDL::Video::blit_surface($self->{surface}, $srcrect, $Games::PangZero::App, $dstrect );
79  
80 # Prepare for next piece
81 $y += $h;
82 $srcrect->y( 32 ); # First piece starts at 0, rest start at 32
83 $maxh = 128;
84 }
85 }
86  
87 1;