Skip to content

Commit

Permalink
Added yellow submarine
Browse files Browse the repository at this point in the history
Added a yellow submarine that moves to the center, extends its periscope, looks both ways, retracts its periscope, then continues along.

Signed-off-by: Daniel Riechers <[email protected]>
  • Loading branch information
driechers committed Feb 17, 2019
1 parent 8bdb7d4 commit 82663a9
Showing 1 changed file with 316 additions and 0 deletions.
316 changes: 316 additions & 0 deletions asciiquarium
Original file line number Diff line number Diff line change
Expand Up @@ -1412,6 +1412,321 @@ q{
);
}

sub submarine_callback {
my ($entity, $anim) = @_;

my @delta = $entity->callback_args();
my @pos = $entity->position();


my $x = $pos[0];
my $y = $pos[1];
my $z = $pos[2];
my $frame = $delta[0][3];
my $delay = $delta[0][4];
my @frame_delay = @{[ 1, 4, 4, 9, 9, 9, 4, 4, 1 ]};

my $maxFrame = scalar(@frame_delay);


# Move if not in center or skipping over the center
if(not (($x < $anim->width()/2-20 and $x + $delta[0][0] > $anim->width()/2-20) or
($x > $anim->width()/2-20 and $x + $delta[0][0] < $anim->width()/2-20))
and $x != $anim->width()/2-20) {
$x += $delta[0][0];
}
else {
if($frame < $maxFrame - 1) {
if($delay < $frame_delay[$frame]) {
$delay += 1;
}
else {
$delay = 0;
$frame += 1;
}
}
else{
$x += $delta[0][0];
}
}

my @args =[$delta[0][0],$delta[0][1],$delta[0][2],$frame,$delay];
$entity->callback_args(@args);
return ($x, $y, $z, $frame);
}

sub add_submarine {
my ($old_ent, $anim) = @_;
my @submarine_image = (
[
q{
__
_|_
/ |
_ ? _______________/____|_______________
( )?/ /
(=< O O O /
(_)?\_________________________________/
}
,q{
__
|
_|_
/ |
_ ? _______________/____|_______________
( )?/ /
(=< O O O /
(_)?\_________________________________/
}
,q{
__
|
|
_|_
/ |
_ ? _______________/____|_______________
( )?/ /
(=< O O O /
(_)?\_________________________________/
}
,q{
__
|
|
|
_|_
/ |
_ ? _______________/____|_______________
( )?/ /
(=< O O O /
(_)?\_________________________________/
}
,q{
__
|
|
|
_|_
/ |
_ ? _______________/____|_______________
( )?/ /
(=< O O O /
(_)?\_________________________________/
}
,q{
__
|
|
|
_|_
/ |
_ ? _______________/____|_______________
( )?/ /
(=< O O O /
(_)?\_________________________________/
}
,q{
__
|
|
_|_
/ |
_ ? _______________/____|_______________
( )?/ /
(=< O O O /
(_)?\_________________________________/
}
,q{
__
|
_|_
/ |
_ ? _______________/____|_______________
( )?/ /
(=< O O O /
(_)?\_________________________________/
}
,q{
__
_|_
/ |
_ ? _______________/____|_______________
( )?/ /
(=< O O O /
(_)?\_________________________________/
}
],[
q{
__
_|_
| \
______________|____\_______________ ? _
\ \?( )
\ O O O >=)
\________________________________/?(_)
}
,q{
__
|
_|_
| \
______________|____\_______________ ? _
\ \?( )
\ O O O >=)
\________________________________/?(_)
}
,q{
__
|
|
_|_
| \
______________|____\_______________ ? _
\ \?( )
\ O O O >=)
\________________________________/?(_)
}
,q{
__
|
|
|
_|_
| \
______________|____\_______________ ? _
\ \?( )
\ O O O >=)
\________________________________/?(_)
}
,q{
__
|
|
|
_|_
| \
______________|____\_______________ ? _
\ \?( )
\ O O O >=)
\________________________________/?(_)
}
,q{
__
|
|
|
_|_
| \
______________|____\_______________ ? _
\ \?( )
\ O O O >=)
\________________________________/?(_)
}
,q{
__
|
|
_|_
| \
______________|____\_______________ ? _
\ \?( )
\ O O O >=)
\________________________________/?(_)
}
,q{
__
|
_|_
| \
______________|____\_______________ ? _
\ \?( )
\ O O O >=)
\________________________________/?(_)
}
,q{
__
_|_
| \
______________|____\_______________ ? _
\ \?( )
\ O O O >=)
\________________________________/?(_)
}
]
);

my @submarine_mask = (
q{
www
ww
ww
ww
w
w
w w
www w w w
www
},q{
www
ww
ww
ww
w
w
w w
w w w www
www
});

my $dir = int(rand(2));
my $x;
my $speed = 1;
if($dir) {
$speed *= -1;
$x = $anim->width()-2;
} else {
$x = -40
}

$anim->new_entity(
shape => $submarine_image[$dir],
auto_trans => 1,
color => $submarine_mask[$dir],
position => [ $x, 6, $depth{'water_gap3'} ],
callback_args => [ $speed, 0, 0, 0, 0 ],
callback => \&submarine_callback,
death_cb => \&random_object,
die_offscreen => 1,
default_color => 'YELLOW',
);
}

sub init_random_objects {
#return ( \&add_shark );
return (
Expand All @@ -1420,6 +1735,7 @@ sub init_random_objects {
\&add_monster,
\&add_big_fish,
\&add_shark,
\&add_submarine,
);
}

Expand Down

0 comments on commit 82663a9

Please sign in to comment.