Skip to content

Commit

Permalink
1. add animation for Frog
Browse files Browse the repository at this point in the history
  • Loading branch information
tadegenban committed Aug 10, 2014
1 parent 5a992d2 commit c1101cc
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 5 deletions.
3 changes: 2 additions & 1 deletion lib/Games/FrogJump.pm
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ package Games::FrogJump;
use 5.012;
use Moo;

our $VERSION = '0.01';
our $VERSION = '0.04';

use Time::HiRes;
our $FRAME_TIME = 1/10;
Expand Down Expand Up @@ -77,6 +77,7 @@ sub run {
foreach my $animation ( @{$game->animations} ){
$game->remove_animation($animation) if $animation->end;
$animation->update;
$game->need_draw_background(1);
}
}
$game->draw;
Expand Down
43 changes: 39 additions & 4 deletions lib/Games/FrogJump/Board.pm
Original file line number Diff line number Diff line change
Expand Up @@ -212,15 +212,50 @@ sub frog_on_stone {
sub jump_frog_left {
my ( $self, $frog, $step ) = @_;
$frog->stone_index($frog->stone_index - $step);
$frog->x($frog->x - $step * ( $self->stone_width + $self->stone_gap ));
$self->need_draw_background(1);

my $stopx = $frog->x - $step * ( $self->stone_width + $self->stone_gap );

my $animation_x = Games::FrogJump::Animation->new(
name => 'x',
duration => 0.5,
obj => $frog,
attr => 'x',
snapshot => [$frog->x, int(($frog->x + $stopx) / 2), $stopx],
);
my $animation_y = Games::FrogJump::Animation->new(
name => 'y',
duration => 0.5,
obj => $frog,
attr => 'y',
snapshot => [$frog->y, $frog->y - $step, $frog->y],
);
$self->add_animation($animation_x);
$self->add_animation($animation_y);

}

sub jump_frog_right {
my ( $self, $frog, $step ) = @_;
$frog->stone_index($frog->stone_index + $step);
$frog->x($frog->x + $step * ( $self->stone_width + $self->stone_gap ));
$self->need_draw_background(1);

my $stopx = $frog->x + $step * ( $self->stone_width + $self->stone_gap);

my $animation_x = Games::FrogJump::Animation->new(
name => 'x',
duration => 0.5,
obj => $frog,
attr => 'x',
snapshot => [$frog->x, int(($frog->x + $stopx) / 2), $stopx],
);
my $animation_y = Games::FrogJump::Animation->new(
name => 'y',
duration => 0.5,
obj => $frog,
attr => 'y',
snapshot => [$frog->y, $frog->y - $step, $frog->y],
);
$self->add_animation($animation_x);
$self->add_animation($animation_y);
}

sub _build__frogs {
Expand Down

0 comments on commit c1101cc

Please sign in to comment.