File Coverage

blib/lib/Games/2048/Animation.pm
Criterion Covered Total %
statement 9 19 47.3
branch 0 2 0.0
condition n/a
subroutine 3 6 50.0
pod 0 3 0.0
total 12 30 40.0


line stmt bran cond sub pod time code
1             package Games::2048::Animation;
2 4     4   115 use 5.012;
  4         13  
  4         144  
3 4     4   18 use Moo;
  4         6  
  4         29  
4              
5 4     4   3293 use POSIX qw/floor ceil/;
  4         23967  
  4         36  
6              
7             has cur_frame => is => 'rw', default => 0;
8             has duration => is => 'rw', default => 0;
9             has first_value => is => 'rw', default => 0;
10             has last_value => is => 'rw', default => 1;
11              
12             sub value {
13 0     0 0   my $self = shift;
14 0           my $value = $self->cur_frame / ($self->frame_count - 1);
15 0           my $range = $self->last_value - $self->first_value;
16 0           return $value * $range + $self->first_value;
17             }
18              
19             sub update {
20 0     0 0   my $self = shift;
21 0 0         return if $self->cur_frame >= $self->frame_count;
22 0           $self->cur_frame($self->cur_frame + 1);
23 0           return 1;
24             }
25              
26             sub frame_count {
27 0     0 0   my $self = shift;
28 0           return floor($self->duration / Games::2048::FRAME_TIME);
29             }
30              
31             1;