Skip to content

Commit

Permalink
Basic scoring and life loss
Browse files Browse the repository at this point in the history
  • Loading branch information
jtpalmer committed Mar 29, 2011
1 parent c8e2699 commit 2fd56fa
Showing 1 changed file with 21 additions and 3 deletions.
24 changes: 21 additions & 3 deletions week4/lib/Games/ElectricLines.pm
Expand Up @@ -215,6 +215,8 @@ sub _store_active_line {
sub handle_move {
my ( $self, $step, $app, $t ) = @_;

return unless $self->_lives > 0;

if ( $t > $self->_plasma_time + $self->_plasma_frequency ) {
$self->_plasma_time($t);
$self->_add_plasma();
Expand All @@ -223,10 +225,26 @@ sub handle_move {
my @plasma;
foreach my $plasma ( @{ $self->_plasma } ) {
$self->_move_plasma( $plasma, $step );
push @plasma, $plasma
if $plasma->{x} < $app->w - $self->_sprite->rect->w / 2;
if ( $plasma->{x} < $app->w - $self->_sprite->rect->w / 2 ) {
push @plasma, $plasma;
}
else {
if ( grep { $plasma->{y} == $_->[1] } @{ $self->_exits } ) {
$self->_score( $self->_score + 1 );
}
else {
$self->_lives( $self->_lives - 1 );
}
}
}

if ( $self->_lives <= 0 ) {
$self->_lives(0);
@{ $self->_plasma } = ();
}
else {
@{ $self->_plasma } = @plasma;
}
@{ $self->_plasma } = @plasma;
}

sub handle_show {
Expand Down

0 comments on commit 2fd56fa

Please sign in to comment.