#!/usr/bin/env perl
#
# demo that illustrates the to_panel method of Game::LevelMap

use strict;
use warnings;
use Game::LevelMap;
use IO::Termios 0.07;
use Time::HiRes qw(sleep);

sub alt_screen ()   { "\e[?1049h" }
sub clear_screen () { "\e[1;1H\e[2J" }
sub term_norm ()    { "\e[m" }
sub unalt_screen () { "\e[?1049l" }

my $lm = Game::LevelMap->new(
    from_string => do { local $/; readline *DATA }
);

STDOUT->autoflush(1);

print alt_screen, clear_screen, term_norm;

my $term = IO::Termios->new( \*STDIN );
my $orig = $term->getattr;
$term->cfmakeraw;

#$lm->to_terminal;
#sleep(1);

# NOTE when the offset is increased the panel size will need to be
# decreased. the panel should also use odd values for a stable point to
# center on
my @panel_offset = ( 2,  2 );
my @panel_size   = ( 77, 21 );
my @where        = ( 3,  3 );

sub move {
    $lm->to_panel( @panel_offset, @panel_size, @where );
    $where[$_] += $_[$_] for 0 .. 1;
    sleep(0.2);
}

move 1, 0 for 1 .. 8;
move 1, 1 for 1 .. 28;
move 0, 1 for 1 .. 34;
move 1, 1 for 1 .. 54;
move 1, 0 for 1 .. 8;

$term->setattr($orig);
sleep(1);
print unalt_screen, $/;

# this map built using termlbrot.c from the Ministry of Silly Vaults
__DATA__
++,,++,,,,,++++++++++++++++#################+,++,++++,+++#######################################################################
++,,,,,,,++++++++++++++++++#################++++,,+,,,+#########################################################################
+++,,,+++++++++++++++++++,++################++++,,++,+##########################################################################
,,,.,,,++++++++++++++++++,,+++############++++++,,++,+,#########################################################################
,,,,,,,,,++++++++++++++++,+++##############+++,+,++++++#########################################################################
,,,+++,,,+,++++++++++,+++,,+++######+###+#+++++,,,++++##########################################################################
,,,,++++,,,+++++++++++++,++++,++####+####+++,+,+,,,+############################################################################
++++++++++++++++++++++++,,++++++####++##+++,+,,+,+,+############################################################################
++++++++++++++++++++++.,,+++,++++###++++++++++,,+++++###########################################################################
,,++++++++++++++++++++++,++,~+++++++++++++++++,,,+++###+####++##################################################################
.,++++++++++++++++++++++,,,++++,++++++++++++,,,,++++++++++#+,###################################################################
,,+++++++++++++++++++++++,,,,,,,++++++++++++,,,++++++,++,+,+,++#################################################################
,,,,++++++++++,+++++++++++,++,+,+++++++++++,++,,+++,+,+,+,,.++##################################################################
+,,,,+++++++++,,,,+++++++,,+++++++++++++++++++,+++,,,,+,++,+####################################################################
+,.,++++++++++,.+,.,++.,,,..+++++++++++++++++,+,+,,,+.+,+++#####################################################################
++,,,++++++++++,,.,++++,,,+++++++++,+++++++++++,,.+++++++#######################################################################
+,,,,++,++++++++,,,,.++,,,,++,++++++,+++++++++++,,.+++++########################################################################
+++,,,,.++++++++,,,,.,,,,.,+,+++++++.+,,+++,,+,,,+,,,+++########################################################################
+++,,,,,,,+++++,,,,.,,,,,,,,,,++++++++,+++++,+.,++,,++++++###################################################################+#+
++++,,,~,,+++,.,,,,,,...,~..,,,,+++++.,,,,+,,,,++++,,,++++###################################################################+,.
++++,,,,,++++,,,,.,,,,,,,,,,+++++++,,+,.,++,,++++++++++,+.+###+#######################################################++######++
,,,,,,,,,++++,,,,,.,,,,,,,,,++++++,,,,,,,.,,,++++++++.,,,++#+++####################################################,+,++######+,
,,,.,,,,,,+++,,.,,,,,,,~,,.,+++++++,,.,,,+,,,++++++++,++,+++,,+######################################################++++###++++
,+,.,,,,,,,,,,,,,,,,,++,,,,,,+++++++,.,,++,+,,+,+++++,++++,++++######################################################+++++#+++,+
,++,,,,,,,,,.,,,,,,,+++++++,,,+++++,,,,,++++,+++++++++++,++++++######################################################+,,++++++.+
++,,,,,+,+,,,,,,,,,,+++++++,,,,,,,,,,,,,++++++++++++++++++++++############################################.,#########+++.+++,,,,
++,,,~,+++,,,,,,.,..,,++++++,,,,,,,,,,,,,+++++++++++##+++++##+#############################################++,######+++++,+++,++
+++,,,,++,,,,,,,++,,,+++++++++,,,.,,,,,+,+++++++++++#####################################################+#+,+++++###++++,++.,++
+,.,,,+++++,+,,,+++,++++++++++,,,.,,,,++++++++++++++###################################################+,,+,+,++.+++++++,,++,+++
+,,,,,,,++++,.,+++++++++++++++,,,,,,,,+++++++,++++####################################################.+#+++++,,,,+++++++,..++++
+,,,+,.,+++++,,++++++++++,,,+,,,,,,,.,,,+++++,++++########################################################+#+,++.++++++++++,,,++
+,+++++++++,,,,,,++++++++..,,,,,,,~,.,,,+++++,++++###########################################################++,,+,,,+++,+,++,,+
.,++++++++,++.+,,+++++++++,,,,,,,+,,,,,+++,,,+,+,############################################################+++,.,+.+,,,,,+++,,
,+,++++++++++,+,,,++++++++++,,.,+++,+,,,++,++++++############################################################+,,,+++,,,,,+++++,,
++.,+++++++++++,++++++++++,,,,.,,++++,,,,,,,,+++++###########################################################,,,+++++,++++++++++
++,,+++++++++++,+++++++++++.++,.+++++,,++,+,,,++##############################################################+.+++++,+++++++++,
+++,,+++++++++++++++++++++++++,,,++++++++.+++,++##############################################################++++++++++++++++++
+,,++++++++++++++++++++++++++,,,,++++++++,+++++++#############################################################++++++++++++++++,,
++,.++++++++++++++++++++++++++,,++++++++,,,+++++##################################################################+++++++++++++,
+,,,,+++++++++++++++++++++++,+.+++++++++++,+++++######################################################################++++++++,+
,,+,+++++++++++++++++++++++++,,,,++++++++,,,++++####+########+#########################################################+++++++++
++++++###++++++++++++++++++,,,,+,,+++++++++,,+++###+#########,,#######################################################++++++++++
,+++#+###+++++++++++++++++++,.,+++++++++++++++++++++########++,######################################################+++++++++++
++#######+##++++++++++++++,,,,,,,+++++++++++++++++++###+##++++++####################################################++++++++++++
#+######+####+++,,,+++++++,,,,,+++++++++++++++++++++###+++++++,++######################################################++++,+++,
#############++++,++++++++++,,+++++++++++++++++++++++++,++,+++++#######################################################+++++,+++
############++++,,,+++++++++,,++++++++++++++++++++++++++,,+++,++#######################################################+,.,+++,+
###########++++++,,++++++++,,,+++++++++++++++++++++++++++++,,,++#####################################################++++,,,,,,,
############+,,,+,,++,++++,,,,++++++++++++++++++++++++++++,,+++++####################################################++++++,,+,,
############+++,,,,,+,+++++,,++,+++++++++++,++++++++++++,++,++++#####################################################++,,,,,,+,,
##########+++++++,,,,.+++++,,,,,,+++++++++++,+++++++++++,,,,,+++++++#############################################++##++++++,++++
###########+,,++,,+,,,,,,++,~,,+++++++++++,,+++++++++++++,,+++++,++++##########################################+#+++++++++++++++
##########++,+,,,+++,,,,,,,,,,,.,++++++++++,++++++++++++++,+++,++,,++########################################++,+++++++++++++++,
###########+++++,+++,,~,,,,,,,,,,,++++++++,,+,+++++++++++.,+++,,,++++###################################+++#+++,+++++++++++++++,
###########+++++++++,,,,,,,,.,++,,++++++++,,,,+,,+++++++++,,+,,+,+++####################################+++++++~+++++++++++++++,
#########++++++++++++,,,,..,,+++++++++++++++,,,,+++++++++++,,++++++####################################+++,,++,+++++++++++++++.,
+#+,.++##+++++++++++,,,,,,,,++++++++++++++++,,+++++++++++++,,,++++++####################################++,,+++.,++++++++++++++,
,+++++++++++++++++,,,,,,,,.,.++++++++,+,,+,,,,+++++++.,++,,,+,,,,++++++###############################++++++++,+++++,++++.++++++
,.+,,++++++++++++++,,,,,,,,,.,,++++++,,,,+,,,,+,++++,,+++,.,++,,++,+,+############################++++,++++,+,.++++++,+,+,++++++
,+++++,,+++++++++++,,,,+++,+,,,+++++++,,,..,,,,.+++++,,,,,,+++++,,++++##########################++,,++,+++++,,+++++++,+,,,++++++
#++~,,,++++++,+,.,+,.,,++++++,.,++++++,,,,,,,.,,,+++,,,,.,+++++,+.~,+++########################++++++,,+,+++,,,,+,,+++,.++++++++
##+,,,,++++++++,,,+,,.,++++++,,,,,,+++,,,,,,,,,,+++,,.,,,+,+++++++,++.##########################++++++,,,+,,,++,,,+,++,,,+++++++
##++++,+,+++++.,,,,,,,,,++++++,,,,,,,,,,,,,,~..,,,+,,,,,++,+++++++++++############################++++,,+.,,++++,,,,,,,,.+++++++
##+++,,,++++,,,,++,,,+,+++++++,,,,,,,,,,,,,,,,,.,,,,,,,,,++++++++++++#############################+++,+++,++++++,,,,,,,,++++.,,,
####+,+,,,+,,,,.++++,++++++,,,,,,,,,,,,,.,,,++,,,,,,,,.,++++++++++++#############################++++,,++++++++,,,,,,,,,,,.,.,,,
####++++,.+.,++,,+++.,,+++++,,,,,,,,,.,,,,,,++++,,,..,,++++,++++++++###+###########################+++++++++++++,+,,.,.,,.,,,,,,
###++++++,,++++++++.++.,+++++,+,,,,,,.,,,,,,+++,,,,,,,,.++,,,++++++++++#############################++++++++++++++++,,,,,,++++++
+++,+++++,,,.+++++++,+,+++++,++,,,,,.,,,+++++++,,,,,..,,+,,+++++++++++##############################+++++++++++++++,,,,,,,,+++++
,,++,+,,,,+,,++++++++++++++++++,,,++++,,++++++,,,,,,,,,.,,,++++++++++###############################+++++++++++++,,,,,+,,+++++++
++,,+,+,++++.,++++++++++++++++,,.,,+++,,,+++++++,,.,++.,,,+,++++++++++########################+##+#+++++++++++,++,,,,,++++++++++
++,,+++++++,,+++++++++++++++++.,,+++++++.,+++++.,,,,+++++,+++++++++++++++#######################+++++++++++++,,.,..,,,++++++++++
#+,+++++++++,,+++++++++++++,,,,,++++++,+,++++++,++,,+++++,,++++++++++++++##+#####################+++++++++++++,,,,,,,,,.++++++++
##+#+#+++++,,,,+++++++++++,+++,,+++++++++++++++++,,+++++++,,++++++++++++,+++######################++++++++++,,++,,,,,,,,++++++++
######+++,+,,+++++++++++++++++,+,+,++++++++++++++,,,+++++++++++++++++++,+++#######################+++++++++++++++,,,,,.,++,,,+++
######+++++,,,+++++++++##+++,,++,+++++++++++++++,,,,++++++++++++++++++,++++######################++++++++++++++++.,..,,,,,,+++++
######+,+,+,,,+,+,+##++###++,+++,++++++++++++++++,.,,++++++++++++++++,++++++#+++#############+##+++++++++++++++++,,,,,,,.,,,++++
######+,,,,+,,,+++####+###++++++,.,+++++++++++++,,,,+++++++++++++++++,+++++++++#####++######++++++++++,,+++++++++++,,,,,,+,+++++
####,+++,,++++,++++###+######++,++++++++++,,++++++,+++++++++++++++++,,+++++,+++#####++#######++++++.,+,,+++++,+++++,,,.,,+++++++
###+,++++,,+++++#############++++++++++++++,+++++,,++++++++++++++++++,,+,,.++++#####+++######+++++++,+.+++,,,,+++++,,.,,++++++++
##,++,+++,.,++++############+##++++++++++++,+++++,,,.,+++++,,+,++++++,,,,+++++++###++++####++++,+++++,,,,++,.+++++,,,,,,+,++++++
###+,,,,,,+++++##+############+++++++++++,+,,,.++,,,,+++++++,,+++++++,.,+++++++++#++++++###++++++,,,,,+,,,,,,,+,,,.,.,,,,,++++,+
+#+,+,,,,,+++++###################+++++++++,,,,,,,,,,,,++++,,.,,++++++,,,,++,,++++++++++++++++++++,,,+++,,.,.,,,.,,,,,,,,,+++~,,
+++++,++++,,,+++#################+++++++++,.+,,,,,.,,,+++++++,,+++,.+,,++,,,.,+++++++++++++++++++++++++,,,,,,,,,,,+,,.,,,,,+,,,,
++++,++++++++++#################++++++++,++++,,,,,,,,,++,++,,,,,++,.,,,++++,+++++++++++++++++++++++++++++,,,,,,+++++,,++,,,.,+++
,,,,++###++,++++###################+++++++++++,,,,,,,+++,..,,,,,,+,,,,,++++++++++++++++++++++++++++++++++,,,,,+++++,,,+++,+,,,,+
,+,++######+######################+++++++++++,.,,,,.,,++,,,..,,,,,,,,,+++++++++++++++++++++++++++++++++,,,,,,+++++++++,++++,++,,
##,++############################++++++++++++,~,,,,,,,,,,,,,,,,,,,,,,++,+++++++++++++++++++++++++++++++,,,,,,,++++++++++++,,++,+
#,,+,+#########################++,++++++++,+,,,.,+++,,,,,,,,,,,,,,.,,,,,++++++++++++++++++++++++++++++,,+,,,,,,,++++++++++,,++++
#,,,############################+,,,,++++++,,,,,.,++,,,,.,,.,,,,,...,,,,+++++++++++++++++++++++++++++++++,,,,.,,++++++++++++++++
+,+#############################++++,,+++++,,,,,+++.,~,,,,,,,,+,.,,,,,.++++++++++++++++++++++++++++++++++,,,,.,++++++++++++,++++
#++#############################+++,+,,+++,,+++,,+++.+,,,,,,++++,,~,++,,+++++++,+++++++++++++++++,+,++,,++,,,,,+++++++++++++++++
#+################################+++.+,+,,++++,,+++++,,,+,,,+++,,,,+++++++++,+,++++++++++++++++++,,++,,,,,,.,,,+,,,++++++++++++
##+###############################++++++.,++++++++++++.+++++,+++++.,++++++++++,.+++++++++++++++,,+,,,,.,,.,,~,,,,,,,,+++++++++++
##################################++++,,,,,+++++++++,,,,+++++++++,.,++++++++++,+,,++++++++++++++.,++,,,,,,,,,,,,,,++++++++++++++
#################################++,,,,,++,++++++++++++,,++++++++,,,++++++++++,,,+++++++++++++++++++,,,,,++,,+++,+++++++++++++++
#################################+++,+++++,,+++++++++++,++++++,+++,,,+++,,,++++,,,,,++++++++++++++++,.,,,+++++++,+++++++++++++++
#################################++++++++,,++++++++++++,++++++,,,,,,,,+++,,++,,.+++++++++++++++++++,,,.,,+++++++++++++++++++++++
#################################,#+++++++,,+,++++++++++++++++,,,,,,,.++,,,,,,,,+++++++++++++++++++++,,,,+++++++++++++++++++++++
#####################################+++,,~,.++++++++++++++++++,,.,,,,,,,,,,,,,,+,++++++++++++++++++,,.,,,,,++++++++++++++++++++
####################################+++++,.++++++++++++++++++,,++,,,,,,,,,,,,,,,,++++++++++++++++,,,,,,,,,,+++++++++++++++++++++
#####################################++,+,,+++++++++++++++++++++,,,,,,,,,.,,,,,,,++++++++++++++,,,,,,,,,+,+,++++++++++++++++++++
#####################################++,+,,++++++++++++++++++++,,,.,,,,,,,,,,,,,,,+++,++++++++++,+,,,,++++++++++++++++++++++++++
#####################################++,+++++++++++++++++++++++.,.,++,.~,,,++,,,+++++,,+++++++++++,,,,,+++++++++++++++++++++++++
####################################++,++++,++++#++++++++,,,,++,,+,+++,,+++++,,,++,++,,,,++++++++,+,,,,,++++++++++++++++++++++++
####################################++,++++++++###+++#++++++,,,,+++++,,.+++++,.,,,,,,,,++++++++++,,,,,.++++++++++++++++++++++++,
####################################++.++++#######++###+++++++,,++++++,+,+++,,,,,,,,,,,,++,+++++++,,,++++++++++++++++++++++++++,
#####################################++++#########+#####++++,,+,,+++++++++++,,,,,,,,,,,,++,,++++++,,,+++++++++++++++++++++++++++
#####################################,+++##+######+#####++,++++,,+++++++++++,,~,,,,,,,,,++,,,++++,,,,++++++++++++++,,++++++++++,
#####################################,,+###############++++++++,,,+++++++++++.,,,,,,,,,,,,,,++++++,,,+++++++,++++++,+,+++++++,,,
##########################################################+++++~,+++++++++,,+,,++.,++,,,,,,,,,,+++,.,,,+,,+++,,++++,,++++++++++,
##########################################################++++.,,,+++++++++,~,+++++++,,,.,,,,.,,,,,,,,,,.,,,,,,+,+++,,,+++++++,,
##########################################################++++,,+++++++++++,,,,+++++++,,,,,.,.,,,,,,,,,,,,,..,,+,,+,,++++++++++,
#########################################################++++++++++++++++++++,,+++++,,,++++,,,,,,,,,,,+.,.,,,,,,,,,,,,+++,++++++
#########################################################+##+++++++++++++++++,,,+++++,,,+++..++,++,.,++++,,,,,,,,,,,.,+++,,.++,,
#############################################################+,++++++++++++++,++++++++,,++++++++++.,,+++++,++.,,,,,,,,++++,++,,,
############################################################++++++++++++++++++++++++++.+++++++++++,,,,+++++++,,,,,,,,,,,,,.,,,,.
############################################################+++++++++++++++++++++++++++++++++++++,,,,.++++++,,,++++,,,,,,.,,,,,.
#################################################################+++++++++++++++++++++++++++++++,,,,,++++++++,,+++,,,.,,,,,,,,,,
#################################################################++++++++++++++++++++++++++++++++,,.,+++++++++,,+++,,.,.,,,,,,,,
#################################################################+++++++++++++++++++++++++++++,+,,,,,,,++++++++++++,,,,,,,,,,~,,
################################################################+++++++++++++++++++++++++++++,,,,,,.,,++++++++++++++,.,,,,+++.,.
###############################################################+++++++++++++++++++++++++++++,,,.,.,,+,++++++++++++++,,++,,++++,,
##############################################################+++++++++++++++++++++++++++++++++,.,,,+++++++++++++,.,,,++++++++,.
############################################################+++++++++++++++++++++++++++++,+++++,,,,,+++++++++++++++,,,,+++++++,.
####################################################################+++++++++++++++++++,+,+++,+,,,,++++++++++++++++,+,+++++++++,
#####################################################################+++++++++++++++++++,,,+,,,,,,,,+,,+++++++++++++,,++++++,,,,
#####################################################################+++++++++++++++++,,,,,,,,,.,,~,,,++++++++++++++,++++++,,,,,
#####################################################################++++++++++++++++++,,+,,.,.,,.,+.,+++++++++++++++,++++++.,.,
