PangZero/GameBase.pm untested

filter: Statementstmt 0.0% 0 / 49 Branchbran 0.0% 0 / 8 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 13 Podpod 0.0% 0 / 13 totaltotal 0.0% 0 / 83 CC 5 SCAR 13.6
CC
5
Cov
0%
Exit
6.0
Delay
6.0
SetBackground
6.0
CRAP 3.9
1 ##########################################################################
2 package Games::PangZero::GameBase;
3 ##########################################################################
4  
5 sub new {
6 my ($class) = @_;
7 my $self = {
8 abortgame => 0,
9 anim => 0,
10 nocollision => 0,
11 backgrounds => [ 'desert2.png', ],
12 };
13 $Games::PangZero::GameSpeed = 1.0;
14 $Games::PangZero::GamePause = 0;
15 bless $self, $class;
16 }
17  
18 sub Exit {
19 Games::PangZero::ShowWebPage("http://apocalypse.rulez.org/pangzero/Thanks_For_Playing_Pang_Zero_$Games::PangZero::VERSION" ) if $Games::PangZero::ShowWebsite ne $Games::PangZero::VERSION;
20 exit;
21 }
22  
23 sub Rand {
24 shift;
25 return rand($_[0]);
26 }
27  
28 sub Delay {
29 my ($self, $ticks) = @_;
30  
31 while ($ticks > 0) {
32 my $advance = $self->CalculateAdvances();
33 %Games::PangZero::Events = ();
34 Games::PangZero::HandleEvents();
35 return if $self->{abortgame};
36 $ticks -= $advance;
37 $self->DrawGame();
38 }
39 }
40  
41 sub SetGameSpeed {
42 }
43  
44 sub SetBackground {
45 my ($self, $backgroundIndex) = @_;
46  
47 return if $backgroundIndex >= scalar( @{$self->{backgrounds}} );
48 Games::PangZero::Graphics::LoadBackground($self->{backgrounds}->[$backgroundIndex]);
49 SDL::Video::blit_surface($Games::PangZero::Background, SDL::Rect->new(0, 0, $Games::PangZero::App->w, $Games::PangZero::App->h), $Games::PangZero::App, SDL::Rect->new(0, 0, $Games::PangZero::App->w, $Games::PangZero::App->h));
50 }
51  
52 sub ShowTooltip {
53 }
54  
55 sub ResetGame {
56 my $self = shift;
57 @Games::PangZero::GameObjects = ();
58 %Guy::Guys = ();
59 %Harpoon::Harpoons = ();
60 $Games::PangZero::GamePause = 0;
61 %Games::PangZero::GameEvents = ();
62 $self->SetBackground(0);
63 }
64  
65 sub CalculateAdvances {
66 my $advance = Games::PangZero::GameTimer::GetAdvances();
67 while ($advance <= 0) {
68 $Games::PangZero::App->delay(3); # Wait 3ms = 0.3 game ticks
69 $advance = Games::PangZero::GameTimer::GetAdvances();
70 }
71 if ($advance > 5) {
72 # print STDERR "advance = $advance!\n";
73 $advance = 5;
74 }
75 return $advance;
76 }
77  
78 sub AdvanceGameObjects {
79 my ($self) = @_;
80  
81 ++$self->{anim};
82 foreach my $gameObject (@Games::PangZero::GameObjects) {
83 $gameObject->Advance();
84 }
85 }
86  
87 sub OnBallPopped {
88 }
89  
90 sub DrawGame {
91 my ($self) = @_;
92  
93 my ($gameObject);
94 foreach $gameObject (@Games::PangZero::GameObjects) {
95 $gameObject->Clear();
96 }
97 $self->DrawScoreBoard();
98 foreach $gameObject (@Games::PangZero::GameObjects) {
99 $gameObject->Draw();
100 }
101 $Games::PangZero::App->sync();
102 }
103  
104 sub DrawScoreBoard {
105 }
106  
107 1;