Game-Kezboard

 view release on metacpan or  search on metacpan

kezboard  view on Meta::CPAN

# put any played cards back into the player's hand
sub clear_played () {
    if ( $deck->get('board')->@* ) {
        $deck->collect(qw(player board));
        return 1;
    }
}

sub collide_hero_bomb ( $ani, $obj ) {
    if ( $ani->[ID] == HERO ) {
        relocate( $ani, $obj->@[ XX, YY ] );
    } else {
        draw_cell( $ani->@[ XX, YY ], $blanki );
    }
    return MOVE_EOL;
}

sub collide_hero_goal ( $ani, $obj ) {
    if ( $ani->[ID] == HERO ) {
        # NOTE this messes up the occupy map; hopefully the EOL
        # resets things
        relocate( $ani, $obj->@[ XX, YY ] );
    } else {
        # goal moves onto hero: undraw where the goal is
        draw_cell( $ani->@[ XX, YY ], $blanki );
    }
    $level++;
    return MOVE_EOL;
}

sub collide_hero_scram ( $ani, $obj ) {
    if ( $ani->[ID] == HERO ) {
        $ani->@[ IX, IY ] = random_inertia(3);
        relocate( $ani, $obj->@[ XX, YY ] );
        $obj->[DEAD] = 1;
        return MOVE_OK;
    } else {
        $obj->@[ IX, IY ] = random_inertia(3);
        draw_cell( $ani->@[ XX, YY ], $blanki );
        unoccupy( $ani->@[ XX, YY ] );
        $ani->[DEAD] = 1;
        return MOVE_NOP;
    }
}

sub collide_gate_scram ( $ani, $obj ) {
    if ( $ani->[ID] == GOAL ) {
        $ani->@[ IX, IY ] = random_inertia(3);
        relocate( $ani, $obj->@[ XX, YY ] );
        $obj->[DEAD] = 1;
        return MOVE_OK;
    } else {
        $obj->@[ IX, IY ] = random_inertia(3);
        draw_cell( $ani->@[ XX, YY ], $blanki );
        unoccupy( $ani->@[ XX, YY ] );
        $ani->[DEAD] = 1;
        return MOVE_NOP;
    }
}

kezboard  view on Meta::CPAN


sub place_animate ($ani) {
    $occupy[ $ani->[YY] ][ $ani->[XX] ] = $ani;
}

sub draw_cell ( $i, $j, $sprite ) {
    my @xy = @gridxy;
    put_sprite( $xy[XX] + $i * $cellsz, $xy[YY] + $j * $cellsz, $sprite );
}

sub relocate ( $ani, $x, $y ) {
    undef $occupy[ $ani->[YY] ][ $ani->[XX] ];
    draw_cell( $ani->@[ XX, YY ], $blanki );
    ( $ani->[XX], $ani->[YY] ) = ( $x, $y );
    draw_animate($ani);
    $occupy[$y][$x] = $ani;
}

# try to put a card from the player's hand to the bottom of the board
# (cards are applied from top to bottom)
sub play_card ($index) {

kezboard  view on Meta::CPAN

        $deck->shuffle('draw');
        deal_cards();
        $mulligan = 1;
        return 1;
    }
}

sub try_move ( $ani, $nx, $ny ) {
    my $other = occupied( $nx, $ny );
    if ( !defined $other ) {
        relocate( $ani, $nx, $ny );
        return MOVE_OK;
    }
    my $fn = $collisions[ $ani->[ID] ][ $other->[ID] ];
    die "no mapping ", $ani->[ID], " ", $other->[ID] unless defined $fn;
    return $fn->( $ani, $other );
}

sub turn_left ($ani) {
    $ani->[ORIENT] = ( $ani->[ORIENT] + 1 ) % @headings;
}



( run in 0.800 second using v1.01-cache-2.11-cpan-71847e10f99 )