lib/Game/HeroesVsAliens/Alien.pm untested

filter: Statementstmt 0.0% 0 / 45 Branchbran 0.0% 0 / 10 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 3 Podpod 0.0% 0 / 2 totaltotal 0.0% 0 / 60 CC 6 SCAR 34.7
CC
6
Cov
0%
draw
42.0
update
2.0
BEGIN
2.0
CRAP 32.0
1 package Game::HeroesVsAliens::Alien;
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 speed => (
26 is => 'rw',
27 default => sub {
28 rand(50) * 0.2 + 0.4;
29 }
30 );
31  
32 has movement => (
33 is => 'rw',
34 default => sub {
35 rand(50) * 0.2 + 0.4;
36 }
37 );
38  
39 has health => (
40 is => 'rw',
41 default => sub { 100 }
42 );
43  
44 has max_health => (
45 is => 'rw',
46 default => sub { 100 }
47 );
48  
49 has walking_sprite => (
50 is => 'rw',
51 default => sub {
52 my $sprite = SDLx::Sprite::Animated->new(
53 image => $_[0]->resource_directory . 'resources/alien1-walk.png',
54 width => 100,
55 height => 100
56 );
57 return $sprite;
58 }
59 );
60  
61 has attacking_sprite => (
62 is => 'rw',
63 default => sub {
64 my $sprite = SDLx::Sprite::Animated->new(
65 image => $_[0]->resource_directory . 'resources/alien1-attack.png',
66 width => 100,
67 height => 100
68 );
69 return $sprite;
70 }
71 );
72  
73 has dead => (
74 is => 'rw',
75 default => sub { 0 }
76 );
77  
78  
79 has death_sprite => (
80 is => 'rw',
81 default => sub {
82 my $sprite = SDLx::Sprite::Animated->new(
83 image => $_[0]->resource_directory . 'resources/alien1-death.png',
84 width => 100,
85 height => 100
86 );
87 return $sprite;
88 }
89 );
90  
91 sub draw {
92 my ($self, $app) = @_;
93 if ($self->dead) {
94 $self->death_sprite->rect->x($self->x);
95 $self->death_sprite->rect->y($self->y);
96 if ($app->frame % 3 == 0) {
97 $self->death_sprite->next;
98 }
99 $self->death_sprite->draw($app->ctx);
100 } elsif (!$self->movement) {
101 $self->attacking_sprite->rect->x($self->x);
102 $self->attacking_sprite->rect->y($self->y);
103 if ($app->frame % 3 == 0) {
104 $self->attacking_sprite->next;
105 }
106 $self->attacking_sprite->draw($app->ctx);
107 } else {
108 $self->walking_sprite->rect->x($self->x);
109 $self->walking_sprite->rect->y($self->y);
110 if ($app->frame % 3 == 0) {
111 $self->walking_sprite->next;
112 }
113 $self->walking_sprite->draw($app->ctx);
114 }
115 $app->draw_text($self->x + 15, $self->y + 15, 18, [100, 100, 100, 255], int($self->health))
116 }
117  
118 sub update {
119 my ($self, $app) = @_;
120 $self->x($self->x - $self->movement);
121 }
122  
123 1;