diff --git a/PerlRPG/Drawing.pm b/PerlRPG/Drawing.pm index 8ed5d4f..2d19cbd 100644 --- a/PerlRPG/Drawing.pm +++ b/PerlRPG/Drawing.pm @@ -25,9 +25,20 @@ sub DrawSpeech { my $speech_border = 3; my $sprite = GetAsset($sayer->{'Sprite'}); - my $sprite_x = $app->width() - $sprite->clip()->w(); - my $sprite_y = $app->height() - $sprite->clip()->h(); + my $sprite_x = 0; + my $speech_x = 0; + + my $sprite_w = $sprite->clip()->w(); my $sprite_h = $sprite->clip()->h(); + + my $sprite_y = $app->height() - $sprite_h; + my $speech_y = $sprite_y; + + if($sayer->{'DrawLeft'}) { + $speech_x = $sprite_w; + } else { + $sprite_x = $app->width() - $sprite_w; + } $sprite = undef; # ShowSprite may unload this, we don't want to keep a handle to it ShowSprite('_SayerSprite', $sayer->{'Sprite'}, $sprite_x, $sprite_y, 254, @{ $sayer->{'SpriteOpts'} }); @@ -35,7 +46,7 @@ sub DrawSpeech { $text_obj->color( $sayer->{'TextColor'} ); $text_obj->text( $text ); - my $surface = SDLx::Surface->new( width => $sprite_x, + my $surface = SDLx::Surface->new( width => $app->width() - $sprite_w, height => $sprite_h, color => [0, 0, 0, 255], ); @@ -50,12 +61,11 @@ sub DrawSpeech { my $text_y = ($surface->height() - $text_obj->h())/2; $text_obj->write_xy( $surface, $text_x, $text_y ); - $sprite = SDLx::Sprite->new( surface => $surface ); $VisibleSprites{'_SayerText'} = { 'Depth' => 255, - 'X' => 0, - 'Y' => $app->height() - $surface->height(), - 'Sprite' => $sprite, + 'X' => $speech_x, + 'Y' => $speech_y, + 'Sprite' => SDLx::Sprite->new( surface => $surface ), }; return 1; @@ -83,15 +93,25 @@ sub ShowSprite { foreach my $o (@opt) { my($name, $val)=$o=~/^\s*(\S+?)=(\S*)/; $name = $o unless($name); - if($o eq 'Reverse' || $o eq 'Circular') { - $a->type($o); + $name = lc($name); + if($name eq 'reverse') { + $a->type('Reverse'); + } elsif($name eq 'circular') { + $a->type('Circular'); } elsif($name eq 'max_loops') { $a->max_loops($val); - } elsif($o eq 'flip') { + } elsif($name eq 'flip') { # Don't want to flip back and forth every time UnloadAsset($file); my $s=$a->surface(); $a->surface( FlipSurface($s) ); + } elsif($name eq 'ticks') { + $val = 1 unless($val); + if($val != 1) { + # Keep a personal copy to support sprites at different speeds from the same asset + UnloadAsset($file); + } + $a->ticks_per_frame($val); } else { LogData(WARN, "Unknown option in ShowSprite '$o' - '$name'='$val'"); } diff --git a/PerlRPG/Script.pm b/PerlRPG/Script.pm index 23ecb0f..1b86140 100644 --- a/PerlRPG/Script.pm +++ b/PerlRPG/Script.pm @@ -186,12 +186,25 @@ sub AddSayer { my @textcolor=($r, $g, $b, $a); $textcolor[3] = 255 unless(defined $a); + my $drawleft = 0; + my @sprite_opts; + + foreach my $opt (@opts) { + if(lc($opt) eq 'left') { + $drawleft = 1; + } else { + push @sprite_opts, $opt; + } + } + + $sayers{$name} = { 'Name' => $name, 'DisplayName' => StringSubst($displayname), 'Sprite' => $sprite, 'TextColor' => \@textcolor, - 'SpriteOpts' => \@opts, + 'DrawLeft' => $drawleft, + 'SpriteOpts' => \@sprite_opts, }; } diff --git a/Resources/script.gs b/Resources/script.gs index f663713..40f6e0d 100644 --- a/Resources/script.gs +++ b/Resources/script.gs @@ -2,6 +2,7 @@ __init__: SetBackground 128 128 128 255 SetAssetOption spritesheet.png Animated AddSayer h "Hermione" aka01.png 200 200 200 255 + AddSayer h2 "Hermione2" aka05.png 200 200 200 255 left flip TargetFPS = 20 ResourceDir = "Resources" @@ -14,15 +15,20 @@ drawroom: Show fireplace fireplace.png 600 150 11 Show candler candle.png 400 100 11 flip Show candlel candle.png 240 100 11 - Show desk 11_genie_00.png 230 220 13 Show fireplacea fireplace_fire.vs 575 147 12 Show candlera fire.vs 400 95 12 flip Show candlela fire.vs 240 95 12 + + Show desk 11_genie_00.png 230 220 13 + Show hermione spritesheet.png 450 310 14 reverse ticks=3 + convo: Wait h "Continue..." + Wait + h2 "Continue2..." - #RecompileScripts drawroom + RecompileScripts drawroom Jump convo