lib/Game/HeroesVsAliens/Projectile.pm untested

filter: Statementstmt 0.0% 0 / 29 Branchbran 0.0% 0 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 3 Podpod 0.0% 0 / 2 totaltotal 0.0% 0 / 40 CC 4 SCAR 26.4
CC
4
Cov
0%
draw
20.0
update
2.0
BEGIN
2.0
CRAP 14.0
1 package Game::HeroesVsAliens::Projectile;
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 { 32 }
18 );
19  
20 has height => (
21 is => 'rw',
22 default => sub { 32 }
23 );
24  
25 has power => (
26 is => 'rw',
27 default => sub { 20 }
28 );
29  
30 has speed => (
31 is => 'rw',
32 default => sub { 5 }
33 );
34  
35 has sprite => (
36 is => 'rw',
37 default => sub {
38 my $sprite = SDLx::Sprite::Animated->new(
39 image => $_[0]->resource_directory . 'resources/boy-hero-projectile.png',
40 width => 32,
41 height => 32,
42 );
43 }
44 );
45  
46 has explode_sprite => (
47 is => 'rw',
48 default => sub {
49 my $sprite = SDLx::Sprite::Animated->new(
50 image => $_[0]->resource_directory . 'resources/boy-hero-explode-projectile.png',
51 width => 32,
52 height => 32,
53 );
54 }
55 );
56  
57 has collision => (
58 is => 'rw',
59 default => sub { 0 }
60 );
61  
62 sub draw {
63 my ($self, $app) = @_;
64  
65 if ($self->collision) {
66 $self->explode_sprite->rect->x($self->x);
67 $self->explode_sprite->rect->y($self->y);
68 if ($app->frame % 3 == 0) {
69 $self->explode_sprite->next;
70 }
71 $self->explode_sprite->draw($app->ctx);
72 } else {
73 $self->sprite->rect->x($self->x);
74 $self->sprite->rect->y($self->y);
75 if ($app->frame % 3 == 0) {
76 $self->sprite->next;
77 }
78 $self->sprite->draw($app->ctx);
79 }
80 # $app->draw_circle($self->x, $self->y, $self->width, $self->height, [200, 100, 200, 255]);
81 }
82  
83 sub update {
84 my ($self, $app) = @_;
85 $self->x($self->x + $self->speed);
86 }
87  
88  
89 1;