lib/Game/HeroesVsAliens/Bonus.pm untested

filter: Statementstmt 0.0% 0 / 25 Branchbran 0.0% 0 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 2 Podpod 0.0% 0 / 1 totaltotal 0.0% 0 / 30 CC 2 SCAR 15.4
CC
2
Cov
0%
draw
6.0
BEGIN
2.0
CRAP 4.7
1 package Game::HeroesVsAliens::Bonus;
2  
3 use Moo;
4  
5 with 'Game::HeroesVsAliens::Role::ResourceDirectory';
6  
7 has x => (
8 is => 'rw'
9 );
10  
11 has y => (
12 is => 'rw'
13 );
14  
15 has width => (
16 is => 'rw',
17 default => sub { 100 }
18 );
19  
20 has height => (
21 is => 'rw',
22 default => sub { 100 }
23 );
24  
25 has amounts => (
26 is => 'rw',
27 lazy => 1,
28 default => sub { [20, 30, 40, 50, 60] }
29 );
30  
31 has amount => (
32 is => 'rw',
33 default => sub {
34 my $amounts = $_[0]->amounts;
35 return $amounts->[int(rand(scalar @{$amounts}))];
36 }
37 );
38  
39 has sprite => (
40 is => 'rw',
41 default => sub {
42 my $sprite = SDLx::Sprite::Animated->new(
43 image => $_[0]->resource_directory . 'resources/bonus.png',
44 width => 50,
45 height => 50,
46 );
47 }
48 );
49  
50 sub draw {
51 my ($self, $app) = @_;
52  
53 $self->sprite->rect->x($self->x + 25);
54 $self->sprite->rect->y($self->y + 20);
55 if ($app->frame % 3 == 0) {
56 $self->sprite->next;
57 }
58 $self->sprite->draw($app->ctx);
59 $app->draw_text(
60 $self->x + 15,
61 $self->y + 15,
62 18,
63 [255, 255, 255, 2555],
64 int($self->amount)
65 );
66 }
67  
68  
69 1;